/* The Hub's one stylesheet: tokens, the shell (sidebar + top bar, drawn once) and what the views share.
   View-specific rules are grouped below under each view's name. */
:root {
  --bg: #f5f7fb; --panel: #ffffff; --ink: #14213d; --slate: #5a6478; --muted: #8b95a9;
  --line: #e2e7f0; --tint: #eef2f9; --orange: #f26b21; --orange-soft: #fdf0e6;
  --btn: #14213d; --btn-ink: #ffffff; --err: #b42318;
  --ok: #0f7a52; --ok-soft: #e3f4ec; --warn: #a15c00; --warn-soft: #fff1da; --bad: #b42318; --bad-soft: #fde8e6; --info: #1d5fbf; --info-soft: #e7effb;
  --font: 'Poppins', -apple-system, 'Segoe UI', system-ui, sans-serif; --mono: ui-monospace, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1426; --panel: #111c33; --ink: #eef2f9; --slate: #a9b3c7; --muted: #7b86a0;
    --line: #223049; --tint: #172542; --orange: #ff8344; --orange-soft: #2a2234;
    --btn: #ff8344; --btn-ink: #0c1426; --err: #f97066;
    --ok: #4cc79a; --ok-soft: #12352b; --warn: #f0b04a; --warn-soft: #3a2c10; --bad: #f97066; --bad-soft: #3d1717; --info: #7fb2ff; --info-soft: #14284a; color-scheme: dark;
  }
}
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.6; }
h1, h2, h3, p { margin: 0; }
button, textarea, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.shell { height: 100%; display: grid; grid-template-columns: 264px minmax(0, 1fr); }
.nav { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 20px 14px; gap: 20px; min-height: 0; overflow-y: auto; box-sizing: border-box; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; font-weight: 600; font-size: 17px; letter-spacing: -.01em; color: var(--ink); text-decoration: none; }
.brand svg { width: 30px; height: 30px; flex: none; }
.nav-label { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 0 8px 6px; }
.items { display: flex; flex-direction: column; gap: 2px; }
.item { display: flex; align-items: center; gap: 11px; width: 100%; box-sizing: border-box; border-radius: 10px; padding: 8px 10px; color: var(--ink); text-decoration: none; font-weight: 500; }
.item:hover { background: var(--tint); }
.item[aria-current="page"] { background: var(--orange-soft); }
.item .ico { width: 18px; height: 18px; flex: none; color: var(--slate); }
.item[aria-current="page"] .ico { color: var(--orange); }
.item .count { margin-left: auto; background: var(--orange); color: #fff; font-size: 11px; font-weight: 600; border-radius: 99px; padding: 0 8px; min-width: 20px; text-align: center; line-height: 18px; }
.nav-foot { margin-top: auto; padding: 0 8px; font-size: 12px; color: var(--muted); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.top { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; }
.top h1 { font-size: 16px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .menu-btn { display: none; }
.top-actions { display: inline-flex; gap: 8px; align-items: center; }
.who-out { display: inline-flex; align-items: center; gap: 10px; }
.who-email { font-size: 12px; color: var(--slate); }
.content { flex: 1; min-height: 0; overflow-y: auto; }
.content.fill { overflow: hidden; display: flex; flex-direction: column; }
.boot { height: 100%; display: grid; place-items: center; color: var(--slate); }
.scrim { display: none; }

/* ---------- Shared bits ---------- */
.btn { cursor: pointer; border: 1px solid var(--line); background: transparent; border-radius: 9px; padding: 7px 14px; font-weight: 500; }
.btn:hover:not(:disabled) { background: var(--tint); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--btn); color: var(--btn-ink); border-color: var(--btn); border-radius: 11px; padding: 9px 20px; font-weight: 600; }
.btn.danger { color: var(--bad); }
.page { max-width: 1100px; margin: 0 auto; padding: 28px 24px 56px; display: flex; flex-direction: column; gap: 24px; box-sizing: border-box; }
.page.narrow { max-width: 860px; gap: 20px; }
.ph h2 { font-size: clamp(22px, 3.4vw, 28px); font-weight: 500; letter-spacing: -.02em; text-wrap: balance; }
.ph p { color: var(--slate); margin-top: 6px; max-width: 70ch; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card h3 { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.muted { color: var(--slate); } .small { font-size: 12px; }
.err { color: var(--err); }
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 6px; line-height: 1.3; font-weight: 600; }
.md h1 { font-size: 17px; } .md h2 { font-size: 15.5px; } .md h3, .md h4 { font-size: 14px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; } .md li { margin: 2px 0; }
.md table { border-collapse: collapse; margin: 0 0 10px; display: block; overflow-x: auto; max-width: 100%; font-size: 13px; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; }
.md th { background: var(--tint); font-weight: 600; }
.md pre { background: var(--tint); padding: 10px 12px; border-radius: 8px; overflow-x: auto; margin: 0 0 10px; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--tint); padding: 1px 5px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0 0 10px; padding: 2px 12px; border-left: 3px solid var(--orange); color: var(--slate); }

/* ---------- Chat view ---------- */
.thread { flex: 1; overflow-y: auto; min-height: 0; }
.thread .inner { width: 100%; max-width: 760px; margin: 0 auto; padding: 28px 24px; display: flex; flex-direction: column; gap: 18px; min-height: 100%; box-sizing: border-box; }
.welcome { margin: auto 0; display: flex; flex-direction: column; gap: 14px; }
.welcome h2 { font-size: clamp(24px, 4vw, 32px); font-weight: 500; line-height: 1.2; letter-spacing: -.02em; text-wrap: balance; }
.welcome h2 em { font-style: normal; color: var(--orange); }
.welcome p { color: var(--slate); max-width: 52ch; }
.starters { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; align-items: flex-start; }
.starter { cursor: pointer; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 10px 14px; color: var(--ink); }
.starter:hover { border-color: var(--orange); }
.starter::after { content: ' \2192'; color: var(--orange); }
.msg { max-width: 92%; min-width: 0; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); padding: 12px 16px; border-radius: 14px 14px 14px 4px; }
.status { font-size: 12px; color: var(--slate); margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.loader { width: 28px; height: 28px; flex: none; }
.loader .ring { transform-origin: 24px 24px; animation: spin 3.6s linear infinite; }
.loader .middle { animation-duration: 2.8s; animation-direction: reverse; }
.loader .inner { animation-duration: 2s; }
@keyframes spin { to { transform: rotate(360deg); } }
.fb { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 12px; color: var(--muted); }
.fb button { cursor: pointer; background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 3px 10px; font-size: 12px; color: var(--slate); }
.fb button:hover { border-color: var(--orange); color: var(--ink); }
.cursor::after { content: ''; display: inline-block; width: 6px; height: 14px; margin-left: 2px; vertical-align: text-bottom; background: var(--orange); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.composer { padding: 12px 24px 18px; flex: none; }
.composer form { max-width: 760px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px 8px 8px 16px; }
.composer form:focus-within { border-color: var(--orange); }
.composer textarea { flex: 1; min-width: 0; resize: none; border: 0; background: transparent; padding: 8px 0; max-height: 160px; outline: none; }
.note { max-width: 760px; margin: 8px auto 0; font-size: 11px; color: var(--muted); text-align: center; }
.chat-chart { margin: 10px 0; min-width: 0; width: 100%; }

/* ---------- Findings view ---------- */
.page section { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.page section > h3 { font-size: 17px; font-weight: 600; }
.lede { color: var(--slate); font-size: 13px; max-width: 75ch; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.controls label { font-size: 12.5px; color: var(--slate); display: inline-flex; gap: 6px; align-items: center; }
.controls select { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 5px 8px; }
.toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.toggle { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 3px 11px; font-size: 12px; cursor: pointer; }
.toggle[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.runs { display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); gap: 16px; align-items: start; }
.runlist { display: flex; flex-direction: column; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 6px; max-height: 640px; overflow-y: auto; }
.run { text-align: left; border: 0; background: transparent; border-radius: 9px; padding: 8px 10px; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.run:hover { background: var(--tint); }
.run[aria-current="true"] { background: var(--orange-soft); }
.run b { font-weight: 600; font-size: 13px; }
.run span { font-size: 12px; color: var(--slate); }

/* ---------- Knowledge view ---------- */
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row .grow { flex: 1; min-width: 160px; }
.seg { display: inline-flex; background: var(--tint); border-radius: 11px; padding: 3px; gap: 2px; align-self: flex-start; }
.seg button { border: 0; background: transparent; cursor: pointer; padding: 5px 14px; border-radius: 8px; font-weight: 500; color: var(--slate); }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(20,33,61,.12); }
label.lbl { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
label.lbl small { font-weight: 400; color: var(--muted); }
.in { background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; width: 100%; min-width: 0; box-sizing: border-box; }
textarea.in { resize: vertical; min-height: 96px; }
textarea.code { font-family: var(--mono); font-size: 12.5px; }
.in:focus { outline: none; border-color: var(--orange); }
.drop { border: 1.5px dashed var(--line); border-radius: 11px; padding: 22px 16px; text-align: center; color: var(--slate); cursor: pointer; background: var(--bg); }
.drop:hover, .drop.over { border-color: var(--orange); background: var(--orange-soft); }
.drop strong { color: var(--ink); font-weight: 500; }
.files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.files li { display: flex; align-items: center; gap: 10px; background: var(--tint); border-radius: 9px; padding: 6px 10px; min-width: 0; }
.files .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files button { background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 16px; }
.check { display: flex; gap: 10px; align-items: flex-start; }
.choice { display: flex; gap: 12px; align-items: flex-start; border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--orange); background: var(--orange-soft); }
.choice input { margin-top: 5px; accent-color: var(--orange); }
.pill { font-size: 11px; font-weight: 600; border-radius: 99px; padding: 2px 10px; white-space: nowrap; background: var(--tint); color: var(--slate); }
.pill.open { background: var(--info-soft); color: var(--info); } .pill.question { background: var(--warn-soft); color: var(--warn); }
.pill.approved { background: var(--ok-soft); color: var(--ok); } .pill.provisional { background: var(--warn-soft); color: var(--warn); } .pill.rejected { background: var(--bad-soft); color: var(--bad); }
.head { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.quote { border-left: 3px solid var(--line); padding: 2px 0 2px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.claim { background: var(--tint); border-radius: 11px; padding: 10px 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; background: var(--tint); border-radius: 8px; padding: 3px 10px; overflow-wrap: anywhere; color: var(--ink); text-decoration: none; }
a.chip:hover { text-decoration: underline; }
.change { border: 1px solid var(--line); border-radius: 11px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.change.off { opacity: .5; }
.change .row label { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.diff { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.diff pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: 12px; border-radius: 8px; padding: 8px 10px; max-height: 220px; overflow: auto; }
.was { background: var(--bad-soft); } .now { background: var(--ok-soft); }
.trail { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.trail div { border-left: 3px solid var(--line); padding-left: 10px; }
.decide { border-top: 1px solid var(--line); padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.notice { background: var(--ink); color: var(--bg); border-radius: 11px; padding: 10px 14px; }
.error { background: var(--bad-soft); color: var(--bad); border-radius: 11px; padding: 10px 14px; }
.empty { text-align: center; color: var(--slate); padding: 30px 16px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.t td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.tbl { overflow-x: auto; }

/* ---------- Narrow screens ---------- */
@media (max-width: 860px) { .runs { grid-template-columns: minmax(0, 1fr); } .runlist { max-height: 260px; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav { position: fixed; z-index: 20; inset: 0 auto 0 0; width: min(300px, 86vw); transform: translateX(-102%); transition: transform .2s; }
  .nav.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; z-index: 10; background: rgba(12, 20, 38, .45); }
  .top { padding: 12px 16px; }
  .top .menu-btn { display: inline-block; }
  .who-email { display: none; }
  .page { padding: 20px 16px 40px; }
  .thread .inner { padding: 20px 16px; }
  .composer { padding: 10px 16px 16px; }
  .diff { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) { .nav { transition: none; } .cursor::after, .loader .ring { animation: none; } }

/* ---------- Findings view: tabs, latest-run strip, sensor table ---------- */
.fpage { gap: 18px; }
.tabs { display: inline-flex; align-self: flex-start; background: var(--tint); border-radius: 14px; padding: 4px; gap: 2px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; cursor: pointer; padding: 7px 16px; border-radius: 10px; font-weight: 500; color: var(--slate); }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(20,33,61,.12); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 12px; align-items: stretch; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; min-width: 0; }
.kpi-l { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.kpi-v { font-size: 24px; font-weight: 600; line-height: 1.25; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi-s { font-size: 12px; color: var(--slate); }
.kpi.warn .kpi-v { color: var(--warn); }
.kpi.ok .kpi-v { color: var(--ok); }
.kpi-link { align-self: center; white-space: nowrap; }
.sensors { gap: 10px; padding: 18px 20px 12px; }
.sensors-head { display: flex; gap: 16px; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; }
.sensors-head h3 { font-size: 16px; }
.sensors-head p { max-width: 62ch; margin-top: 2px; }
.sensors-head select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px 6px; margin: 0 2px; }
table.st { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.st th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.st td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.st tr[data-row] { cursor: pointer; }
table.st tr[data-row]:hover td, table.st tr.open td { background: var(--tint); }
table.st tr[data-row]:focus-visible { outline: 2px solid var(--orange); outline-offset: -2px; }
table.st .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
table.st .spark-col { width: 180px; }
table.st .chev { color: var(--muted); display: inline-block; width: 12px; }
table.st tr.detail td { background: var(--bg); padding: 14px; }
table.st tr.detail .viz-card { border: 0; padding: 0; background: transparent; max-width: 720px; }
.runcharts { border-top: 1px solid var(--line); padding-top: 10px; }
.runcharts summary { cursor: pointer; font-weight: 600; }
.runcharts[open] summary { margin-bottom: 10px; }
.ideas .md { max-width: 80ch; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kpi-link { grid-column: 1 / -1; justify-self: start; } }
@media (max-width: 640px) { table.st .spark-col, table.st th:nth-child(3), table.st td:nth-child(3) { display: none; } }
/* Status chips also appear outside chart cards (the Findings table), so they take the app's own tokens. */
.viz-chip { font-size: 11px; font-weight: 600; border-radius: 99px; padding: 2px 10px; white-space: nowrap; background: var(--tint); color: var(--slate); }
.viz-chip.in { background: var(--ok-soft); color: var(--ok); }
.viz-chip.low, .viz-chip.high { background: var(--warn-soft); color: var(--warn); }
