:root {
  --bg: #f2f6f8;
  --surface: #ffffff;
  --ink: #0f2430;
  --muted: #5b7384;
  --line: #dbe6ec;
  --brand: #0e7490;
  --brand-ink: #ffffff;
  --user-bubble: #0e7490;
  --user-ink: #ffffff;
  --bot-bubble: #eef4f7;
  --error: #b4232a;
  --shadow: 0 1px 3px rgba(16, 42, 56, .08), 0 8px 24px rgba(16, 42, 56, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b171e;
    --surface: #10222c;
    --ink: #e8f1f5;
    --muted: #8fa9b6;
    --line: #1e3742;
    --brand: #22a7c7;
    --user-bubble: #157e99;
    --bot-bubble: #172c37;
    --error: #ff8a8a;
    --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.view { height: 100dvh; }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
.login-view { display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 18px; padding: 32px 28px;
  box-shadow: var(--shadow); text-align: center;
}
.logo { font-size: 44px; line-height: 1; }
.login-card h1 { margin: 8px 0 2px; font-size: 28px; letter-spacing: -.02em; }
.tagline { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
form { display: grid; gap: 14px; text-align: left; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input, textarea {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
button {
  font: inherit; font-weight: 600; cursor: pointer; border: none; border-radius: 10px;
  background: var(--brand); color: var(--brand-ink); padding: 12px 16px;
}
button:disabled { opacity: .6; cursor: progress; }
.fineprint { margin: 18px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.error { color: var(--error); font-size: 13px; margin: 4px 0 0; }

/* ---------- Chat ---------- */
.chat-view { display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; }
.ghost { background: transparent; color: var(--muted); padding: 6px 10px; font-size: 13px; }
.ghost:hover { color: var(--ink); }

.messages { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 12px; }
.messages { max-width: 760px; width: 100%; margin: 0 auto; }
.welcome { color: var(--muted); font-size: 15px; line-height: 1.55; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  background: var(--bot-bubble); color: var(--ink); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 500;
}
.chip:hover { border-color: var(--brand); }

.msg { max-width: 84%; padding: 11px 14px; border-radius: 16px; line-height: 1.5; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user-bubble); color: var(--user-ink); border-bottom-right-radius: 5px; white-space: pre-wrap; }
.msg.bot { align-self: flex-start; background: var(--bot-bubble); color: var(--ink); border-bottom-left-radius: 5px; }

/* Markdown inside assistant bubbles */
.msg.bot strong { font-weight: 700; }
.msg.bot > :first-child { margin-top: 0; }
.msg.bot > :last-child { margin-bottom: 0; }
.msg.bot p { margin: .5em 0; }
.msg.bot h1, .msg.bot h2, .msg.bot h3, .msg.bot h4 { margin: .7em 0 .3em; line-height: 1.25; }
.msg.bot h1 { font-size: 1.25em; }
.msg.bot h2 { font-size: 1.15em; }
.msg.bot h3 { font-size: 1.05em; }
.msg.bot h4 { font-size: 1em; }
.msg.bot ul, .msg.bot ol { margin: .4em 0; padding-left: 1.4em; }
.msg.bot li { margin: .2em 0; }
.msg.bot li > p { margin: .2em 0; }
.msg.bot hr { border: none; border-top: 1px solid var(--line); margin: .8em 0; }
.msg.bot a { color: var(--brand); text-decoration: underline; }
.msg.bot code { background: rgba(127,127,127,.16); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
.msg.bot pre { background: rgba(127,127,127,.12); padding: .6em .8em; border-radius: 8px; overflow-x: auto; }
.msg.bot pre code { background: none; padding: 0; }
.msg.bot blockquote { margin: .5em 0; padding-left: .8em; border-left: 3px solid var(--line); color: var(--muted); }
.msg.bot table { border-collapse: collapse; margin: .5em 0; }
.msg.bot th, .msg.bot td { border: 1px solid var(--line); padding: .3em .5em; text-align: left; }
.status {
  align-self: flex-start; color: var(--muted); font-size: 13px; font-style: italic;
  display: flex; align-items: center; gap: 8px;
}
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

.composer {
  display: flex; gap: 8px; align-items: end; padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
  max-width: 760px; width: 100%; margin: 0 auto;
}
.composer textarea { flex: 1; resize: none; max-height: 160px; }
#send-btn { border-radius: 50%; width: 44px; height: 44px; padding: 0; font-size: 18px; flex-shrink: 0; }
