/* Financial Model — stylesheet */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --border-strong: #c9ced6;
  --text: #17202b;
  --text-2: #4b5563;
  --text-3: #7b8494;
  --accent: #1f5eff;
  --accent-soft: #e8efff;
  --pos: #12805c;
  --pos-soft: #e3f5ee;
  --neg: #c4321f;
  --neg-soft: #fbe9e6;
  --warn: #a8650a;
  --warn-soft: #fdf1dc;
  --input: #fffbea;
  --input-border: #e9d98c;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --c1: #1f5eff; --c2: #12a37a; --c3: #f29a1a; --c4: #d6453a; --c5: #7a52e0; --c6: #0f9bb8; --c7: #d04b92; --c8: #6b8e23;
  --radius: 10px;
  --sidebar: 268px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --surface: #161a21; --surface-2: #1d222b; --border: #2a303b; --border-strong: #3a4250;
    --text: #e7eaf0; --text-2: #b4bbc8; --text-3: #8790a0; --accent: #6b95ff; --accent-soft: #1c2742;
    --pos: #3cc48f; --pos-soft: #12291f; --neg: #ff7a66; --neg-soft: #331915; --warn: #f0b04a; --warn-soft: #2e2412;
    --input: #26241a; --input-border: #5a5124; --shadow: none; color-scheme: dark;
    --c1: #6b95ff; --c2: #3cc48f; --c3: #f5b041; --c4: #ff7a66; --c5: #a487f5; --c6: #4cc3dc; --c7: #f07ab5; --c8: #9cc650;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --surface: #161a21; --surface-2: #1d222b; --border: #2a303b; --border-strong: #3a4250;
  --text: #e7eaf0; --text-2: #b4bbc8; --text-3: #8790a0; --accent: #6b95ff; --accent-soft: #1c2742;
  --pos: #3cc48f; --pos-soft: #12291f; --neg: #ff7a66; --neg-soft: #331915; --warn: #f0b04a; --warn-soft: #2e2412;
  --input: #26241a; --input-border: #5a5124; --shadow: none; color-scheme: dark;
  --c1: #6b95ff; --c2: #3cc48f; --c3: #f5b041; --c4: #ff7a66; --c5: #a487f5; --c6: #4cc3dc; --c7: #f07ab5; --c8: #9cc650;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; line-height: 1.25; margin: 4px 0 6px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 28px 0 10px; }
h3 { font-size: 14px; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); }
p { margin: 0 0 10px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.lead { color: var(--text-2); max-width: 820px; margin-bottom: 18px; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }

/* Layout */
#app { display: flex; min-height: 100vh; overflow-x: clip; }
#sidebar { width: var(--sidebar); flex: 0 0 var(--sidebar); background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 14px 10px 40px; transition: margin-left .22s ease, transform .22s ease; }
body.nav-collapsed #sidebar { margin-left: calc(-1 * var(--sidebar)); }
#nav-backdrop { display: none; }
main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border); padding: 10px 24px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
#content { padding: 18px 24px 60px; max-width: 1500px; width: 100%; }

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.brand-name { font-weight: 650; font-size: 13.5px; line-height: 1.2; }
.brand-sub { font-size: 11.5px; color: var(--text-3); }
.nav-sec { margin: 6px 0; }
.nav-sec > button { all: unset; cursor: pointer; display: flex; width: 100%; box-sizing: border-box; justify-content: space-between; align-items: center;
  padding: 6px 8px; font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); border-radius: 6px; }
.nav-sec > button:hover { color: var(--text); }
.nav-sec > button::after { content: "▾"; font-size: 10px; transition: transform .15s; }
.nav-sec.closed > button::after { transform: rotate(-90deg); }
.nav-sec.closed ul { display: none; }
.nav-sec ul { list-style: none; margin: 0; padding: 0; }
.nav-sec a { display: block; padding: 5px 10px; border-radius: 6px; color: var(--text-2); font-size: 13px; }
.nav-sec a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav-sec a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.icon-btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; min-width: 34px; padding: 0 9px; justify-content: center; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.icon-btn:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.menu-btn { padding: 0; width: 36px; }
.cur-picker { position: relative; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 11px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-size: 12.5px; cursor: pointer; white-space: nowrap; }
.chip:hover { border-color: var(--border-strong); background: var(--surface-2); }
.chip-sub { color: var(--text-3); max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.popover { position: absolute; right: 0; top: 42px; width: 300px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,.18); padding: 14px; display: none; z-index: 70; }
.popover.open { display: block; }
.popover .field { margin-bottom: 10px; }
.popover select { width: 100%; text-align: left; }
.search { position: relative; flex: 1; max-width: 380px; }
.search input { width: 100%; padding: 7px 10px 7px 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; }
.search::before { content: "⌕"; position: absolute; left: 10px; top: 5px; color: var(--text-3); font-size: 15px; }
.search-results { position: absolute; top: 38px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,.15); max-height: 60vh; overflow-y: auto; display: none; z-index: 50; }
.search-results.open { display: block; }
.search-results a { display: block; padding: 7px 12px; color: var(--text); border-bottom: 1px solid var(--border); }
.search-results a:hover, .search-results a.sel { background: var(--accent-soft); text-decoration: none; }
.search-results .sr-sec { font-size: 11px; color: var(--text-3); margin-left: 6px; }
.topbar-right { margin-left: auto; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Controls */
select, input[type="text"], input[type="number"], input[type="file"] { font: inherit; color: var(--text); }
select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--neg); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status.ok { background: var(--pos-soft); color: var(--pos); }
.status.bad { background: var(--neg-soft); color: var(--neg); }
.status.warn { background: var(--warn-soft); color: var(--warn); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.tabs { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; margin: 4px 0 12px; }
.tabs button, .tabs a { all: unset; cursor: pointer; padding: 5px 12px; border-radius: 7px; font-size: 13px; color: var(--text-2); }
.tabs button.on, .tabs a.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 6px 0 12px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .k-label { font-size: 12px; color: var(--text-3); }
.kpi .k-val { font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; }
.kpi .k-sub { font-size: 12px; color: var(--text-2); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.tile { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 11px 13px; color: var(--text); }
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile .t-title { font-weight: 600; font-size: 13.5px; }
.tile .t-sub { font-size: 12px; color: var(--text-3); }
.tile .t-val { font-variant-numeric: tabular-nums; font-size: 13px; margin-top: 4px; }

/* Financial tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 16px; }
table.fin { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; font-size: 13px; }
table.fin th, table.fin td { padding: 6px 12px; white-space: nowrap; text-align: right; border-bottom: 1px solid var(--border); }
table.fin thead th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; font-size: 12px; color: var(--text-2); z-index: 2; }
table.fin th:first-child, table.fin td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 240px; }
table.fin thead th:first-child { background: var(--surface-2); z-index: 3; }
table.fin tr.h td { font-weight: 650; padding-top: 14px; color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
table.fin tr.t td { font-weight: 650; border-top: 1px solid var(--border-strong); }
table.fin tr.g td { font-weight: 700; border-top: 1px solid var(--text-2); border-bottom: 3px double var(--text-2); background: var(--surface-2); }
table.fin tr.g td:first-child { background: var(--surface-2); }
table.fin tr.p td { font-style: italic; color: var(--text-3); font-size: 12px; }
table.fin tr.c td { color: var(--pos); font-size: 12px; }
table.fin tr.c.bad td { color: var(--neg); font-weight: 700; }
table.fin td.i1 { padding-left: 26px; } table.fin td.i2 { padding-left: 42px; color: var(--text-2); }
table.fin td.n { color: var(--neg); }
table.fin tr:hover td { background: var(--accent-soft); }
table.fin td a { color: inherit; }
table.fin td a:hover { color: var(--accent); }
table.fin .colsub { display: block; font-weight: 400; font-size: 11px; color: var(--text-3); }
table.fin th.ytot, table.fin td.ytot { background: var(--surface-2); font-weight: 650; }
table.heat td.cell { min-width: 90px; }
table.heat td.base { outline: 2px solid var(--text); outline-offset: -2px; font-weight: 700; }
table.heat th.axis { color: var(--accent); }
.unit-note { font-size: 12px; color: var(--text-3); margin: -4px 0 8px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px 20px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.field .help { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }
.field input, .field select, table.inputs input, table.inputs select { width: 100%; padding: 7px 9px; border-radius: 7px; border: 1px solid var(--input-border);
  background: var(--input); color: var(--text); font: inherit; font-variant-numeric: tabular-nums; text-align: right; }
.field input[type="text"], table.inputs input[type="text"] { text-align: left; }
.field input:focus, table.inputs input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.field .suffix { position: relative; }
.field .suffix span { position: absolute; right: 9px; top: 7px; color: var(--text-3); pointer-events: none; }
.field .suffix input { padding-right: 26px; }
table.inputs { border-collapse: collapse; width: 100%; font-size: 13px; }
table.inputs th, table.inputs td { padding: 4px 6px; text-align: right; border-bottom: 1px solid var(--border); }
table.inputs th:first-child, table.inputs td:first-child { text-align: left; min-width: 180px; }
table.inputs thead th { font-size: 12px; color: var(--text-2); font-weight: 600; }
table.inputs input { min-width: 84px; padding: 5px 7px; }
.saved { font-size: 12px; color: var(--pos); opacity: 0; transition: opacity .3s; }
.saved.show { opacity: 1; }
.preview { position: sticky; top: 70px; }
.assume-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.mini-table { width: 100%; font-size: 12.5px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.mini-table td { padding: 4px 0; border-bottom: 1px solid var(--border); }
.mini-table td:last-child { text-align: right; font-weight: 600; }

/* Charts */
.chart { position: relative; height: 290px; width: 100%; }
.chart.tall { height: 360px; } .chart.short { height: 200px; }
.chart canvas { display: block; width: 100%; height: 100%; }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px;
  font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.15); display: none; z-index: 5; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart-tip b { display: block; margin-bottom: 3px; }
.chart-tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin: 0 0 8px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--sw); margin-right: 6px; vertical-align: -1px; }
.spark { width: 110px; height: 28px; display: inline-block; vertical-align: middle; }

/* Content pages */
.crumbs { font-size: 12.5px; color: var(--text-3); margin-bottom: 4px; }
.crumbs a { color: var(--text-3); }
.crumbs span { margin: 0 6px; }
.doc { max-width: 820px; font-size: 15px; line-height: 1.65; }
.doc h2 { font-size: 18px; }
.doc ul, .doc ol { padding-left: 22px; }
.doc li { margin-bottom: 5px; }
.formula { font-family: var(--mono); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin: 10px 0 16px; font-size: 13px; overflow-x: auto; }
.callout { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 10px 14px; border-radius: 0 8px 8px 0; margin: 12px 0; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--border); }
.pager a { display: block; padding: 9px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); max-width: 48%; }
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager .lbl { display: block; font-size: 11px; color: var(--text-3); }
.check-list { list-style: none; padding: 0; margin: 0; }
.check-list li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.check-list .ic { flex: 0 0 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.check-list .ic.ok { background: var(--pos-soft); color: var(--pos); }
.check-list .ic.bad { background: var(--neg-soft); color: var(--neg); }
.check-list .ic.warn { background: var(--warn-soft); color: var(--warn); }
.sitemap-sec { columns: 3 240px; column-gap: 24px; }
.sitemap-sec a { display: block; padding: 2px 0; font-size: 13px; break-inside: avoid; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-size: 13px; z-index: 100; opacity: 0; transition: opacity .25s; pointer-events: none; }
.toast.show { opacity: 1; }
.noscript { padding: 20px; background: var(--warn-soft); color: var(--warn); }

@media (max-width: 1100px) { .assume-layout { grid-template-columns: 1fr; } .preview { position: static; } .grid.c3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px) {
  #sidebar { position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.25); }
  body.nav-collapsed #sidebar { margin-left: 0; }
  body.nav-open #sidebar { transform: none; }
  body.nav-open #nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 55; }
  .chip-sub, #fm-theme span { display: none; }
  .popover { position: fixed; left: 16px; right: 16px; top: 64px; width: auto; }
  #topbar, #content { padding-left: 16px; padding-right: 16px; }
  .grid.c2, .grid.c3 { grid-template-columns: 1fr; }
  h1 { font-size: 21px; }
  table.fin th:first-child, table.fin td:first-child { min-width: 170px; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
}
@media print {
  #sidebar, #topbar, .pager, .btn, .tabs, .toolbar, .no-print { display: none !important; }
  body { background: #fff; color: #000; font-size: 11px; }
  #content { padding: 0; max-width: none; }
  .card, .table-wrap { box-shadow: none; break-inside: avoid; border-color: #bbb; }
  .table-wrap { overflow: visible; }
  table.fin th:first-child, table.fin td:first-child { position: static; }
  .page-break { break-before: page; }
}

/* Input data: start page, import, status */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill.sample { background: var(--warn-soft); color: var(--warn); }
.pill.edited { background: var(--pos-soft); color: var(--pos); }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 16px; }
.step { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.step .num { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.step h3 { margin: 0 0 6px; text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--text); }
.howto { border: 1px solid var(--border); border-left: 4px solid var(--accent); background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; padding: 12px 16px; margin-bottom: 16px; }
.howto ul { margin: 6px 0 0; padding-left: 20px; }
.howto li { margin-bottom: 3px; font-size: 13.5px; }
.legend-input { display: inline-block; width: 14px; height: 14px; border-radius: 3px; background: var(--input); border: 1px solid var(--input-border); vertical-align: -2px; }
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 28px 16px; text-align: center; background: var(--surface-2); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone b { font-size: 15px; }
.msg-list { list-style: none; padding: 0; margin: 8px 0; font-size: 13px; }
.msg-list li { padding: 6px 10px; border-radius: 6px; margin-bottom: 4px; }
.msg-list li.err { background: var(--neg-soft); color: var(--neg); }
.msg-list li.warn { background: var(--warn-soft); color: var(--warn); }
.chg-old { color: var(--text-3); text-decoration: line-through; }
.chg-new { color: var(--pos); font-weight: 600; }
.fmt-preview { font-variant-numeric: tabular-nums; font-size: 13px; }
@media print { #nav-backdrop, .popover { display: none !important; } }
