/* 审计搭子 AuditPilot — UI system
   Ledger-like: paper surface, ink text, one audit-green accent, mono numerals. */

:root {
  --bg: #f4f3ee;
  --surface: #ffffff;
  --surface-2: #f9f8f5;
  --sunken: #efede6;
  --line: #e3e0d7;
  --line-strong: #cfcbc0;
  --ink: #1b1d1f;
  --ink-2: #53575c;
  --ink-3: #8b8e92;
  --accent: #0d6b59;
  --accent-ink: #ffffff;
  --accent-soft: #e2eeea;
  --high: #b3261e;
  --high-soft: #fbe9e7;
  --mid: #9a5b00;
  --mid-soft: #fbf0d9;
  --low: #2e7a46;
  --low-soft: #e5f1e8;
  --shadow: 0 1px 2px rgba(27, 29, 31, .04), 0 4px 16px rgba(27, 29, 31, .04);
  --shadow-pop: 0 12px 40px rgba(27, 29, 31, .16);
  --r: 10px;
  --r-sm: 6px;
  --sans: "PingFang SC", "HarmonyOS Sans SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121315;
    --surface: #1a1b1e;
    --surface-2: #1f2023;
    --sunken: #16171a;
    --line: #2b2d31;
    --line-strong: #3a3d42;
    --ink: #ecebe6;
    --ink-2: #a9aaa8;
    --ink-3: #74777b;
    --accent: #4db39b;
    --accent-ink: #0b1a16;
    --accent-soft: #173029;
    --high: #f07a6e;
    --high-soft: #3a1e1b;
    --mid: #e2a64c;
    --mid-soft: #33281a;
    --low: #6cc38b;
    --low-soft: #1a3022;
    --shadow: none;
    --shadow-pop: 0 16px 48px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121315; --surface: #1a1b1e; --surface-2: #1f2023; --sunken: #16171a;
  --line: #2b2d31; --line-strong: #3a3d42; --ink: #ecebe6; --ink-2: #a9aaa8; --ink-3: #74777b;
  --accent: #4db39b; --accent-ink: #0b1a16; --accent-soft: #173029;
  --high: #f07a6e; --high-soft: #3a1e1b; --mid: #e2a64c; --mid-soft: #33281a; --low: #6cc38b; --low-soft: #1a3022;
  --shadow: none; --shadow-pop: 0 16px 48px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden, [hidden] { display: none !important; }
.mono, code { font-family: var(--mono); font-size: .92em; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.prewrap { white-space: pre-wrap; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 24px;
  padding: 20px 14px;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.seal { width: 34px; height: 34px; flex: none; display: block; }
.brand-name { display: flex; flex-direction: column; font-weight: 650; font-size: 15px; line-height: 1.2; }
.brand-name small { font: 500 11px/1.3 var(--mono); color: var(--ink-3); letter-spacing: .02em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 500;
}
.nav-link svg, .search-trigger svg {
  width: 17px; height: 17px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.nav-link:hover { background: var(--sunken); color: var(--ink); }
.nav-link.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.nav-link.is-active svg { color: var(--accent); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.search-trigger {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink-3); cursor: pointer; text-align: left;
}
.search-trigger span { flex: 1; }
.search-trigger:hover { border-color: var(--line-strong); color: var(--ink-2); }
kbd { font: 11px var(--mono); padding: 1px 5px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink-3); }
.health { display: flex; align-items: center; gap: 8px; padding: 0 6px; font-size: 12px; color: var(--ink-3); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--low); flex: none; }
.health.is-warn .dot { background: var(--mid); }

.main { min-width: 0; padding: 26px 36px 64px; max-width: 1360px; width: 100%; }
.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  min-height: 40px; margin-bottom: 22px;
}
.page-head h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-actions:empty { display: none; }

/* ---------- Primitives ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font-weight: 500; font-size: 13px; white-space: nowrap; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--sunken); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--sunken); color: var(--ink); }
.btn.danger { color: var(--high); }
.btn.sm, .record-actions .btn, .item .btn { height: 28px; padding: 0 10px; font-size: 12px; }
.text-link { color: var(--accent); font-size: 13px; font-weight: 500; }
.text-link:hover { text-decoration: underline; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .label { font-size: 12px; font-weight: 500; color: var(--ink-2); }
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea {
  width: 100%; min-height: 34px; padding: 6px 10px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; line-height: 1.55; }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="file"] { font-size: 13px; color: var(--ink-2); max-width: 100%; }
input[type="file"]::file-selector-button {
  margin-right: 10px; height: 30px; padding: 0 12px; cursor: pointer;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface); color: var(--ink);
}

.badge, .status-chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px; border-radius: 4px;
  background: var(--sunken); color: var(--ink-2);
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.badge.high, .badge.blocked, .badge.danger, .badge.critical { background: var(--high-soft); color: var(--high); }
.badge.medium, .badge.review, .badge.warning, .badge.needs_review { background: var(--mid-soft); color: var(--mid); }
.badge.low, .badge.pass, .badge.success, .badge.passed { background: var(--low-soft); color: var(--low); }

/* ---------- Layout ---------- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.layout-2 { grid-template-columns: minmax(0, 1fr) 340px; }
.layout-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.section { margin-top: 28px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar.stretch { flex-wrap: nowrap; }
.toolbar.stretch input { flex: 1; }
.toolbar .spacer { flex: 1; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.panel.flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head > div { min-width: 0; }
.panel-title, .section-title h2 { font-size: 14px; font-weight: 600; }
.panel > .panel-title { margin-bottom: 12px; }
.panel-meta { font-size: 12px; color: var(--ink-3); }
.sub-title { font-size: 12px; font-weight: 600; color: var(--ink-3); margin: 18px 0 8px; letter-spacing: .02em; }
.sub-title:first-child { margin-top: 0; }

/* Stat strip — ledger columns */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow); overflow: hidden;
}
.stat { padding: 14px 18px; border-left: 1px solid var(--line); min-width: 0; }
.stat:first-child { border-left: 0; }
.stat dt, .stat .k { font-size: 12px; color: var(--ink-3); }
.stat dd, .stat .v { margin: 2px 0 0; font: 600 24px/1.25 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .v.text { font: 600 18px/1.6 var(--sans); }
.stat small { display: block; font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Tabs */
.tabs {
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--line); margin-bottom: 18px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border: 0; background: none; cursor: pointer;
  color: var(--ink-3); font-weight: 500; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px; }
.tab .step { font: 500 11px var(--mono); color: var(--ink-3); }
.tab[aria-selected="true"] .step { color: var(--accent); }
.tab-panel[hidden] { display: none; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 8px; background: var(--sunken); }
.seg { height: 28px; padding: 0 12px; border: 0; border-radius: 6px; background: none; color: var(--ink-2); cursor: pointer; font-size: 13px; font-weight: 500; }
.seg.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* Disclosure */
details.fold { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
details.fold > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500; color: var(--ink-2);
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: "›"; display: inline-block; width: 12px; transition: transform .15s; font-size: 16px; line-height: 1; }
details.fold[open] > summary::before { transform: rotate(90deg); }
details.fold > summary:hover { color: var(--ink); }
details.fold > .fold-body { padding-top: 14px; }

details.section-fold { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); margin-top: 16px; }
details.section-fold > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; font-weight: 600;
}
details.section-fold > summary::-webkit-details-marker { display: none; }
details.section-fold > summary::after { content: "展开"; font-size: 12px; font-weight: 500; color: var(--ink-3); }
details.section-fold[open] > summary::after { content: "收起"; }
details.section-fold > summary .panel-meta { margin-left: auto; font-weight: 400; }
details.section-fold > .fold-body { padding: 0 20px 20px; }

/* ---------- Lists & items ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.list.dense { gap: 6px; }
.scroll-panel { max-height: 520px; overflow-y: auto; }
.item, .card {
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  min-width: 0; overflow-wrap: anywhere;
}
.item.compact { padding: 10px 12px; }
.item > strong, .card > strong { display: block; font-weight: 600; }
.item p, .card p { margin-top: 2px; }
.item-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.item-head strong { min-width: 0; }
.clickable { cursor: pointer; }
.clickable:hover, .hover-lift:hover { border-color: var(--line-strong); }
.selected-task { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag-row, .trace-summary, .loop-status, .assertion-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.trace-summary span, .loop-status span, .assertion-list span {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 4px;
  background: var(--sunken); color: var(--ink-2); font-size: 12px;
}
.loop-status { margin-top: 0; }
.assertion-list span.pass { background: var(--low-soft); color: var(--low); }
.compact-bullets { margin: 6px 0 0; padding-left: 18px; color: var(--ink-2); }

.empty, .empty-compact {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 18px 2px; color: var(--ink-3); font-size: 13px;
}
.empty strong, .empty-compact strong { color: var(--ink-2); font-weight: 500; }
.panel > p.muted:only-child, .list > p.muted { color: var(--ink-3); font-size: 13px; padding: 6px 0; }

/* record rows (archive / history) */
details.record-detail, details.eval-detail { padding: 0; }
details.record-detail > summary, details.eval-detail > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px;
}
details.record-detail > summary::-webkit-details-marker, details.eval-detail > summary::-webkit-details-marker { display: none; }
details.eval-detail > :not(summary) { margin-left: 12px; margin-right: 12px; }
details.eval-detail[open] > :last-child { margin-bottom: 12px; }
.record-title { display: flex; flex-direction: column; min-width: 0; }
.record-title strong { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-title small { color: var(--ink-3); font: 11px var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.record-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.detail-body { padding: 0 12px 12px; }

/* tables */
.matrix { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 500; font-size: 12px; color: var(--ink-3); padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td strong { display: block; font-weight: 600; }
td small { color: var(--ink-3); font: 11px var(--mono); }

/* metric cards created by JS */
.card.metric { padding: 12px 14px; }
.metric-value { font: 600 22px/1.3 var(--mono); font-variant-numeric: tabular-nums; }
.metric-value.small { font-size: 18px; }
.metric-label { font-size: 12px; color: var(--ink-3); }
.score-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 6px; margin-top: 8px; }
.score-pill { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); }
.score-pill span { font-size: 11px; color: var(--ink-3); overflow-wrap: anywhere; }
.score-pill strong { font: 600 15px var(--mono); }

/* progress */
.progress-track { height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 3px; }
progress { width: 100%; height: 6px; appearance: none; border: 0; border-radius: 3px; background: var(--sunken); overflow: hidden; margin: 10px 0 4px; }
progress::-webkit-progress-bar { background: var(--sunken); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 3px; }
progress::-moz-progress-bar { background: var(--accent); }

/* quality ring */
.quality { display: flex; align-items: flex-start; gap: 16px; font-size: 13px; }
.quality > div:last-child > * + * { margin-top: 6px; }
.quality-ring {
  --score: 0;
  position: relative; flex: none; width: 80px; height: 80px; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--ring, var(--accent)) calc(var(--score) * 1%), var(--sunken) 0);
}
.quality-ring::before { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--surface); }
.quality-ring span { position: relative; font: 600 16px var(--mono); letter-spacing: -.03em; }
.quality-ring[data-status="blocked"] { --ring: var(--high); }
.quality-ring[data-status="review"] { --ring: var(--mid); }
.quality-ring[data-status="pass"] { --ring: var(--low); }
.quality .list { flex: 1; }

/* skeleton */
.skeleton-lines { display: flex; flex-direction: column; gap: 8px; }
.skeleton-line { height: 10px; border-radius: 4px; background: linear-gradient(90deg, var(--sunken), var(--line), var(--sunken)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* markdown */
.markdown-body { line-height: 1.7; overflow-wrap: anywhere; }
.markdown-body > * + * { margin-top: 10px; }
.markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5 { font-size: 15px; font-weight: 650; margin-top: 18px; }
.markdown-body h2:first-child, .markdown-body h3:first-child { margin-top: 0; }
.markdown-body ul, .markdown-body ol { padding-left: 20px; margin-bottom: 0; }
.markdown-body li + li { margin-top: 3px; }
.markdown-body code { padding: 1px 5px; border-radius: 4px; background: var(--sunken); }
.markdown-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.markdown-table th { background: var(--surface-2); }

/* ---------- Toast & command palette ---------- */
.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast {
  max-width: 360px; padding: 10px 14px; border-radius: 8px;
  background: var(--ink); color: var(--bg); font-size: 13px; box-shadow: var(--shadow-pop);
  opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--high); color: #fff; }
.command-overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; justify-content: center; align-items: flex-start;
  padding: 12vh 16px 16px; background: rgba(20, 20, 18, .32);
}
.command-panel-wrap { width: min(620px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-pop); overflow: hidden; }
.command-input-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.command-input-row input { border: 0 !important; box-shadow: none !important; padding-left: 0 !important; font-size: 15px; }
.command-icon { color: var(--ink-3); font-size: 18px; }
.command-hint { display: none; }
.command-results { max-height: 52vh; overflow-y: auto; padding: 6px; }
.command-result { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 10px; border: 0; border-radius: 6px; background: none; text-align: left; cursor: pointer; }
.command-result.active { background: var(--sunken); }
.command-type { flex: none; width: 36px; font-size: 11px; color: var(--ink-3); }
.command-copy { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.command-copy strong { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.command-copy small { color: var(--ink-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.command-badge { font-size: 12px; color: var(--ink-3); }
.command-empty { display: flex; flex-direction: column; gap: 2px; padding: 20px 12px; color: var(--ink-3); font-size: 13px; }
.command-empty strong { color: var(--ink-2); font-weight: 500; }
body.command-open { overflow: hidden; }

/* ---------- Home ---------- */
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; margin-top: 16px; align-items: start; }
.project-table td:nth-child(2), .project-table td:nth-child(4) { white-space: nowrap; }
.queue-row, .readiness-row, .trace-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line);
}
.queue-row:last-child, .readiness-row:last-child, .trace-row:last-child { border-bottom: 0; }
.queue-row > div, .readiness-row > div, .trace-row > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.queue-row strong, .readiness-row strong, .trace-row strong { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-row small, .readiness-row small, .trace-row small { color: var(--ink-3); font-size: 12px; }
.readiness-mark, .trace-mark { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--ink-3); }
.readiness-mark.pass, .trace-mark.success { background: var(--low); }
.readiness-mark.review { background: var(--mid); }
.readiness-mark.blocked, .trace-mark.danger { background: var(--high); }

.templates { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.tpl {
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
  transition: border-color .12s, transform .12s;
}
.tpl:hover { border-color: var(--accent); }
.tpl-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-3); }
.tpl-top .std { font-family: var(--mono); }
.tpl h3 { font-size: 14px; font-weight: 600; }
.tpl p { font-size: 13px; color: var(--ink-2); line-height: 1.55; }
.tpl-meta { margin-top: auto; padding-top: 6px; font: 12px var(--mono); color: var(--ink-3); }
.risk-dot { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; }
.risk-dot::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: var(--ink-3); }
.risk-dot.high::before { background: var(--high); }
.risk-dot.medium::before { background: var(--mid); }
.risk-dot.low::before { background: var(--low); }

.control-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px 32px; align-items: center; gap: 12px; padding: 8px 0; }
.control-meta { display: flex; flex-direction: column; min-width: 0; }
.control-meta strong { font-weight: 500; }
.control-meta span { font-size: 12px; color: var(--ink-3); }
.control-score { font: 600 13px var(--mono); text-align: right; }

/* ---------- Audit ---------- */
.audit-top { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.scenario-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.scenario-chips .scenario {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
  font-size: 12px; color: var(--ink-2); cursor: pointer;
}
.scenario-chips .scenario:hover { border-color: var(--accent); color: var(--ink); }
.scenario-chips .scenario.is-picked { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.scenario-chips .scenario > :not(strong) { display: none; }
.scenario-chips .scenario strong { font-weight: 500; }
.form-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr; gap: 12px; }
.run-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.run-bar .spacer { flex: 1; }

.trace-list { display: flex; flex-direction: column; }
.trace-item { position: relative; padding: 0 0 12px 20px; }
.trace-item::before { content: ""; position: absolute; left: 0; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.trace-item.is-running::before { background: var(--surface); border: 2px solid var(--accent); animation: blink 1s infinite; }
.trace-item.is-queued::before { background: var(--line-strong); }
.trace-item:not(:last-child)::after { content: ""; position: absolute; left: 4px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.trace-stage { font: 500 12px var(--mono); color: var(--ink-3); }
.trace-detail { font-size: 13px; color: var(--ink); }

.side-stack { display: flex; flex-direction: column; gap: 16px; }
.kpis { margin-top: 16px; }
.timeline { display: flex; flex-direction: column; gap: 8px; }
.timeline-step { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; align-items: start; }
.step-index { display: grid; place-items: center; width: 24px; height: 24px; margin-top: 8px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font: 600 12px var(--mono); }
.delivery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.delivery-card { display: flex; flex-direction: column; gap: 2px; }
.delivery-number { font: 600 22px var(--mono); }
.item .grid.grid-4 { grid-template-columns: 1.1fr 1fr 1.6fr auto; gap: 8px; align-items: center; }
#findings, #recommendations { gap: 10px; }

/* ---------- Chat ---------- */
.chat-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; height: calc(100vh - 114px); min-height: 520px; }
.chat-main { display: flex; flex-direction: column; min-height: 0; padding: 0; overflow: hidden; }
.chat-box { flex: 1; overflow-y: auto; padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; }
.message { position: relative; max-width: 82%; padding: 12px 16px; border-radius: 12px; line-height: 1.7; overflow-wrap: anywhere; }
.message.ai { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-top-left-radius: 4px; }
.message.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-top-right-radius: 4px; white-space: pre-wrap; }
.message-copy { position: absolute; top: 8px; right: 8px; height: 24px; padding: 0 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink-3); font-size: 11px; cursor: pointer; opacity: 0; transition: opacity .12s; }
.message:hover .message-copy { opacity: 1; }
.typing-title { font-weight: 500; }
.typing-step { font-size: 12px; color: var(--ink-3); }
.typing-dots { display: inline-flex; gap: 4px; margin: 6px 0; }
.typing-dots span { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: blink 1s infinite; }
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 50% { opacity: .25; } }
.agent-chain { display: flex; flex-wrap: wrap; gap: 4px; }
.agent-chip { height: 22px; padding: 0 8px; display: inline-flex; align-items: center; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-size: 12px; }
.chat-compose { border-top: 1px solid var(--line); padding: 12px 16px 14px; background: var(--surface); }
.quick-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.quick-row .btn { height: 28px; font-size: 12px; border-radius: 14px; color: var(--ink-2); }
.chat-rail { overflow-y: auto; }
.chat-rail .panel { padding: 14px 16px; }
.route-plan { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.route-step { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 8px; }
.route-index { font: 500 12px var(--mono); color: var(--ink-3); padding-top: 1px; }
.route-step strong { font-size: 13px; font-weight: 500; }
.route-step p { font-size: 12px; }
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; text-align: right; }
#auditContext .item, #riskPanel .item { padding: 8px 10px; }

/* ---------- Runtime / Training ---------- */
.value-card { display: flex; flex-direction: column; gap: 4px; }
.value-card > strong { font-size: 13px; }
.value-card .muted { font-size: 12px; }
.proposal-stack, .backlog-list, .control-plane { display: flex; flex-direction: column; gap: 8px; }
.proposal-card, .backlog-item, .lane-card, .candidate-card, .quality-card { padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.candidate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.candidate-card > summary, .quality-card > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.candidate-card > summary::-webkit-details-marker, .quality-card > summary::-webkit-details-marker { display: none; }
.lane-card { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 8px; }
.lane-index { font: 500 12px var(--mono); color: var(--ink-3); }
.control-mode { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mini-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.mini-head h3 { font-size: 13px; font-weight: 600; }
.quality-pitch { display: flex; flex-direction: column; gap: 6px; }
.pitch-line { display: flex; gap: 8px; align-items: baseline; font-size: 13px; color: var(--ink-2); }
.signal-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; transform: translateY(-1px); }
.quality-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; }
.quality-scoreline { display: flex; align-items: center; gap: 8px; }
.quality-body { padding-top: 10px; }
.component-evaluation-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.component-score-card { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.component-score-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.component-score-head strong { font-weight: 600; }
.component-score-head .muted { font-size: 12px; }
.step-evaluation { margin-top: 8px; padding: 10px; border-radius: 6px; background: var(--surface-2); }
.metric-toggle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.metric-toggle { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.metric-toggle input { margin-top: 4px; accent-color: var(--accent); }
.metric-toggle-text { display: flex; flex-direction: column; }
.metric-toggle-text strong { font-size: 13px; font-weight: 500; }
.metric-toggle-text small { font-size: 11px; color: var(--ink-3); line-height: 1.45; }
.gate { display: flex; align-items: center; gap: 20px; }
.gate .kv { flex: 1; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form-grid .field:first-child { grid-column: 1 / -1; }
  .templates { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
  .layout-2, .audit-top, .home-grid, .chat-layout, .layout-3 { grid-template-columns: minmax(0, 1fr); }
  .chat-layout { height: auto; }
  .chat-main { height: 72vh; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: sticky; top: 0; z-index: 20; height: auto;
    flex-direction: row; align-items: center; gap: 12px;
    padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line);
    overflow-x: auto; scrollbar-width: none;
  }
  .side::-webkit-scrollbar { display: none; }
  .brand-name, .health, .search-trigger span, .search-trigger kbd, .nav-link svg { display: none; }
  .brand { padding: 0; }
  .nav { flex-direction: row; gap: 2px; }
  .nav-link { padding: 6px 10px; white-space: nowrap; }
  .side-foot { margin: 0 0 0 auto; }
  .search-trigger { padding: 7px; }
  .main { padding: 18px 16px 48px; }
  .page-head h1 { font-size: 20px; }
  .grid-2, .grid-3, .templates { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scenario-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
  .scenario-chips::-webkit-scrollbar { display: none; }
  .scenario-chips .scenario { flex: none; }
  .project-table th:nth-child(3), .project-table td:nth-child(3), .project-table th:nth-child(5), .project-table td:nth-child(5) { display: none; }
  .page-actions { flex: 1; justify-content: flex-end; }
  .page-actions input { flex: 1; width: auto !important; }
  .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .item .grid.grid-4 { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(odd) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
  .message { max-width: 92%; }
  .panel { padding: 16px; }
  .panel.chat-main, .panel.flush { padding: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* JS-rendered card heads: title on its own line, meta below */
.item-head > div > strong, .quality-card summary > div > strong, .candidate-card summary strong { display: block; font-weight: 600; }
.item-head > div > small, .quality-card summary > div > small, .proposal-card small, .backlog-item small { display: block; font-size: 12px; color: var(--ink-3); line-height: 1.5; }
.quality-card summary > div:first-child { min-width: 0; }
.quality-card summary > div > small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.quality-scoreline strong { font: 600 15px var(--mono); }
.quality-body h4 { font-size: 12px; font-weight: 600; color: var(--ink-3); margin-bottom: 4px; }
.proposal-card > * + *, .backlog-item > * + *, .candidate-card .detail-body > * + * { margin-top: 6px; }
