/* ====================================================================
   SWS Funding Tracker — UI styles
   Direction: editorial-minimal operator dashboard. Warm paper canvas,
   hairline borders, near-flat surfaces, ink chrome. COLOR IS RESERVED
   for data semantics (the clawback flags / status badges) — never spent
   on decoration. Numbers are mono + tabular for honest alignment.
   ==================================================================== */

@font-face {
  font-family: 'Geist';
  src: url('/static/fonts/Geist-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('/static/fonts/GeistMono-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Surfaces — warm neutral, one hue family */
  --paper: #f6f5f1;       /* app canvas (warm bone) */
  --surface: #ffffff;     /* cards, table, inputs */
  --surface-2: #faf9f6;   /* table header / subtle raised fills */
  --surface-hover: #f7f6f2;

  /* Hairlines — the single most-used rule */
  --line: #e7e4dd;
  --line-strong: #d9d5cc;
  --line-faint: #f0eee8;

  /* Ink — warm charcoal, never pure black */
  --ink: #23211d;
  --ink-soft: #6b6760;
  --ink-faint: #98948b;

  /* Brand coin gold (used only on the $ mark / login, away from data) */
  --coin: #d98b1f;

  /* Deep, muted semantic tones — legible + calm, for KPI values & flag text */
  --c-red: #b42318;
  --c-amber: #b54708;
  --c-gold: #c4540b;
  --c-yellow: #a15c07;
  --c-green: #067647;
  --c-purple: #6941c6;
  --c-blue: #3538cd;
  --c-teal: #107569;
  --c-pink: #c11574;

  /* Soft, warm-tinted elevation */
  --shadow-xs: 0 1px 2px rgba(35, 33, 29, 0.04);
  --shadow-sm: 0 1px 3px rgba(35, 33, 29, 0.05), 0 1px 2px rgba(35, 33, 29, 0.03);
  --shadow: 0 6px 16px -6px rgba(35, 33, 29, 0.1), 0 2px 6px -2px rgba(35, 33, 29, 0.05);

  --radius: 12px;
  --radius-sm: 9px;
  --topbar-h: 56px;

  --sans: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.25, 1, 0.5, 1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; padding: 0; }
body {
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 5px; }
::selection { background: rgba(217, 139, 31, 0.18); }

/* ---- Top bar (light, hairline) ---- */
.topbar { background: rgba(246, 245, 241, 0.85); backdrop-filter: saturate(1.4) blur(8px); position: sticky; top: 0; z-index: 30; border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1320px; margin: 0 auto; padding: 0 24px; height: var(--topbar-h); display: flex; align-items: center; gap: 22px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 14.5px; color: var(--ink); letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; color: var(--coin); }
.brand-mark svg { display: block; }
.brand-text { letter-spacing: -0.01em; }
.topnav { display: flex; gap: 2px; margin-right: auto; }
.topnav a { color: var(--ink-soft); padding: 6px 11px; border-radius: 8px; font-weight: 500; font-size: 13.5px; transition: color 0.15s var(--ease), background 0.15s var(--ease); }
.topnav a:hover { color: var(--ink); background: rgba(35, 33, 29, 0.05); text-decoration: none; }
.topnav a.is-active { color: var(--ink); background: rgba(35, 33, 29, 0.07); font-weight: 550; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-email { color: var(--ink-faint); font-size: 12.5px; }
.inline-form { display: inline; margin: 0; }

/* ---- Layout ---- */
.page { max-width: 1320px; margin: 0 auto; padding: 30px 24px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.page-title { font-size: 25px; font-weight: 600; letter-spacing: -0.03em; margin: 0; text-wrap: balance; }
.page-sub { color: var(--ink-soft); font-size: 13.5px; margin: 6px 0 0; max-width: 80ch; }
.head-meta { display: flex; align-items: center; gap: 10px; }
.updated { color: var(--ink-faint); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; font: inherit; font-weight: 550; font-size: 13.5px; border: 1px solid transparent; border-radius: var(--radius-sm); padding: 8px 14px; cursor: pointer; transition: background 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.08s var(--ease); }
.btn:active { transform: scale(0.98); }
.btn svg { display: block; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; padding: 11px 14px; }
.btn-primary { background: var(--ink); color: #fff; box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: #38352f; text-decoration: none; box-shadow: var(--shadow-sm); }
.btn:disabled, .btn[disabled] { background: #d6d2c9; color: #fff; cursor: not-allowed; box-shadow: none; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink-soft); box-shadow: var(--shadow-xs); }
.btn-ghost:hover { background: var(--surface-hover); border-color: var(--line-strong); color: var(--ink); text-decoration: none; }

/* ---- KPI cards ---- */
/* Flat surfaces, hairline border, ink numbers. Severity is read from the
   label (emoji + words), not a screaming colored figure. Hierarchy comes
   from the headline card's larger value, not decoration. No side stripes. */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); gap: 12px; margin-bottom: 26px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 17px; box-shadow: var(--shadow-xs); transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease), transform 0.18s var(--ease); }
.kpi:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.kpi-label { color: var(--ink-soft); font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 6px; line-height: 1.3; }
.kpi-value { font-family: var(--mono); font-size: 25px; font-weight: 540; letter-spacing: -0.035em; margin-top: 10px; line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums; }
.kpi-sub { color: var(--ink-faint); font-size: 11.5px; margin-top: 6px; }
.kpi.accent-brand .kpi-value { font-size: 29px; }
.kpi.accent-red .kpi-value { color: var(--c-red); }
.kpi.accent-gold .kpi-value { color: var(--c-gold); }
.kpi.accent-green .kpi-value { color: var(--c-green); }

/* ---- Panels (chart + legend) ---- */
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 26px; }
@media (min-width: 880px) { .grid-2 { grid-template-columns: 300px 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-xs); padding: 18px 20px; }
.panel h3 { margin: 0 0 14px; font-size: 11px; font-weight: 600; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.07em; }
.chart-box { position: relative; height: 210px; }

/* ---- Legend = the flag distribution breakdown (fills the panel, single source) ---- */
.legend { display: flex; flex-direction: column; }
.legend-item { display: flex; align-items: flex-start; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line-faint); }
.legend-item:last-child { border-bottom: none; }
.legend-item .em { font-size: 14px; line-height: 1.25; }
.legend-main { flex: 1; min-width: 0; }
.legend-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.legend-top b { color: var(--ink); font-weight: 550; font-size: 13.5px; }
.legend-count { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 540; font-size: 13.5px; }
.legend-bar { height: 5px; border-radius: 999px; background: var(--line-faint); margin: 7px 0; overflow: hidden; }
.legend-bar-fill { display: block; height: 100%; border-radius: 999px; min-width: 2px; }
.legend-bar-fill.flag-yellow { background: var(--c-yellow); }
.legend-bar-fill.flag-red { background: var(--c-red); }
.legend-bar-fill.flag-purple { background: var(--c-purple); }
.legend-bar-fill.flag-gold { background: var(--c-gold); }
.legend-desc { color: var(--ink-faint); font-size: 12px; }

/* ---- Toolbar (filters) ---- */
.toolbar { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type="search"], .select-filter { padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); font: inherit; font-size: 13.5px; background: var(--surface); color: var(--ink); transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease); box-shadow: var(--shadow-xs); }
.toolbar input[type="search"] { flex: 1 1 240px; min-width: 190px; }
.toolbar input[type="search"]::placeholder { color: var(--ink-faint); }
.select-filter { cursor: pointer; }
.toolbar input[type="search"]:focus, .select-filter:focus { outline: none; border-color: var(--ink-soft); box-shadow: 0 0 0 3px rgba(35, 33, 29, 0.08); }
.toolbar-spacer { margin-left: auto; }
.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); padding: 6px 11px; border-radius: 999px; font: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer; box-shadow: var(--shadow-xs); transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.08s var(--ease); }
.chip:hover { background: var(--surface-hover); border-color: var(--line-strong); color: var(--ink); }
.chip:active { transform: scale(0.97); }
.chip.is-on { background: var(--ink); color: #fff; border-color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---- Table ---- */
/* overflow: clip rounds the corners without making a scroll container, so the
   sticky header keeps anchoring to the page below the top bar. */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-xs); overflow: clip; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 11px 15px; text-align: left; border-bottom: 1px solid var(--line-faint); white-space: nowrap; }
table.data th { background: var(--surface-2); color: var(--ink-faint); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; position: sticky; top: var(--topbar-h); z-index: 10; box-shadow: inset 0 -1px 0 var(--line); }
table.data th.sortable { cursor: pointer; user-select: none; transition: color 0.12s var(--ease), background 0.12s var(--ease); }
table.data th.sortable:hover { color: var(--ink-soft); background: var(--surface-hover); }
table.data th.sortable::after { content: " ↕"; opacity: 0.35; font-size: 10px; }
table.data th[data-sort-dir="asc"]::after { content: " ↑"; opacity: 1; color: var(--ink); }
table.data th[data-sort-dir="desc"]::after { content: " ↓"; opacity: 1; color: var(--ink); }
table.data tbody tr { transition: background 0.12s var(--ease); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-hover); }
table.data td.wrap { white-space: normal; max-width: 260px; }
table.data td { color: var(--ink); }
table.data .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; color: var(--ink); }
.row-hidden { display: none; }
.empty { padding: 54px 24px; text-align: center; color: var(--ink-faint); font-size: 13.5px; }

/* ---- Flag (clawback) ---- */
.flag { display: inline-flex; align-items: center; gap: 7px; font-weight: 550; white-space: nowrap; }
.flag .em { font-size: 13px; line-height: 1; }
.flag.green { color: var(--c-green); }
.flag.yellow { color: var(--c-yellow); }
.flag.red { color: var(--c-red); }
.flag.purple { color: var(--c-purple); }
.flag.gold { color: var(--c-gold); }
.flag.is-directive { color: var(--c-teal); }   /* "Claw Back ESG" — an action */
.flag.is-early { color: var(--c-pink); }        /* "ESG clawed early" */
.countdown { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 540; letter-spacing: -0.01em; color: var(--ink-soft); }
.countdown.over { color: var(--c-red); font-weight: 550; }

/* ---- Badges (status) — pill, pastel, semantic ---- */
.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 550; letter-spacing: 0.005em; line-height: 1.5; white-space: nowrap; }
.badge.yes { background: #e9f7ef; color: var(--c-green); }
.badge.no { background: #f2f1ec; color: var(--ink-faint); }
.badge.due { background: #eef0ff; color: var(--c-blue); }
.badge.muted { background: #f2f1ec; color: var(--ink-faint); }
.badge.clawed { background: #fdeceb; color: var(--c-red); }
.badge.us { background: var(--ink); color: #fff; }      /* "Pay M1/M2" — an action to take */
.badge.sws { background: #fbeede; color: var(--c-amber); }
.mismatch { color: var(--c-gold); cursor: help; }

/* ---- Alerts ---- */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 16px; border: 1px solid transparent; }
.alert-error { background: #fdeceb; color: var(--c-red); border-color: #f6d4d1; }
.alert-ok { background: #e9f7ef; color: var(--c-green); border-color: #c7ebd6; }
.alert-info { background: var(--surface-2); color: var(--ink-soft); border-color: var(--line); }
.alert code { font-family: var(--mono); font-size: 0.92em; background: rgba(35, 33, 29, 0.06); padding: 1px 5px; border-radius: 5px; }

/* ---- Auth (login / error) ---- */
.auth-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; background:
  radial-gradient(1100px 520px at 50% -160px, #fbf6ec 0%, rgba(251, 246, 236, 0) 70%), var(--paper); }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 32px; width: 100%; max-width: 384px; }
.auth-brand { display: flex; align-items: center; gap: 9px; font-weight: 600; color: var(--ink); margin-bottom: 22px; letter-spacing: -0.01em; }
.auth-brand .brand-mark { color: var(--coin); }
.auth-title { font-size: 21px; font-weight: 600; letter-spacing: -0.02em; margin: 0; }
.auth-sub { color: var(--ink-soft); font-size: 13.5px; margin: 6px 0 22px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; font-weight: 550; color: var(--ink-soft); }
.field input { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); font: inherit; font-size: 14.5px; background: var(--surface); color: var(--ink); transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease); }
.field input:focus { outline: none; border-color: var(--ink-soft); box-shadow: 0 0 0 3px rgba(35, 33, 29, 0.08); }

/* ---- Admin ---- */
.admin-form { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.admin-form input { padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); font: inherit; font-size: 13.5px; min-width: 220px; background: var(--surface); transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease); }
.admin-form input:focus, .reset-form input:focus { outline: none; border-color: var(--ink-soft); box-shadow: 0 0 0 3px rgba(35, 33, 29, 0.08); }
.reset-form { display: flex; gap: 7px; align-items: center; }
.reset-form input { padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; font: inherit; font-size: 12.5px; max-width: 168px; background: var(--surface); }

/* ---- Digest preview ---- */
.digest-meta { display: flex; gap: 18px; flex-wrap: wrap; color: var(--ink-soft); font-size: 13px; margin-bottom: 14px; }
.subject-line { font-size: 13px; color: var(--ink-soft); margin-bottom: 10px; }
.subject-line b { color: var(--ink); }
.digest-preview { position: relative; }
.digest-frame { width: 100%; height: 640px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-xs); display: block; opacity: 0; transition: opacity 0.4s var(--ease); }
.digest-frame.is-loaded { opacity: 1; }

/* ---- Footer ---- */
.page-foot { max-width: 1320px; margin: 0 auto; padding: 26px 24px; color: var(--ink-faint); font-size: 12px; display: flex; gap: 8px; align-items: center; }
.page-foot .dot { opacity: 0.5; }

/* ====================================================================
   Skeleton loaders — shown during the live-sheet round-trip (refresh /
   navigation) and while the digest email preview iframe loads.
   ==================================================================== */
@keyframes skel-shimmer { 0% { background-position: -360px 0; } 100% { background-position: 360px 0; } }
.skel { position: relative; border-radius: 6px;
  background: linear-gradient(100deg, var(--line-faint) 30%, #efeee9 50%, var(--line-faint) 70%);
  background-size: 720px 100%; animation: skel-shimmer 1.25s linear infinite; }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }
.skel-line { height: 11px; }
tr.skel-row td { border-bottom: 1px solid var(--line-faint); }
tr.skel-row .skel-line { height: 12px; }
.kpi-value .skel-line { height: 22px; width: 72%; display: block; }
.digest-skeleton { position: absolute; inset: 0; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; overflow: hidden; background: var(--surface); }
.digest-skeleton .skel-line { margin-bottom: 12px; }
.digest-frame.is-loaded + .digest-skeleton,
.digest-skeleton.is-hidden { opacity: 0; visibility: hidden; transition: opacity 0.35s var(--ease), visibility 0s 0.35s; }

/* ====================================================================
   Print — a clean, fitted table view. Chrome is dropped; only the page
   title, a print caption, and the table print. Rows hidden by the active
   filters carry .row-hidden (display:none) so the print naturally shows
   exactly what's on screen.
   ==================================================================== */
.print-only { display: none; }

@media print {
  @page { size: landscape; margin: 12mm; }
  :root { --topbar-h: 0px; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { background: #fff; font-size: 11px; }
  .topbar, .toolbar, .kpis, .grid-2, .page-foot, .head-meta, .alert { display: none !important; }
  .page { max-width: none; margin: 0; padding: 0; }
  .page-head { margin: 0 0 6px; display: block; }
  .page-title { font-size: 17px; }
  .page-sub { display: none; }

  .print-only { display: block; }
  .print-meta { color: #444; font-size: 11px; margin: 0 0 10px; }
  .print-meta .sep { color: #aaa; margin: 0 7px; }

  .table-wrap { border: none; box-shadow: none; border-radius: 0; overflow: visible; }
  table.data { font-size: 10px; }
  thead { display: table-header-group; }   /* repeat header on every page */
  table.data th { position: static; background: #f3f2ee !important; color: #333 !important; box-shadow: none; border-bottom: 1.5px solid #999; letter-spacing: 0.03em; }
  table.data th.sortable::after { content: ""; }
  table.data th, table.data td { padding: 5px 8px; white-space: normal; }
  table.data tbody tr { break-inside: avoid; }
  table.data tbody tr:hover { background: none; }
  .badge { border: 1px solid rgba(0, 0, 0, 0.12); }
  .row-hidden { display: none !important; }
}
