:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-elevated: #1c2128;
  --bg-inset: #010409;
  --border: #30363d;
  --border-muted: #21262d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-faint: #6e7681;
  --accent: #58a6ff;
  --accent-dim: #388bfd26;
  --critical: #f85149;
  --high: #db8b1a;
  --medium: #d4a72c;
  --low: #58a6ff;
  --info: #8b949e;
  --cat-security: #f778ba;
  --cat-quality: #a5d6ff;
  --cat-performance: #7ee787;
  --cat-flexibility: #d2a8ff;
  --cat-consistency: #ffa657;
  --sidebar-w: 264px;
  --radius: 10px;
  --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, "SF Mono", Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 15px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-weight: 600; }

/* ---------- Layout & sidebar ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; top: 0; left: 0; width: var(--sidebar-w); height: 100vh;
  background: var(--bg-card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 100; overflow-y: auto;
}
.sidebar-header { padding: 1.1rem 1rem 0.9rem; border-bottom: 1px solid var(--border); }
.sidebar-header h1 { margin: 0 0 0.25rem; font-size: 0.98rem; }
.sidebar-header .task-id { font-size: 0.72rem; color: var(--text-muted); letter-spacing: 0.04em; }
.sidebar nav { padding: 0.6rem 0; flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: 0.5rem; justify-content: space-between;
  padding: 0.45rem 1rem; color: var(--text-muted); font-size: 0.86rem;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { color: var(--text); background: var(--bg-elevated); text-decoration: none; }
.sidebar nav a.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-dim); }
.sidebar nav a .nav-count {
  font-size: 0.68rem; color: var(--text-faint); font-family: var(--font-mono);
  background: var(--bg-inset); border-radius: 999px; padding: 0.05rem 0.45rem;
}
.sidebar-footer { padding: 0.8rem 1rem; border-top: 1px solid var(--border); font-size: 0.72rem; color: var(--text-faint); }
.sidebar-toggle {
  display: none; position: fixed; top: 0.7rem; left: 0.7rem; z-index: 200;
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  padding: 0.45rem 0.7rem; border-radius: 6px; cursor: pointer;
}
.main { margin-left: var(--sidebar-w); flex: 1; padding: 2rem 2.5rem 5rem; max-width: 1240px; }

.hero h2 { margin: 0 0 0.4rem; font-size: 1.7rem; }
.hero .lead { color: var(--text-muted); max-width: 78ch; margin: 0; }
.mvp-note {
  margin-top: 1rem; padding: 0.7rem 1rem; background: var(--bg-card);
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius); font-size: 0.85rem; color: var(--text-muted);
}
section { margin-bottom: 2.75rem; scroll-margin-top: 1rem; }
section > h2 {
  margin: 0 0 0.4rem; font-size: 1.28rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border);
}
section > .section-hint { color: var(--text-muted); font-size: 0.85rem; margin: 0 0 1.25rem; }

/* ---------- KPI ---------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.9rem; margin: 1.4rem 0 0;
}
.kpi-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.9rem 1.05rem; position: relative; overflow: hidden;
}
.kpi-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--border); }
.kpi-card.critical::before { background: var(--critical); }
.kpi-card.high::before { background: var(--high); }
.kpi-card.medium::before { background: var(--medium); }
.kpi-card.low::before { background: var(--low); }
.kpi-card.accent::before { background: var(--accent); }
.kpi-card .value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.kpi-card.critical .value { color: var(--critical); }
.kpi-card.high .value { color: var(--high); }
.kpi-card.medium .value { color: var(--medium); }
.kpi-card.low .value { color: var(--low); }
.kpi-card.accent .value { color: var(--accent); }
.kpi-card .label { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.2rem; }
.kpi-card.clickable { cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
.kpi-card.clickable:hover { border-color: var(--accent); transform: translateY(-1px); }
.kpi-card.svc::before { background: var(--svc, var(--accent)); }
.kpi-card.svc .value { color: var(--text); }
.kpi-card .kpi-sub { font-size: 0.66rem; color: var(--text-faint); margin-top: 0.3rem; font-family: var(--font-mono); }

/* ---------- Charts ---------- */
.charts-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.1rem; }
.chart-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.95rem 1.1rem;
}
.chart-card.full-width { grid-column: 1 / -1; }
.chart-card h3 { margin: 0 0 0.2rem; font-size: 0.92rem; }
.chart-card .chart-sub { margin: 0 0 0.6rem; font-size: 0.76rem; color: var(--text-faint); }
.chart-wrap { position: relative; width: 100%; height: 300px; }
.chart-wrap.tall { height: 440px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 0.12rem 0.5rem; border-radius: 999px;
  font-size: 0.66rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
  white-space: nowrap;
}
.badge-critical { background: #f8514926; color: var(--critical); }
.badge-high { background: #db8b1a26; color: #e3a93f; }
.badge-medium { background: #d4a72c26; color: var(--medium); }
.badge-low { background: #58a6ff26; color: var(--low); }
.badge-info { background: #8b949e26; color: var(--info); }
.badge-confidence { background: var(--accent-dim); color: var(--accent); font-size: 0.62rem; text-transform: none; }
.badge-source { background: var(--bg-inset); color: var(--text-faint); font-size: 0.62rem; text-transform: none; font-family: var(--font-mono); }
.badge-unit { background: var(--bg-inset); color: var(--text-muted); font-family: var(--font-mono); text-transform: none; }
.badge-svc { text-transform: none; font-size: 0.64rem; font-family: var(--font-mono); background: var(--bg-inset); color: var(--text-muted); }
.badge-svc.svc-services { background: #f778ba22; color: #f4a9d2; }
.badge-svc.svc-agent { background: #7ee78722; color: #7ee787; }
.badge-svc.svc-backend { background: #a5d6ff22; color: #a5d6ff; }
.badge-svc.svc-infra { background: #ffa65722; color: #ffa657; }
.badge-svc.svc-crosscut { background: #d2a8ff22; color: #d2a8ff; }
.badge-unverified { background: #bb800926; color: #d2a857; text-transform: none; }
.badge-cat { text-transform: none; font-size: 0.64rem; }
.badge-cat.Security { background: #f778ba22; color: var(--cat-security); }
.badge-cat[data-cat="Code Quality"] { background: #a5d6ff22; color: var(--cat-quality); }
.badge-cat.Performance { background: #7ee78722; color: var(--cat-performance); }
.badge-cat.Flexibility { background: #d2a8ff22; color: var(--cat-flexibility); }
.badge-cat.Consistency { background: #ffa65722; color: var(--cat-consistency); }
.cat-approx { opacity: 0.7; font-style: italic; }

/* ---------- Curated critical cards ---------- */
.finding-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 0.7rem; border-left: 4px solid var(--critical); overflow: hidden;
}
.finding-card .fc-head { padding: 0.8rem 1rem; cursor: pointer; display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: baseline; }
.finding-card .fc-head:hover { background: var(--bg-elevated); }
.finding-card .fc-title { flex: 1 1 60%; font-weight: 500; }
.finding-card .fc-body { display: none; padding: 0 1rem 0.95rem; font-size: 0.875rem; color: var(--text-muted); border-top: 1px solid var(--border-muted); }
.finding-card .fc-body.open { display: block; padding-top: 0.75rem; }
.finding-card .fc-files { font-family: var(--font-mono); font-size: 0.78rem; color: var(--accent); word-break: break-word; }
.finding-card .fc-sources { font-size: 0.78rem; color: var(--text-faint); margin-top: 0.45rem; }

/* ---------- Data table (dedup) ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.data-table th, .data-table td { padding: 0.55rem 0.7rem; text-align: left; border-bottom: 1px solid var(--border-muted); vertical-align: top; }
.data-table th { color: var(--text-muted); font-weight: 500; font-size: 0.78rem; position: sticky; top: 0; background: var(--bg); }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--bg-elevated); }
.data-table .dx-id { font-family: var(--font-mono); color: var(--accent); font-weight: 600; white-space: nowrap; }
.data-table .dx-conf { color: var(--text-faint); white-space: nowrap; }

/* ---------- Aspects ---------- */
.aspect-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.aspect-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1.1rem; }
.aspect-card .aspect-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.45rem; gap: 0.5rem; }
.aspect-card .aspect-title { font-weight: 600; }
.aspect-card .score-dots { display: flex; gap: 4px; }
.aspect-card .score-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.aspect-card .score-dot.filled { background: var(--accent); }
.aspect-card .aspect-sum { font-size: 0.82rem; color: var(--text-muted); margin: 0; }

/* ---------- Roadmap ---------- */
.roadmap-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0.9rem; }
.roadmap-stage { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1.05rem; }
.roadmap-stage.s0 { border-top: 3px solid var(--critical); }
.roadmap-stage.s1 { border-top: 3px solid var(--high); }
.roadmap-stage.s2 { border-top: 3px solid var(--medium); }
.roadmap-stage.s3 { border-top: 3px solid var(--low); }
.roadmap-stage h3 { margin: 0 0 0.6rem; font-size: 0.95rem; }
.roadmap-stage .stage-num { display: inline-block; background: var(--accent-dim); color: var(--accent); padding: 0.1rem 0.45rem; border-radius: 4px; font-size: 0.72rem; margin-right: 0.4rem; font-family: var(--font-mono); }
.roadmap-list { margin: 0; padding-left: 1.1rem; }
.roadmap-list li { margin-bottom: 0.4rem; font-size: 0.84rem; }
.roadmap-list .rl-ref { font-family: var(--font-mono); font-size: 0.72rem; color: var(--accent); cursor: pointer; }

/* ---------- Explorer ---------- */
.explorer-toolbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding: 0.6rem 0 0.8rem; margin-bottom: 0.5rem; border-bottom: 1px solid var(--border);
}
.facet-row { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; margin-bottom: 0.55rem; }
.facet-label { font-size: 0.72rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; width: 58px; flex-shrink: 0; }
.facet-pill {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text-muted);
  border-radius: 999px; padding: 0.2rem 0.65rem; font-size: 0.78rem; cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.35rem; user-select: none;
}
.facet-pill:hover { border-color: var(--accent); color: var(--text); }
.facet-pill .pill-count { font-size: 0.68rem; color: var(--text-faint); font-family: var(--font-mono); }
.facet-pill.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.facet-pill.active.sev-critical { background: #f8514922; border-color: var(--critical); color: var(--critical); }
.facet-pill.active.sev-high { background: #db8b1a22; border-color: var(--high); color: #e3a93f; }
.facet-pill.active.sev-medium { background: #d4a72c22; border-color: var(--medium); color: var(--medium); }
.facet-pill.active.sev-low { background: #58a6ff22; border-color: var(--low); color: var(--low); }
.facet-pill.active.sev-info { background: #8b949e22; border-color: var(--info); color: var(--info); }
.facet-pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.explorer-search {
  flex: 1; min-width: 200px; padding: 0.4rem 0.7rem; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 7px; color: var(--text); font-size: 0.85rem;
}
.explorer-search:focus { outline: none; border-color: var(--accent); }
.explorer-status { display: flex; align-items: center; gap: 0.8rem; font-size: 0.8rem; color: var(--text-muted); flex-wrap: wrap; }
.explorer-status .count-num { color: var(--text); font-weight: 600; }
.btn-clear { background: none; border: 1px solid var(--border); color: var(--text-muted); border-radius: 6px; padding: 0.2rem 0.6rem; font-size: 0.76rem; cursor: pointer; }
.btn-clear:hover { border-color: var(--critical); color: var(--critical); }
.active-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.active-chip { display: inline-flex; align-items: center; gap: 0.3rem; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 999px; padding: 0.12rem 0.55rem; font-size: 0.73rem; color: var(--text-muted); }
.active-chip .x { cursor: pointer; color: var(--text-faint); font-weight: 700; }
.active-chip .x:hover { color: var(--critical); }

.findings-list { margin-top: 0.6rem; }
.finding-row { border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: 8px; margin-bottom: 0.4rem; background: var(--bg-card); overflow: hidden; }
.finding-row.sev-critical { border-left-color: var(--critical); }
.finding-row.sev-high { border-left-color: var(--high); }
.finding-row.sev-medium { border-left-color: var(--medium); }
.finding-row.sev-low { border-left-color: var(--low); }
.finding-row.sev-info { border-left-color: var(--info); }
.fr-head { display: flex; align-items: baseline; gap: 0.5rem; padding: 0.6rem 0.85rem; cursor: pointer; }
.fr-head:hover { background: var(--bg-elevated); }
.fr-tag { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-faint); flex-shrink: 0; min-width: 2.5rem; }
.fr-title { flex: 1; font-size: 0.9rem; }
.fr-title code { font-family: var(--font-mono); font-size: 0.84em; background: var(--bg-inset); padding: 0.05rem 0.3rem; border-radius: 4px; color: var(--text); }
.fr-meta { display: flex; gap: 0.35rem; align-items: center; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.fr-files-n { font-size: 0.7rem; color: var(--text-faint); font-family: var(--font-mono); }
.fr-detail { display: none; padding: 0.25rem 0.95rem 0.95rem; border-top: 1px solid var(--border-muted); }
.finding-row.expanded .fr-detail { display: block; }
.fr-filechips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.6rem 0; }
.file-ref-chip { font-family: var(--font-mono); font-size: 0.74rem; background: var(--bg-inset); border: 1px solid var(--border-muted); color: var(--accent); border-radius: 5px; padding: 0.1rem 0.4rem; word-break: break-all; }
.fr-actions { margin-top: 0.7rem; display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.btn-source { background: var(--accent-dim); border: 1px solid var(--accent); color: var(--accent); border-radius: 6px; padding: 0.28rem 0.7rem; font-size: 0.78rem; cursor: pointer; text-decoration: none; }
.btn-source:hover { background: #388bfd44; text-decoration: none; }
.fr-empty { color: var(--text-faint); font-size: 0.82rem; font-style: italic; }
.explorer-empty { text-align: center; color: var(--text-faint); padding: 3rem 1rem; }

/* ---------- Prose (rendered finding bodies + source pages) ---------- */
.prose { font-size: 0.875rem; line-height: 1.6; color: var(--text-muted); }
.prose > *:first-child { margin-top: 0; }
.prose > *:last-child { margin-bottom: 0; }
.prose p, .prose li { color: var(--text-muted); }
.prose strong { color: var(--text); }
.prose h1, .prose h2, .prose h3, .prose h4 { color: var(--text); margin: 1.2rem 0 0.5rem; line-height: 1.3; }
.prose h1 { font-size: 1.3rem; } .prose h2 { font-size: 1.12rem; } .prose h3 { font-size: 1rem; } .prose h4 { font-size: 0.92rem; }
.prose code { font-family: var(--font-mono); background: var(--bg-inset); padding: 0.08rem 0.32rem; border-radius: 4px; font-size: 0.82em; color: var(--text); }
.prose pre { background: var(--bg-inset); border: 1px solid var(--border); border-radius: 7px; padding: 0.7rem 0.95rem; overflow-x: auto; }
.prose pre code { background: none; padding: 0; font-size: 0.8rem; }
.prose table { width: 100%; border-collapse: collapse; margin: 0.7rem 0; font-size: 0.82rem; }
.prose th, .prose td { border: 1px solid var(--border); padding: 0.35rem 0.55rem; text-align: left; }
.prose th { background: var(--bg-card); color: var(--text); }
.prose blockquote { margin: 0.7rem 0; padding: 0.2rem 0.9rem; border-left: 3px solid var(--border); color: var(--text-faint); }
.prose a { color: var(--accent); }

/* ---------- Source report pages ---------- */
.source-page { background: var(--bg); }
.source-wrap { max-width: 940px; margin: 0 auto; padding: 2rem 1.5rem 5rem; }
.source-back { margin: 0 0 0.4rem; font-size: 0.85rem; }
.source-file { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-faint); margin: 0 0 1.5rem; }
.source-wrap :target { scroll-margin-top: 1rem; background: #d4a72c1f; border-radius: 4px; box-shadow: 0 0 0 6px #d4a72c1f; }

/* ---------- Glossary ---------- */
.glossary-group { margin-bottom: 1.6rem; }
.glossary-group h3 { font-size: 1rem; margin: 0 0 0.6rem; color: var(--text); }
.glossary-group .g-note { font-size: 0.8rem; color: var(--text-faint); margin: 0.6rem 0 0; }
.g-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.6rem; }
.g-item { display: flex; gap: 0.6rem; align-items: baseline; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.8rem; }
.g-item .g-def { font-size: 0.82rem; color: var(--text-muted); }
.g-unit-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.g-unit-table th, .g-unit-table td { padding: 0.45rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border-muted); vertical-align: top; }
.g-unit-table th { color: var(--text-muted); font-weight: 500; font-size: 0.78rem; }
.g-unit-table .g-unit-risk { color: var(--text-muted); }
#glossary :target { background: #d4a72c1f; border-radius: 4px; box-shadow: 0 0 0 6px #d4a72c1f; scroll-margin-top: 1rem; }

/* ---------- Glossary "?" chips in finding detail ---------- */
.fr-facetbar { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; margin-bottom: 0.7rem; padding-bottom: 0.6rem; border-bottom: 1px solid var(--border-muted); }
.fr-facetbar .fb-item { display: inline-flex; align-items: center; gap: 0.2rem; }
.g-chip { display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--border); color: var(--text-faint); font-size: 0.62rem; font-weight: 700; line-height: 1; text-decoration: none; }
.g-chip:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

/* ---------- highlight.js (github-dark) integration ---------- */
/* github-dark sets `pre code.hljs { padding: 1em }` (specificity 0,1,2); this
   override (0,2,2) wins regardless of link order, so highlighted blocks keep the
   dashboard's own .prose pre framing (--bg-inset bg + padding) and don't double up.
   The .hljs-* token colors still come from the vendored github-dark theme. */
.prose pre code.hljs { padding: 0; background: transparent; }

/* ---------- Utilities ---------- */
.hidden { display: none !important; }

@media (max-width: 960px) {
  .charts-grid, .aspect-grid { grid-template-columns: 1fr; }
  .sidebar { transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .main { margin-left: 0; padding: 3.5rem 1.1rem 3rem; }
  .facet-label { width: 100%; }
}
