/* ==========================================================================
   Data views: the case brief, the coverage heatmap, the ownership and
   people network, the dashboard's KPI strip and list-age meters, the mini
   coverage bars and stage segments.

   Signal colours are status colours: reserved meanings, never series colours,
   and always with an icon or words. Only red flags (red) and finished work
   (green) carry colour; pending, gaps and "nothing recorded" are steps of
   the neutral ramp.
   ========================================================================== */

.viz-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); padding: var(--sp-6); }
.viz-card + .viz-card { margin-top: var(--sp-4); }
.viz-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3) var(--sp-6); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.viz-head h3 { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-lg); font-weight: 500; }
.viz-head h3 .icon { color: var(--text-3); }
.viz-sub { color: var(--text-3); font-size: var(--fs-sm); margin: calc(-1 * var(--sp-2)) 0 var(--sp-4); }
.viz-legend { list-style: none; display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-xs); color: var(--text-2); }
.viz-legend li { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 6px; border-radius: 2px; border: 1px solid transparent; flex: none; }

/* the state fills, shared by the heatmap, its legend and the mini coverage bars */
.state-redflag { --st-solid: var(--danger); --st-bg: var(--danger-bg); --st-text: var(--danger-text); --st-border: var(--danger-border); }
.state-pending { --st-solid: var(--text-3); --st-bg: var(--med-bg); --st-text: var(--text-2); --st-border: var(--med-border); }
.state-gaps { --st-solid: var(--border-strong); --st-bg: var(--gap-bg); --st-text: var(--text-3); --st-border: var(--border-strong); }
.state-clear { --st-solid: var(--high-solid); --st-bg: var(--high-bg); --st-text: var(--high-text); --st-border: var(--high-border); }
.state-unchecked { --st-solid: var(--border-strong); --st-bg: var(--surface-2); --st-text: var(--text-3); --st-border: var(--border); }
.swatch.state-redflag, .swatch.state-pending, .swatch.state-clear, .swatch.state-gaps { background: var(--st-solid); }
.swatch.state-unchecked { background: transparent; border-color: var(--border-strong); }

/* ---------------------------------------------------------------- the case overview */

.overview > .panel-head { padding: 0 var(--sp-1); }

/* the coverage heatmap */
/* one matrix: every group on the same seven columns, so tiles line up across groups */
.heatmap-groups { display: flex; flex-direction: column; gap: var(--sp-6); }
.heatmap-group-label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); margin-bottom: var(--sp-1); }
.heatmap { list-style: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--sp-8); }
.heat-tile {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(72px, 0.7fr) 148px; grid-template-areas: "name bar counts" "state bar counts";
  align-items: center; column-gap: var(--sp-4); row-gap: 2px; padding: 10px var(--sp-2);
  border-bottom: 1px solid var(--border); color: var(--text); text-decoration: none;
  transition: background-color .15s var(--ease);
}
a.heat-tile:hover { background: var(--surface-2); border-radius: var(--r-md); color: var(--text); }
.heat-name { grid-area: name; font-size: var(--fs-md); font-weight: 500; line-height: 1.3; color: var(--text); }
.heat-state { grid-area: state; display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--st-text); }
.heat-state .icon { width: 12px; height: 12px; }
.heat-counts { grid-area: counts; font-size: var(--fs-xs); color: var(--text-3); text-align: right; }
.heat-counts .mono { font-family: inherit; font-size: inherit; }
.heat-bar { grid-area: bar; display: block; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.heat-bar span { display: block; height: 100%; border-radius: inherit; background: var(--st-solid); }

/* the ownership and people network (server-side SVG) */
.network-scroll { overflow-x: auto; border-radius: var(--r-lg); background: var(--surface-2); }
.network { display: block; max-width: 100%; height: auto; margin: 0 auto; font-family: var(--font); }
.network-scroll.is-wide .network { max-width: none; }
.net-edge { fill: none; stroke: var(--input-border); stroke-width: 1.5; stroke-linejoin: round; }
.net-edge.edge-owner { stroke: var(--text-3); stroke-width: 1.75; }
.net-stake { font: 500 11px var(--font); fill: var(--text-2); paint-order: stroke; stroke: var(--surface-2); stroke-width: 4px; stroke-linejoin: round; }
.net-box { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1; }
.net-rel { fill: transparent; } /* the relation shows in the icon and the label; only the partner is marked */
.rel-partner .net-box { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.rel-partner .net-rel { fill: var(--accent); }
.has-redflag .net-box, .has-confirmed .net-box { stroke: var(--danger); stroke-width: 1.5; }
.has-match:not(.has-redflag):not(.has-confirmed) .net-box { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 3; }
.net-icon { color: var(--text-3); }
.rel-partner .net-icon { color: var(--accent-text); }
.net-name { font-size: 13px; font-weight: 500; fill: var(--text); }
.net-detail { font-size: 11.5px; fill: var(--text-3); }
.net-badge rect { stroke: var(--surface); stroke-width: 2; }
.net-badge text { font: 500 10.5px var(--font); }
.badge-redflag rect, .badge-confirmed rect { fill: var(--danger); }
.badge-redflag text, .badge-confirmed text { fill: var(--on-danger); }
.badge-match rect { fill: var(--accent); }
.badge-match text { fill: var(--on-accent); }
.badge-pep rect { fill: var(--text); }
.badge-pep text { fill: var(--surface); }
a.net-node { cursor: pointer; }
a.net-node:hover .net-box { fill: var(--surface-2); stroke: var(--accent); }
a.net-node:focus { outline: none; }
a.net-node:focus-visible .net-box { stroke: var(--focus); stroke-width: 3; }
.net-key { display: inline-flex; align-items: center; padding: 0 7px; border-radius: var(--r-xs); font: 500 11px/1.6 var(--font); white-space: nowrap; }
.key-redflag, .key-confirmed { background: var(--danger); color: var(--on-danger); }
.key-match { background: var(--accent); color: var(--on-accent); }
.key-pep { background: var(--text); color: var(--surface); }
.network-list { margin-top: var(--sp-3); font-size: var(--fs-sm); }
.network-list > summary { cursor: pointer; color: var(--text); font-weight: 500; width: max-content; }
.network-list h4 { font-size: var(--fs-xs); font-weight: 500; color: var(--text-3); margin: var(--sp-3) 0 var(--sp-1); }
.network-list ul { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.network-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--sp-2); }
.network-list a, .net-list-name { font-weight: 500; }
.network-list .net-key { margin-left: 2px; }

/* ---------------------------------------------------------------- the dashboard */

.kpi-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.6fr); gap: var(--sp-3); margin-bottom: var(--sp-5); }
.kpi {
  position: relative; display: flex; flex-direction: column; gap: 2px; padding: var(--sp-5) var(--sp-6);
  border-radius: var(--r-xl); background: var(--surface); border: 1px solid var(--border); color: var(--text);
  text-decoration: none; overflow: hidden; transition: background-color .15s var(--ease);
}
a.kpi:hover { background: var(--surface-2); color: var(--text); }
.kpi-label { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: 400; color: var(--text-2); }
.kpi-label .icon { display: none; }
.kpi-value { font-size: 40px; font-weight: 500; line-height: 1.1; letter-spacing: -0.01em; margin-top: var(--sp-2); }
.kpi-unit { font-size: var(--fs-lg); font-weight: 500; letter-spacing: 0; color: var(--text-2); }
.kpi-none { color: var(--text-3); }
.kpi-note { font-size: var(--fs-xs); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi-note a { font-weight: 500; }
.kpi-lists .kpi-value { font-size: var(--fs-2xl); margin-bottom: var(--sp-2); }
.list-ages { list-style: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px var(--sp-4); }
.list-age { display: grid; grid-template-columns: 74px minmax(40px, 1fr) auto; align-items: center; gap: var(--sp-2); font-size: var(--fs-2xs); color: var(--text-3); }
.list-age-id { font-size: var(--fs-xs); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-age-text { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.list-age-text .icon { width: 12px; height: 12px; }
/* a meter: the fill is how much of the list's maximum age is used; the track is the same hue, lighter */
.age-meter { display: block; height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.age-meter span { display: block; height: 100%; border-radius: inherit; background: var(--text-3); }
.age-stale .age-meter span { background: var(--accent); }
.age-stale .list-age-text { color: var(--warn-text); font-weight: 500; }
.age-missing .age-meter { background: var(--danger-bg); }
.age-missing .age-meter span { background: var(--danger); }
.age-missing .list-age-text { color: var(--danger-text); font-weight: 500; }
.age-optional .age-meter span { background: transparent; }
.list-fetched .list-age { grid-template-columns: 120px auto; margin-top: 4px; }

/* the case list's mini coverage bar: one cell per report section, in heatmap order */
.mini-coverage { display: grid; grid-template-columns: repeat(17, minmax(0, 1fr)); gap: 2px; margin-top: 7px; max-width: 260px; }
.mini-coverage .cell { height: 6px; border-radius: 1.5px; background: var(--st-solid); }
.mini-coverage .cell.state-unchecked { background: var(--surface-3); }

/* the case list's stage indicator for runs not yet in review */
.stage-progress { display: flex; align-items: center; gap: var(--sp-3); }
.stage-segments { display: inline-grid; grid-template-columns: repeat(8, 1fr); gap: 2px; flex: 1; min-width: 80px; }
.seg { height: 6px; border-radius: 1.5px; background: var(--surface-3); }
.seg.is-done { background: var(--text-2); }
.seg.is-at { background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
.stage-waiting .seg.is-at, .stage-stalled .seg.is-at { background: var(--accent); animation: none; }
.stage-failed .seg.is-at { background: var(--danger); animation: none; }
.stage-todo .seg { background: var(--surface-3); }

/* a read-only copy keeps only the lists card: one wide card */
.kpi-strip.kpi-strip-single { grid-template-columns: minmax(0, 1fr); }
.kpi-strip-single .list-ages { grid-template-columns: repeat(4, minmax(0, 1fr)); }
/* the case list's "Next": what the case needs now */
.next-action { font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap; }
.next-action.is-todo { color: var(--accent-text); font-weight: 500; }

/* ---------------------------------------------------------------- responsive (data views) */

@media (max-width: 1279px) {
  .heatmap { grid-template-columns: 1fr; }
  .kpi-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-lists { grid-column: 1 / -1; }
  .list-ages { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 1023px) {
  .kpi-strip { grid-template-columns: 1fr; }
  .list-ages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------------------------------------------------------------- the case brief (where a case opens) */

.brief-welcome {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-4) var(--sp-8); margin-bottom: var(--sp-5);
  padding: var(--sp-5) var(--sp-6); border-radius: var(--r-xl); background: var(--warn-bg); border: 1px solid var(--warn-border);
}
.brief-welcome > div:first-child { flex: 999 1 420px; }
.brief-welcome-title { font: 500 var(--fs-2xl)/1.2 var(--display); margin-bottom: 4px; }
.brief-welcome p { color: var(--text-2); max-width: 80ch; }
.brief-welcome-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.brief-welcome-actions .icon { width: 16px; height: 16px; }
.brief-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: var(--sp-5); align-items: start; margin-bottom: var(--sp-4); }
.brief-main, .brief-side { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
.brief-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); padding: var(--sp-6); scroll-margin-top: calc(var(--topbar-h) + var(--dossier-h) + var(--sp-6)); }
.brief-card > h2 { font: 500 var(--fs-2xl)/1.2 var(--display); }
.brief-sub { margin-top: 4px; color: var(--text-2); font-size: var(--fs-sm); }
.brief-note { margin-top: var(--sp-4); padding: var(--sp-3); border-radius: var(--r-md); background: var(--surface-2); color: var(--text-2); font-size: var(--fs-sm); }

/* at a glance: the key facts, two columns, each a link to its finding */
.facts { list-style: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--sp-8); margin-top: var(--sp-4); }
.fact { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-3) 0; border-top: 1px solid var(--border); color: var(--text); text-decoration: none; height: 100%; box-sizing: border-box; }
.fact:hover .fact-value { text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
.fact-label { font-size: var(--fs-xs); color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.fact-value { font-size: var(--fs-lg); line-height: 1.35; overflow-wrap: anywhere; }
.fact-source { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 4px; font-size: var(--fs-xs); color: var(--text-2); }
.fact-source .tag { font-size: var(--fs-2xs); padding: 0 7px; }
.fact-conflict { display: inline-flex; align-items: center; gap: 4px; color: var(--accent-text); font-weight: 500; }
.fact-conflict .icon { width: 12px; height: 12px; }

/* worth a closer look: each item says what it is, what was found and why it is here */
.attention { list-style: none; display: flex; flex-direction: column; gap: var(--sp-3); margin-top: var(--sp-4); }
.attention-item { display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: var(--sp-1) var(--sp-3); padding: var(--sp-4); border-radius: var(--r-lg); border: 1px solid var(--border); background: var(--surface-2); scroll-margin-top: calc(var(--topbar-h) + var(--dossier-h) + var(--sp-6)); }
.attention-item.is-flag { background: var(--danger-bg); border-color: var(--danger-border); }
.attention-item.is-conflict, .attention-item.is-match { background: var(--warn-bg); border-color: var(--warn-border); }
.attention-icon { margin-top: 2px; color: var(--text-3); }
.is-flag .attention-icon { color: var(--danger-text); }
.is-conflict .attention-icon, .is-match .attention-icon { color: var(--accent-text); }
.attention-body { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.attention-kind { display: flex; flex-wrap: wrap; gap: 2px var(--sp-2); font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); }
.kind-flag { color: var(--danger-text); }
.kind-warn { color: var(--accent-text); }
.attention-title { font-size: var(--fs-md); color: var(--text); }
.attention-why { font-size: var(--fs-sm); color: var(--text-2); }
.attention-why strong { color: var(--text); font-weight: 600; }
.attention-link { font-size: var(--fs-sm); font-weight: 500; white-space: nowrap; align-self: start; }
.attention .red-flag-findings { margin-top: 4px; font-size: var(--fs-sm); }

/* the sources behind the case, grouped by reliability */
.brief-stats { display: flex; gap: var(--sp-6); margin-top: var(--sp-3); }
.brief-stats div { display: flex; flex-direction: column-reverse; }
.brief-stats dd { font: 400 var(--fs-3xl)/1 var(--display); }
.brief-stats dt { font-size: var(--fs-xs); color: var(--text-2); margin-top: 4px; }
.source-group { padding: var(--sp-3) 0; border-top: 1px solid var(--border); }
.brief-stats + .source-group { margin-top: var(--sp-4); }
.source-group-head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); font-weight: 600; }
.source-group-items { margin-top: 2px; font-size: var(--fs-sm); color: var(--text-2); }

/* the steps to sign-off */
.brief-steps { list-style: none; margin-top: var(--sp-3); }
.brief-steps li { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: var(--sp-3); padding: var(--sp-3) 0; border-top: 1px solid var(--border); }
.brief-step-n { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border-strong); font: 500 var(--fs-xs)/1 var(--mono); color: var(--text-2); }
.brief-steps li.is-done .brief-step-n { background: var(--high-bg); border-color: var(--high-border); color: var(--high-text); }
.brief-step-n .icon { width: 12px; height: 12px; }
.brief-step-title { display: flex; justify-content: space-between; gap: var(--sp-2); font-weight: 600; }
.brief-step-title a { color: var(--text); }
.brief-step-status { font-size: var(--fs-xs); font-weight: 500; color: var(--text-2); text-align: right; }
.brief-step-what { font-size: var(--fs-sm); color: var(--text-2); }

@container (max-width: 980px) {
  .brief-grid { grid-template-columns: minmax(0, 1fr); }
}
@container (max-width: 620px) {
  .facts { grid-template-columns: minmax(0, 1fr); }
  .attention-item { grid-template-columns: 20px minmax(0, 1fr); }
  .attention-link { grid-column: 2; }
}
