/* ForwardAI for Soup King — "enamel pot & steam"
   One loud surface (the hero), everything after it is quiet paper. */

:root {
  color-scheme: light;
  --sans: Seravek, "Gill Sans Nova", Candara, "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "Hoefler Text", Georgia, serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "DejaVu Sans Mono", monospace;

  --paper: #ebede7;
  --surface: #fbfbf8;
  --ink: #101c1a;
  --ink-2: #47534f;
  --muted: #5f6b67;
  --rule: #d5dad2;
  --rule-soft: #e1e5dd;
  --pot: #0c3f39;
  --pot-ink: #eff1ea;
  --pot-ink-2: #b9c9c3;
  --accent: #b26a00;
  --accent-bright: #e7b14a;
  --danger: #a3341f;

  --grid: #e1e4dc;
  --axis: #c7cdc4;
  --mark-muted: #868e89;

  --measure: 63ch;
  --col: 44rem;
  --r: 6px;
  --ease: cubic-bezier(.2,.7,.3,1);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #0d1514;
    --surface: #17211f;
    --ink: #f1f3ee;
    --ink-2: #b6bfba;
    --muted: #98a29d;
    --rule: #2a3532;
    --rule-soft: #212b29;
    --pot: #0a302c;
    --pot-ink: #f1f3ee;
    --pot-ink-2: #a9bbb5;
    --accent: #e0a63b;
    --accent-bright: #e0a63b;
    --danger: #ef8f78;
    --grid: #29332f;
    --axis: #3a4643;
    --mark-muted: #79837e;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: 1rem; top: -4rem; z-index: 10;
  background: var(--surface); color: var(--ink); padding: .6rem 1rem; border-radius: var(--r);
}
.skip:focus { top: 1rem; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ---------- header ---------- */

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: baseline; gap: 1rem 1.25rem; flex-wrap: wrap;
  padding: .85rem clamp(1rem, 4vw, 2.5rem);
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: baseline; gap: .55rem; }
.pot { width: 26px; height: 23px; align-self: center; }
.pot .bowl, .pot .rim { stroke: var(--pot); }
@media (prefers-color-scheme: dark) { .pot .bowl, .pot .rim { stroke: var(--ink-2); } }
.pot .steam { stroke: var(--accent); }
.shop { font-size: 1.0625rem; font-weight: 600; letter-spacing: .01em; }
.product {
  font-size: .8125rem; color: var(--ink-2);
  padding-left: .55rem; border-left: 1px solid var(--rule);
}
.meta { margin: 0 auto 0 0; font-size: .8125rem; color: var(--muted); }

button { font: inherit; cursor: pointer; }
.ghost {
  background: none; border: 1px solid var(--rule); color: var(--ink-2);
  border-radius: 999px; padding: .3rem .85rem; font-size: .8125rem;
}
.ghost:hover { border-color: var(--ink-2); color: var(--ink); }

/* ---------- layout ---------- */

main {
  flex: 1;
  width: 100%; max-width: var(--col);
  margin: 0 auto;
  padding: 1.75rem clamp(1rem, 4vw, 2rem) 2rem;
}

/* ---------- hero: the one bold surface ---------- */

.hero {
  background: var(--pot);
  color: var(--pot-ink);
  border-radius: 10px;
  padding: clamp(1.6rem, 5vw, 2.75rem);
}
.hero[hidden] { display: none; }
.hero h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.75rem, 5.4vw, 2.6rem);
  line-height: 1.14;
  letter-spacing: -.012em;
  margin: 0 0 .85rem;
  max-width: 19ch;
  text-wrap: balance;
}
.hero-lede {
  margin: 0 0 1.6rem; max-width: 52ch;
  color: var(--pot-ink-2); font-size: 1rem; line-height: 1.6;
}
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: .5rem; margin: 0; padding: 0; }
.chips button {
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.26);
  color: var(--pot-ink);
  border-radius: 999px; padding: .5rem .95rem;
  font-size: .9375rem; text-align: left;
  transition: background .18s var(--ease), border-color .18s var(--ease);
}
.chips button:hover { background: rgba(255,255,255,.12); border-color: var(--accent-bright); }
.chips button:focus-visible { outline-color: var(--accent-bright); }
.hero-foot { margin: 1.6rem 0 0; font-size: .78125rem; color: var(--pot-ink-2); opacity: .85; }

/* ---------- thread ---------- */

.thread { display: flex; flex-direction: column; gap: 2rem; }
.thread:not(:empty) { margin-top: .5rem; }

.turn { max-width: 100%; }
.turn.user {
  border-left: 3px solid var(--accent);
  padding: .1rem 0 .1rem 1rem;
  font-size: 1.0625rem; font-weight: 600; color: var(--ink);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.turn.assistant { font-family: var(--serif); font-size: 1.0625rem; line-height: 1.65; color: var(--ink); }
.turn.assistant .prose { max-width: var(--measure); }
.turn.assistant p { margin: 0 0 .9rem; }
.turn.assistant > *:last-child p:last-child { margin-bottom: 0; }
.turn.assistant h1, .turn.assistant h2, .turn.assistant h3, .turn.assistant h4 {
  font-family: var(--sans); font-size: 1rem; font-weight: 600; letter-spacing: .01em;
  margin: 1.4rem 0 .5rem;
}
.turn.assistant ul, .turn.assistant ol { margin: 0 0 .9rem; padding-left: 1.2rem; }
.turn.assistant li { margin-bottom: .3rem; }
.turn.assistant strong { font-weight: 600; }
.turn.assistant a { color: var(--ink); text-decoration-color: var(--accent); text-underline-offset: 2px; }
.turn.assistant blockquote {
  margin: 0 0 .9rem; padding-left: .9rem; border-left: 2px solid var(--rule); color: var(--ink-2);
}
.turn.assistant code {
  font-family: var(--mono); font-size: .85em;
  background: var(--rule-soft); padding: .1em .35em; border-radius: 3px;
}
.turn.assistant pre {
  font-family: var(--mono); background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r); padding: .8rem; overflow-x: auto; font-size: .8125rem;
}
.turn.assistant pre code { background: none; padding: 0; }

/* markdown tables inside answers */
.turn.assistant table, table.data-table {
  border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .875rem;
  font-variant-numeric: tabular-nums;
}
.turn.assistant table { margin: 0 0 1rem; }
th, td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--rule-soft); }
th { font-weight: 600; font-size: .8125rem; color: var(--ink-2); border-bottom-color: var(--rule); }
td.num, th.num { text-align: right; }
tbody tr:last-child td { border-bottom: none; }

/* working indicator */
.working {
  display: flex; align-items: center; gap: .55rem;
  font-family: var(--sans); font-size: .875rem; color: var(--muted);
  margin: 0 0 .9rem;
}
.working .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: .25; } 50% { opacity: 1; } }

.caret {
  display: inline-block; width: .5ch; height: 1.05em; vertical-align: -.15em;
  background: var(--accent); margin-left: .1em; animation: pulse 1.1s ease-in-out infinite;
}

/* ---------- chart card ---------- */

.chart-card {
  margin: 0 0 1.25rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 1.1rem 1.1rem .9rem;
}
.chart-card figcaption { margin-bottom: .9rem; }
.chart-title {
  font-family: var(--sans); font-size: .9375rem; font-weight: 600; margin: 0; color: var(--ink);
}
.chart-sub { font-family: var(--sans); font-size: .8125rem; color: var(--muted); margin: .2rem 0 0; }
.chart-box { position: relative; height: 320px; }
.chart-note { font-family: var(--sans); font-size: .75rem; color: var(--muted); margin: .6rem 0 0; }

/* ---------- data block ---------- */

.data-block {
  margin: 0 0 1.25rem;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r);
  font-family: var(--sans);
}
.data-block > summary, .sql-block > summary {
  list-style: none; cursor: pointer;
  font-size: .875rem; color: var(--ink-2);
  padding: .65rem .9rem;
  display: flex; align-items: center; gap: .5rem;
}
.data-block > summary::-webkit-details-marker, .sql-block > summary::-webkit-details-marker { display: none; }
.data-block > summary::before, .sql-block > summary::before {
  content: ""; width: 0; height: 0;
  border-left: 5px solid currentColor; border-top: 4px solid transparent; border-bottom: 4px solid transparent;
  transition: transform .18s var(--ease);
}
.data-block[open] > summary::before, .sql-block[open] > summary::before { transform: rotate(90deg); }
.data-block > summary:hover, .sql-block > summary:hover { color: var(--ink); }
.data-body { padding: 0 .9rem .3rem; }
.table-scroll { overflow-x: auto; max-height: 22rem; overflow-y: auto; }
.sql-block { border-top: 1px solid var(--rule-soft); margin: 0 -.9rem; }
.sql-block > summary { font-size: .8125rem; }
.sql-block pre {
  margin: 0 .9rem .9rem; padding: .75rem; background: var(--paper);
  border-radius: var(--r); overflow-x: auto;
  font-family: var(--mono); font-size: .78125rem; line-height: 1.5; color: var(--ink-2);
  white-space: pre-wrap; word-break: break-word;
}

/* ---------- error ---------- */

.error {
  font-family: var(--sans); font-size: .9375rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--rule); border-left: 3px solid var(--danger);
  border-radius: var(--r); padding: .8rem .9rem; margin: 0 0 1rem;
  max-width: var(--measure);
}
.error strong { display: block; color: var(--danger); font-weight: 600; margin-bottom: .15rem; }
.error button { margin-top: .5rem; }

/* ---------- composer ---------- */

.ask {
  position: sticky; bottom: 0;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  padding: .85rem clamp(1rem, 4vw, 2rem) .9rem;
}
.ask-inner {
  max-width: var(--col); margin: 0 auto;
  display: flex; gap: .6rem; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 12px;
  padding: .5rem .55rem .5rem .85rem;
}
.ask-inner:focus-within { border-color: var(--ink-2); }
#prompt {
  flex: 1; border: 0; background: none; resize: none;
  font-family: var(--sans); font-size: 1rem; line-height: 1.5; color: var(--ink);
  padding: .45rem 0; max-height: 9rem; overflow-y: auto;
}
#prompt:focus { outline: none; }
#prompt::placeholder { color: var(--muted); }
#prompt:disabled { opacity: .55; }
.send, .stop {
  border: 0; border-radius: 8px; padding: .5rem 1.1rem; font-size: .9375rem; font-weight: 600;
  background: var(--pot); color: var(--pot-ink);
}
@media (prefers-color-scheme: dark) { .send, .stop { background: var(--accent); color: #17211f; } }
.send:hover, .stop:hover { filter: brightness(1.12); }
.send:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.stop { background: none; color: var(--ink-2); border: 1px solid var(--rule); font-weight: 500; }
.stop:hover { filter: none; border-color: var(--ink-2); color: var(--ink); }
.ask-hint {
  max-width: var(--col); margin: .5rem auto 0;
  font-size: .75rem; color: var(--muted);
}

@media (max-width: 640px) {
  .chart-box { height: 260px; }
  .meta { flex-basis: 100%; order: 3; }
  .topbar { padding-block: .7rem; }
  .ask-hint { display: none; }
  .thread { gap: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .working .dot, .caret { opacity: .8; }
}
