/* Data Assistant demo. Colours come from the made-up grocer: fennel green and fig purple. */
:root {
  --paper: #edf2ea;
  --surface: #fbfcf9;
  --sunk: #e3eadf;
  --ink: #24182a;
  --muted: #5d5564;
  --line: #c7d2c2;
  --fig: #6b2d5c;
  --fig-soft: #f0e4ed;
  --fennel: #2a6a43;
  --fennel-soft: #dcebdd;
  --amber: #8f560a;
  --amber-soft: #f7ebd0;
  --danger: #9c2b2b;
  --danger-soft: #f8e4e1;
  --sans: "Avenir Next", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --gutter: clamp(16px, 4vw, 40px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.55 var(--sans); overflow-wrap: break-word; }
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.25rem); line-height: 1.15; font-weight: 700; letter-spacing: -0.015em; text-wrap: balance; }
h2 { font-size: 1.2rem; line-height: 1.3; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
a { color: var(--fig); text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.5; }
:focus-visible { outline: 3px solid var(--fig); outline-offset: 2px; border-radius: 4px; }
code, pre { font-family: var(--mono); font-size: 0.86em; }
code { background: var(--sunk); padding: 0.08em 0.3em; border-radius: 4px; }
.small { font-size: 0.875rem; }
.muted { color: var(--muted); }
.label { font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff; padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }

/* ---- header, disclosure, footer ---- */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 28px; padding: 14px var(--gutter) 10px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand small { font-weight: 500; color: var(--muted); font-size: 0.85em; }
.top nav { display: flex; flex-wrap: wrap; gap: 2px 4px; margin-left: -8px; }
.top nav a { color: var(--ink); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: 0.95rem; }
.top nav a:hover { background: var(--sunk); }
.top nav a[aria-current="page"] { background: var(--ink); color: var(--paper); }
.disclosure { margin: 0 var(--gutter); padding: 9px 14px; background: var(--amber-soft); border-left: 4px solid var(--amber); border-radius: 0 8px 8px 0; font-size: 0.9rem; line-height: 1.45; }
#view { padding: 28px var(--gutter) 56px; min-height: 60vh; outline: none; }
.loading { color: var(--muted); }
.foot { border-top: 1px solid var(--line); padding: 20px var(--gutter) 32px; font-size: 0.95rem; }

.lede { max-width: 68ch; margin-top: 10px; color: var(--muted); font-size: 1.02rem; }
.page > h1 + .lede { margin-bottom: 24px; }
.notice { background: var(--amber-soft); border: 1px solid #e2c98f; border-radius: 8px; padding: 9px 12px; font-weight: 600; }
.notice.calm { font-weight: 400; max-width: 80ch; margin-bottom: 24px; }
.primary { background: var(--fig); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600; }
.primary:hover:not(:disabled) { background: #57234b; }

/* ---- ask: layout ---- */
.ask { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "chat hood" "picker hood"; grid-template-rows: auto 1fr; gap: 20px 32px; align-items: start; max-width: 1400px; margin: 0 auto; }
.chat { min-width: 0; grid-area: chat; }
.picker { min-width: 0; grid-area: picker; }
.hood { grid-area: hood; }
.role-switch { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 22px; }
.segs { display: inline-flex; flex-wrap: wrap; background: var(--sunk); border-radius: 10px; padding: 3px; gap: 3px; }
.seg { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 0.92rem; }
.seg[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 2px rgba(36, 24, 42, 0.18); font-weight: 600; }
.role-note { margin-top: 6px; max-width: 64ch; }
.h-small { font-size: 0.95rem; color: var(--muted); font-weight: 600; }
.questions { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; margin-top: 8px; }
.question { width: 100%; height: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; display: flex; flex-direction: column; gap: 2px; }
.question:hover { border-color: var(--fig); }
.question[aria-pressed="true"] { border-color: var(--fig); background: var(--fig-soft); box-shadow: inset 3px 0 0 var(--fig); }
.kind { font-size: 0.78rem; color: var(--fennel); font-weight: 600; }
.qtext { font-size: 0.93rem; line-height: 1.35; }

.thread { margin-top: 24px; display: flex; flex-direction: column; gap: 12px; scroll-margin-top: 12px; }
.empty { border: 1px dashed var(--line); border-radius: 12px; padding: 22px; color: var(--muted); text-align: center; }
.msg { max-width: 100%; padding: 12px 16px; border-radius: 14px; min-width: 0; }
.msg .who { display: block; font-size: 0.78rem; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.msg.user { align-self: flex-end; background: var(--ink); color: var(--paper); border-bottom-right-radius: 4px; max-width: 85%; }
.msg.user .who { color: #cbbfd0; }
.msg.assistant { align-self: stretch; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .notice { margin: 4px 0 8px; }
.progress { color: var(--muted); font-style: italic; }
.progress::after { content: "…"; }
.prose-answer:empty { display: none; }
.extras { margin-top: 12px; display: grid; gap: 14px; min-width: 0; }
.extras:empty { display: none; }
.thread-note { font-size: 0.85rem; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 10px; }
.composer { margin-top: 14px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; color: var(--muted); font-size: 0.88rem; background: repeating-linear-gradient(135deg, transparent 0 8px, rgba(36, 24, 42, 0.03) 8px 16px); }

/* ---- ask: under the hood, drawn as a packing ticket ---- */
.hood { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 18px 20px 6px; min-width: 0; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; overscroll-behavior: contain; }
.step { position: relative; }
.hood-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 6px; }
.controls { display: inline-flex; gap: 6px; }
.ctl { background: var(--surface); border: 1px solid var(--ink); border-radius: 8px; padding: 5px 12px; font-size: 0.9rem; font-weight: 600; min-width: 64px; }
.ctl:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.steps { margin-top: 12px; }
.step { border-top: 2px dashed var(--line); padding: 14px 0 16px; }
.step-head { display: flex; align-items: center; gap: 10px; }
.step-num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 0.85rem; background: var(--sunk); color: var(--muted); flex: none; }
.status { margin-left: auto; font-size: 0.8rem; font-weight: 600; color: var(--muted); padding: 2px 9px; border-radius: 99px; background: var(--sunk); }
.step[data-state="running"] .step-num { background: var(--fig); color: #fff; }
.step[data-state="running"] .status { background: var(--fig-soft); color: var(--fig); }
.step[data-state="done"] .step-num { background: var(--fennel); color: #fff; }
.step[data-state="done"] .status { background: var(--fennel-soft); color: var(--fennel); }
.step-idle { font-size: 0.88rem; color: var(--muted); margin: 6px 0 0 36px; }
.step-body { margin: 10px 0 0 36px; display: grid; gap: 10px; min-width: 0; }
.step[data-state="idle"] .step-body, .step[data-state="waiting"] .step-body { display: none; }
.step-body:empty { display: none; }

.tree { display: grid; gap: 8px; font-size: 0.82rem; }
.tree-topic { display: grid; gap: 4px; }
.topic-name { font-weight: 700; }
.tree-tag { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 6px; align-items: baseline; }
.tag-name { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; background: var(--surface); }
.chip.considered { border-color: var(--amber); background: var(--amber-soft); }
.chip.chosen { border-color: var(--fennel); background: var(--fennel); color: #fff; font-weight: 600; }
.cands { display: grid; gap: 10px; }
.cands:empty { display: none; }
.cand-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.conf-num { font-variant-numeric: tabular-nums; font-weight: 600; }
.verdict { margin-left: auto; font-size: 0.8rem; font-weight: 700; }
.verdict.pass { color: var(--fennel); }
.verdict.miss { color: var(--amber); }
.conf-track { position: relative; height: 10px; background: var(--sunk); border-radius: 5px; margin-top: 4px; }
.conf-fill { position: absolute; inset: 0 auto 0 0; background: var(--fig); border-radius: 5px; }
.conf-line { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); }
.reason { font-size: 0.84rem; color: var(--muted); margin-top: 5px; }
.outcome { font-weight: 600; }

.doc { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.doc summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; padding: 7px 10px; cursor: pointer; font-size: 0.9rem; }
.doc-title { font-weight: 600; }
.doc-sub { color: var(--muted); font-size: 0.8rem; margin-left: auto; }
.doc .md { padding: 2px 12px 10px; font-size: 0.86rem; border-top: 1px solid var(--line); }
.doc-type { font-size: 0.72rem; font-weight: 700; padding: 1px 7px; border-radius: 4px; background: var(--sunk); }
.doc-type.metric { background: var(--fig-soft); color: var(--fig); }
.doc-type.rule { background: var(--amber-soft); color: var(--amber); }
.doc-type.table { background: var(--fennel-soft); color: var(--fennel); }
.md { display: grid; gap: 8px; min-width: 0; }
.md ul, .md ol { padding-left: 1.2em; display: grid; gap: 3px; }
.md ul { list-style: disc; }
.md ol { list-style: decimal; }

pre.code { margin: 0; background: #2a1d30; color: #f1e9f3; padding: 12px 14px; border-radius: 8px; overflow-x: auto; white-space: pre; line-height: 1.5; font-size: 0.8rem; }
pre.code code { background: none; padding: 0; font-size: inherit; }
pre.sql { min-height: 3em; white-space: pre-wrap; }
.checks { display: grid; gap: 5px; font-size: 0.86rem; }
.checks li { padding-left: 24px; position: relative; }
.checks li::before { position: absolute; left: 0; top: 0; font-weight: 700; width: 18px; text-align: center; }
.checks .pass::before { content: "✓"; color: var(--fennel); }
.checks .fail::before { content: "✕"; color: var(--danger); }
.checks .capped::before { content: "!"; color: var(--amber); }
.checks .na::before { content: "–"; color: var(--muted); }
.checks .na { color: var(--muted); }
.checks .fail strong { color: var(--danger); }
.result-box { display: grid; gap: 6px; min-width: 0; }
.match { color: var(--fennel); font-weight: 600; }
.mismatch, .refused { color: var(--danger); }
.refused { background: var(--danger-soft); border: 1px solid #e6b8b2; border-radius: 8px; padding: 9px 12px; }
.raw { font-size: 0.9rem; white-space: pre-wrap; border-left: 3px solid var(--line); padding-left: 10px; min-height: 1.4em; }
.chart-line { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); overflow-wrap: anywhere; }

/* ---- tables ---- */
.table-scroll { overflow: auto; max-width: 100%; max-height: 340px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
table.result { border-collapse: collapse; font-size: 0.84rem; width: 100%; }
table.result caption { text-align: left; padding: 6px 10px; font-size: 0.8rem; color: var(--muted); caption-side: top; position: sticky; left: 0; }
table.result th, table.result td { padding: 5px 10px; text-align: left; white-space: nowrap; border-top: 1px solid var(--line); }
table.result th { background: var(--sunk); position: sticky; top: 0; font-weight: 600; }
table.result .num { text-align: right; font-variant-numeric: tabular-nums; }
table.result .null { color: var(--muted); font-style: italic; }
table.result td.ok { color: var(--fennel); font-weight: 600; white-space: normal; }
table.result td.bad { color: var(--danger); font-weight: 600; white-space: normal; }

/* ---- charts ---- */
.chart figcaption { font-weight: 600; font-size: 0.92rem; margin-bottom: 8px; }
.chart-body { position: relative; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .axis { stroke: var(--muted); stroke-width: 1; }
.chart .tick { font-size: 11px; fill: var(--muted); font-family: var(--sans); }
.chart .value { font-size: 12px; font-weight: 700; fill: var(--ink); font-family: var(--sans); }
.chart .series-line { fill: none; stroke: var(--fig); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-dot { fill: var(--fig); }
.chart .series-dot.ring { stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; }
.bars { display: grid; gap: 2px; }
.bar-row { display: grid; grid-template-columns: minmax(70px, 34%) minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 0.82rem; padding: 3px 0; border-radius: 4px; }
.bar-row:hover { background: var(--sunk); }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: block; height: 12px; border-left: 1px solid var(--muted); }
.bar { display: block; height: 100%; background: var(--fig); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-value { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 4ch; text-align: right; }
.chart-note { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.chart-tip { position: absolute; transform: translate(-50%, calc(-100% - 12px)); background: var(--ink); color: #fff; font-size: 0.78rem; padding: 4px 8px; border-radius: 6px; pointer-events: none; white-space: nowrap; display: flex; gap: 8px; z-index: 2; }
.chart-tip[hidden] { display: none; }

/* ---- guardrails ---- */
.page { max-width: 1200px; margin: 0 auto; }
.gr-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 32px; align-items: start; }
.gr-form { display: grid; gap: 10px; min-width: 0; }
.gr-form label { font-weight: 600; }
textarea { width: 100%; font-family: var(--mono); font-size: 0.86rem; line-height: 1.5; padding: 12px; border: 1px solid var(--muted); border-radius: 8px; background: var(--surface); resize: vertical; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 4px 12px; font-size: 0.86rem; }
.chip-btn:hover { border-color: var(--fig); }
.gr-output { display: grid; gap: 12px; margin-top: 6px; min-width: 0; }
.gr-side { display: grid; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 16px 18px; min-width: 0; }
.gr-side h2 { font-size: 1rem; }
.gr-side h2:not(:first-child) { margin-top: 10px; }
.schema dl { display: grid; gap: 6px; font-size: 0.82rem; }
.schema dt { font-family: var(--mono); font-weight: 700; }
.schema dd { color: var(--muted); font-family: var(--mono); font-size: 0.78rem; overflow-wrap: anywhere; }
.plain { display: grid; gap: 6px; font-size: 0.88rem; }

/* ---- knowledge base ---- */
.kb-role { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 20px; }
.kb-role label { font-weight: 600; }
.kb-role select { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--muted); background: var(--surface); }
.kb-role p { flex-basis: 100%; max-width: 80ch; }
.kb-grid { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 32px; align-items: start; }
.kb-tree { display: grid; gap: 20px; }
.kb-topic h2 { font-size: 1.05rem; }
.kb-topic h3 { font-size: 0.85rem; color: var(--muted); margin: 10px 0 4px; }
.kb-topic ul { display: grid; gap: 2px; border-left: 2px solid var(--line); padding-left: 8px; }
.kb-sub { width: 100%; text-align: left; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; background: none; border: 0; border-radius: 6px; padding: 5px 8px; font-size: 0.92rem; }
.kb-sub:hover { background: var(--sunk); }
.kb-sub[aria-current="true"] { background: var(--fig); color: #fff; font-weight: 600; }
.kb-sub .count { font-size: 0.76rem; opacity: 0.75; white-space: nowrap; }
.kb-sub.hidden-for-role span:first-child { text-decoration: line-through; opacity: 0.6; }
.kb-detail { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 22px 24px; display: grid; gap: 12px; min-width: 0; scroll-margin-top: 12px; }
.crumbs { font-size: 0.85rem; color: var(--muted); }
.who-sees { display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.84rem; }
.who-sees li { padding: 3px 10px; border-radius: 99px; }
.who-sees .yes { background: var(--fennel-soft); color: var(--fennel); }
.who-sees .no { background: var(--danger-soft); color: var(--danger); }
.kb-doc { border-top: 2px dashed var(--line); padding-top: 14px; display: grid; gap: 10px; min-width: 0; }
.kb-doc header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.kb-doc .md { font-size: 0.93rem; max-width: 78ch; }
.upkeep { margin-top: 20px; }

/* ---- scheduled ---- */
.sched-card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 18px 22px; max-width: 80ch; }
.sched-meta { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 18px; margin-top: 10px; font-size: 0.93rem; }
.sched-meta dt { color: var(--muted); }
.previews { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px; margin-top: 28px; align-items: start; }
.preview { min-width: 0; }
.preview h2 { margin-bottom: 10px; }
.post { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; display: grid; gap: 10px; min-width: 0; }
.post-head { display: flex; gap: 10px; align-items: center; }
.avatar { width: 36px; height: 36px; border-radius: 8px; background: var(--fig); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 0.8rem; flex: none; }
.app-badge { font-size: 0.68rem; background: var(--sunk); border-radius: 3px; padding: 1px 5px; margin-left: 6px; font-weight: 600; }
.post-title { font-weight: 700; }
.post-body { display: grid; gap: 12px; min-width: 0; font-size: 0.93rem; }
.mail-head { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 12px; font-size: 0.86rem; border-bottom: 1px solid var(--line); padding-bottom: 10px; overflow-wrap: anywhere; }
.mail-head dt { color: var(--muted); }

/* ---- about ---- */
.prose { max-width: 70ch; margin: 0 auto; display: grid; gap: 14px; }
.prose h2 { margin-top: 18px; }
.prose ul { list-style: disc; padding-left: 1.2em; display: grid; gap: 8px; }
.selfcheck-box { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 16px 18px; display: grid; gap: 12px; justify-items: start; min-width: 0; }
.selfcheck { display: grid; gap: 10px; width: 100%; min-width: 0; }
.selfcheck:empty { display: none; }

/* ---- phone width: the pipeline panel moves below the chat ---- */
@media (max-width: 900px) {
  .gr-grid, .kb-grid, .previews { grid-template-columns: minmax(0, 1fr); }
  .ask { grid-template-columns: minmax(0, 1fr); grid-template-areas: "chat" "picker" "hood"; grid-template-rows: none; }
  .ask.started { grid-template-areas: "chat" "hood" "picker"; }
  .hood { position: static; max-height: none; }
  .questions { grid-template-columns: minmax(0, 1fr); }
  .msg.user { max-width: 92%; }
}
@media (max-width: 520px) {
  .step-idle, .step-body { margin-left: 0; }
  .tree-tag { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .hood { padding: 14px 14px 4px; }
  .kb-detail { padding: 16px; }
  .sched-meta { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .sched-meta dd { margin-bottom: 8px; }
}
@media (prefers-reduced-motion: no-preference) {
  .conf-fill { transition: width 80ms linear; }
}
