:root {
  --bg: #f6f5fb;
  --surface: #ffffff;
  --sunken: #efedf7;
  --text: #1c1830;
  --muted: #6b6785;
  --line: #e6e3f1;
  --accent: #6d28d9;
  --accent-ink: #ffffff;
  --mine: #6d28d9;
  --mine-ink: #ffffff;
  --bad: #b91c1c;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0d1a;
    --surface: #181527;
    --sunken: #13101f;
    --text: #ece9f7;
    --muted: #9b96b5;
    --line: #2a2540;
    --accent: #a78bfa;
    --accent-ink: #1e1238;
    --mine: #5b21b6;
    --mine-ink: #f5f3ff;
    --bad: #f87171;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 "Segoe UI", Tahoma, system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; padding: 0 14px; }
.error { color: var(--bad); min-height: 1.5em; margin: .25rem 0 0; font-size: .9rem; }
.screen { height: 100dvh; display: flex; }

/* ---------- login ---------- */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-card { width: min(360px, 100%); text-align: center; }
.logo { width: 84px; height: 84px; border-radius: 22px; }
.login-card h1 { margin: 12px 0 0; font-size: 2.1rem; letter-spacing: .5px; }
.login-card p { margin: 0 0 22px; }
#login-form { display: grid; gap: 10px; }
#login-form input {
  padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); text-align: center; outline: none;
}
#login-form input:focus { border-color: var(--accent); }
.primary {
  padding: 13px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.ghost { background: none; border: 0; color: var(--accent); padding: 6px 10px; border-radius: 10px; }
.ghost:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* ---------- drawer (conversations) ---------- */
#drawer {
  position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 20;
  width: min(300px, 84vw); background: var(--surface); border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  transform: translateX(100%); transition: transform .22s ease;
}
#drawer.open { transform: none; }
#scrim { position: fixed; inset: 0; z-index: 10; background: rgb(0 0 0 / .35); }
.drawer-head { padding: 14px 16px 6px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.2rem; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.new-chat {
  margin: 8px 12px; display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 11px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-weight: 600;
}
.new-chat svg { width: 20px; height: 20px; }
.new-chat:hover { border-color: var(--accent); color: var(--accent); }
.drawer-label { padding: 12px 16px 4px; font-size: .8rem; color: var(--muted); }
#conv-list { flex: 1; overflow-y: auto; padding: 0 8px; }
.conv { display: flex; align-items: center; border-radius: 10px; }
.conv:hover, .conv.active { background: var(--sunken); }
.conv-title {
  flex: 1; min-width: 0; text-align: start; background: none; border: 0; padding: 9px 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv.active .conv-title { font-weight: 600; }
.conv-del { background: none; border: 0; color: var(--muted); padding: 6px 10px; opacity: 0; }
.conv:hover .conv-del, .conv.active .conv-del { opacity: 1; }
@media (hover: none) { .conv-del { opacity: .6; } }
.drawer-foot { border-top: 1px solid var(--line); padding: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); display: grid; }
.drawer-item { background: none; border: 0; text-align: start; padding: 10px; border-radius: 10px; }
.drawer-item:hover { background: var(--sunken); }

@media (min-width: 900px) {
  #drawer { position: static; transform: none; }
  #scrim, #menu { display: none !important; }
}

/* ---------- main column ---------- */
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.title { flex: 1; text-align: center; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.icon-btn {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: none; color: var(--muted);
}
.icon-btn:hover { color: var(--text); }
.icon-btn svg { width: 24px; height: 24px; }

/* ---------- chat ---------- */
#messages {
  flex: 1; overflow-y: auto; padding: 18px 14px 8px;
  display: flex; flex-direction: column; gap: 10px;
  width: 100%; max-width: 780px; margin: 0 auto;
}
.msg { max-width: 86%; }
.msg .text { white-space: pre-wrap; word-wrap: break-word; }
.msg.user {
  align-self: flex-start; background: var(--mine); color: var(--mine-ink);
  padding: 9px 14px; border-radius: 18px; border-start-start-radius: 6px;
}
.msg.assistant { align-self: stretch; max-width: 100%; padding: 2px 4px; }
.msg img { display: block; max-width: min(320px, 100%); border-radius: 14px; margin-bottom: 6px; }
.msg-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.msg-tools button, .msg-tools a {
  border: 1px solid var(--line); background: none; border-radius: 999px;
  padding: 2px 10px; font-size: .82rem; color: var(--muted); text-decoration: none;
}
.msg-tools button:hover, .msg-tools a:hover { color: var(--accent); border-color: var(--accent); }
.msg.typing { color: var(--muted); padding: 6px; }
.msg.typing span { animation: blink 1.2s infinite; }
.msg.typing span:nth-child(2) { animation-delay: .2s; }
.msg.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2 } 40% { opacity: 1 } }

.welcome { margin: auto; text-align: center; padding: 12px 4px 24px; width: 100%; }
.welcome .logo { width: 64px; height: 64px; border-radius: 18px; }
.welcome h2 { font-size: 1.35rem; margin: 12px 0 18px; }
.suggestions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; max-width: 520px; margin: 0 auto; }
.suggestions button {
  display: grid; justify-items: start; gap: 2px; text-align: start;
  padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
  font-size: 1.2rem;
}
.suggestions button b { font-size: 1rem; }
.suggestions button span { font-size: .82rem; color: var(--muted); }
.suggestions button:hover { border-color: var(--accent); }

.composer-wrap {
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  width: 100%; max-width: 800px; margin: 0 auto;
}
#composer {
  display: flex; align-items: flex-end; gap: 4px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px;
}
#composer:focus-within { border-color: var(--accent); }
#text {
  flex: 1; min-width: 0; resize: none; border: 0; outline: none; background: none;
  padding: 9px 6px; max-height: 160px; line-height: 1.5;
}
.icon-btn.send { background: var(--accent); color: var(--accent-ink); }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; margin-bottom: 6px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent); font-size: .85rem; flex: none;
}
.chip button { border: 0; background: none; padding: 0 2px; }
.recording {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--bad); border-radius: 24px;
}
.recording .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); animation: blink 1s infinite; }

/* ---------- reminders ---------- */
.page { width: 100%; max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; flex: 1; min-height: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 4px; }
.page-head h2 { margin: 0; font-size: 1.25rem; }
.list { flex: 1; overflow-y: auto; padding: 8px 16px; display: grid; gap: 10px; align-content: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card .row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card .name { font-weight: 600; }
.card .meta { font-size: .88rem; color: var(--muted); margin-top: 4px; }
.card .del { color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }
.hint { padding: 4px 16px 16px; font-size: .85rem; margin: 0; }
