/* Alfer Financials. Tokens ported from alfernet (web/static/css/styles.css):
   slate-and-blue base, 13px system font, 52px top bar, 256px sidebar.
   CSP allows no inline styles: every look comes from a class here. */

:root {
  --primary: #0f172a;
  --primary-light: #1e293b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --bg-main: #f1f5f9;
  --bg-white: #ffffff;
  --bg-subtle: #f8fafc;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --ok: #16a34a;     --ok-bg: #dcfce7;     --ok-fg: #166534;
  --warn: #f59e0b;   --warn-bg: #fef3c7;   --warn-fg: #92400e;
  --bad: #ef4444;    --bad-bg: #fee2e2;    --bad-fg: #991b1b;
  --info: #3b82f6;   --info-bg: #dbeafe;   --info-fg: #1e40af;
  --neg: #b91c1c;

  --fs-2xs: 10px; --fs-xs: 11px; --fs-sm: 12px; --fs-base: 13px;
  --fs-md: 14px; --fs-lg: 16px; --fs-xl: 20px; --fs-2xl: 24px;

  --sp-1: 2px; --sp-2: 4px; --sp-3: 6px; --sp-4: 8px;
  --sp-5: 12px; --sp-6: 16px; --sp-8: 24px;

  --r-sm: 4px; --r-md: 6px; --r-lg: 10px; --r-pill: 9999px;

  --sh-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --sh-md: 0 2px 6px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --sh-lg: 0 10px 20px -6px rgba(15, 23, 42, 0.18), 0 4px 8px -4px rgba(15, 23, 42, 0.08);

  --z-sticky: 10; --z-topbar: 60; --z-modal: 1000; --z-tooltip: 1200;

  --sidebar-width: 256px;
  --h-topbar: 52px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  color: var(--text-main);
  background: var(--bg-main);
  line-height: 1.4;
}
a { color: var(--accent-hover); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: var(--fs-xl); margin: 0 0 var(--sp-5); font-weight: 600; }
h2 { font-size: var(--fs-lg); margin: var(--sp-6) 0 var(--sp-4); font-weight: 600; }
h3 { font-size: var(--fs-md); margin: var(--sp-5) 0 var(--sp-3); font-weight: 600; }
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------------------------------------- app shell */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--h-topbar); z-index: var(--z-topbar);
  display: flex; align-items: center; gap: var(--sp-5);
  padding: 0 var(--sp-6); background: var(--primary); color: #e2e8f0;
}
.brand { width: calc(var(--sidebar-width) - var(--sp-6)); font-weight: 700; font-size: var(--fs-md); color: #fff; white-space: nowrap; }
.brand small { font-weight: 400; color: var(--text-subtle); margin-left: var(--sp-2); }
.controls { display: flex; align-items: center; gap: var(--sp-4); flex: 1; min-width: 0; }
.controls label { font-size: var(--fs-xs); color: var(--text-subtle); display: flex; align-items: center; gap: var(--sp-2); }
.controls select {
  font: inherit; font-size: var(--fs-sm); color: var(--text-main); background: #fff;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 3px 6px;
}
.topbar .meta { display: flex; align-items: center; gap: var(--sp-4); font-size: var(--fs-xs); color: var(--text-subtle); white-space: nowrap; min-width: 0; }
.topbar .meta a { color: #e2e8f0; }
.topbar .meta a.badge-bad { color: var(--bad-fg); }
.topbar .meta .import-info { overflow: hidden; text-overflow: ellipsis; }
.topbar form.inline { display: inline; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: #e2e8f0; cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }

.sidebar {
  position: fixed; top: var(--h-topbar); bottom: 0; left: 0; width: var(--sidebar-width);
  background: var(--bg-white); border-right: 1px solid var(--border); overflow-y: auto; padding: var(--sp-5) 0;
}
.sidebar .group { padding: var(--sp-4) var(--sp-6) var(--sp-2); font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: .06em; color: var(--text-subtle); }
.sidebar a { display: block; padding: var(--sp-3) var(--sp-6); color: var(--text-main); border-left: 3px solid transparent; }
.sidebar a:hover { background: var(--bg-subtle); text-decoration: none; }
.sidebar a.active { background: var(--info-bg); border-left-color: var(--accent); color: var(--info-fg); font-weight: 600; }
.sidebar a.sub { padding-left: calc(var(--sp-6) + var(--sp-5)); font-size: var(--fs-sm); }

.main { margin-left: var(--sidebar-width); padding: calc(var(--h-topbar) + var(--sp-6)) var(--sp-6) var(--sp-8); min-width: 0; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-5); flex-wrap: wrap; }
.page-head .actions { display: flex; gap: var(--sp-4); align-items: center; flex-wrap: wrap; }

.card { background: var(--bg-white); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--sh-sm); padding: var(--sp-5) var(--sp-6); margin-bottom: var(--sp-6); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-6); }
.grid-2 > .card { margin-bottom: 0; }
.empty { padding: var(--sp-8); text-align: center; color: var(--text-muted); }

/* ------------------------------------------------------------- buttons, badges */
.btn {
  display: inline-flex; align-items: center; gap: var(--sp-2); font: inherit; font-size: var(--fs-sm); font-weight: 500;
  padding: 5px 12px; border-radius: var(--r-sm); border: 1px solid var(--border-strong); background: #fff; color: var(--text-main); cursor: pointer;
}
.btn:hover { background: var(--bg-subtle); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-small { padding: 2px 8px; font-size: var(--fs-xs); }

.badge { display: inline-block; padding: 1px 7px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; line-height: 1.5; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-bad { background: var(--bad-bg); color: var(--bad-fg); }
.badge-info { background: var(--info-bg); color: var(--info-fg); }
.badge-muted { background: var(--border); color: var(--text-muted); }
a.badge:hover { text-decoration: none; filter: brightness(.96); }

.notice { padding: var(--sp-4) var(--sp-5); border-radius: var(--r-sm); margin: var(--sp-4) 0; font-size: var(--fs-sm); }
.notice-warn { background: var(--warn-bg); color: var(--warn-fg); }
.notice-bad { background: var(--bad-bg); color: var(--bad-fg); }
.notice-info { background: var(--info-bg); color: var(--info-fg); }
.notice-ok { background: var(--ok-bg); color: var(--ok-fg); }

/* ------------------------------------------------------------- figures */
.fig { font-variant-numeric: tabular-nums; white-space: nowrap; cursor: pointer; border-bottom: 1px dotted transparent; }
.fig:hover, .fig:focus-visible { border-bottom-color: var(--accent); outline: none; }
.fig.neg { color: var(--neg); }
.fig.zero { color: var(--text-subtle); }
.fig.nil { color: var(--text-subtle); cursor: default; }
.fig.restated { box-shadow: inset 0 -2px 0 var(--warn); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ------------------------------------------------------------- tables */
.table-wrap { overflow: auto; max-height: calc(100vh - var(--h-topbar) - 140px); border: 1px solid var(--border); border-radius: var(--r-md); background: #fff; }
.table-wrap.short { max-height: none; }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: var(--fs-sm); }
table.data th, table.data td { padding: 4px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data thead th {
  position: sticky; top: 0; z-index: calc(var(--z-sticky) + 1); background: var(--bg-subtle);
  font-weight: 600; text-align: left; color: var(--text-muted); font-size: var(--fs-xs); white-space: nowrap;
}
table.data thead th.num { text-align: right; }
table.data th.sticky, table.data td.sticky { position: sticky; left: 0; background: #fff; z-index: var(--z-sticky); }
table.data thead th.sticky { z-index: calc(var(--z-sticky) + 2); background: var(--bg-subtle); }
table.data tbody tr:hover td { background: #f8fafc; }
table.data tbody tr:hover td.sticky { background: #f8fafc; }
table.data tr.bold td { font-weight: 600; }
table.data tr.subtotal td { border-top: 1px solid var(--border-strong); font-weight: 600; background: var(--bg-subtle); }
table.data tr.subtotal td.sticky { background: var(--bg-subtle); }
table.data tr.heading td { font-weight: 600; color: var(--text-muted); padding-top: 10px; }
table.data tr.zero-row.hide { display: none; }
table.data td.code { color: var(--text-muted); font-size: var(--fs-xs); white-space: nowrap; }
table.data td.label { min-width: 240px; }
table.data th.sortable { cursor: pointer; }
table.data th.sortable:hover { color: var(--text-main); }
table.data th.sorted-asc::after { content: " ▲"; }
table.data th.sorted-desc::after { content: " ▼"; }
table.data tfoot td { font-weight: 600; border-top: 1px solid var(--border-strong); background: var(--bg-subtle); }
.col-ytd { border-left: 1px solid var(--border-strong); }
.note-icon { display: inline-block; margin-left: 4px; color: var(--info); cursor: help; font-size: var(--fs-xs); }
.table-tools { display: flex; gap: var(--sp-4); align-items: center; margin-bottom: var(--sp-4); flex-wrap: wrap; font-size: var(--fs-sm); }
.table-tools input[type=search] { font: inherit; padding: 3px 6px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); }

/* ------------------------------------------------------------- tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--sp-5); margin-bottom: var(--sp-6); }
.tile { background: #fff; border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-5); box-shadow: var(--sh-sm); }
.tile .label { font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.tile .value { font-size: var(--fs-lg); font-weight: 600; margin: var(--sp-2) 0; }
.tile .delta { font-size: var(--fs-xs); color: var(--text-muted); }
.tile .delta .up { color: var(--ok-fg); }
.tile .delta .down { color: var(--bad-fg); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-6); }
.kcard { background: #fff; border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-4) var(--sp-5); box-shadow: var(--sh-sm); }
.kcard .label { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kcard .value { font-size: var(--fs-md); font-weight: 600; margin: var(--sp-1) 0; }
.kcard .delta { font-size: var(--fs-xs); color: var(--text-muted); }
svg.spark { display: block; width: 100%; height: 30px; margin: var(--sp-2) 0; }
svg.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
svg.spark circle { fill: var(--accent); }
svg.spark line.zero { stroke: var(--border-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
td svg.spark { width: 110px; height: 22px; margin: 0; }

.strip { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-bottom: var(--sp-6); }
.chip { display: inline-flex; gap: var(--sp-2); align-items: baseline; padding: 3px 10px; border-radius: var(--r-pill); font-size: var(--fs-xs);
  border: 1px solid var(--border); background: #fff; color: var(--text-main); }
.chip:hover { text-decoration: none; border-color: var(--border-strong); }
.chip .chip-label { color: var(--text-muted); }
.chip-green { border-color: #86efac; background: var(--ok-bg); }
.chip-amber { border-color: #fcd34d; background: var(--warn-bg); }
.chip-red { border-color: #fca5a5; background: var(--bad-bg); }

.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 320px; }
.chart-box.small { height: 90px; }

.bridge td.label { min-width: 280px; }

/* ------------------------------------------------------------- modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: var(--z-modal); background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh var(--sp-6) var(--sp-6);
  visibility: hidden; opacity: 0; transition: opacity .12s;
}
.modal-overlay.show { visibility: visible; opacity: 1; }
.modal {
  background: #fff; border-radius: var(--r-lg); box-shadow: var(--sh-lg); width: min(980px, 100%);
  max-height: 88vh; display: flex; flex-direction: column;
}
.modal.wide { width: min(1240px, 100%); }
.modal-head { display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-5) var(--sp-6); border-bottom: 1px solid var(--border); }
.modal-head .crumbs { flex: 1; min-width: 0; font-size: var(--fs-sm); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-head .crumbs button { background: none; border: 0; padding: 0; font: inherit; color: var(--accent-hover); cursor: pointer; }
.modal-head .crumbs .sep { margin: 0 var(--sp-2); color: var(--text-subtle); }
.modal-title { font-size: var(--fs-md); font-weight: 600; color: var(--text-main); }
.modal-close { background: none; border: 0; font-size: 20px; line-height: 1; cursor: pointer; color: var(--text-muted); padding: 0 var(--sp-2); }
.modal-body { padding: var(--sp-5) var(--sp-6); overflow: auto; }
.modal-foot { padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--sp-4); }
.modal-body .loading { color: var(--text-muted); padding: var(--sp-6); text-align: center; }
.confirm-box { background: var(--warn-bg); color: var(--warn-fg); border-radius: var(--r-sm); padding: var(--sp-5); margin-top: var(--sp-5); }
.confirm-box .row { display: flex; gap: var(--sp-4); justify-content: flex-end; margin-top: var(--sp-4); }

/* ------------------------------------------------------------- tooltip */
.tip {
  position: fixed; z-index: var(--z-tooltip); max-width: 440px; background: var(--primary); color: #e2e8f0;
  border-radius: var(--r-md); box-shadow: var(--sh-lg); padding: var(--sp-4) var(--sp-5); font-size: var(--fs-sm);
  pointer-events: none; visibility: hidden;
}
.tip.show { visibility: visible; }
.tip .t-title { font-weight: 600; color: #fff; margin-bottom: var(--sp-2); }
.tip .t-formula { color: #cbd5e1; margin-bottom: var(--sp-3); }
.tip table { border-collapse: collapse; width: 100%; }
.tip td { padding: 1px 0; vertical-align: top; }
.tip td.num { padding-left: var(--sp-5); }
.tip .fig.neg, .tip .neg { color: #fca5a5; }
.tip .t-foot { margin-top: var(--sp-3); color: var(--text-subtle); font-size: var(--fs-xs); }
.tip .t-gap { margin-top: var(--sp-3); color: #fde68a; font-size: var(--fs-xs); }

/* ------------------------------------------------------------- detail */
.detail-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-5); margin-bottom: var(--sp-4); }
.detail-head .big { font-size: var(--fs-xl); font-weight: 600; }
.formula-words { background: var(--bg-subtle); border-radius: var(--r-sm); padding: var(--sp-4) var(--sp-5); margin: var(--sp-4) 0; font-size: var(--fs-sm); }
.formula-text { font-family: ui-monospace, Consolas, monospace; font-size: var(--fs-xs); color: var(--text-muted); word-break: break-all; }
.recon { margin-top: var(--sp-4); font-size: var(--fs-sm); }
.recon .diff-bad { color: var(--bad-fg); font-weight: 600; }
.recon .diff-ok { color: var(--ok-fg); }
.gap-note { color: var(--warn-fg); background: var(--warn-bg); padding: var(--sp-3) var(--sp-5); border-radius: var(--r-sm); font-size: var(--fs-sm); margin: var(--sp-4) 0; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-2) var(--sp-6); margin: 0 0 var(--sp-4); font-size: var(--fs-sm); }
dl.kv dt { color: var(--text-muted); }
dl.kv dd { margin: 0; }

/* ------------------------------------------------------------- upload */
.dropzone {
  border: 2px dashed var(--border-strong); border-radius: var(--r-lg); padding: var(--sp-8); text-align: center;
  color: var(--text-muted); background: var(--bg-subtle); cursor: pointer;
}
.dropzone.over { border-color: var(--accent); background: var(--info-bg); color: var(--info-fg); }
.dropzone input[type=file] { display: none; }
.filelist { margin: var(--sp-4) 0; padding: 0; list-style: none; font-size: var(--fs-sm); }
.filelist li { padding: 2px 0; }
.progress { height: 6px; background: var(--border); border-radius: var(--r-pill); overflow: hidden; margin: var(--sp-4) 0; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ------------------------------------------------------------- forms */
.form-row { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-5); }
.form-row label { font-size: var(--fs-sm); color: var(--text-muted); }
.form-row input, .form-row select, .form-row textarea {
  font: inherit; padding: 6px 8px; border: 1px solid var(--border-strong); border-radius: var(--r-sm);
}
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 360px; background: #fff; border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-md); padding: var(--sp-8); }
.login-card h1 { font-size: var(--fs-lg); }
.login-card .btn { width: 100%; justify-content: center; padding: 8px; }

.tabs { display: flex; gap: var(--sp-2); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-5); }
.tabs a { padding: var(--sp-3) var(--sp-5); border-bottom: 2px solid transparent; color: var(--text-muted); }
.tabs a.active { border-bottom-color: var(--accent); color: var(--text-main); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text-main); }

.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--r-sm); overflow: hidden; }
.seg a { padding: 3px 10px; font-size: var(--fs-sm); color: var(--text-main); border-right: 1px solid var(--border-strong); }
.seg a:last-child { border-right: 0; }
.seg a.active { background: var(--accent); color: #fff; }
.seg a:hover { text-decoration: none; }

@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 1280px) {
  .topbar .meta .import-info { display: none; }
  .brand { width: auto; }
}
@media (max-width: 767px) {
  .sidebar { position: static; width: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .main { margin-left: 0; padding-top: var(--sp-6); }
  .topbar { position: static; height: auto; flex-wrap: wrap; padding: var(--sp-4); }
  .brand { width: auto; }
}
