/* US Census Chat. Plain and calm: one column, system fonts, light and dark. */

:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f0f1ee;
  --ink: #1c2220;
  --ink-2: #3b4441;
  --muted: #5b6561;
  --rule: #dfe2de;
  --rule-strong: #c5cac5;
  --accent: #2c5bc7;
  --accent-hover: #234aa6;
  --accent-ink: #ffffff;
  --focus: #2c5bc7;
  --user-bg: #e6ecf8;
  --code-bg: #f3f4f1;
  --refusal-bg: #eff3f9;
  --refusal-rule: #7d93bf;
  --refusal-ink: #34496f;
  --error-bg: #fbf4e8;
  --error-rule: #c4893a;
  --error-ink: #7a4d12;
  --scroll-shadow: rgba(0, 0, 0, 0.16);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121514;
    --surface: #1a1e1c;
    --surface-2: #222725;
    --ink: #e3e7e5;
    --ink-2: #c3cac7;
    --muted: #9ba49f;
    --rule: #2c3330;
    --rule-strong: #3d4542;
    --accent: #8db0ff;
    --accent-hover: #a9c3ff;
    --accent-ink: #0f1a33;
    --focus: #8db0ff;
    --user-bg: #22304b;
    --code-bg: #151817;
    --refusal-bg: #1a2130;
    --refusal-rule: #6f86b3;
    --refusal-ink: #b9c8e6;
    --error-bg: #29211a;
    --error-rule: #c9984f;
    --error-ink: #e9c792;
    --scroll-shadow: rgba(0, 0, 0, 0.6);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

/* Reserve the scrollbar's space, so the column does not shift when a long chat starts to scroll. */
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
}
h1, h2, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.muted { color: var(--muted); }

/* Page frame: the page scrolls; the header and the composer stick. */
.page {
  max-width: 760px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
}
.top {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 12px;
  padding: 14px 0 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}
.top h1 { grid-column: 1; font-size: 1.125rem; font-weight: 650; letter-spacing: -0.01em; }
.scope { grid-column: 1; font-size: 0.875rem; color: var(--muted); }
.top-actions { grid-column: 2; grid-row: 1 / span 2; align-self: center; display: flex; gap: 8px; }
@media (max-width: 520px) {
  /* On phones the buttons sit beside the title and the scope line takes the full width. */
  .top-actions { grid-row: 1; }
  .scope { grid-column: 1 / -1; }
}

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:not(:disabled):hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-quiet {
  background: transparent;
  border-color: var(--rule-strong);
  padding: 7px 12px;
  font-size: 0.875rem;
  font-weight: 500;
}
.btn-quiet:not(:disabled):hover { background: var(--surface-2); }

/* Sign in */
.login { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 10vh 0 32px; }
.login-card {
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: 12px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 12px;
}
.login-card h2 { font-size: 1.25rem; font-weight: 650; }
.login-card label { font-size: 0.875rem; font-weight: 600; margin-top: 4px; }
.login-card input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 1rem;
  background: var(--bg);
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
}
.form-error { color: var(--error-ink); font-size: 0.9rem; }

/* Chat */
.chat { flex: 1; padding: 20px 0 28px; }
.intro { display: grid; gap: 8px; margin-bottom: 8px; }
.intro h2 { font-size: 1.25rem; font-weight: 650; }
.examples-label { margin-top: 12px; font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.examples { display: grid; gap: 8px; }
.example {
  text-align: left;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  cursor: pointer;
  line-height: 1.4;
}
.example:hover { border-color: var(--accent); }

.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 22px; }
.msg-user {
  align-self: flex-end;
  max-width: 85%;
  padding: 10px 14px;
  background: var(--user-bg);
  border-radius: 14px 14px 4px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-assistant { display: grid; gap: 10px; min-width: 0; }
.answer { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }

.progress { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--muted); }
.progress-elapsed { font-variant-numeric: tabular-nums; }
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }

.meta { font-size: 0.8125rem; color: var(--muted); }

.notice {
  display: grid;
  gap: 4px;
  padding: 10px 14px;
  border-left: 3px solid;
  border-radius: 0 8px 8px 0;
}
.notice-label { font-size: 0.8125rem; font-weight: 650; }
.notice-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.notice .btn { justify-self: start; margin-top: 6px; }
.notice-refusal { background: var(--refusal-bg); border-color: var(--refusal-rule); }
.notice-refusal .notice-label { color: var(--refusal-ink); }
.notice-error { background: var(--error-bg); border-color: var(--error-rule); }
.notice-error .notice-label { color: var(--error-ink); }

/* How this was answered */
.sources { background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; min-width: 0; }
.sources summary { padding: 8px 12px; font-size: 0.875rem; color: var(--ink-2); cursor: pointer; }
.sources[open] summary { border-bottom: 1px solid var(--rule); }
.queries { display: grid; gap: 14px; padding: 12px; }
.query { display: grid; gap: 8px; min-width: 0; }
.query-label { font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.query pre {
  margin: 0;
  padding: 10px 12px;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  font: 0.8125rem/1.5 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.table-wrap {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--rule);
  border-radius: 6px;
  /* Scroll shadows: an edge darkens while there is more table to scroll to (the covers move
     with the content, the shadows stay put). */
  background:
    linear-gradient(to right, var(--surface) 30%, transparent) left / 32px 100% no-repeat local,
    linear-gradient(to left, var(--surface) 30%, transparent) right / 32px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, var(--scroll-shadow), transparent) left / 12px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, var(--scroll-shadow), transparent) right / 12px 100% no-repeat scroll,
    var(--surface);
}
table { border-collapse: collapse; width: 100%; font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--rule); }
tr:last-child td { border-bottom: 0; }
th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; }
th.num, td.num { text-align: right; }
.rows-note { font-size: 0.75rem; color: var(--muted); }

/* Composer */
.composer-bar {
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: 12px 0 calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  border-top: 1px solid var(--rule);
}
.composer { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  max-height: 200px;
  padding: 11px 12px;
  font-size: 1rem;
  line-height: 1.4;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  resize: none;
  overflow-y: hidden;
}
.composer textarea:disabled { opacity: 0.6; }
.composer .btn { min-height: 46px; }
.hint { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 0.75rem; color: var(--muted); }
#count { margin-left: auto; font-variant-numeric: tabular-nums; }

@media (pointer: coarse) {
  .hint > span:first-child { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .dot { animation: none; }
}
