/* ConectaClima-Fin — same paper/ink register as SICAC: paper canvas, ink text,
   one confirming green, one challenging red/amber for governance notes, serif
   for headings, mono tabular figures for every number. Both themes must stay
   readable — no colour is hardcoded outside these variables. */

:root {
  --paper: #faf9f5;
  --surface: #ffffff;
  --surface-alt: #f3f2ec;
  --ink: #201f1c;
  --ink-muted: #6b675e;
  --ink-faint: #8f8b80;
  --rule: #ddd9cd;
  --rule-strong: #201f1c;
  --green: #1f5c3a;
  --green-strong: #1f5c3a;
  --green-hover: #16452b;
  --green-bg: #eaf1ec;
  --red: #8c3a2e;
  --red-bg: #f7ede9;
  --amber: #8a6a1e;
  --amber-bg: #f7f0df;
  --row-hover: rgba(31,92,58,0.05);
  --focus: #1f5c3a;
  --shadow-rgb: 32,31,28;

  --band-low: #8c3a2e;
  --band-moderate: #8a6a1e;
  --band-high: #3a6b8a;
  --band-very-high: #1f5c3a;

  --font-serif: 'Source Serif 4', Georgia, serif;
  --font-mono: 'Roboto Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --font-sans: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

:root[data-theme="dark"] {
  --paper: #1c1b18;
  --surface: #242320;
  --surface-alt: #2c2a25;
  --ink: #efece3;
  --ink-muted: #a8a394;
  --ink-faint: #7d7869;
  --rule: #3a382f;
  --rule-strong: #efece3;
  --green: #57b98a;
  --green-strong: #1f7a4c;
  --green-hover: #268257;
  --green-bg: #16261d;
  --red: #e08a72;
  --red-bg: #2e1f1b;
  --amber: #d9b45c;
  --amber-bg: #2e2712;
  --row-hover: rgba(87,185,138,0.10);
  --focus: #57b98a;
  --shadow-rgb: 0,0,0;

  --band-low: #e08a72;
  --band-moderate: #d9b45c;
  --band-high: #77b6e0;
  --band-very-high: #57b98a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
}
body { transition: background 0.2s ease, color 0.2s ease; }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }

.app { max-width: 1180px; margin: 0 auto; padding: 56px 24px 96px; }
.hidden { display: none !important; }

/* ---------- Top bar / masthead ---------- */

/* Lifted above the drawer/modal (z-index 50) so the language and theme toggles
 * stay live while a panel is open — the language change then re-renders the open
 * panel in place (panels.js refreshOpenPanel). */
.top-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; position: relative; z-index: 60; }
.top-bar-slug { font-family: var(--font-mono); font-size: 0.82rem; color: var(--ink-muted); }
.top-bar-controls { display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* Language control — same height and register as the theme toggle beside it. */
.lang-toggle { display: inline-flex; height: 40px; border: 1px solid var(--rule-strong); border-radius: 8px; overflow: hidden; background: var(--surface); }
.lang-option {
  background: none; border: none; cursor: pointer; color: var(--ink-muted);
  padding: 0 12px; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.03em;
  transition: background 0.15s ease, color 0.15s ease;
}
.lang-option + .lang-option { border-left: 1px solid var(--rule); }
.lang-option:hover { color: var(--green); background: var(--green-bg); }
.lang-option.active { background: var(--green-bg); color: var(--green); }
.lang-option:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

.masthead { text-align: left; margin-bottom: 20px; }
.masthead h1 { font-family: var(--font-serif); font-weight: 700; font-size: 2.4rem; letter-spacing: -0.02em; margin: 0 0 12px; }
.masthead .subtitle { max-width: 72ch; margin: 0; color: var(--ink-muted); font-size: 0.9rem; line-height: 1.6; }

.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex-shrink: 0;
  background: var(--surface); border: 1px solid var(--rule-strong); color: var(--ink);
  border-radius: 8px; cursor: pointer; transition: background 0.15s ease, color 0.15s ease;
}
.theme-toggle:hover { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun, .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root:not([data-theme="dark"]) .theme-toggle .icon-moon { display: block; }

/* ---------- Governance banner (§32) — always visible, never a footnote ---------- */

.governance-banner {
  background: var(--amber-bg);
  border: 1px solid var(--amber);
  color: var(--ink);
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 0.85rem;
  line-height: 1.55;
  margin-bottom: 28px;
}
.governance-banner strong { color: var(--amber); }
.governance-banner:empty { display: none; }

/* ---------- Divider / headings ---------- */

.divider { border: none; border-top: 1px solid var(--rule); margin: 28px 0; }
h2.section-title, h3.subhead {
  font-family: var(--font-serif); font-weight: 600; margin: 0 0 14px;
}
h2.section-title { font-size: 1.5rem; }
h3.subhead { font-size: 1.1rem; margin-top: 28px; }
p.hint { color: var(--ink-muted); font-size: 0.85rem; margin: 0 0 16px; line-height: 1.55; }
p.design-note { color: var(--ink-muted); font-size: 0.78rem; margin: 6px 0 0; font-style: italic; }

/* ---------- Company selector ---------- */

.company-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.company-card {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 18px 20px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.company-card:hover { border-color: var(--green); background: var(--green-bg); }
.company-card.malformed { border-color: var(--red); background: var(--red-bg); cursor: default; }
.company-card .name { font-family: var(--font-serif); font-weight: 600; font-size: 1.05rem; margin-bottom: 4px; }
.company-card .meta { font-size: 0.8rem; color: var(--ink-muted); }
.company-card .warn { font-size: 0.78rem; color: var(--red); margin-top: 8px; line-height: 1.5; }

.empty-state {
  border: 1px dashed var(--rule-strong);
  border-radius: 10px;
  padding: 40px 28px;
  text-align: center;
  color: var(--ink-muted);
  margin-bottom: 32px;
}
.empty-state h3 { font-family: var(--font-serif); color: var(--ink); margin: 0 0 8px; font-size: 1.15rem; }
.empty-state p { max-width: 52ch; margin: 0 auto 4px; font-size: 0.88rem; line-height: 1.6; }

.create-form {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 20px 22px;
  max-width: 480px;
}
.create-form .field { margin-bottom: 14px; }
.create-form label { display: block; font-size: 0.83rem; margin-bottom: 5px; color: var(--ink-muted); }
.create-form input[type="text"] {
  width: 100%; border: 1px solid var(--rule); border-radius: 6px; padding: 9px 11px; background: var(--paper);
}
.create-form input:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
.create-form .row-error { color: var(--red); font-size: 0.82rem; margin: 8px 0 0; }
.create-form .row-ok { color: var(--green); font-size: 0.82rem; margin: 8px 0 0; }

button.btn {
  background: var(--green-strong); color: #fff; border: none;
  padding: 10px 18px; border-radius: 6px; font-weight: 500; cursor: pointer;
}
button.btn:hover { background: var(--green-hover); }
button.btn.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--rule-strong); }
button.btn.secondary:hover { background: var(--green-bg); border-color: var(--green); color: var(--green); }
button.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Dashboard layout ---------- */

.company-header {
  display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap;
  gap: 16px; margin-bottom: 8px;
}
.company-header h2 { font-family: var(--font-serif); font-size: 1.6rem; margin: 0 0 4px; }
.company-header .meta { color: var(--ink-muted); font-size: 0.85rem; }
.back-link {
  background: none; border: none; color: var(--ink-muted); cursor: pointer; font-size: 0.85rem;
  padding: 0; margin-bottom: 14px; display: inline-flex; align-items: center; gap: 6px;
}
.back-link:hover { color: var(--green); }

.weight-config-select { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--ink-muted); margin-bottom: 10px; }
.weight-config-select select { border: 1px solid var(--rule); border-radius: 6px; padding: 6px 8px; background: var(--surface); }
.export-links { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--ink-muted); }
.export-links .btn { padding: 6px 12px; font-size: 0.8rem; text-decoration: none; display: inline-block; }

.badge {
  display: inline-block; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 2px 7px; border-radius: 4px;
}
.badge.risk { background: var(--red-bg); color: var(--red); }
.badge.opportunity { background: var(--green-bg); color: var(--green); }

/* ---------- Portfolio band ---------- */

.portfolio-band { margin-top: 24px; }
.portfolio-band > .hint { margin-bottom: 8px; }
.portfolio-details { padding: 0; }
.portfolio-details > summary {
  list-style: none; cursor: pointer; padding: 16px 20px;
  font-family: var(--font-serif); font-weight: 600; font-size: 1.1rem;
  display: flex; align-items: center; gap: 8px;
}
.portfolio-details > summary::-webkit-details-marker { display: none; }
.portfolio-details > summary::before {
  content: ""; width: 8px; height: 8px; flex-shrink: 0;
  border-right: 2px solid var(--ink-muted); border-bottom: 2px solid var(--ink-muted);
  transform: rotate(-45deg); transition: transform 0.15s ease;
}
.portfolio-details[open] > summary::before { transform: rotate(45deg); }
.portfolio-details > summary + *,
.portfolio-details > *:not(summary) { margin-left: 20px; margin-right: 20px; }
.portfolio-details > *:last-child { margin-bottom: 18px; }
.portfolio-band .acc-disclaimer { margin-top: 4px; }

/* ---------- Statement / KPI grid (shared by cards and the full-analysis modal) ---------- */

.statement { color: var(--ink-muted); font-size: 0.88rem; margin: 0 0 16px; line-height: 1.55; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 18px 22px; margin-bottom: 8px; }
.kpi-cell { cursor: default; }
.kpi-label { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--ink-muted); margin-bottom: 4px; }
.kpi-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 1.5rem; font-weight: 500; }
.kpi-band { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; margin-top: 2px; }
.kpi-cell.na .kpi-value, .kpi-cell.na .kpi-band { color: var(--ink-faint); }

.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 22px; }
@media (max-width: 720px) { .panel-grid { grid-template-columns: 1fr; } }
.panel-block { border-top: 1px solid var(--rule); padding-top: 14px; }
.panel-block .label { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted); margin-bottom: 6px; }
.panel-block .value { font-size: 0.92rem; line-height: 1.55; }
.panel-block ul { margin: 4px 0 0; padding-left: 18px; }
.panel-block li { margin-bottom: 4px; font-size: 0.88rem; line-height: 1.5; }

/* ---------- Tables ---------- */

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.data-table th {
  text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--rule-strong);
}
table.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.data-table tbody tr:hover { background: var(--row-hover); }
table.data-table tbody tr.clickable { cursor: pointer; }
table.data-table td.num, table.data-table th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data-table caption.table-note { caption-side: bottom; text-align: left; color: var(--ink-muted); font-size: 0.8rem; padding-top: 10px; }
table.data-table .cell-sub { font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-faint); margin-top: 2px; }

/* ---------- Sideways scroll for anything wider than the column ----------
   Wide charts and the six-column evidence table used to squash or clip at phone
   width; here they keep their size and scroll instead. */

.scroll-x {
  overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; max-width: 100%;
  /* Shadows appear only on the side that still has content off-screen, so the
     fact that a block scrolls is visible without having to try it. */
  background:
    linear-gradient(to right, var(--surface) 40%, rgba(255,255,255,0)) left / 28px 100% no-repeat local,
    linear-gradient(to left, var(--surface) 40%, rgba(255,255,255,0)) right / 28px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(var(--shadow-rgb),0.16), rgba(255,255,255,0)) left / 12px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(var(--shadow-rgb),0.16), rgba(255,255,255,0)) right / 12px 100% no-repeat scroll;
}
.scroll-x table.data-table { min-width: 560px; }
.chart-scroll .chart-svg { width: 100%; height: auto; }

button.link-button {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--green); font-size: inherit; text-decoration: underline;
}
button.link-button:hover { color: var(--green-hover); }
p.scope-line { margin-bottom: 12px; }

/* ---------- Charts (hand-rolled SVG) ---------- */

.chart-block { border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); padding: 20px 22px; margin-bottom: 24px; }
.chart-block h3.subhead { margin-top: 0; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-caption { font-size: 0.78rem; color: var(--ink-muted); text-align: center; margin-bottom: 6px; }

/* §1 and §2 read the same four values; side by side the radar is a shape you
   glance at rather than a second full-height chart you scroll past. */
.index-pair { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 24px; align-items: center; }
.index-pair-radar { min-width: 0; }
@media (max-width: 720px) { .index-pair { grid-template-columns: 1fr; } .index-pair-radar { max-width: 300px; margin: 0 auto; } }
.chart-svg text { font-family: var(--font-sans); fill: var(--ink-muted); }
.chart-svg .num-label { font-family: var(--font-mono); fill: var(--ink); font-variant-numeric: tabular-nums; }
.chart-svg .num-label.na { fill: var(--ink-faint); }
.chart-svg .axis-line { stroke: var(--rule-strong); stroke-width: 1; }
.chart-svg .grid-line { stroke: var(--rule); stroke-width: 1; stroke-dasharray: 2,3; }
.bar-icc { fill: var(--band-high); }
.bar-icf { fill: var(--amber); }
.bar-icct { fill: var(--red); }
.bar-ics { fill: var(--green); }
.bar-core { fill: var(--ink); }
.radar-fill { fill: var(--green); fill-opacity: 0.16; stroke: var(--green); stroke-width: 1.5; }
.radar-grid { stroke: var(--rule); fill: none; stroke-width: 1; }
.heat-cell { stroke: var(--paper); stroke-width: 2; cursor: pointer; }
.heat-cell:hover { stroke: var(--focus); stroke-width: 2; }
.causal-node { fill: var(--surface); stroke: var(--rule-strong); stroke-width: 1; }
.causal-node.gap { stroke: var(--ink-faint); stroke-dasharray: 3,3; }
.chart-svg .causal-node-label { fill: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.chart-svg .causal-node-value { fill: var(--ink); }
.chart-svg .causal-node-value.gap { fill: var(--ink-faint); font-style: italic; }
.chart-svg .label-leader { stroke: var(--ink-faint); stroke-width: 1; }
.ranking-row { cursor: pointer; }
.ranking-row:hover rect:first-of-type { fill: var(--row-hover); }
.priority-dot circle { transition: r 0.12s ease; }
.priority-dot:hover circle { r: 9; stroke: var(--focus); stroke-width: 2; }
.causal-link { fill: none; stroke-width: 1.5; }
.causal-link.existing { stroke: var(--green); }
.causal-link.partial { stroke: var(--amber); stroke-dasharray: 4,3; }
.causal-link.inferred { stroke: var(--ink-muted); stroke-dasharray: 2,3; }
.causal-link.not_evidenced { stroke: var(--red); stroke-dasharray: 1,4; }
.priority-dot { cursor: pointer; }
.priority-dot circle { stroke: var(--surface); stroke-width: 1.5; }
.scenario-line { fill: none; stroke-width: 2; }
.scenario-line.conservative { stroke: var(--band-high); }
.scenario-line.base { stroke: var(--ink); }
.scenario-line.adverse { stroke: var(--red); }

.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; margin: 0 0 14px; font-size: 0.78rem; color: var(--ink-muted); }
.chart-legend .item { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-legend .swatch.bar-icc { background: var(--band-high); }
.chart-legend .swatch.bar-icf { background: var(--amber); }
.chart-legend .swatch.bar-icct { background: var(--red); }
.chart-legend .swatch.bar-ics { background: var(--green); }
.chart-legend .swatch.bar-core { background: var(--ink); }

/* ---------- Scenario form ---------- */

.scenario-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.scenario-form .field label { display: block; font-size: 0.78rem; color: var(--ink-muted); margin-bottom: 4px; }
.scenario-form input[type="number"] { width: 100%; border: 1px solid var(--rule); border-radius: 6px; padding: 7px 9px; background: var(--paper); }
.scenario-form .field-hint { font-size: 0.72rem; color: var(--ink-faint); margin-top: 4px; }
p.hint.delta-hint { margin: 0 0 10px; font-size: 0.78rem; }

/* ---------- Drawer (explain / create) ---------- */

.overlay { position: fixed; inset: 0; background: rgba(var(--shadow-rgb),0.55); backdrop-filter: blur(2px); z-index: 40; opacity: 0; transition: opacity 0.2s ease; }
.overlay.hidden { display: none; }
.overlay.show { opacity: 1; }
/* An actual drawer: it slides in from the right, so the page behind stays where
   the reader left it instead of being covered from the centre outwards. */
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 460px; max-width: 100vw;
  background: var(--paper); border-left: 1px solid var(--rule-strong); z-index: 50;
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(100%); opacity: 1;
  transition: transform 0.22s ease;
  box-shadow: -12px 0 48px rgba(var(--shadow-rgb),0.28);
}
.drawer.hidden { display: none; }
.drawer.show { transform: translateX(0); }
.drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--rule); }
.drawer-header h2 { font-family: var(--font-serif); font-size: 1.1rem; margin: 0; }
.drawer-close { background: none; border: none; cursor: pointer; color: var(--ink-muted); padding: 4px; }
.drawer-close svg { width: 18px; height: 18px; }
.drawer-close:hover { color: var(--ink); }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 22px 32px; }
.explain-row { margin-bottom: 14px; }
.explain-row .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted); margin-bottom: 3px; }
.explain-row .value { font-size: 0.9rem; line-height: 1.55; }
.evidence-item { border: 1px solid var(--rule); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; font-size: 0.83rem; line-height: 1.55; }
.evidence-item .src { color: var(--ink-muted); font-size: 0.76rem; margin-bottom: 4px; }

/* ---------- Toast / error ---------- */

.error-banner { background: var(--red-bg); border: 1px solid var(--red); color: var(--red); border-radius: 8px; padding: 12px 14px; font-size: 0.85rem; margin-bottom: 16px; }

/* ---------- Filter / sort bar ---------- */

.filter-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; z-index: 20;
  background: var(--paper); border-bottom: 1px solid var(--rule);
  padding: 10px 0; margin: 20px 0 4px;
}
.filter-group { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 8px; overflow: hidden; }
.filter-btn {
  background: none; border: none; cursor: pointer; color: var(--ink-muted);
  padding: 7px 14px; font-size: 0.82rem; font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.filter-btn + .filter-btn { border-left: 1px solid var(--rule); }
.filter-btn:hover { color: var(--green); background: var(--green-bg); }
.filter-btn.active { background: var(--green-bg); color: var(--green); }
.filter-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.sort-select { display: inline-flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--ink-muted); }
.sort-select select { border: 1px solid var(--rule); border-radius: 6px; padding: 6px 8px; background: var(--surface); }

/* ---------- Topic card grid ---------- */

/* minmax(min(100%, 480px), 1fr): two columns at the 1180px .app width, one
   column below ~1030px, and the card shrinks with the viewport below 480px
   instead of forcing a sideways scroll. */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 480px), 1fr));
  gap: 24px;
  margin-top: 16px;
}

.topic-card {
  border: 1px solid var(--rule);
  border-left: 3px solid var(--rule);
  border-radius: 10px;
  background: var(--surface);
  padding: 16px 18px;
  scroll-margin-top: 64px;
}
.topic-card.risk { border-left-color: var(--red); }
.topic-card.opportunity { border-left-color: var(--green); }
.topic-card.flash { animation: card-flash 1.3s ease; }
@keyframes card-flash {
  0%, 100% { box-shadow: 0 0 0 0 rgba(var(--shadow-rgb), 0); }
  15% { box-shadow: 0 0 0 3px var(--focus); }
}

.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-head-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; min-width: 0; }
.card-head-main h3 { font-family: var(--font-serif); font-size: 1.15rem; margin: 0; }
.card-head-meta { display: inline-flex; align-items: center; gap: 10px; flex-shrink: 0; }
.priority-chip { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
.card-ici { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 0.82rem; color: var(--ink-muted); white-space: nowrap; }
.card-collapse {
  background: none; border: none; cursor: pointer; color: var(--ink-muted); padding: 2px; flex-shrink: 0;
  display: inline-flex;
}
.card-collapse svg { width: 18px; height: 18px; transition: transform 0.15s ease; }
.card-collapse[aria-expanded="false"] svg { transform: rotate(-90deg); }
.topic-card.is-collapsed { padding-bottom: 14px; }
.card-unavailable { margin: 10px 0 0; }

.card-overview { margin-top: 12px; }
.card-kpis {
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 12px 14px;
}
.card-kpis .kpi-value { font-size: 1.25rem; }
.card-priority-line { font-size: 0.8rem; color: var(--ink-muted); margin: 12px 0 0; line-height: 1.5; }

/* Card sections — real <details>/<summary> for keyboard + collapse without re-render */
.card-section { border-top: 1px solid var(--rule); }
.card-section:first-of-type { margin-top: 14px; }
.card-section > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  padding: 11px 2px; font-size: 0.85rem; font-weight: 600; color: var(--ink);
}
.card-section > summary::-webkit-details-marker { display: none; }
.card-section > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.card-section .sec-icon { width: 15px; height: 15px; color: var(--ink-muted); flex-shrink: 0; }
.card-section .sec-label { flex: 1; }
.card-section > summary > svg:last-child { width: 16px; height: 16px; color: var(--ink-muted); transition: transform 0.15s ease; }
.card-section[open] > summary > svg:last-child { transform: rotate(180deg); }
.card-section-body { padding: 2px 2px 14px; }
.card-section-body .chart-svg { min-width: 0 !important; }

/* Compact dimension rows */
.dim-compact { list-style: none; margin: 0; padding: 0; }
.dim-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 6px 6px; border-radius: 6px; cursor: pointer;
  font-size: 0.82rem;
}
.dim-row:hover { background: var(--row-hover); }
.dim-row:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.dim-row .dim-name { flex: 1; min-width: 0; }
.dim-row .dim-idx { color: var(--ink-muted); font-size: 0.74rem; }
.dim-row .dim-score { font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--ink); }

/* Chart tabs inside a card */
.viz-tabs { display: inline-flex; border: 1px solid var(--rule); border-radius: 7px; overflow: hidden; margin-bottom: 12px; }
.viz-tabs [role="tab"] {
  background: none; border: none; cursor: pointer; color: var(--ink-muted);
  padding: 6px 12px; font-size: 0.78rem; font-weight: 600;
}
.viz-tabs [role="tab"] + [role="tab"] { border-left: 1px solid var(--rule); }
.viz-tabs [role="tab"][aria-selected="true"] { background: var(--green-bg); color: var(--green); }
.viz-tabs [role="tab"]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.viz-radar { max-width: 260px; margin: 0 auto; }
.viz-strip { overflow: hidden; }

/* Evidence & accounting preview */
.mini-head { font-family: var(--font-serif); font-size: 0.92rem; margin: 14px 0 6px; }
.mini-head:first-child { margin-top: 0; }
.card-section-body .acc-disclaimer { margin: 0 0 8px; font-size: 0.78rem; }
.mini-list { list-style: none; margin: 0 0 4px; padding: 0; }
.mini-list li { padding: 5px 0; border-bottom: 1px solid var(--rule); font-size: 0.8rem; }
.mini-list li:last-child { border-bottom: none; }
.mini-main { display: block; }
.mini-sub { display: block; font-family: var(--font-mono); font-size: 0.7rem; color: var(--ink-faint); margin-top: 1px; }
.mini-more { margin: 6px 0 0; font-size: 0.78rem; }

.card-footer { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--rule); }
.card-footer .btn { padding: 7px 14px; font-size: 0.8rem; }

/* ---------- Modal (centred wide panel, scrolls internally) ---------- */

.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 20px; overflow: hidden;
  opacity: 0; transition: opacity 0.2s ease;
}
.modal.hidden { display: none; }
.modal.show { opacity: 1; }
.modal-panel {
  background: var(--paper); border: 1px solid var(--rule-strong); border-radius: 12px;
  width: 900px; max-width: 100%; max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 64px rgba(var(--shadow-rgb), 0.35);
  transform: translateY(12px); transition: transform 0.2s ease;
}
.modal.show .modal-panel { transform: translateY(0); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--rule); }
.modal-header h2 { font-family: var(--font-serif); font-size: 1.2rem; margin: 0; }
.modal-body { overflow-y: auto; padding: 20px 22px 28px; }
.modal-body .subhead:first-child { margin-top: 0; }

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .masthead h1 { font-size: 1.9rem; }
  .app { padding: 32px 16px 72px; }
  .drawer { width: 100vw; border-left: none; }
  .panel-grid { grid-template-columns: 1fr; }
  .chart-block { padding: 16px 14px; }
  .topic-card { padding: 14px 14px; }
  .modal { padding: 0; }
  .modal-panel { max-height: 100vh; border-radius: 0; border: none; }
}

@media (prefers-reduced-motion: reduce) {
  body, .drawer, .overlay, .modal, .modal-panel, .theme-toggle, .lang-option,
  .company-card, .priority-dot circle, .card-collapse svg, .card-section > summary > svg,
  .portfolio-details > summary::before {
    transition: none !important;
  }
  .topic-card.flash { animation: none; }
}
