:root {
  --bg: #f4f6f6;
  --surface: #ffffff;
  --text: #182325;
  --muted: #5d6b6e;
  --brand: #0e5e66;
  --brand-ink: #ffffff;
  --user: #0e5e66;
  --user-ink: #ffffff;
  --border: #dde3e4;
  --notice-bg: #fff7e6;
  --notice-border: #d99a16;
  --emergency-bg: #fdecec;
  --emergency-border: #c62828;
  --error: #b3261e;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10191b;
    --surface: #182427;
    --text: #e6eeef;
    --muted: #9aaaad;
    --brand: #5cc3cc;
    --brand-ink: #062a2e;
    --user: #1f6f77;
    --user-ink: #ffffff;
    --border: #2a393c;
    --notice-bg: #2e2614;
    --notice-border: #d99a16;
    --emergency-bg: #3a1a1a;
    --emergency-border: #ef5350;
    --error: #ff8a80;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
button { font: inherit; cursor: pointer; }

/* Login */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px max(16px, env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 22px;
  text-align: center;
}
.login-icon { border-radius: 14px; }
.login-card h1 { font-size: 1.3rem; margin: 12px 0 4px; }
.login-card p { margin: 0 0 18px; }
.login-card input {
  width: 100%;
  font-size: 16px; /* prevents iOS zoom */
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
.login-card button {
  width: 100%;
  margin-top: 12px;
  padding: 13px;
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 600;
}
.login-card button:disabled { opacity: .6; }
.error { color: var(--error); min-height: 1.5em; margin: 12px 0 0 !important; font-size: .95rem; }

/* Chat layout */
.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 820px;
  margin: 0 auto;
}
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.bar h1 { font-size: 1.05rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ghost {
  flex: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: .9rem;
}
.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.empty { margin: auto 0; text-align: center; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: .92rem;
}

.msg { max-width: 92%; overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end;
  background: var(--user);
  color: var(--user-ink);
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  white-space: pre-wrap;
}
.msg.bot {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: 16px 16px 16px 4px;
  width: 92%;
}
.msg.bot .body p { margin: 0 0 .6em; }
.msg.bot .body p:last-child { margin-bottom: 0; }
.msg.bot .body ol, .msg.bot .body ul { margin: .2em 0 .6em; padding-left: 1.3em; }
.msg.bot .body li { margin: .15em 0; }
.sources {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: .85rem;
  color: var(--muted);
}
.sources strong { color: var(--text); font-weight: 600; }
.notice {
  margin-top: 10px;
  padding: 10px 12px;
  border-left: 4px solid var(--notice-border);
  background: var(--notice-bg);
  border-radius: 6px;
  font-size: .85rem;
  line-height: 1.45;
}
.notice.emergency { border-left-color: var(--emergency-border); background: var(--emergency-bg); font-weight: 600; }
.typing span {
  display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%;
  background: var(--muted); animation: blink 1.2s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

/* Composer */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  resize: none;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom */
  line-height: 1.4;
  max-height: 140px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--bg);
  color: var(--text);
}
.composer button {
  flex: none;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  display: grid;
  place-items: center;
}
.composer button:disabled { opacity: .45; }
.foot {
  padding: 4px 16px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface);
  color: var(--muted);
  font-size: .75rem;
  text-align: center;
}
