/* One stylesheet. Colours carry a fixed meaning everywhere:
   bad = red, warn = amber, good = green, info = blue, dim = grey.
   Follows the system light/dark setting. Works from 360px wide upwards. */

:root {
  --bg: #f6f7f9; --panel: #ffffff; --panel-border: #dfe3e8; --text: #1b1f24; --text-dim: #5f6b7a;
  --accent: #2563eb; --row-border: #e7eaee;
  --red: #c62828; --amber: #b26a00; --green: #1b7f3b; --blue: #1d4ed8; --grey: #6b7280;
  --red-bg: #fde8e8; --amber-bg: #fff3dc; --green-bg: #e3f6e9; --blue-bg: #e4ecfd; --grey-bg: #eceff3;
  --purple: #6d28d9; --purple-bg: #ede9fe;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --panel: #171b21; --panel-border: #262c35; --text: #e6e9ee; --text-dim: #9aa5b4;
    --accent: #7aa2ff; --row-border: #232932;
    --red: #ff7b7b; --amber: #ffc46b; --green: #6fd38f; --blue: #8ab4ff; --grey: #9aa5b4;
    --red-bg: #3a1d1d; --amber-bg: #3a2d14; --green-bg: #173322; --blue-bg: #1b2742; --grey-bg: #232932;
    --purple: #c4b5fd; --purple-bg: #2b2150;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-size: 13px; background: var(--grey-bg); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--panel-border); position: sticky; top: 0; z-index: 2; }
.brand { display: flex; align-items: center; gap: 8px; }
.logo { width: 14px; height: 14px; border-radius: 4px; background: linear-gradient(135deg, var(--accent), var(--green)); }
.name { font-weight: 650; }
.ver { font-size: 12px; color: var(--text-dim); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--text); }
.nav a.active, .nav a:hover { background: var(--grey-bg); text-decoration: none; }

.main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.foot { max-width: 1200px; margin: 0 auto; padding: 12px 16px 28px; font-size: 12px; color: var(--text-dim); }

h1 { font-size: 22px; margin: 4px 0 14px; }
h1 small { font-size: 13px; color: var(--text-dim); font-weight: 400; margin-left: 8px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); margin: 0 0 10px; }
.crumb { margin: 0 0 6px; font-size: 13px; color: var(--text-dim); }

.panel { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; padding: 12px 14px; margin: 0 0 12px; min-width: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 760px) { .two { grid-template-columns: 1fr; } }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 0 0 12px; }
@media (max-width: 420px) { .tile .v { font-size: 26px; } .spark { width: 80px; } }
.tile { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.tile .k { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.tile .row { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.tile .v { font-size: 32px; font-weight: 650; line-height: 1.05; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.spark { width: 120px; height: 30px; flex: 0 0 auto; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.6; }

.tone-bad { color: var(--red); } .tone-warn { color: var(--amber); } .tone-good { color: var(--green); }
.tone-info { color: var(--blue); } .tone-dim { color: var(--text-dim); }
.tone-bg-bad { background: var(--red-bg); color: var(--red); }
.tone-bg-warn { background: var(--amber-bg); color: var(--amber); }
.tone-bg-good { background: var(--green-bg); color: var(--green); }
.tone-bg-info { background: var(--blue-bg); color: var(--blue); }
.tone-bg-dim { background: var(--grey-bg); color: var(--grey); }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }

.bars { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--row-border); }
.bars span { display: block; height: 100%; }
.bars .tone-bg-bad { background: var(--red); } .bars .tone-bg-warn { background: var(--amber); }
.bars .tone-bg-good { background: var(--green); } .bars .tone-bg-info { background: var(--blue); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; margin-top: 8px; color: var(--text-dim); }
.legend b { color: var(--text); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.dot.tone-bg-bad { background: var(--red); } .dot.tone-bg-warn { background: var(--amber); }
.dot.tone-bg-good { background: var(--green); } .dot.tone-bg-info { background: var(--blue); }

.hbars { list-style: none; margin: 0; padding: 0; }
.hbars li { display: grid; grid-template-columns: 110px 1fr 36px; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.hbars .bar { height: 10px; background: var(--row-border); border-radius: 5px; overflow: hidden; }
.hbars .bar i { display: block; height: 100%; background: var(--accent); }
.hbars b { text-align: right; font-variant-numeric: tabular-nums; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--row-border); font-size: 13px; flex-wrap: wrap; }
.list li:last-child { border-bottom: 0; }
.list .t { flex: 1 1 160px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plain { margin: 0; padding-left: 18px; }
.plain li { margin: 4px 0; }

.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 8px; margin: 0 0 12px; }
@media (max-width: 760px) { .filters { grid-template-columns: 1fr 1fr; } .filters input { grid-column: 1 / -1; } }
.filters input, .filters select { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--panel-border); background: var(--panel); color: var(--text); min-width: 0; }

.grid { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; overflow: hidden; font-size: 13px; }
.grid th, .grid td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--row-border); vertical-align: top; }
.grid th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); background: var(--grey-bg); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid.compact td, .grid.compact th { padding: 6px 8px; }
@media (max-width: 760px) {
  .grid thead { display: none; }
  .grid, .grid tbody, .grid tr, .grid td { display: block; width: 100%; }
  .grid tr { border-bottom: 2px solid var(--panel-border); padding: 6px 0; }
  .grid td { display: flex; justify-content: flex-start; align-items: baseline; gap: 10px; border-bottom: 0; padding: 3px 10px; min-width: 0; }
  .grid td::before { content: attr(data-l); color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; flex: 0 0 80px; }
  .hbars li { grid-template-columns: 90px 1fr 32px; }
  .grid .num { text-align: left; }
}

.askbox { display: flex; gap: 8px; align-items: center; margin: 0 0 12px; flex-wrap: wrap; }
.askbox input { flex: 1 1 320px; font: inherit; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--panel-border); background: var(--panel); color: var(--text); min-width: 0; }
.askbox button { font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 8px; border: 0; background: var(--accent); color: #fff; cursor: pointer; }
.busy { display: none; font-size: 12px; color: var(--text-dim); }
.htmx-request .busy, .htmx-request.busy { display: inline; }
.answer { font-size: 16px; margin: 8px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.chips a { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--grey-bg); color: var(--text); }
.chips a:hover { background: var(--blue-bg); text-decoration: none; }
.sources { margin: 0; padding-left: 20px; font-size: 13px; }
.sources li { margin: 0 0 10px; }

.facts { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; margin: 0; font-size: 14px; }
.facts dt { color: var(--text-dim); } .facts dd { margin: 0; }
.summary { margin: 12px 0 0; }
.insight p { margin: 0 0 8px; }
.insight .meta { font-size: 12px; color: var(--text-dim); }
.empty { color: var(--text-dim); padding: 10px; text-align: center; }

/* How it works: one colour per thing, the same as everywhere else in the app, plus purple for
   the company AI. The .scene blocks stack on the page; in play mode (body.stage) one shows at
   a time and its .step children rise in one after the other. */
.c-rec { --c: var(--blue); --c-bg: var(--blue-bg); }
.c-doc { --c: var(--green); --c-bg: var(--green-bg); }
.c-chk { --c: var(--amber); --c-bg: var(--amber-bg); }
.c-risk { --c: var(--red); --c-bg: var(--red-bg); }
.c-ai { --c: var(--purple); --c-bg: var(--purple-bg); }
.c-run { --c: var(--grey); --c-bg: var(--grey-bg); }
#view-how .card { background: var(--c-bg); border: 2px solid var(--c); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
#view-how .card small { display: block; color: var(--text-dim); font-size: 12px; margin-top: 4px; }
#view-how .dot { background: var(--c); width: 11px; height: 11px; }
#view-how .big { font-size: 34px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0 0 8px; }
#view-how .lead { font-size: 18px; margin: 8px 0; }
#view-how .meta { font-size: 13px; color: var(--text-dim); }
#view-how .caption { margin: 12px 0 0; padding-top: 8px; border-top: 1px dashed var(--panel-border); font-size: 14px; color: var(--text-dim); }
.legend-cards { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.legend-cards .card { text-align: center; font-weight: 600; }
.person { display: flex; gap: 18px; align-items: flex-start; }
.avatar { width: 64px; height: 64px; border-radius: 50%; flex: 0 0 auto; background: linear-gradient(135deg, var(--accent), var(--green)); }
.bubble { display: inline-block; margin: 4px 0; padding: 8px 14px; border-radius: 16px; background: var(--c-bg); border: 2px solid var(--c); font-size: 16px; }
.flow { width: 100%; height: auto; display: block; margin: 0 0 10px; }
.flow .box rect { fill: var(--c-bg); stroke: var(--c); stroke-width: 2; }
.flow .box.hot rect { stroke-width: 5; }
.flow .box text { fill: var(--text); font-size: 17px; font-weight: 600; text-anchor: middle; }
.flow .box text.s { font-size: 12px; font-weight: 400; fill: var(--text-dim); }
.flow .wire { fill: none; stroke: var(--grey); stroke-width: 2; }
.flow .mover { fill: var(--accent); }
.risk-flow, .ai-flow { display: grid; grid-template-columns: auto 24px 1fr 24px auto; gap: 10px; align-items: center; }
.ai-flow { grid-template-columns: auto 24px 1fr 24px 1fr 24px 1fr; }
.rules, .providers { display: grid; gap: 8px; }
.arrow { width: 0; height: 0; border-top: 10px solid transparent; border-bottom: 10px solid transparent; border-left: 16px solid var(--grey); justify-self: center; }
.runs { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.runs .card { text-align: center; font-weight: 600; }
.modules { list-style: none; margin: 0; padding: 0; }
.modules li { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--row-border); font-size: 14px; flex-wrap: wrap; }
.modules li:last-child { border-bottom: 0; }
@media (max-width: 760px) {
  .risk-flow, .ai-flow { grid-template-columns: 1fr; }
  .arrow { transform: rotate(90deg); }
  #view-how .big { font-size: 26px; }
}

/* play mode */
body.stage .top, body.stage .foot, body.stage h1 { display: none; }
body.stage .main { max-width: none; padding: 0; }
body.stage .scene { display: none; }
body.stage .scene.on { display: flex; flex-direction: column; justify-content: center; min-height: 100vh; margin: 0; border: 0; border-radius: 0; padding: 40px 56px 110px; }
body.stage .scene.on .big { font-size: 48px; }
body.stage .scene.on .lead { font-size: 24px; }
body.stage .scene.on .card { font-size: 18px; padding: 14px 16px; }
body.stage .scene.on .modules li { font-size: 19px; padding: 7px 0; }
body.stage .scene.on .bubble { font-size: 22px; }
body.stage #view-how .scene.on .caption { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; padding: 18px 40px; border: 0;
  background: rgba(10, 12, 16, .82); color: #fff; font-size: 24px; text-align: center; }
body.stage .scene.on .step { animation: rise .7s ease-out both; }
body.stage .scene.on .step:nth-child(2), body.stage .scene.on .rules .step:nth-child(1) { animation-delay: .5s; }
body.stage .scene.on .step:nth-child(3), body.stage .scene.on .rules .step:nth-child(2) { animation-delay: 1s; }
body.stage .scene.on .step:nth-child(4), body.stage .scene.on .rules .step:nth-child(3) { animation-delay: 1.5s; }
body.stage .scene.on .step:nth-child(5), body.stage .scene.on .rules .step:nth-child(4) { animation-delay: 2s; }
body.stage .scene.on .step:nth-child(6) { animation-delay: 2.5s; }
body.stage .scene.on .step:nth-child(7) { animation-delay: 3s; }
body.stage .scene.on .step:nth-child(8) { animation-delay: 3.5s; }
body.stage .scene.on .step:nth-child(9) { animation-delay: 4s; }
body.stage .scene.on .step:nth-child(10) { animation-delay: 4.5s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
