@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("fonts/atkinson-hyperlegible-latin-400-italic.woff2") format("woff2");
  font-weight: 400; font-style: italic; font-display: swap;
}

:root {
  --ink: #22313F;
  --muted: #526170;
  --mist: #EEF2F5;
  --paper: #FFFFFF;
  --line: #D5DDE4;
  --plum: #6B2D5C;
  --plum-deep: #4A1D40;
  --plum-tint: #F4ECF2;
  --plum-line: #D9BDD1;
  --sage: #2F6B4F;
  --sage-tint: #E3F0E8;
  --amber: #8A5A00;
  --amber-tint: #FFF4D6;
  --red: #B42318;
  --red-tint: #FDECEA;
  --teal: #1F5F7A;
  --teal-tint: #E4F0F5;
  --focus: #6B2D5C;
  --radius-card: 18px;
  --radius-ctl: 12px;
  --aside: 380px;
  --topbar-h: 69px;  /* updated from the real height by app.js, since the top bar can wrap */
  font-size: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; }
body {
  min-height: 100%;
  margin: 0;
  font-family: "Atkinson Hyperlegible", "Helvetica Neue", Helvetica, Arial, sans-serif;
  line-height: 1.55;
  color: var(--ink);
  background: var(--mist);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 14px 28px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px 12px 12px 4px;
  background: var(--plum);
  box-shadow: inset 0 -10px 0 var(--plum-deep);
}
.brand-name { margin: 0; font-size: 1.3rem; line-height: 1.1; letter-spacing: 0.01em; }
.brand-sub { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }
.controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: flex-end; }

.status {
  border: 1px solid var(--line); background: var(--paper); border-radius: 999px;
  padding: 6px 14px 6px 30px; font-size: 0.8rem; color: var(--muted); cursor: pointer; position: relative;
  max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (max-width: 1240px) { .brand-sub { display: none; } }
.status::before { content: ""; position: absolute; left: 12px; top: 50%; width: 9px; height: 9px; margin-top: -4.5px; border-radius: 50%; background: var(--line); }
.status.is-ok::before { background: var(--sage); }
.status.is-bad { color: var(--amber); border-color: #E8C77A; background: var(--amber-tint); }
.status.is-bad::before { background: var(--amber); }

.icon-btn {
  display: inline-grid; place-items: center; width: 42px; height: 42px; padding: 0;
  border: 1px solid var(--plum-line); border-radius: 50%; background: var(--paper); color: var(--plum-deep);
  cursor: pointer;
}
.icon-btn:hover { background: var(--plum-tint); border-color: var(--plum); }

/* ---------------------------------------------------------------- layout */
/* The sources column is hidden until someone selects "Sources" or a citation number. */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr);
  min-height: calc(100vh - var(--topbar-h));
}
.layout.has-sources { grid-template-columns: minmax(0, 1fr) var(--aside); }
.chat { display: flex; flex-direction: column; padding: 22px clamp(16px, 4vw, 48px) 0; min-width: 0; }
.chat > * { width: 100%; max-width: 780px; margin-inline: auto; }

.notice {
  margin-top: 0; margin-bottom: 18px; padding: 12px 16px;
  font-size: 0.82rem; color: var(--muted);
  background: var(--paper); border: 1px solid var(--line); border-left: 5px solid var(--plum-line);
  border-radius: 10px;
}

/* ---------------------------------------------------------------- thread */
.thread { list-style: none; margin-block: 0; padding: 0; display: flex; flex-direction: column; gap: 18px; flex: 1; }
.msg { max-width: 100%; }
.msg p { margin: 0 0 0.7em; }
.msg p:last-child { margin-bottom: 0; }

.msg--user {
  align-self: flex-end; max-width: 78%;
  padding: 12px 18px; border-radius: 18px 18px 4px 18px;
  background: var(--plum-tint); color: var(--plum-deep);
  border: 1px solid var(--plum-line);
}
.msg--bot { align-self: stretch; }
.intro, .note-card {
  padding: 20px 24px; background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--radius-card);
}
.note-sub { margin-top: 0.6em !important; font-size: 0.9rem; color: var(--muted); }
.note-tags { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; padding: 0; }
.note-tags li {
  padding: 3px 12px; border-radius: 999px; font-size: 0.82rem;
  background: var(--plum-tint); color: var(--plum-deep); border: 1px solid var(--plum-line);
}
.intro-lead { font-size: 1.2rem; font-weight: 700; }
.intro-ask { font-weight: 700; margin-top: 1em !important; }
.audience { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; }

.btn {
  border: 1px solid transparent; border-radius: var(--radius-ctl); padding: 10px 18px;
  cursor: pointer; font-weight: 700; line-height: 1.2;
}
.btn--primary { background: var(--plum); color: var(--paper); }
.btn--primary:hover { background: var(--plum-deep); }
.btn--primary:disabled { background: #B8A3B2; cursor: not-allowed; }
.btn--choice { background: var(--paper); color: var(--plum-deep); border-color: var(--plum); padding: 12px 20px; }
.btn--choice:hover { background: var(--plum-tint); }
.btn--choice[aria-pressed="true"] { background: var(--plum); color: var(--paper); }
.btn--quiet { background: transparent; color: var(--plum-deep); border-color: var(--line); padding: 7px 12px; font-size: 0.85rem; }
.btn--quiet:hover { background: var(--plum-tint); border-color: var(--plum-line); }
.btn--quiet:disabled { color: var(--muted); cursor: default; background: transparent; }
a.btn { display: inline-block; text-decoration: none; }

/* ---------------------------------------------------------------- answer card */
.answer {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-card);
  padding: 22px 26px 16px;
}
.answer.is-selected { border-color: var(--plum-line); box-shadow: 0 0 0 3px var(--plum-tint); }
.answer-body { max-width: 68ch; }
.answer-body > p:first-child { font-size: 1.12rem; }
.answer-body ul, .answer-body ol { padding-left: 1.3em; margin: 0.4em 0 0.9em; }
.answer-body li { margin: 0.35em 0; }
.answer-body li::marker { color: var(--plum); }
.answer-body strong { color: var(--plum-deep); }
.answer-body h3, .answer-body h4 { font-size: 1rem; margin: 1em 0 0.3em; color: var(--plum-deep); }

.thinking { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.95rem; }
.thinking-dots { display: inline-flex; gap: 5px; }
.thinking-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--plum-line); animation: pulse 1.2s infinite ease-in-out; }
.thinking-dots i:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.35; transform: scale(0.85); } 40% { opacity: 1; transform: scale(1); } }

.cite {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.5em; height: 1.5em; padding: 0 0.35em; margin: 0 0.12em;
  font-size: 0.72rem; font-weight: 700; line-height: 1; vertical-align: 0.2em;
  color: var(--plum); background: var(--plum-tint); border: 1px solid var(--plum-line); border-radius: 6px;
  cursor: pointer;
}
.cite:hover, .cite.is-active { background: var(--plum); color: var(--paper); border-color: var(--plum); }
.cite--static { cursor: default; }

.figure { margin: 14px 0 16px; padding: 0; }
.figure button { display: block; width: 100%; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); cursor: zoom-in; overflow: hidden; }
.figure img { display: block; width: 100%; height: auto; }
.figure figcaption { margin-top: 6px; font-size: 0.8rem; color: var(--muted); }

.answer-meta {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line);
}
.answer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grade {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 4px 12px; border-radius: 999px; font-size: 0.8rem;
  background: var(--sage-tint); color: var(--sage);
}
.grade b { font-size: 1rem; }
.grade.is-mid { background: var(--amber-tint); color: var(--amber); }
.grade.is-high { background: var(--red-tint); color: var(--red); }
.answer-time { font-size: 0.75rem; color: var(--muted); }

.alert { margin: 0 0 14px; padding: 12px 16px; border-radius: 12px; font-size: 0.95rem; }
.alert--urgent { background: var(--red-tint); color: var(--red); border: 1px solid #F2B8B5; font-weight: 700; }
.alert--crisis { background: var(--plum-tint); color: var(--plum-deep); border: 1px solid var(--plum-line); font-weight: 700; }
.alert--error { background: var(--amber-tint); color: var(--amber); border: 1px solid #E8C77A; }

/* ---------------------------------------------------------------- sign-in page */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(420px, 100%); padding: 28px 28px 24px; background: var(--paper);
  border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 18px 50px rgba(34, 49, 63, 0.12);
}
.login-lead { margin: 16px 0 18px; color: var(--muted); font-size: 0.95rem; }
.login-label { display: block; margin-bottom: 6px; font-weight: 700; font-size: 0.95rem; }
.login-input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-ctl);
  background: var(--paper);
}
.login-input:focus { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--plum); }
.login-submit { width: 100%; margin-top: 16px; padding: 12px 18px; }

/* ---------------------------------------------------------------- "About you" dialog */
.modal {
  width: min(640px, 94vw); max-height: calc(100vh - 32px); padding: 0; overflow: auto;
  border: 0; border-radius: 20px; color: var(--ink); background: var(--paper);
  box-shadow: 0 24px 60px rgba(34, 49, 63, 0.28);
}
.modal::backdrop { background: rgba(34, 49, 63, 0.55); }
.modal form { padding: 18px 24px 0; }
.modal-note { margin: 6px 0 0; font-size: 0.82rem; font-weight: 700; color: var(--plum-deep); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-head h2 { margin: 0; font-size: 1.3rem; }
.modal-x {
  display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0;
  border: 1px solid var(--line); border-radius: 50%; background: var(--paper); color: var(--muted); cursor: pointer;
}
.modal-x:hover { color: var(--ink); border-color: var(--plum-line); }
.modal-lead { margin: 4px 0 14px; font-size: 0.88rem; color: var(--muted); }
.inline-icon { vertical-align: -3px; color: var(--plum-deep); }
.field { margin: 0 0 12px; padding: 0; border: 0; min-width: 0; }
.field legend { padding: 0; margin-bottom: 5px; font-weight: 700; font-size: 0.95rem; }
.field-hint { margin: -2px 0 6px; font-size: 0.8rem; color: var(--muted); }
.field-error { margin: 6px 0 0; font-size: 0.85rem; font-weight: 700; color: var(--red); }
.modal .chipset { margin: 0; }
.modal .chip { padding: 6px 14px; font-size: 0.88rem; background: var(--paper); }
.modal-actions {  /* pinned, so Save stays in view on short screens */
  position: sticky; bottom: 0; z-index: 1;
  display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap;
  margin-top: 14px; padding: 12px 0 16px; border-top: 1px solid var(--line); background: var(--paper);
}

/* ---------------------------------------------------------------- chips + composer */
.chipset { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
.chip {
  border: 1px solid var(--line); background: var(--mist); border-radius: 999px; padding: 6px 14px;
  font-size: 0.85rem; cursor: pointer;
}
.chip:hover { border-color: var(--plum-line); }
.chip[aria-pressed="true"] { background: var(--plum-tint); border-color: var(--plum); color: var(--plum-deep); font-weight: 700; }

.composer-wrap {
  position: sticky; bottom: 0; z-index: 3; padding: 12px 0 12px; margin-top: 18px;
  background: var(--mist);
  box-shadow: 0 -14px 14px -10px rgba(238, 242, 245, 0.95);
}
.suggest-toggle { margin: 0 0 8px; border: 0; background: none; padding: 2px 0; color: var(--plum-deep); font-size: 0.85rem; font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.suggestions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.suggestions .chip { background: var(--paper); text-align: left; }
.composer { display: flex; gap: 10px; align-items: flex-end; padding: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; }
.composer:focus-within { border-color: var(--plum); }
.composer textarea { flex: 1; resize: none; border: 0; padding: 8px 10px; max-height: 180px; background: transparent; line-height: 1.45; }
.composer textarea:focus { outline: none; }
.composer textarea:disabled { cursor: not-allowed; }
.hint { margin: 6px 4px 0; font-size: 0.75rem; color: var(--muted); }

/* ---------------------------------------------------------------- sources */
.sources {
  position: sticky; top: var(--topbar-h); align-self: start; height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  padding: 22px 22px 28px; background: var(--paper); border-left: 1px solid var(--line);
}
.sources-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sources h2 { margin: 0; font-size: 1.05rem; }
.sources-close { border: 1px solid var(--line); background: var(--paper); border-radius: 10px; padding: 6px 12px; cursor: pointer; font-size: 0.85rem; }
.sources-close:hover { border-color: var(--plum-line); background: var(--plum-tint); }
.sources-empty, .sources-q { font-size: 0.85rem; color: var(--muted); }
.sources-q { margin: 0 0 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.sources-q b { color: var(--ink); }
.source-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.src { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 10px; padding: 12px; border-radius: 12px; border: 1px solid var(--line); scroll-margin-top: 12px; }
.src.is-active { border-color: var(--plum); background: var(--plum-tint); }
.src-n { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: var(--plum-tint); color: var(--plum); font-weight: 700; font-size: 0.85rem; }
.src.is-active .src-n { background: var(--plum); color: var(--paper); }
.src-label { margin: 0; font-size: 0.78rem; font-weight: 700; color: var(--plum-deep); }
.src-title { margin: 2px 0 6px; font-size: 0.88rem; font-weight: 700; }
.src-excerpt { margin: 0; font-size: 0.82rem; color: var(--muted); }
.src--expert .src-label { color: var(--sage); }
.src--review .src-label { color: var(--amber); }
.src--research .src-label { color: var(--teal); }
.src--research .src-n { background: var(--teal-tint); color: var(--teal); }
.src-cite { margin: 0 0 4px; font-size: 0.76rem; color: var(--muted); font-style: italic; }
.src-facts { margin: 0 0 6px; font-size: 0.76rem; font-weight: 700; color: var(--teal); }
.src-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.src-note { margin: 6px 0 0; font-size: 0.74rem; color: var(--muted); }
.src-page { margin-top: 8px; }
.src-uncited { opacity: 0.9; border-style: dashed; }  /* not cited in the answer; stays above AA contrast */
.sources-foot { margin-top: 20px; font-size: 0.72rem; color: var(--muted); }

.viewer { border: 0; border-radius: 16px; padding: 18px; max-width: min(960px, 94vw); max-height: 92vh; }
.viewer::backdrop { background: rgba(34, 49, 63, 0.6); }
.viewer img { display: block; max-width: 100%; max-height: 78vh; margin: 0 auto; }
.viewer p { margin: 10px 0 0; font-size: 0.85rem; color: var(--muted); }
.viewer-close { float: right; margin: 0 0 8px 8px; border: 1px solid var(--line); background: var(--paper); border-radius: 10px; padding: 6px 12px; cursor: pointer; }

/* ---------------------------------------------------------------- small screens */
@media (max-width: 1020px) {
  :root { font-size: 17px; }
  .layout { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .brand-sub { display: none; }
  .layout.has-sources { grid-template-columns: 1fr; }
  .sources {
    position: fixed; inset: auto 0 0 0; top: auto; height: 72vh; z-index: 20;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
    box-shadow: 0 -12px 40px rgba(34, 49, 63, 0.18);
    animation: sheet-in 0.25s ease;
  }
  .msg--user { max-width: 90%; }
  .modal form { padding: 18px 18px 0; }
}
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) {
  .thinking-dots i { animation: none; opacity: 0.7; }
  .sources { animation: none; }
}
