:root {
  /* Astrid blue #3D93D1; buttons use a slightly deeper shade so white text stays readable */
  --bg: #f5f8fb;
  --panel: #ffffff;
  --text: #0d2438;
  --muted: #5b6b7a;
  --line: #dfe6ee;
  --accent: #2f80bd;
  --accent-ink: #ffffff;
  --accent-soft: #e4f0fa;
  --mine: #3d93d1;
  --mine-ink: #ffffff;
  --card: #ffffff;
  --card-line: #c9def0;
  --err: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1824;
    --panel: #10202f;
    --text: #e6eef5;
    --muted: #93a4b4;
    --line: #22364a;
    --accent: #5aaee6;
    --accent-ink: #0d2438;
    --accent-soft: #16304a;
    --mine: #23608f;
    --mine-ink: #f1f7fc;
    --card: #132739;
    --card-line: #2a4a66;
    --err: #ff8a7a;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "cv11", "ss01";
  -webkit-tap-highlight-color: transparent;
}
button, textarea, input { font: inherit; color: inherit; }
#app { max-width: 760px; margin: 0 auto; height: 100dvh; display: flex; flex-direction: column; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; padding-top: max(12px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: -0.01em; }
.brand img { width: 30px; height: 30px; }
.top-actions { display: flex; gap: 4px; }
.offline-tag {
  font-style: normal; font-size: 12px; font-weight: 600; letter-spacing: .02em;
  color: var(--muted); background: var(--accent-soft); border-radius: 999px; padding: 3px 9px;
}
.pending-note { align-self: flex-end; margin-top: -8px; font-size: 13px; color: var(--muted); text-align: right; max-width: 88%; }
.ghost { background: none; border: 0; color: var(--muted); padding: 8px 10px; border-radius: 10px; cursor: pointer; font-size: 15px; }
.ghost:hover { background: var(--accent-soft); color: var(--text); }
/* phones: four header buttons need the room, so show just the logo */
@media (max-width: 440px) {
  .brand span { display: none; }
  .ghost { padding: 8px 6px; white-space: nowrap; }
  .brand { gap: 6px; }
  .offline-tag { font-size: 11px; padding: 2px 7px; }
}

.gate { flex: 1; display: grid; place-items: center; padding: 24px 18px; }
.gate form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.gate-icon { width: 64px; height: 64px; margin: 0 auto 4px; }
.gate h1 { margin: 0; font-size: 26px; }
.gate p { margin: 0; color: var(--muted); }
.gate input {
  padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
}
.err { color: var(--err) !important; min-height: 1.5em; }

#chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.list { flex: 1; overflow-y: auto; padding: 8px 18px 16px; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; }
.empty { margin: auto 0; text-align: center; color: var(--muted); padding: 24px 8px; }
.empty h2 { color: var(--text); margin: 0 0 6px; font-size: 22px; }
.empty p { margin: 0 auto; max-width: 420px; }

.msg { max-width: 88%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--mine); color: var(--mine-ink); padding: 10px 14px; border-radius: 18px 18px 4px 18px; }
.msg.user .tag { display: block; font-size: 13px; opacity: .8; margin-bottom: 2px; font-weight: 600; }
.msg.user .clip { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.msg.bot { align-self: flex-start; max-width: 100%; width: 100%; }
.msg.bot p { margin: 0 0 8px; }
.msg.err { color: var(--err); }

.reply-card {
  background: var(--card); border: 1px solid var(--card-line); border-radius: 14px;
  padding: 14px 16px 10px; margin: 4px 0 10px;
}
.reply-card .label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.reply-card .body { white-space: pre-wrap; }
.reply-card .copy {
  margin-top: 10px; border: 0; border-radius: 10px; padding: 8px 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 15px;
}

.tabs {
  display: flex; gap: 4px; margin: 0 18px 6px; padding: 4px;
  background: var(--accent-soft); border-radius: 14px;
}
.tab {
  flex: 1; border: 0; background: none; color: var(--muted); font-weight: 600; font-size: 15px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer; touch-action: manipulation; user-select: none;
}
a.tab { text-align: center; text-decoration: none; }
.reply-card .copy.secondary { margin-left: 6px; background: var(--accent-soft); color: var(--text); }
.tab.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(13, 36, 56, .12); }

.quick { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.change { display: flex; gap: 8px; }
.change input {
  flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px;
  background: var(--panel); font-size: 15px;
}
.change input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.chip.go { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip {
  border: 1px solid var(--card-line); background: var(--accent-soft); color: var(--text);
  border-radius: 999px; padding: 7px 13px; font-size: 14px; font-weight: 550; cursor: pointer;
  touch-action: manipulation; user-select: none;
}
.chip:hover:not(:disabled) { border-color: var(--accent); }

.empty.troy h2 { font-size: 30px; letter-spacing: -0.01em; }
.empty.troy p { font-size: 19px; }

.dlg-wrap {
  position: fixed; inset: 0; z-index: 20; background: rgba(13, 36, 56, .4);
  display: grid; place-items: center; padding: 24px 18px;
}
.dlg {
  width: 100%; max-width: 360px; background: var(--panel); border-radius: 18px; padding: 20px;
  box-shadow: 0 12px 40px rgba(13, 36, 56, .25); display: flex; flex-direction: column; gap: 10px;
}
.dlg h2 { margin: 0; font-size: 19px; }
.dlg p { margin: 0; color: var(--muted); }
.dlg input {
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; background: var(--bg); font-size: 16px;
}
.dlg input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.dlg-row { display: flex; gap: 10px; margin-top: 6px; }
.dlg-row button { flex: 1; }
.primary.danger { background: #c4321f; color: #fff; }

.mem-note { font-size: 13px; color: var(--muted); margin: -4px 0 0; }

.sheet-wrap {
  position: fixed; inset: 0; z-index: 10; background: rgba(13, 36, 56, .35);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--panel); width: 100%; max-width: 760px; max-height: 85dvh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 16px 18px; padding-bottom: max(18px, env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet h2 { margin: 0; font-size: 20px; }
.sheet h3 { margin: 18px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.sheet-note { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.mem-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.mem-list li {
  display: flex; align-items: flex-start; gap: 8px; padding: 9px 12px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line); font-size: 15px;
}
.mem-list li span { flex: 1; overflow-wrap: anywhere; }
.mem-list li.none { color: var(--muted); background: none; border-style: dashed; }
.mem-del { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 0 2px; }
.mem-del:hover { color: var(--err); }
.mem-add { display: flex; gap: 8px; margin-top: 8px; }
.mem-add input {
  flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px;
  background: var(--panel); font-size: 15px;
}
.mem-add input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.link-danger { margin-top: 20px; border: 0; background: none; color: var(--err); cursor: pointer; font-size: 14px; padding: 4px 0; }

.typing { display: flex; gap: 5px; padding: 8px 2px; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .4; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: .9; } }
@media (prefers-reduced-motion: reduce) { .typing span { animation: none; opacity: .6; } }

.composer {
  border-top: 1px solid var(--line); background: var(--panel);
  padding: 12px 18px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
.composer textarea {
  width: 100%; resize: none; border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; background: var(--bg); max-height: 40dvh; font-size: 16px;
}
.composer textarea:focus, .gate input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row { display: flex; gap: 10px; }
.row button { flex: 1; }
.primary, .secondary {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 650; cursor: pointer;
  touch-action: manipulation; user-select: none;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.secondary { background: var(--accent-soft); color: var(--text); }
button:disabled { opacity: .5; cursor: default; }
button:active:not(:disabled) { transform: scale(.98); }
