/* Insights Hub admin. One accent colour, one spacing scale (4/8/12/16/24/32), light and dark via prefers-color-scheme. */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f0f2f5; --text: #1b1f24; --muted: #5a6573;
  --border: #e1e5ea; --border-strong: #c9d0d8;
  --accent: #3b5bdb; --accent-hover: #2f4cc0; --accent-soft: #e8edff; --on-accent: #ffffff;
  --ok: #1d7a3b; --ok-soft: #e1f4e7; --warn: #895700; --warn-soft: #fff2d1; --bad: #b42318; --bad-soft: #fde7e5;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --r: 8px; --r-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1318; --surface: #171c23; --surface-2: #1e252e; --text: #e5e8ec; --muted: #98a3b0;
    --border: #2a323c; --border-strong: #3a4552;
    --accent: #8aa4ff; --accent-hover: #a5b9ff; --accent-soft: #1d2848; --on-accent: #0b1020;
    --ok: #62d08a; --ok-soft: #153322; --warn: #f2bd57; --warn-soft: #3a2d0b; --bad: #ff8f85; --bad-soft: #401a17;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0; font-weight: 650; }
h3 { font-size: 14px; margin: var(--s4) 0 var(--s2); font-weight: 650; }
p { margin: 0 0 var(--s3); }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .mono { font-family: var(--mono); font-size: 12.5px; }
.strong { font-weight: 650; } .strong-link { font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.wrap-any { overflow-wrap: anywhere; word-break: break-word; }
.inline { display: inline; margin: 0; }
.spacer { flex: 1; }

/* Shell */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-in { max-width: 1280px; margin: 0 auto; padding: var(--s2) var(--s4); display: flex; align-items: center; gap: var(--s3); }
.brand { display: inline-flex; align-items: center; gap: var(--s2); font-weight: 700; color: var(--text); }
.brand svg { color: var(--accent); }
.brand:hover { text-decoration: none; }
.proj-switch select { width: auto; max-width: 200px; min-height: 32px; padding: 3px 8px; }
.wrap { max-width: 1280px; margin: 0 auto; padding: var(--s5) var(--s4) var(--s6); }
.bare { max-width: 420px; margin: 12vh auto 0; padding: 0 var(--s4); }
.proj-head, .page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.proj-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--s3); }
.small-link { font-size: 12.5px; }
.tabs { display: flex; gap: var(--s1); overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: var(--s4); scrollbar-width: thin; }
.tab { padding: var(--s2) var(--s3); white-space: nowrap; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.subtabs { display: flex; gap: var(--s2); margin-bottom: var(--s3); }
.subtabs a { padding: var(--s1) var(--s3); border-radius: 999px; color: var(--muted); }
.subtabs a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.foot { margin-top: var(--s6); font-size: 12px; }
.crumbs { color: var(--muted); font-size: 12.5px; margin-bottom: var(--s2); }
.content > * + * { margin-top: var(--s4); }
.content > .kpis + p { margin-top: var(--s2); }

/* Range picker + segmented controls */
.range { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--r-sm); overflow: hidden; background: var(--surface); }
.seg a { padding: 5px var(--s3); color: var(--text); border-right: 1px solid var(--border); font-size: 13px; }
.seg a:last-child { border-right: 0; }
.seg a:hover { background: var(--surface-2); text-decoration: none; }
.seg a.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.range-more > summary { cursor: pointer; color: var(--accent); font-size: 13px; list-style: none; padding: 5px var(--s2); }
.range-more > summary::-webkit-details-marker { display: none; }
@media (min-width: 701px) { .range-more > summary { display: none; } }
.range-more[open] > summary { padding-bottom: var(--s2); }
.range-custom { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.range-custom input[type=date] { width: auto; min-height: 32px; padding: 3px 8px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: var(--s4); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); flex-wrap: wrap; }
.card.narrow, .narrow { max-width: 460px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: var(--s4); align-items: start; }
.login h1 { margin-bottom: var(--s1); }
.detail-head h2 { font-size: 18px; margin-bottom: var(--s2); overflow-wrap: anywhere; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: var(--s3); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: var(--s3) var(--s4); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi-label { color: var(--muted); font-size: 12.5px; }
.kpi-value { font-size: 24px; font-weight: 650; line-height: 1.2; text-align: left; }
.kpi-value.small-v { font-size: 15px; padding: 5px 0; }
.kpi-value a { color: inherit; }
.kpi-delta { font-size: 12.5px; font-weight: 600; } .kpi-delta.good { color: var(--ok); } .kpi-delta.badd { color: var(--bad); } .kpi-delta.flat { color: var(--muted); font-weight: 400; }
.kpi-prev { font-size: 12px; }
.live { margin-bottom: var(--s3); color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r-sm); }
table.data { border-collapse: collapse; width: 100%; font-size: 13.5px; min-width: 30rem; }
table.data.wide { min-width: 44rem; }
table.data.fit { min-width: 0; }
table.data th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--muted); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border-strong); white-space: nowrap; background: var(--surface); }
table.data th.num { text-align: right; }
table.data td { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data td.wrap-any { min-width: 9rem; }
table.data.fit td.wrap-any { min-width: 6rem; }
table.projects td { vertical-align: middle; }
.sortable th[data-sort] { cursor: pointer; user-select: none; }
.sortable th[data-sort]:hover { color: var(--text); }
.sortable th[aria-sort=ascending]::after { content: " ▲"; font-size: 10px; } .sortable th[aria-sort=descending]::after { content: " ▼"; font-size: 10px; }
.bar-col { width: 90px; min-width: 70px; }
.sbar { display: block; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.sbar-fill { display: block; height: 100%; background: var(--accent); }
.spark-cell { width: 160px; min-width: 120px; }
.spark { width: 140px; height: 28px; display: block; }
.spark .s { stroke: var(--accent); stroke-width: 1.5; } .spark .area { fill: var(--accent); opacity: .12; }

/* Retention heat */
td.ret { background: color-mix(in srgb, var(--accent) calc(var(--v) * 70%), var(--surface)); color: var(--text); text-align: right; }
td.ret-empty { background: var(--surface-2); }
table.retention td, table.retention th { white-space: nowrap; }

/* Charts */
.chart { margin: 0; }
.chart-legend { display: flex; gap: var(--s4); flex-wrap: wrap; font-size: 12.5px; margin-bottom: var(--s2); color: var(--muted); }
.lg::before { content: ""; display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--accent); vertical-align: middle; margin-right: 6px; }
.lg-1::before { border-top-style: dashed; } .lg-2::before { border-top-color: var(--muted); }
.chart-body { display: grid; grid-template-columns: 2.6em minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: var(--s2); height: 180px; }
.chart-y { display: flex; flex-direction: column; justify-content: space-between; text-align: right; font-size: 11.5px; color: var(--muted); line-height: 1; padding: 0 0 0 0; }
.chart-plot { width: 100%; height: 100%; display: block; overflow: visible; }
.chart-plot .grid { stroke: var(--border); stroke-width: 1; }
.chart-plot .s { stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-plot .s0 { stroke: var(--accent); } .chart-plot .s1 { stroke: var(--accent); stroke-dasharray: 6 4; opacity: .85; } .chart-plot .s2 { stroke: var(--muted); }
.chart-plot circle.s { fill: var(--accent); stroke: none; }
.chart-plot .area { fill: var(--accent); opacity: .08; }
.chart-plot .bar { fill: var(--accent); }
.chart-plot .hit { fill: transparent; } .chart-plot .hit:hover { fill: var(--accent); fill-opacity: .1; }
.chart-x { display: flex; justify-content: space-between; padding-left: calc(2.6em + var(--s2)); font-size: 11.5px; color: var(--muted); margin-top: var(--s1); }

/* Funnel */
.funnel { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s3); }
.funnel-row { display: grid; gap: 4px; }
.funnel-label { display: flex; gap: var(--s2); align-items: baseline; }
.funnel-n { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex: none; }
.funnel-bar { height: 14px; background: var(--surface-2); border-radius: 4px; overflow: hidden; border: 1px solid var(--border); }
.funnel-fill { display: block; height: 100%; background: var(--accent); }
.funnel-nums { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3); font-size: 13px; }
.drop { color: var(--muted); } .drop.worst { color: var(--bad); font-weight: 650; }
.callout { background: var(--warn-soft); color: var(--text); border-left: 3px solid var(--warn); padding: var(--s2) var(--s3); border-radius: var(--r-sm); margin-top: var(--s3); }
.steps { display: grid; gap: var(--s2); margin-bottom: var(--s3); }
.step-row { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.step-row select { width: auto; } .step-row .grow { flex: 1 1 220px; width: auto; min-width: 160px; } .step-row .target-input { flex: 0 1 180px; width: auto; }
.step-n { width: 22px; text-align: center; color: var(--muted); }
.narrow-input { width: 120px !important; }
.saved-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; }
.saved-list li { display: inline-flex; align-items: center; gap: var(--s2); }

/* Forms */
input, select, textarea, button { font: inherit; }
:where(input:not([type=checkbox]):not([type=hidden]), select, textarea) { width: 100%; min-height: 36px; padding: 6px var(--s3); background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--r-sm); }
textarea { resize: vertical; line-height: 1.45; } textarea.tall { min-height: 120px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); margin: 2px 0 0; flex: none; }
.field { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
.filters, .grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--s3); align-items: start; }
.stack-form { display: grid; gap: var(--s3); }
.form-actions { display: flex; gap: var(--s2); align-items: flex-end; flex-wrap: wrap; grid-column: 1 / -1; }
.filters .form-actions { grid-column: auto; align-self: end; }
.check { display: flex; gap: var(--s2); align-items: flex-start; }
.check.big { font-size: 14px; }
.inline-form { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-top: var(--s3); }
.inline-form input { width: auto; flex: 1 1 200px; }
.inline-details { margin-top: var(--s3); } .inline-details summary { cursor: pointer; color: var(--accent); }
.chips-row { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-top: var(--s3); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 36px; padding: 6px var(--s4); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: var(--r-sm); cursor: pointer; font-weight: 550; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn.danger { color: var(--bad); border-color: var(--bad); } .btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); } .btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.small { min-height: 32px; padding: 3px var(--s3); } .btn.tiny { min-height: 26px; padding: 0 var(--s2); font-size: 12.5px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: var(--s2); flex-wrap: wrap; }

/* Pills, chips */
.pill { display: inline-block; padding: 0 var(--s2); border-radius: 999px; font-size: 12px; line-height: 20px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.info, .pill.ai { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chips { display: inline-flex; flex-wrap: wrap; gap: var(--s1); }
.chip { display: inline-block; padding: 0 var(--s2); border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; line-height: 20px; overflow-wrap: anywhere; }
.chip-k { color: var(--muted); margin-right: 2px; }
.chip-link { display: inline-block; padding: 2px var(--s3); border-radius: 999px; border: 1px solid var(--border-strong); color: var(--text); font-size: 13px; }
.chip-link:hover { background: var(--surface-2); text-decoration: none; } .chip-link.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Lists, key-value */
.feed { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s3); }
.feed li { min-width: 0; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin-top: var(--s1); font-size: 12.5px; }
.highlights { margin: 0; padding-left: var(--s5); display: grid; gap: var(--s2); }
dl.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s2) var(--s4); margin: 0 0 var(--s3); }
dl.kv dt { color: var(--muted); font-size: 12.5px; padding-top: 1px; } dl.kv dd { margin: 0; overflow-wrap: anywhere; }
code.copyable { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border); padding: 2px var(--s2); border-radius: var(--r-sm); cursor: copy; word-break: break-all; }
code.secret { border-color: var(--warn); }
pre { margin: 0; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--s3); overflow-x: auto; max-height: 420px; }
pre.plain { white-space: pre-wrap; overflow-wrap: anywhere; font-family: inherit; font-size: 13.5px; background: transparent; border: 0; padding: 0; max-height: none; }
pre.code-block { max-height: none; }
blockquote.fragment { margin: 0; padding: var(--s3) var(--s4); border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 var(--r-sm) var(--r-sm) 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Feedback */
.threads { list-style: none; padding: 0; margin: 0; }
.thread-row { padding: var(--s3) 0; border-bottom: 1px solid var(--border); } .thread-row:last-child { border-bottom: 0; }
.thread-link { color: var(--text); font-weight: 550; overflow-wrap: anywhere; } .thread-link:hover { color: var(--accent); }
.thread-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--s4); align-items: start; }
.thread-main > * + *, .thread-side > * + * { margin-top: var(--s4); }
.messages { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s3); }
.msg { border: 1px solid var(--border); border-radius: var(--r); padding: var(--s3); background: var(--surface); }
.msg.admin { border-color: var(--accent); background: var(--accent-soft); }
.msg.ai, .msg.agent, .msg.host_ai { border-style: dashed; }
.msg.deleted { opacity: .6; }
.msg-head { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; margin-bottom: var(--s1); }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-status, .ai-result { font-size: 13px; }
.ai-box { display: grid; gap: var(--s2); }
.ai-reply { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--s3); margin-top: var(--s2); }
.ai-note { border-left: 3px solid var(--warn); background: var(--warn-soft); padding: var(--s2) var(--s3); border-radius: var(--r-sm); margin-top: var(--s2); }
.ai-error { border-left: 3px solid var(--bad); background: var(--bad-soft); padding: var(--s2) var(--s3); border-radius: var(--r-sm); margin-top: var(--s2); }
.tool-call { margin-top: var(--s2); font-size: 12.5px; }

/* Story */
.story { list-style: none; padding: 0; margin: 0; }
.story-break { margin: var(--s4) 0 var(--s2); padding: var(--s1) var(--s3); background: var(--surface-2); border-radius: var(--r-sm); font-size: 13px; }
.story-break:first-child { margin-top: 0; }
.story-gap { color: var(--muted); font-size: 12.5px; padding: var(--s1) 0 var(--s1) 86px; }
.story-row { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: var(--s3); padding: 5px 0; border-bottom: 1px dashed var(--border); }
.story-row.error .story-body { color: var(--text); }
.story-time { color: var(--muted); }
.story-body { overflow-wrap: anywhere; }
ol.crumbs-list { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s1); font-size: 13px; }
.occ-list, .req-list { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s2); }
details.occ, details.req { border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--s2) var(--s3); }
details.occ summary, details.req summary { cursor: pointer; overflow-wrap: anywhere; }
.occ-body, .req-body { margin-top: var(--s3); display: grid; gap: var(--s2); }
.occ-msg { color: var(--muted); }

/* Flash, empty */
.flash { padding: var(--s2) var(--s3); border-radius: var(--r-sm); margin-bottom: var(--s3); border: 1px solid var(--border); }
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; } .flash.err { background: var(--bad-soft); color: var(--bad); border-color: transparent; } .flash.warn { background: var(--warn-soft); color: var(--text); border-left: 3px solid var(--warn); }
.empty { background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--r); padding: var(--s5); text-align: left; }
.empty h3 { margin-top: 0; font-size: 16px; }

@media (max-width: 900px) {
  .thread-layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .wrap { padding: var(--s4) var(--s4) var(--s5); }
  .topbar-in { gap: var(--s2); }
  .brand span { display: none; }
  .kpi-value { font-size: 20px; }
  dl.kv { grid-template-columns: minmax(0, 1fr); gap: 0; } dl.kv dd { margin-bottom: var(--s2); }
  .story-row { grid-template-columns: 62px minmax(0, 1fr); gap: var(--s2); } .story-gap { padding-left: 70px; }
  .chart-body { height: 150px; }
  .range { width: 100%; }
}
@media (prefers-reduced-motion: no-preference) { .btn, .tab, a { transition: background-color .12s, color .12s; } }
