/* Mobile-first. Base rules target a phone; media queries add the sidebar and
   multi-column grids for wider screens.

   Colors are the validated palette from charts.py as custom properties, so
   light/dark swap in one place and the rest of the file is written against
   roles rather than raw hex. Keeping accents SMALL is deliberate: saturated
   fills belong on small marks, never large blocks. */

:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #141416;
  --surface-2: #1c1c20;
  --page: #08080a;
  --ink: #ffffff;
  --ink2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --border: rgba(255, 255, 255, 0.055);
  --border-strong: rgba(255, 255, 255, 0.13);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --up: #0ca30c; --down: #e66767;
  --glow: rgba(57, 135, 229, 0.16);
}

:root[data-theme="light"] {
  color-scheme: light;
  --surface: #ffffff;
  --surface-2: #f4f3f0;
  --page: #f4f4f2;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.16);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --up: #006300; --down: #d03b3b;
  --glow: rgba(42, 120, 214, 0.10);
}

/* ---- switchable accents -------------------------------------------------
   Each pair was run through the contrast/CVD validator in BOTH modes.
   --s1 is the primary series colour and the UI accent; --glow is its soft
   derivative, used only on chrome (cards, focus rings, the hero halo) and
   never as a data encoding. */
:root[data-accent="violet"] { --s1: #8b5cf6; --glow: rgba(139, 92, 246, 0.16); }
:root[data-accent="teal"]   { --s1: #0e9f8f; --glow: rgba(14, 159, 143, 0.16); }
:root[data-accent="orange"] { --s1: #d95926; --glow: rgba(217, 89, 38, 0.16); }
:root[data-accent="blue"]   { --s1: #3987e5; --glow: rgba(57, 135, 229, 0.16); }

:root[data-theme="light"][data-accent="violet"] { --s1: #6d3fd4; --glow: rgba(109, 63, 212, 0.10); }
:root[data-theme="light"][data-accent="teal"]   { --s1: #0e9f8f; --glow: rgba(14, 159, 143, 0.10); }
:root[data-theme="light"][data-accent="orange"] { --s1: #eb6834; --glow: rgba(235, 104, 52, 0.10); }
:root[data-theme="light"][data-accent="blue"]   { --s1: #2a78d6; --glow: rgba(42, 120, 214, 0.10); }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }

/* ======================================================= shell & sidebar */
.shell { display: block; }

.sidebar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--page) 90%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.logo { display: flex; align-items: center; gap: 9px; flex: none; }
.mark {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: linear-gradient(140deg, var(--s1), var(--s3));
  box-shadow: 0 0 0 1px var(--border), 0 4px 14px var(--glow);
}
.logo-text { display: flex; flex-direction: column; line-height: 1.15; }
.logo-text strong { font-size: 14px; font-weight: 650; letter-spacing: -0.01em; }
.logo-text small { font-size: 10.5px; color: var(--muted); }

.nav-group { display: none; }
.side-nav { display: none; }
.side-nav a {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 11px; border-radius: 9px;
  font-size: 13.5px; color: var(--ink2); text-decoration: none;
  white-space: nowrap; min-height: 34px;
}
.side-nav a svg { width: 15px; height: 15px; flex: none; }
.side-nav a:hover { background: var(--surface); color: var(--ink); }
.side-nav a.on {
  background: var(--surface); color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.side-foot { display: none; }
/* Mobile: the brand bar carries only the logo and a theme toggle; navigation
   lives in the bottom tab bar. */
.theme-icon {
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: auto; flex: none;
  width: 34px; height: 34px; border-radius: 9px;
  color: var(--ink2); border: 1px solid var(--border);
}
.theme-icon svg { width: 15px; height: 15px; }
.theme-icon:hover { color: var(--ink); border-color: var(--border-strong); }
.theme-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 11px; border-radius: 9px; min-height: 34px;
  font-size: 13px; color: var(--ink2); text-decoration: none;
  border: 1px solid var(--border);
}
.theme-btn svg { width: 14px; height: 14px; }
.theme-btn:hover { color: var(--ink); border-color: var(--border-strong); }
.sync { display: none; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.pip { width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.pip.critical { background: var(--critical); }
.sync.warn { color: var(--serious); }

.content { min-width: 0; }

/* ====================================================== bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--page) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  /* Clears the iPhone home indicator. */
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px 8px; text-decoration: none;
  font-size: 10.5px; color: var(--muted); min-height: 52px;
}
.tabbar a svg { width: 19px; height: 19px; }
.tabbar a.on { color: var(--s1); }
.tabbar a.on span { color: var(--ink); font-weight: 560; }
/* Keep the last card clear of the fixed bar. */
.footer { padding-bottom: calc(76px + env(safe-area-inset-bottom, 0)); }

/* ==================================================== segmented control */
/* One row, equal widths, shared borders -- reads as a single control instead
   of a scattered row of pills. */
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  border: 1px solid var(--border); border-radius: 11px;
  background: var(--surface); overflow: hidden; width: 100%;
}
.seg a {
  display: flex; align-items: center; justify-content: center;
  padding: 8px 4px; min-height: 36px;
  font-size: 12.5px; color: var(--ink2); text-decoration: none;
  border-left: 1px solid var(--border);
}
.seg a:first-child { border-left: 0; }
.seg a:hover { color: var(--ink); background: var(--surface-2); }
.seg a.on { color: var(--ink); background: var(--glow); font-weight: 560;
            box-shadow: inset 0 -2px 0 var(--s1); }

/* The period stepper as one tidy row. */
.stepbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 11px; background: var(--surface);
}
.stepbar .mid { text-align: center; min-width: 0; }
.stepbar .mid .periodname { display: block; font-size: 13.5px; }
.stepbar .mid .periodrange { display: block; font-size: 11px; }
.stepbar .nav {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  color: var(--ink2); text-decoration: none; border: 1px solid var(--border);
}
.stepbar .nav:hover { color: var(--ink); border-color: var(--border-strong); }
.stepbar .nav.off { opacity: 0.32; pointer-events: none; }

/* ========================================================== page header */
.pagehead {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 18px 16px 10px; max-width: 1240px; margin: 0 auto;
}
.crumbs {
  margin: 0 0 2px; font-size: 11.5px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.07em;
}
.pagehead h1 { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: -0.02em; }
.headright { font-size: 13px; color: var(--muted); }

main { padding: 6px 16px 8px; max-width: 1240px; margin: 0 auto; }

/* ================================================================ tiles */
.tiles { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); margin-bottom: 16px; }
.tile {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 15px; padding: 12px 13px;
}
.tile-label {
  font-size: 11.5px; color: var(--muted); margin-bottom: 5px;
  display: flex; align-items: center; gap: 6px;
}
/* Proportional figures on standalone values; tabular-nums is reserved for
   columns that must align vertically. */
.tile-value { font-size: 26px; font-weight: 640; letter-spacing: -0.025em; line-height: 1.08; }
.tile-value .unit { font-size: 12.5px; font-weight: 500; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.tile-sub { font-size: 11.5px; color: var(--ink2); margin-top: 6px; }
.tile-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; margin-top: 8px; }
.spark { display: block; opacity: 0.95; }

/* Exactly one hero figure per view. */
.hero { grid-column: 1 / -1; }
.hero .tile-value { font-size: 44px; letter-spacing: -0.03em; }
.hero .tile-foot { margin-top: 12px; }

/* Delta pill: signed, direction-colored, always with an arrow glyph so the
   direction is never carried by color alone. */
.delta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 560; padding: 3px 8px;
  border-radius: 999px; border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;   /* never wrap "vs prev" onto its own line */
}
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--muted); }
.delta .vs { color: var(--muted); font-weight: 450; }

/* A status dot NEVER carries meaning alone -- always beside a text label. */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.good { background: var(--good); }
.dot.warning { background: var(--warning); }
.dot.serious { background: var(--serious); }
.dot.critical { background: var(--critical); }
.dot.muted { background: var(--muted); }

/* ================================================================ cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 15px; padding: 14px; margin-bottom: 14px;
}
.card h2 { font-size: 14.5px; font-weight: 620; margin: 0 0 2px; letter-spacing: -0.01em; }
.cap { font-size: 11.5px; color: var(--muted); margin: 0 0 9px; max-width: 64ch; line-height: 1.4; }
.muted { color: var(--muted); }
.card.alert { border-color: color-mix(in srgb, var(--critical) 40%, var(--border)); }
.card.conclusion { border-style: dashed; }
.summary-text { white-space: pre-wrap; font-size: 14px; color: var(--ink2); }
figure.card { margin: 0 0 14px; }
figure.card figcaption { margin-bottom: 2px; }

.issues { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.issues li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.issues li:last-child { border-bottom: 0; }

/* ======================================================== control rows */
/* Filters sit in one row above the charts. */
.controls { display: flex; flex-direction: column; gap: 9px; margin-bottom: 14px; }
.ctlrow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ctlrow .lbl {
  font-size: 10.5px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.07em; margin-right: 2px;
}
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; color: var(--ink2); text-decoration: none;
  padding: 6px 11px; border-radius: 999px; min-height: 32px;
  border: 1px solid var(--border); background: var(--surface);
}
.chip:hover { color: var(--ink); border-color: var(--border-strong); }
.chip.on { color: var(--ink); border-color: var(--s1); background: var(--glow); }
.chip.ghost { border-style: dashed; }
.chip .n { color: var(--muted); font-size: 11px; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper .chip { min-width: 32px; justify-content: center; padding: 6px 9px; }
.periodname { font-size: 13.5px; font-weight: 560; padding: 0 4px; white-space: nowrap; }
.periodrange { font-size: 11.5px; color: var(--muted); }
.datefilter { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
/* Disclosure rows for long filter lists. */
.disc {
  border: 1px solid var(--border); border-radius: 11px;
  background: var(--surface); padding: 0;
}
.disc > summary {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 9px 12px; list-style: none; min-height: 38px;
}
.disc > summary::-webkit-details-marker { display: none; }
.disc > summary::after {
  content: '⌄'; margin-left: auto; color: var(--muted);
  font-size: 14px; line-height: 1;
}
.disc[open] > summary::after { content: '⌃'; }
.disc > summary:hover .discval { color: var(--ink); }
.discval { font-size: 12.5px; color: var(--ink2); }
.disc .ctlrow, .disc .datefilter { padding: 0 12px 12px; }
.disc .lbl { margin-right: 0; }

.datefilter input[type="date"] {
  font: inherit; font-size: 12.5px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 5px 9px; min-height: 32px;
}
.datefilter button {
  font: inherit; font-size: 12.5px; cursor: pointer; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: 9px; padding: 6px 12px; min-height: 32px;
}

/* =============================================================== tables */
.scroller { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 550; font-size: 11.5px; white-space: nowrap; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap { white-space: nowrap; }
table.dense th, table.dense td { padding: 5px 7px; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 7px; vertical-align: 0; }
td strong { font-weight: 570; }

/* =============================================================== footer */
.footer {
  padding: 16px; max-width: 1240px; margin: 0 auto;
  font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--border);
}
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em; background: var(--surface-2);
  padding: 1px 5px; border-radius: 5px; border: 1px solid var(--border);
}
.js-plotly-plot, .plot-container { width: 100% !important; }

/* ======================================================= wider screens */
@media (min-width: 620px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .pagehead h1 { font-size: 24px; }
}

@media (min-width: 1000px) {
  /* Desktop: real sidebar, no bottom tabs. */
  .tabbar { display: none; }
  .theme-icon { display: none; }
  .side-nav { display: flex; }
  .side-foot { display: flex; }
  .sync { display: flex; }
  .footer { padding-bottom: 16px; }
  .seg { width: auto; display: inline-grid; }
  .shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; }
  .sidebar {
    position: sticky; top: 0; height: 100vh;
    flex-direction: column; align-items: stretch; gap: 0;
    padding: 18px 14px; overflow: visible;
    border-bottom: 0; border-right: 1px solid var(--border);
    background: var(--page);
  }
  .logo { margin-bottom: 22px; }
  .side-nav { flex-direction: column; gap: 2px; }
  .nav-group {
    display: block; margin: 16px 0 6px; padding-left: 11px;
    font-size: 10.5px; color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.08em;
  }
  .nav-group:first-child { margin-top: 0; }
  .side-foot {
    margin-left: 0; margin-top: auto; flex-direction: column;
    align-items: stretch; gap: 8px;
  }
  .theme-btn { justify-content: flex-start; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .charts figure.card { margin-bottom: 0; }
  /* The hero occupies a 2x2 block so the four small tiles fill the space
     beside it instead of stranding a half-empty row. */
  .hero { grid-column: span 2; grid-row: span 2; display: flex;
          flex-direction: column; justify-content: center; }
  .hero .tile-value { font-size: 52px; }
  main, .pagehead, .footer { padding-left: 24px; padding-right: 24px; }
}

@media (min-width: 1280px) {
  .tiles:not(.rollup) { grid-template-columns: repeat(5, 1fr); }
}

/* ================================================================== forms */
/* Inputs are 16px on purpose: iOS Safari zooms the whole page when you focus
   an input smaller than that, which is jarring on a logging form you use every
   morning. */
.form { display: flex; flex-direction: column; gap: 12px; }
.fields { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); }
.f { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.f.wide { grid-column: 1 / -1; }
.f > span { font-size: 12px; color: var(--ink2); }
.f > span em { color: var(--muted); font-style: normal; font-size: 11px; }

.f input[type="text"], .f input[type="number"], .f input[type="date"],
.f input[type="time"], .f select, .f textarea {
  font: inherit; font-size: 16px; color: var(--ink);
  background: var(--page); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 11px; width: 100%; min-height: 42px;
  -webkit-appearance: none; appearance: none;
}
.f textarea { line-height: 1.4; resize: vertical; min-height: 64px; }
.f select {
  /* room for the custom chevron */
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 18px, calc(100% - 12px) 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.f input:focus, .f select:focus, .f textarea:focus {
  outline: none; border-color: var(--s1);
  box-shadow: 0 0 0 3px var(--glow);
}
.f input::placeholder, .f textarea::placeholder { color: var(--muted); }

.f.check {
  flex-direction: row; align-items: center; gap: 9px;
  align-self: end; min-height: 42px;
}
.f.check input[type="checkbox"] {
  width: 20px; height: 20px; accent-color: var(--s1); flex: none;
}
.f.check > span { font-size: 14px; color: var(--ink); }

button.primary {
  font: inherit; font-size: 15px; font-weight: 560; cursor: pointer;
  color: #fff; background: var(--s1); border: 0;
  border-radius: 11px; padding: 12px 18px; min-height: 46px;
  align-self: flex-start;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:active { transform: translateY(1px); }

form.inline { margin: 0; }
form.inline select {
  font: inherit; font-size: 13px; color: var(--ink);
  background: var(--page); border: 1px solid var(--border);
  border-radius: 9px; padding: 5px 8px; min-height: 32px;
}

/* Flash messages: a status color always ships with words, never alone. */
.flash {
  padding: 10px 13px; border-radius: 11px; margin-bottom: 12px;
  font-size: 13.5px; border: 1px solid var(--border);
}
.flash.ok { color: var(--up); border-color: color-mix(in srgb, var(--good) 45%, var(--border)); }
.flash.error { color: var(--down); border-color: color-mix(in srgb, var(--critical) 45%, var(--border)); }

@media (min-width: 720px) {
  .fields { grid-template-columns: repeat(4, 1fr); }
  .f.wide { grid-column: 1 / -1; }
}

/* ================================================================== chat */
.chat { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }

.chat-empty {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 15px; padding: 16px; text-align: center;
}
.chat-empty p { margin: 0 0 12px; color: var(--ink2); font-size: 14px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; }
.chip.suggest { font: inherit; font-size: 12.5px; cursor: pointer; text-align: left; }

.msg { display: flex; flex-direction: column; max-width: 100%; }
.msg.user { align-items: flex-end; }
.msg .bubble {
  border-radius: 15px; padding: 11px 14px; max-width: 92%;
  border: 1px solid var(--border); font-size: 14.5px; line-height: 1.5;
  overflow-wrap: anywhere;
}
/* The accent is a small mark, not a large saturated block: the user's own
   bubble is tinted, not filled. */
.msg.user .bubble {
  background: var(--glow); border-color: color-mix(in srgb, var(--s1) 35%, var(--border));
  white-space: pre-wrap;
}
.msg.assistant .bubble { background: var(--surface); max-width: 100%; }

/* Markdown inside an answer */
.msg.assistant .bubble > :first-child { margin-top: 0; }
.msg.assistant .bubble > :last-child { margin-bottom: 0; }
.msg.assistant .bubble h1, .msg.assistant .bubble h2,
.msg.assistant .bubble h3 { font-size: 14px; margin: 14px 0 6px; font-weight: 620; }
.msg.assistant .bubble p { margin: 0 0 9px; }
.msg.assistant .bubble ul, .msg.assistant .bubble ol { margin: 0 0 9px; padding-left: 20px; }
.msg.assistant .bubble li { margin-bottom: 3px; }
.msg.assistant .bubble code {
  font-size: 0.9em; background: var(--page); border: 1px solid var(--border);
}
.msg.assistant .bubble table { margin: 4px 0 10px; font-size: 12.5px; }
.msg.assistant .bubble th, .msg.assistant .bubble td { padding: 5px 8px; }
.msg.assistant .bubble td:not(:first-child),
.msg.assistant .bubble th:not(:first-child) {
  text-align: right; font-variant-numeric: tabular-nums;
}

/* "Show me the working" */
.sqlpeek { margin: 5px 0 0 2px; font-size: 11.5px; }
.sqlpeek summary { cursor: pointer; color: var(--muted); list-style: none; }
.sqlpeek summary::-webkit-details-marker { display: none; }
.sqlpeek summary::before { content: '⌄ '; }
.sqlpeek[open] summary::before { content: '⌃ '; }
.sqlpeek summary:hover { color: var(--ink2); }
.sqlpeek pre {
  margin: 7px 0 0; padding: 10px 12px; overflow-x: auto;
  background: var(--page); border: 1px solid var(--border);
  border-radius: 10px; font-size: 11.5px; line-height: 1.45;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ink2); white-space: pre-wrap;
}

/* Thinking indicator -- a 5-step answer takes ~30s, so show something. */
.dots { display: inline-flex; gap: 4px; vertical-align: middle; }
.dots i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--s1);
  animation: blink 1.3s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: 0.18s; }
.dots i:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: 0.6; } }

/* Composer sits above the bottom tab bar on mobile. */
.composer {
  position: sticky; bottom: calc(60px + env(safe-area-inset-bottom, 0));
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px; border-radius: 15px;
  background: color-mix(in srgb, var(--page) 94%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
}
.composer textarea {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 11px; padding: 10px 12px; resize: none;
  min-height: 44px; max-height: 180px; line-height: 1.4;
}
.composer textarea:focus {
  outline: none; border-color: var(--s1); box-shadow: 0 0 0 3px var(--glow);
}
.composer textarea:disabled { opacity: 0.55; }
.composer button { flex: none; min-height: 44px; padding: 11px 18px; }
.composer button:disabled { opacity: 0.55; cursor: default; }
.composer-note { text-align: center; margin-top: 8px; }

@media (min-width: 1000px) {
  .composer { bottom: 12px; }
  .msg .bubble { max-width: 80%; }
  .msg.assistant .bubble { max-width: 92%; }
}


/* Shown on any instance that is not the production one. Deliberately loud:
   its whole job is to stop you logging data into the wrong database. */
.localbanner {
  margin: 0 16px 10px; padding: 9px 13px; border-radius: 11px;
  font-size: 12.5px; color: var(--ink2);
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warning) 45%, var(--border));
}
.localbanner strong { color: var(--ink); }
.localbanner a { margin-left: 6px; white-space: nowrap; }
@media (min-width: 1000px) { .localbanner { margin-left: 24px; margin-right: 24px; } }

/* ================================================================== login */
.loginpage { display: flex; min-height: 100vh; }
.loginwrap {
  display: flex; align-items: center; justify-content: center;
  width: 100%; padding: 24px; max-width: none;
}
.logincard {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px;
}
.loginhead { display: flex; align-items: center; gap: 11px; margin-bottom: 20px; }
.loginhead > div { display: flex; flex-direction: column; line-height: 1.15; }
.loginhead strong { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.loginhead small { font-size: 11px; color: var(--muted); }
.logincard .form { gap: 14px; }
.logincard button.primary { width: 100%; justify-content: center; }
.logincard .cap { text-align: center; margin: 14px 0 0; }

.signout { display: none; }
@media (min-width: 1000px) {
  .signout { display: block; }
  .signout button {
    font: inherit; font-size: 12px; cursor: pointer; width: 100%;
    color: var(--muted); background: none; border: 1px solid var(--border);
    border-radius: 9px; padding: 6px 10px; min-height: 30px;
  }
  .signout button:hover { color: var(--ink); border-color: var(--border-strong); }
}

/* Marks a row the agent transcribed from something you said, as opposed to one
   you typed into a form. Never carried by colour alone -- it says "chat". */
.viachat {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  border-radius: 999px; font-size: 10.5px; color: var(--ink2);
  border: 1px solid var(--border);
}


/* ======================================================== accent picker */
.accentpicker { display: flex; align-items: center; gap: 7px; }
.accentpicker a {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid transparent; box-sizing: border-box;
  display: inline-block; position: relative;
}
.accentpicker a::after {
  content: ""; position: absolute; inset: 2px; border-radius: 50%;
  background: var(--swatch);
}
.accentpicker a.on { border-color: var(--ink); }
.accentpicker a[data-swatch="violet"] { --swatch: #8b5cf6; }
.accentpicker a[data-swatch="teal"]   { --swatch: #0e9f8f; }
.accentpicker a[data-swatch="orange"] { --swatch: #d95926; }
.accentpicker a[data-swatch="blue"]   { --swatch: #3987e5; }
:root[data-theme="light"] .accentpicker a[data-swatch="violet"] { --swatch: #6d3fd4; }
:root[data-theme="light"] .accentpicker a[data-swatch="orange"] { --swatch: #eb6834; }
:root[data-theme="light"] .accentpicker a[data-swatch="blue"]   { --swatch: #2a78d6; }


/* ============================================= today strip (chat home) */
.todaystrip {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px;
  margin-bottom: 12px; padding: 12px 6px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 15px;
  /* The glow is chrome, never a data encoding. */
  box-shadow: 0 6px 24px -14px var(--glow);
}
.todaystrip:hover { border-color: var(--border-strong); }
.ts-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 0; padding: 0 4px; text-align: center;
}
.ts-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.ts-value { font-size: 20px; font-weight: 640; letter-spacing: -0.02em; color: var(--ink); line-height: 1.1; }
.ts-value i { font-size: 10.5px; font-weight: 500; font-style: normal; color: var(--muted); margin-left: 2px; }
.ts-sub { font-size: 10.5px; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
@media (min-width: 620px) { .ts-value { font-size: 24px; } }


/* ==================================================================== */
/* HERO + METRICS -- the visual core.                                   */
/* Depth comes from darkness and a soft accent halo, not from outlines.  */
/* ==================================================================== */
.hero-block {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 20px;
  padding: 22px 20px; margin-bottom: 12px;
  border-radius: 22px;
  background:
    radial-gradient(120% 140% at 12% 0%, var(--glow) 0%, transparent 58%),
    var(--surface);
  border: 1px solid var(--border);
}

.hero-ring { position: relative; flex: none; line-height: 0; }
.hero-ring .ring { display: block; filter: drop-shadow(0 0 12px var(--glow)); }
.hero-ring-inner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
}
/* Proportional figures: a large standalone number looks loose in tabular. */
.hero-num { font-size: 42px; font-weight: 680; letter-spacing: -0.035em; line-height: 1; color: var(--ink); }
.hero-cap { font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }

.hero-side { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.hero-verdict { margin: 0; font-size: 19px; font-weight: 620; letter-spacing: -0.02em; }
.hero-note { margin: 0; font-size: 12.5px; color: var(--ink2); line-height: 1.4; }
.hero-note:empty { display: none; }

/* Metrics: no boxes at all. Whitespace and a hairline do the separating. */
.metrics {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 1px; margin-bottom: 16px;
  background: var(--border); border-radius: 18px; overflow: hidden;
}
.metric {
  display: flex; flex-direction: column; gap: 3px;
  padding: 15px 16px; background: var(--surface);
}
.m-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.09em; }
.m-value { font-size: 30px; font-weight: 660; letter-spacing: -0.032em; line-height: 1.05; color: var(--ink); }
.m-value i { font-size: 11px; font-weight: 500; font-style: normal; color: var(--muted); margin-left: 3px; letter-spacing: 0; }
.m-sub { font-size: 11.5px; color: var(--ink2); }

@media (min-width: 620px) {
  .metrics { grid-template-columns: repeat(4, 1fr); }
  .hero-num { font-size: 52px; }
  .m-value { font-size: 32px; }
}
@media (min-width: 1000px) {
  .hero-block { padding: 28px 30px; gap: 30px; }
  .hero-num { font-size: 58px; }
  .hero-verdict { font-size: 23px; }
}

/* Cards lose their hard outline and gain a little lift. */
.card, figure.card {
  border-color: var(--border);
  box-shadow: 0 1px 0 rgba(255,255,255,0.02) inset;
}
:root[data-theme="light"] .card { box-shadow: 0 1px 2px rgba(11,11,11,0.04); }

/* Section headings get a touch more presence, captions less. */
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink2); font-weight: 600; }
.cap { font-size: 11.5px; }

/* The today strip picks up the same halo treatment. */
.todaystrip {
  background:
    radial-gradient(110% 160% at 8% 0%, var(--glow) 0%, transparent 60%),
    var(--surface);
  box-shadow: none;
}

/* ==================================================================== */
/* SHARE CARD -- built to be screenshotted.                             */
/* Everything here is sized so a phone screenshot reads as a deliberate  */
/* card rather than a cropped dashboard: few stats, large type, generous */
/* breathing room, one accent.                                          */
/* ==================================================================== */
.sharecard {
  position: relative; overflow: hidden;
  border-radius: 26px; padding: 26px 22px 20px;
  margin: 0 auto 18px; max-width: 460px;
  background:
    radial-gradient(130% 90% at 50% -10%, var(--glow) 0%, transparent 62%),
    linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 42%);
  border: 1px solid var(--border);
}
/* A hairline of accent along the top edge, so the card has an identity even
   in a screenshot with no surrounding app. */
.sharecard::before {
  content: ""; position: absolute; top: 0; left: 12%; right: 12%; height: 2px;
  background: linear-gradient(90deg, transparent, var(--s1), transparent);
}

.sc-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 22px;
}
.sc-kicker {
  font-size: 11px; font-weight: 640; color: var(--s1);
  text-transform: uppercase; letter-spacing: 0.14em;
}
.sc-range { font-size: 11.5px; color: var(--muted); }

.sc-hero { text-align: center; margin-bottom: 26px; }
.sc-label {
  display: block; font-size: 10.5px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.12em; margin-bottom: 4px;
}
/* The one number the card is about. */
.sc-big {
  display: block; font-size: 58px; font-weight: 700;
  letter-spacing: -0.04em; line-height: 1; color: var(--ink);
}
.sc-delta {
  display: inline-block; margin-top: 10px; font-size: 12px; font-weight: 560;
  padding: 4px 11px; border-radius: 999px; border: 1px solid var(--border);
  white-space: nowrap;
}
.sc-delta.up { color: var(--up); }
.sc-delta.down { color: var(--down); }
.sc-delta.flat { color: var(--muted); }

.sc-stats {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 20px 12px; margin-bottom: 24px; text-align: center;
}
.sc-stats-sm { grid-template-columns: repeat(3, 1fr); gap: 14px 8px; margin: 18px 0 4px; }
.sc-stat { min-width: 0; }
.sc-value {
  display: block; font-size: 27px; font-weight: 660;
  letter-spacing: -0.03em; line-height: 1.05; color: var(--ink);
}
.sc-stats-sm .sc-value { font-size: 19px; }
.sc-value i {
  font-size: 11px; font-weight: 500; font-style: normal;
  color: var(--muted); margin-left: 3px; letter-spacing: 0;
}

.sc-breakdown {
  border-top: 1px solid var(--border); padding-top: 14px; margin-bottom: 6px;
}
.sc-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; padding: 6px 0; font-size: 13px;
}
.sc-row-name { font-weight: 570; color: var(--ink); }
.sc-row-val { color: var(--ink2); font-size: 12px; text-align: right; }

.sc-chart { margin: 6px -8px 0; }

.sc-foot {
  display: flex; align-items: center; gap: 8px;
  margin-top: 16px; padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 10.5px; color: var(--muted);
}
.sc-mark {
  width: 15px; height: 15px; border-radius: 5px; flex: none;
  background: linear-gradient(140deg, var(--s1), var(--s3));
}

@media (min-width: 620px) {
  .sc-big { font-size: 66px; }
  .sc-stats { grid-template-columns: repeat(4, 1fr); }
}

/* ==================================================================== */
/* SPACING -- the thing that made it feel clunky. Consistent rhythm:     */
/* 10px inside a group, 16px between groups, 22px between sections.      */
/* ==================================================================== */
main { padding: 10px 16px 8px; }
.card, figure.card { padding: 16px; margin-bottom: 16px; border-radius: 18px; }
.controls { gap: 10px; margin-bottom: 16px; }
.card h2 { margin-bottom: 4px; }
.cap { margin-bottom: 12px; }
.scroller table { margin-top: 2px; }
th, td { padding: 9px 10px; }

/* A five-chart grid leaves an orphan in two columns; the last odd one
   spans the full width instead of sitting beside empty space. */
@media (min-width: 1000px) {
  .charts { gap: 16px; }
  .charts > figure:last-child:nth-child(odd) { grid-column: 1 / -1; }
  main { padding: 14px 24px 10px; }
}

/* ============================================================ quick ask */
.quickask {
  display: flex; gap: 8px; align-items: center;
  margin-bottom: 12px; padding: 7px 7px 7px 8px;
  border-radius: 16px;
  background:
    radial-gradient(100% 200% at 0% 50%, var(--glow) 0%, transparent 55%),
    var(--surface);
  border: 1px solid var(--border);
}
.quickask input[type="text"] {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; color: var(--ink);
  background: none; border: 0; padding: 9px 4px; min-height: 40px;
}
.quickask input:focus { outline: none; }
.quickask input::placeholder { color: var(--muted); }
.qa-go {
  flex: none; font-size: 17px; line-height: 1; cursor: pointer;
  width: 40px; height: 40px; border-radius: 12px;
  color: #fff; background: var(--s1); border: 0;
}
.qa-go:hover { filter: brightness(1.08); }
.qa-go:disabled { opacity: 0.5; cursor: default; }
.qa-answer {
  margin-bottom: 16px; padding: 14px 16px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 14px; line-height: 1.5; color: var(--ink2);
}
.qa-answer > :first-child { margin-top: 0; }
.qa-answer table { font-size: 12.5px; margin: 4px 0 10px; }
.qa-answer .cap { margin: 10px 0 0; }
.qa-wait { display: flex; align-items: center; gap: 8px; }

/* ======================================================= column picker */
.card-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 6px;
}
.card-head h2 { margin: 0; }
.colpicker { flex: none; }
.colpicker > summary {
  cursor: pointer; list-style: none; font-size: 11.5px; color: var(--ink2);
  padding: 4px 11px; border-radius: 999px; border: 1px solid var(--border);
  white-space: nowrap;
}
.colpicker > summary::-webkit-details-marker { display: none; }
.colpicker > summary::after { content: " ⌄"; color: var(--muted); }
.colpicker[open] > summary::after { content: " ⌃"; }
.colpicker > summary:hover { color: var(--ink); border-color: var(--border-strong); }
.colpicker form { padding-top: 12px; }
.colgrid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 2px 10px; margin-bottom: 14px;
}
.colopt {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; padding: 5px 0; cursor: pointer; min-height: 32px;
}
.colopt input { width: 17px; height: 17px; accent-color: var(--s1); flex: none; }
@media (min-width: 620px) { .colgrid { grid-template-columns: repeat(4, 1fr); } }

.flashes { padding: 0 16px; max-width: 1240px; margin: 0 auto; }
@media (min-width: 1000px) { .flashes { padding: 0 24px; } }
