:root {
  --bg: #212121;
  --sidebar: #171717;
  --surface: #2f2f2f;
  --hover: #2a2a2a;
  --border: #3a3a3a;
  --text: #ececec;
  --muted: #9b9b9b;
  --accent: #10a37f;
  --danger: #ef4444;
  --sidebar-w: 270px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Hind Siliguri", "Noto Sans Bengali", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }
input, textarea { font: inherit; color: inherit; }
a { color: #6cb6ff; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Logo ---------- */
.logo {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 20px; margin: 0 auto 12px;
}
.logo.big { width: 56px; height: 56px; font-size: 26px; }

/* ---------- Auth ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-card {
  width: 100%; max-width: 380px; text-align: center;
  display: flex; flex-direction: column; gap: 12px;
}
.auth-card h1 { font-size: 26px; font-weight: 600; }
.sub { color: var(--muted); margin-bottom: 8px; }
.auth-card input, .modal-card input {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  background: transparent; border: 1px solid var(--border);
}
.auth-card input:focus, .modal-card input:focus { outline: none; border-color: var(--accent); }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.btn {
  padding: 12px 16px; border-radius: 12px; font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-outline { border: 1px solid var(--border); }
.btn-outline:hover, .btn-ghost:hover { background: var(--hover); }
.btn-ghost { color: var(--muted); }
.error { color: var(--danger); font-size: 14px; min-height: 20px; }

/* ---------- Layout ---------- */
.app { display: flex; height: 100dvh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w); background: var(--sidebar);
  display: flex; flex-direction: column; flex-shrink: 0;
  padding: 10px; transition: transform .25s ease;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.side-btn {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; font-size: 15px;
}
.side-btn:hover { background: var(--hover); }
.side-label { color: var(--muted); font-size: 12px; padding: 14px 12px 6px; }

.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-item {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 8px 8px 12px; border-radius: 10px; cursor: pointer;
  font-size: 15px;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--surface); }
.chat-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-del {
  opacity: 0; width: 28px; height: 28px; border-radius: 6px;
  display: grid; place-items: center; color: var(--muted); flex-shrink: 0;
}
.chat-item:hover .chat-del, .chat-item.active .chat-del { opacity: 1; }
.chat-del:hover { color: var(--danger); background: #3a2a2a; }
.empty-list { color: var(--muted); font-size: 14px; padding: 8px 12px; }

.side-bottom { border-top: 1px solid var(--border); padding-top: 8px; display: flex; flex-direction: column; gap: 2px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 9px 12px; border-radius: 10px; font-size: 14px; color: var(--muted);
}
.menu-item:hover { background: var(--hover); color: var(--text); }
.user-row { display: flex; align-items: center; gap: 10px; padding: 8px 8px 4px 12px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: #5b5bd6;
  display: grid; place-items: center; font-size: 14px; font-weight: 600; flex-shrink: 0;
}
.user-email { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; min-height: 52px; }
.menu-toggle { display: none; }
.brand { font-size: 18px; font-weight: 600; color: var(--muted); padding: 0 6px; }

/* ---------- Messages ---------- */
.messages { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.welcome { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; text-align: center; }
.welcome h2 { font-size: 26px; font-weight: 600; margin-bottom: 24px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 640px; }
.chip { border: 1px solid var(--border); border-radius: 16px; padding: 10px 16px; font-size: 14px; color: var(--muted); }
.chip:hover { background: var(--hover); color: var(--text); }

.thread { max-width: 768px; margin: 0 auto; padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 22px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--surface); padding: 10px 18px; border-radius: 22px;
  max-width: 80%; white-space: pre-wrap; word-break: break-word;
}
.msg.ai { gap: 14px; align-items: flex-start; }
.msg.ai .ai-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent);
  display: grid; place-items: center; font-size: 14px; font-weight: 700; flex-shrink: 0; margin-top: 2px;
}
.msg.ai .bubble { flex: 1; min-width: 0; word-break: break-word; }
.msg.err .bubble { color: var(--danger); }

/* Markdown content */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md pre, .md blockquote, .md table { margin: 0 0 12px; }
.md ul, .md ol { padding-left: 24px; }
.md li { margin: 4px 0; }
.md h1, .md h2, .md h3 { margin: 18px 0 8px; line-height: 1.3; }
.md h1 { font-size: 1.4em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; }
.md code { background: #3a3a3a; padding: 2px 6px; border-radius: 6px; font-size: .9em; font-family: ui-monospace, Menlo, Consolas, monospace; }
.md pre { background: #0d0d0d; border-radius: 12px; overflow: hidden; }
.md pre code { display: block; background: none; padding: 14px 16px; overflow-x: auto; font-size: 13.5px; line-height: 1.55; }
.code-head { display: flex; justify-content: space-between; align-items: center; background: #2a2a2a; padding: 6px 14px; font-size: 12px; color: var(--muted); }
.copy-btn:hover { color: var(--text); }
.md blockquote { border-left: 3px solid var(--border); padding-left: 14px; color: var(--muted); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 12px; }
.md a { color: #6cb6ff; }

.typing::after { content: "●"; animation: blink 1s infinite; margin-left: 4px; font-size: 12px; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- Composer ---------- */
.composer-wrap { padding: 0 16px calc(10px + env(safe-area-inset-bottom, 0px)); }
.composer {
  max-width: 768px; margin: 0 auto; background: var(--surface);
  border-radius: 26px; display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px 8px 20px;
}
.composer textarea {
  flex: 1; background: none; border: none; outline: none; resize: none;
  max-height: 200px; padding: 8px 0; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--muted); }
.send-btn {
  width: 36px; height: 36px; border-radius: 50%; background: #fff; color: #000;
  display: grid; place-items: center; flex-shrink: 0;
}
.send-btn:disabled { background: #4a4a4a; color: #888; cursor: not-allowed; }
.disclaimer { text-align: center; color: var(--muted); font-size: 12px; margin-top: 8px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal-card { background: var(--sidebar); border: 1px solid var(--border); border-radius: 16px; padding: 22px; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; }
.hint { color: var(--muted); font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Mobile ---------- */
.overlay { display: none; }
@media (max-width: 768px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .overlay.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30; }
  .menu-toggle { display: grid; }
  .welcome h2 { font-size: 22px; }
  .chat-del { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
