/* ===== CSS Custom Properties — Light/Dark ===== */
:root {
  --bg: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-sidebar: #f9fafb;
  --surface: #f3f4f6;
  --surface-hover: #e5e7eb;
  --border: #e5e7eb;
  --text: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --user-bubble: #2563eb;
  --user-text: #ffffff;
  --bot-bubble: #f3f4f6;
  --bot-text: #111827;
  --input-bg: #ffffff;
  --input-border: #d1d5db;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

html.dark {
  --bg: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-sidebar: #16213e;
  --surface: #1e293b;
  --surface-hover: #334155;
  --border: #334155;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --user-bubble: #3b82f6;
  --user-text: #ffffff;
  --bot-bubble: #1e293b;
  --bot-text: #e2e8f0;
  --input-bg: #1e293b;
  --input-border: #475569;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ===== Base ===== */
body {
  font-family: 'Manrope', sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  overflow: hidden;
}

a { cursor: pointer; }

/* ===== Sidebar ===== */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  transition: width 0.2s ease, transform 0.2s ease;
  width: 260px;
  flex-shrink: 0;
}

.sidebar.collapsed {
  width: 0;
  overflow: hidden;
  border-right: none;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 35;
  }
  .sidebar.open ~ .sidebar-overlay {
    display: block;
  }
}

/* ===== Conversation list ===== */
.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s;
  font-size: 14px;
}
.conv-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.conv-item.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
}
.conv-item .delete-btn {
  opacity: 0;
  transition: opacity 0.15s;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 2px;
  line-height: 1;
}
.conv-item:hover .delete-btn {
  opacity: 1;
}

/* ===== Header ===== */
.main-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

/* ===== Messages ===== */
.messages-area {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
}

.message-user .bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-radius: 18px 18px 4px 18px;
  padding: 10px 16px;
  max-width: 75%;
  word-wrap: break-word;
}

.message-assistant .bubble {
  background: var(--bot-bubble);
  color: var(--bot-text);
  border-radius: 18px 18px 18px 4px;
  padding: 10px 16px;
  max-width: 75%;
  word-wrap: break-word;
}

/* ===== Prose (markdown) ===== */
.bubble.prose a { color: var(--accent); text-decoration: underline; }
.bubble.prose ul { list-style-type: disc; padding-left: 20px; margin: 8px 0; }
.bubble.prose ol { list-style-type: decimal; padding-left: 20px; margin: 8px 0; }
.bubble.prose li { margin-bottom: 4px; }
.bubble.prose p { margin: 4px 0; }
.bubble.prose code {
  background: rgba(0,0,0,0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}
html.dark .bubble.prose code { background: rgba(255,255,255,0.1); }
.bubble.prose pre {
  background: rgba(0,0,0,0.06);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
html.dark .bubble.prose pre { background: rgba(255,255,255,0.06); }
.bubble.prose strong { font-weight: 700; }

/* ===== Input area ===== */
.input-area {
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.chat-input {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text);
  border-radius: 24px;
  padding: 12px 48px 12px 20px;
  font-size: 15px;
  font-family: 'Manrope', sans-serif;
  resize: none;
  width: 100%;
  outline: none;
  max-height: 200px;
  line-height: 1.5;
}
.chat-input::placeholder { color: var(--text-muted); }
.chat-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }

.send-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Scrollbar ===== */
.messages-area::-webkit-scrollbar { width: 6px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== Typing indicator ===== */
.typing-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ===== Theme toggle icon ===== */
.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s;
}
.theme-toggle:hover { background: var(--surface-hover); }
