/* FinPulse 2 — components on top of the Institutional design system (styles.css).
   Every value comes from the token files; the dark theme re-points the semantic tokens only. */

:root {
  --text-accent: var(--df-orange-700);          /* orange text that clears AA on white */
  --btn-primary-bg: var(--df-orange-700);
  --btn-primary-bg-hover: var(--df-navy-500);
  --btn-primary-text: var(--df-white);
  --ok-text: var(--df-navy-500);
  --bad-text: var(--status-danger);
  --chip-bg: var(--df-navy-050);
  --chip-text: var(--df-navy-700);
  --nav-bg: var(--df-white);
  --chart-a: var(--df-navy-500);
  --chart-b: var(--df-orange-500);
  color-scheme: light;
}

[data-theme="dark"] {
  --surface-page: var(--df-navy-900);
  --surface-card: var(--grey-950);
  --surface-subtle: var(--grey-800);
  --surface-sunken: var(--grey-950);
  --text-strong: var(--df-navy-050);
  --text-body: var(--grey-200);
  --text-muted: var(--grey-300);
  --text-faint: var(--grey-400);
  --text-accent: var(--df-peach);
  --border-subtle: var(--grey-800);
  --border-default: var(--grey-600);
  --ok-text: var(--df-peach);
  --bad-text: var(--df-orange-100);
  --chip-bg: var(--grey-800);
  --chip-text: var(--grey-100);
  --nav-bg: var(--grey-950);
  --chart-a: var(--df-navy-300);
  --chart-b: var(--df-peach);
  color-scheme: dark;
}
[data-theme="dark"] a:hover { color: var(--df-orange-100); }

body { background: var(--surface-page); color: var(--text-body); min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; }
img { max-width: 100%; display: block; }
.icon { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.container { width: 100%; max-width: var(--container-lg); margin: 0 auto; padding: 0 var(--space-6); }
:focus-visible { outline: var(--focus-ring-width) solid var(--focus-ring); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: var(--space-4); top: var(--space-4); z-index: 100; background: var(--surface-card); padding: var(--space-2) var(--space-4); }

/* Header */
.topbar { position: sticky; top: 0; z-index: 40; background: var(--nav-bg); border-bottom: var(--border-hairline) solid var(--border-subtle); }
.topbar .container { display: flex; align-items: center; gap: var(--space-4); min-height: 64px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--text-strong); font-family: var(--font-display); font-weight: var(--fw-bold); font-size: var(--fs-h4); letter-spacing: var(--ls-label); text-transform: uppercase; min-height: 44px; }
.brand:hover { text-decoration: none; color: var(--text-strong); }
.brand img { height: 32px; width: 32px; }
.nav { display: flex; gap: var(--space-1); flex-wrap: wrap; margin-left: auto; align-items: center; }
.nav a, .nav button.link { display: inline-flex; align-items: center; gap: var(--space-2); min-height: 44px; padding: 0 var(--space-3); border-radius: var(--radius-sm); color: var(--text-body); font-weight: var(--fw-semibold); background: none; border: 0; cursor: pointer; font: inherit; }
.nav a:hover, .nav button.link:hover { background: var(--surface-subtle); color: var(--text-strong); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text-accent); box-shadow: inset 0 -2px 0 var(--divider-accent); }

/* Buttons and fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: 44px; padding: 0 var(--space-5); border-radius: var(--radius-sm); border: var(--border-hairline) solid var(--border-default); background: var(--surface-card); color: var(--text-strong); font: inherit; font-weight: var(--fw-semibold); cursor: pointer; transition: background var(--dur-fast) var(--ease-standard); text-decoration: none; }
.btn:hover { background: var(--surface-subtle); text-decoration: none; color: var(--text-strong); }
.btn.primary { background: var(--btn-primary-bg); border-color: var(--btn-primary-bg); color: var(--btn-primary-text); }
.btn.primary:hover { background: var(--btn-primary-bg-hover); border-color: var(--btn-primary-bg-hover); color: var(--btn-primary-text); }
.btn[disabled], .btn[aria-busy="true"] { opacity: 0.6; cursor: progress; }
.btn.small { min-height: 44px; padding: 0 var(--space-3); font-size: var(--fs-body-sm); }
.field { display: grid; gap: var(--space-1); }
.field label { font-weight: var(--fw-semibold); color: var(--text-strong); font-size: var(--fs-body-sm); }
.field .hint { color: var(--text-muted); font-size: var(--fs-body-sm); }
.field .err { color: var(--bad-text); font-size: var(--fs-body-sm); min-height: 0; }
input, select, textarea { font: inherit; color: var(--text-strong); background: var(--surface-card); border: var(--border-hairline) solid var(--border-default); border-radius: var(--radius-sm); min-height: 44px; padding: var(--space-2) var(--space-3); width: 100%; max-width: 100%; }
textarea { min-height: 88px; resize: vertical; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--status-danger); }
.form-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.error-summary { border: var(--border-thick) solid var(--status-danger); border-radius: var(--radius-md); padding: var(--space-4); background: var(--surface-card); color: var(--text-body); }
.error-summary h2 { font-size: var(--fs-h4); color: var(--bad-text); }
.checks { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.checks label { display: inline-flex; align-items: center; gap: var(--space-2); min-height: 44px; font-weight: var(--fw-medium); }
.checks input { width: 20px; min-height: 20px; height: 20px; }

/* Cards, sections */
.page { padding: var(--space-8) 0 var(--space-16); }
.page-head { display: flex; flex-wrap: wrap; gap: var(--space-4); align-items: flex-end; justify-content: space-between; margin-bottom: var(--space-6); }
.page-head h1 { margin: 0; font-size: var(--fs-h2); }
.overline { font-family: var(--font-display); font-size: var(--fs-overline); font-weight: var(--fw-semibold); letter-spacing: var(--ls-overline); text-transform: uppercase; color: var(--text-accent); margin: 0 0 var(--space-2); }
.rule { border: 0; border-top: var(--border-thick) solid var(--divider-accent); width: 64px; margin: var(--space-3) 0 var(--space-5); }
.card { background: var(--surface-card); border: var(--border-hairline) solid var(--border-subtle); border-radius: var(--radius-lg); padding: var(--space-6); box-shadow: var(--shadow-xs); min-width: 0; }
.card h2, .card h3 { font-size: var(--fs-h4); }
.grid { display: grid; gap: var(--space-5); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.muted { color: var(--text-muted); }
.toolbar { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; }
.toolbar .field { min-width: 160px; flex: 1 1 160px; }
.asat { display: inline-flex; align-items: center; gap: var(--space-2); background: var(--chip-bg); color: var(--chip-text); border-radius: var(--radius-pill); padding: var(--space-1) var(--space-3); font-size: var(--fs-body-sm); font-weight: var(--fw-semibold); }
.chip { display: inline-flex; align-items: center; gap: var(--space-1); background: var(--chip-bg); color: var(--chip-text); border-radius: var(--radius-pill); padding: var(--space-1) var(--space-3); font-size: var(--fs-caption); font-weight: var(--fw-bold); letter-spacing: var(--ls-label); text-transform: uppercase; white-space: nowrap; }
.chip.ok { box-shadow: inset 0 0 0 1px var(--status-success); }
.chip.bad { box-shadow: inset 0 0 0 1px var(--status-danger); }
.chip.warn { box-shadow: inset 0 0 0 1px var(--status-warning); }

/* Money and numbers */
.money, .num { white-space: nowrap; font-variant-numeric: tabular-nums; }
td.money, th.money, td.num, th.num { text-align: right; }
.up { color: var(--ok-text); }
.down { color: var(--bad-text); }

/* KPI tiles */
.tiles { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.tile { text-align: left; display: grid; gap: var(--space-2); background: var(--surface-card); border: var(--border-hairline) solid var(--border-subtle); border-top: var(--border-thick) solid var(--divider-accent); border-radius: var(--radius-md); padding: var(--space-5); cursor: pointer; font: inherit; color: var(--text-body); min-height: 132px; transition: box-shadow var(--dur-base) var(--ease-standard), transform var(--dur-base) var(--ease-standard); }
.tile:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.tile .label { font-size: var(--fs-body-sm); color: var(--text-muted); font-weight: var(--fw-semibold); }
.tile .value { font-family: var(--font-display); font-size: var(--fs-h2); color: var(--text-strong); font-weight: var(--fw-semibold); line-height: var(--lh-tight); }
.tile .delta { font-size: var(--fs-body-sm); font-weight: var(--fw-semibold); }

.tile.s-good { border-top-color: var(--status-success); }
.tile.s-watch { border-top-color: var(--status-warning); }
.tile.s-bad { border-top-color: var(--status-danger); }
.tile .tile-head { display: flex; justify-content: space-between; gap: var(--space-2); align-items: flex-start; flex-wrap: wrap; }
.tile .foot { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-2); flex-wrap: wrap; }
.spark { width: 120px; height: 32px; display: block; }
.status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--border-default); }
.status-dot.good { background: var(--status-success); }
.status-dot.watch { background: var(--status-warning); }
.status-dot.bad { background: var(--status-danger); }
.fresh { display: flex; gap: var(--space-3); align-items: flex-start; flex-wrap: wrap; border-left: var(--border-thick) solid var(--status-success); background: var(--surface-card); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); margin: var(--space-3) 0 var(--space-5); }
.fresh.stale, .fresh.manual { border-left-color: var(--status-warning); }
.fresh.failing, .fresh.never { border-left-color: var(--status-danger); }
.fresh p { margin: 0; }
.filterbar { position: sticky; top: 64px; z-index: 20; margin-bottom: var(--space-5); }
.notes { list-style: none; padding: 0; display: grid; gap: var(--space-3); margin: 0 0 var(--space-4); }
.notes li { border-left: var(--border-thick) solid var(--divider-accent); padding: var(--space-2) var(--space-3); background: var(--surface-subtle); border-radius: var(--radius-sm); }
.formula { font-family: var(--font-mono, monospace); font-size: var(--fs-body-sm); background: var(--surface-subtle); color: var(--text-strong); padding: var(--space-1) var(--space-2); border-radius: var(--radius-xs); word-break: break-word; }
.chip-btns { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.status-text.good { color: var(--ok-text); }
.status-text.bad { color: var(--bad-text); }

/* Tables */
.table-wrap { overflow-x: auto; max-width: 100%; border: var(--border-hairline) solid var(--border-subtle); border-radius: var(--radius-md); background: var(--surface-card); }
table { border-collapse: collapse; width: 100%; font-size: var(--fs-body-sm); }
th, td { padding: var(--space-3) var(--space-4); border-bottom: var(--border-hairline) solid var(--border-subtle); text-align: left; vertical-align: top; }
thead th { position: sticky; top: 0; background: var(--surface-subtle); color: var(--text-strong); font-weight: var(--fw-bold); z-index: 1; }
th button.sort { background: none; border: 0; font: inherit; color: inherit; cursor: pointer; display: inline-flex; gap: var(--space-1); align-items: center; min-height: 32px; padding: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover, tbody tr.clickable:focus-visible { background: var(--surface-subtle); }
.table-tools { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.table-tools input { max-width: 280px; }
.pager { display: flex; gap: var(--space-2); align-items: center; justify-content: flex-end; padding: var(--space-3); flex-wrap: wrap; }

/* Bars */
.bars { display: grid; gap: var(--space-2); }
.bar { display: grid; grid-template-columns: minmax(90px, 1fr) 2fr auto; gap: var(--space-3); align-items: center; background: none; border: 0; padding: var(--space-1) 0; color: var(--text-body); font: inherit; text-align: left; cursor: pointer; min-height: 44px; }
.bar:hover .bar-name { color: var(--text-accent); text-decoration: underline; }
.bar-track { height: 10px; border-radius: var(--radius-pill); background: var(--surface-sunken); overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--chart-a); border-radius: var(--radius-pill); }
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { fill: var(--text-muted); font-size: 11px; }
.legend { display: flex; gap: var(--space-4); flex-wrap: wrap; font-size: var(--fs-body-sm); color: var(--text-muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: var(--radius-xs); margin-right: var(--space-1); vertical-align: -1px; }

/* States */
.skeleton { height: 18px; border-radius: var(--radius-xs); background: linear-gradient(90deg, var(--surface-sunken), var(--surface-subtle), var(--surface-sunken)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; margin: var(--space-3) 0; }
@keyframes shimmer { to { background-position: -200% 0; } }
.state { text-align: center; padding: var(--space-10) var(--space-4); display: grid; gap: var(--space-3); justify-items: center; }
.notice { border-left: var(--border-thick) solid var(--status-warning); background: var(--surface-card); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); margin-bottom: var(--space-4); }

/* Dialog and toast */
dialog { border: var(--border-hairline) solid var(--border-subtle); border-radius: var(--radius-lg); background: var(--surface-card); color: var(--text-body); padding: var(--space-6); width: min(560px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(12, 29, 66, 0.6); }
.dialog-actions { display: flex; gap: var(--space-3); justify-content: flex-end; margin-top: var(--space-5); flex-wrap: wrap; }
.toasts { position: fixed; right: var(--space-4); bottom: var(--space-4); display: grid; gap: var(--space-2); z-index: 200; max-width: calc(100vw - 32px); }
.toast { background: var(--df-navy-900); color: var(--df-white); border-left: 4px solid var(--df-orange-500); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); max-width: 420px; }
.toast.error { border-left-color: var(--df-peach); }

/* Steps */
.steps { display: flex; gap: var(--space-2); flex-wrap: wrap; list-style: none; padding: 0; margin: 0 0 var(--space-6); counter-reset: s; }
.steps li { counter-increment: s; display: inline-flex; gap: var(--space-2); align-items: center; padding: var(--space-2) var(--space-3); border-radius: var(--radius-pill); background: var(--chip-bg); color: var(--chip-text); font-size: var(--fs-body-sm); font-weight: var(--fw-semibold); }
.steps li::before { content: counter(s); display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--surface-card); color: var(--text-strong); font-size: var(--fs-caption); }
.steps li[aria-current="step"] { background: var(--btn-primary-bg); color: var(--btn-primary-text); }
.kpi-block { border: var(--border-hairline) solid var(--border-subtle); border-radius: var(--radius-md); padding: var(--space-4); display: grid; gap: var(--space-4); margin-bottom: var(--space-4); }

/* Landing */
.hero { position: relative; color: var(--df-white); background-color: var(--df-navy-900); background-image: linear-gradient(100deg, rgba(12, 29, 66, 0.96) 0%, rgba(12, 29, 66, 0.88) 45%, rgba(12, 29, 66, 0.55) 100%), url('/assets/stock-1.jpg'); background-size: cover; background-position: center; padding: var(--space-24) 0 var(--space-20); }
.hero h1 { color: var(--df-white); font-size: clamp(2.25rem, 6vw, var(--fs-display-xl)); line-height: var(--lh-tight); max-width: 15ch; margin-bottom: var(--space-5); }
.hero .lead { font-size: var(--fs-lead); max-width: 52ch; color: var(--df-navy-050); }
.hero .overline { color: var(--df-peach); }
.hero .cta { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-8); }
.hero .btn.ghost { background: transparent; color: var(--df-white); border-color: var(--df-navy-100); }
.hero .btn.ghost:hover { background: var(--df-navy-700); }
.section { padding: var(--space-20) 0; }
.section.alt { background: var(--surface-subtle); }
.section h2 { font-size: var(--fs-h1); max-width: 22ch; }
.feature .icon { width: 32px; height: 32px; color: var(--text-accent); margin-bottom: var(--space-3); }
.split { display: grid; gap: var(--space-10); grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-items: center; }
.split img { border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }
.steps-list { counter-reset: n; list-style: none; padding: 0; display: grid; gap: var(--space-5); }
.steps-list li { counter-increment: n; display: grid; grid-template-columns: 48px 1fr; gap: var(--space-4); }
.steps-list li::before { content: counter(n, decimal-leading-zero); font-family: var(--font-display); font-size: var(--fs-h3); color: var(--text-accent); font-weight: var(--fw-semibold); }
.footer { background: var(--df-navy-900); color: var(--df-navy-100); padding: var(--space-12) 0 var(--space-8); }
.footer a { color: var(--df-peach); }
.footer .trust { display: flex; flex-wrap: wrap; gap: var(--space-5); margin: var(--space-5) 0; }
.footer .trust span { display: inline-flex; gap: var(--space-2); align-items: center; }
.footer small { color: var(--grey-300); }

/* Admin shell */
.admin-shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--df-navy-900); color: var(--df-navy-100); padding: var(--space-5) var(--space-3); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { color: var(--df-white); padding: 0 var(--space-3); margin-bottom: var(--space-6); }
.sidebar .brand small { display: block; font-size: var(--fs-overline); color: var(--df-peach); letter-spacing: var(--ls-overline); }
.sidebar nav a { display: flex; align-items: center; gap: var(--space-3); min-height: 44px; padding: 0 var(--space-3); border-radius: var(--radius-sm); color: var(--df-navy-100); font-weight: var(--fw-semibold); }
.sidebar nav a:hover { background: var(--df-navy-700); color: var(--df-white); text-decoration: none; }
.sidebar nav a[aria-current="page"] { background: var(--df-navy-700); color: var(--df-white); box-shadow: inset 3px 0 0 var(--df-orange-500); }
.admin-top { position: sticky; top: 0; z-index: 30; display: flex; gap: var(--space-3); align-items: center; justify-content: space-between; flex-wrap: wrap; padding: var(--space-3) var(--space-6); background: var(--nav-bg); border-bottom: var(--border-hairline) solid var(--border-subtle); min-height: 64px; }
.admin-main { padding: var(--space-6); min-width: 0; }
.kpis { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: var(--space-6); }
.kpi { background: var(--surface-card); border: var(--border-hairline) solid var(--border-subtle); border-radius: var(--radius-md); padding: var(--space-4); }
.kpi .v { font-family: var(--font-display); font-size: var(--fs-h3); color: var(--text-strong); font-weight: var(--fw-semibold); }
.kpi .l { font-size: var(--fs-body-sm); color: var(--text-muted); }
.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }
.toggle { min-height: 44px; min-width: 88px; border-radius: var(--radius-pill); border: var(--border-hairline) solid var(--border-default); background: var(--surface-card); color: var(--text-strong); font: inherit; font-weight: var(--fw-semibold); cursor: pointer; }
.toggle[aria-pressed="true"] { background: var(--chip-bg); box-shadow: inset 0 0 0 2px var(--status-success); }
.toggle[aria-pressed="false"] { box-shadow: inset 0 0 0 2px var(--status-danger); }
code.token { word-break: break-all; font-size: var(--fs-caption); }

@media (max-width: 860px) {
  .admin-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: var(--space-1); }
  .admin-main { padding: var(--space-4); }
}
@media (max-width: 600px) {
  .container { padding: 0 var(--space-4); }
  .hero { padding: var(--space-16) 0 var(--space-12); }
  .section { padding: var(--space-12) 0; }
  .section h2 { font-size: var(--fs-h2); }
  .card { padding: var(--space-4); }
  .tile .value { font-size: var(--fs-h3); }
  .bar { grid-template-columns: 1fr; gap: var(--space-1); }
  .topbar .container { padding-top: var(--space-2); padding-bottom: var(--space-2); }
  .nav { margin-left: 0; width: 100%; }
  .filterbar { position: static; }
}
