:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #e3e3e0;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --me: #4f46e5;
  --me-text: #ffffff;
  --them: #ffffff;
  --chip: #ffffff;
  --danger: #c0392b;
  --ok: #1f9d55;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --surface: #1e1e21;
    --text: #f2f2f4;
    --muted: #9a9aa2;
    --line: #2c2c31;
    --accent: #7c74ff;
    --me: #5b52f0;
    --them: #232327;
    --chip: #1e1e21;
    --danger: #ff6b5b;
    --ok: #4cd38a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* login */
.login { min-height: 100%; display: grid; place-content: center; gap: 12px; padding: 24px; text-align: center; }
.login-icon { width: 72px; height: 72px; margin: 0 auto; border-radius: 18px; }
.login h1 { margin: 0 0 8px; font-size: 24px; }
.login form { display: grid; gap: 10px; width: min(320px, 100vw - 48px); }
.login input { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.login button[type=submit] { padding: 12px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 14px; }

/* app shell */
.app { height: 100dvh; display: flex; flex-direction: column; }
.bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.title { display: flex; flex-direction: column; line-height: 1.15; }
.name { font-weight: 650; font-size: 17px; }
.status { font-size: 12px; color: var(--muted); }
.status.live { color: var(--ok); }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; }
.icon-btn svg { fill: currentColor; }
.icon-btn:active { background: var(--line); }

.banner {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  margin: 8px 12px 0; padding: 10px 12px; border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface)); font-size: 14px;
}
.banner button { border: 0; border-radius: 999px; padding: 6px 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; white-space: nowrap; }

.thread { flex: 1; overflow-y: auto; padding: 12px 12px 4px; -webkit-overflow-scrolling: touch; }
#messages { display: flex; flex-direction: column; gap: 6px; }
.older { display: block; margin: 0 auto 12px; border: 0; background: none; color: var(--accent); font-size: 14px; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }

.bubble {
  max-width: min(82%, 560px); padding: 9px 13px; border-radius: 18px;
  white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--shadow);
}
.bubble.user { align-self: flex-end; background: var(--me); color: var(--me-text); border-bottom-right-radius: 6px; }
.bubble.assistant { align-self: flex-start; background: var(--them); border-bottom-left-radius: 6px; border: 1px solid var(--line); }
.bubble.reminder { border-left: 4px solid #f59e0b; }
.bubble.email { border-left: 4px solid #0ea5e9; }
.bubble.brief { border-left: 4px solid #eab308; }
.bubble.draft { border-left: 4px solid var(--accent); }
.bubble a { color: inherit; }
.meta { display: block; font-size: 11px; opacity: .6; margin-top: 3px; text-align: right; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.actions button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px;
  padding: 6px 12px; font-size: 14px;
}
.actions button:active { background: var(--line); }
.actions button:disabled { opacity: .5; }
.pending { opacity: .6; }

.typing { display: flex; gap: 4px; padding: 13px 14px; width: fit-content; margin-top: 6px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 6px 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--chip); border-radius: 999px; padding: 6px 12px; font-size: 14px; }

.composer {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 8px);
  border-top: 1px solid var(--line); background: var(--bg);
}
.composer textarea {
  flex: 1; resize: none; max-height: 160px; padding: 9px 14px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--surface); outline: none; line-height: 1.35;
}
.composer textarea:focus { border-color: var(--accent); }
.send { width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%; background: var(--accent); display: grid; place-items: center; }
.send svg { fill: var(--accent-text); }
.send:disabled { opacity: .4; }
#mic.listening { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

/* menu sheet */
.sheet {
  border: 0; border-radius: 18px; padding: 16px; width: min(420px, 100vw - 24px);
  background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, .35); }
.sheet h2 { margin: 0 0 8px; font-size: 18px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row.muted span:last-child { color: var(--muted); }
.sheet button, .sheet .btn {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 7px 12px;
  text-decoration: none; color: var(--text); font-size: 14px; white-space: nowrap;
}
.sheet .danger { color: var(--danger); }
.hint { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
