* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  height: 100vh;
  overflow: hidden;
}

/* ─── App Layout ─────────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* ─── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: 240px;
  background: #111827;
  color: #f9fafb;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 18px 16px 12px;
  font-size: 1rem;
  font-weight: 700;
  border-bottom: 1px solid #1f2937;
  flex-shrink: 0;
}

.new-chat-btn {
  margin: 12px 10px;
  padding: 10px 14px;
  background: #4f46e5;
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.new-chat-btn:hover {
  background: #4338ca;
}

.sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.15s;
  gap: 6px;
}

.session-item:hover {
  background: #1f2937;
}
.session-item.active {
  background: #1f2937;
  border-left: 3px solid #4f46e5;
}

.session-title {
  font-size: 0.85rem;
  color: #d1d5db;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.session-item.active .session-title {
  color: #f9fafb;
}

.session-delete {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 5px;
  border-radius: 4px;
  opacity: 0;
  transition:
    opacity 0.15s,
    color 0.15s;
  flex-shrink: 0;
}

.session-item:hover .session-delete {
  opacity: 1;
}
.session-delete:hover {
  color: #ef4444;
}

.sessions-list::-webkit-scrollbar {
  width: 3px;
}
.sessions-list::-webkit-scrollbar-track {
  background: transparent;
}
.sessions-list::-webkit-scrollbar-thumb {
  background: #374151;
  border-radius: 2px;
}

/* ─── Chat Container ─────────────────────────────────────────── */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

/* ─── Header ─────────────────────────────────────────────────── */
.chat-header {
  padding: 14px 20px;
  background: #4f46e5;
  color: white;
  font-size: 0.95rem;
  font-weight: 600;
  flex-shrink: 0;
}

/* ─── Messages ───────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  display: flex;
  max-width: 78%;
}

.user-message {
  align-self: flex-end;
}
.bot-message {
  align-self: flex-start;
}

.message-content {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.user-message .message-content {
  background: #4f46e5;
  color: white;
  border-bottom-right-radius: 4px;
}

.bot-message .message-content {
  background: #f1f3f4;
  color: #1f2937;
  border-bottom-left-radius: 4px;
}

.error-content {
  background: #fee2e2 !important;
  color: #dc2626 !important;
}

/* ─── Typing indicator ───────────────────────────────────────── */
.typing-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #9ca3af;
  border-radius: 50%;
  margin: 0 2px;
  animation: blink 1.2s infinite;
}
.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.2;
  }
  40% {
    opacity: 1;
  }
}

/* ─── Generated image ────────────────────────────────────────── */
.generated-image {
  max-width: 280px;
  border-radius: 12px;
  display: block;
  margin-bottom: 6px;
}

.image-caption {
  font-size: 0.8rem;
  color: #6b7280;
  font-style: italic;
}

/* ─── Image preview strip ────────────────────────────────────── */
.image-preview-container {
  position: relative;
  padding: 8px 20px 0;
  display: inline-flex;
  flex-shrink: 0;
}

.image-preview-container img {
  height: 64px;
  border-radius: 8px;
  border: 2px solid #e5e7eb;
  object-fit: cover;
}

.remove-image-btn {
  position: absolute;
  top: 4px;
  right: 16px;
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ─── Input area ─────────────────────────────────────────────── */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
}

.input-controls {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #6b7280;
  cursor: pointer;
  user-select: none;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 22px;
  transition: 0.3s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}

input:checked + .toggle-slider {
  background: #4f46e5;
}
input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

.input-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.upload-btn {
  width: 40px;
  height: 40px;
  background: #f3f4f6;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: background 0.2s;
}
.upload-btn:hover {
  background: #e5e7eb;
}

#userInput {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
#userInput:focus {
  border-color: #4f46e5;
}

#sendBtn {
  padding: 10px 20px;
  background: #4f46e5;
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.2s;
  flex-shrink: 0;
}
#sendBtn:hover {
  background: #4338ca;
}
#sendBtn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
#userInput:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ─── Scrollbar ───────────────────────────────────────────────── */
.chat-messages::-webkit-scrollbar {
  width: 4px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 2px;
}
