:root {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #F3F5F8; --surface: #FFFFFF; --surface-2: #F8F9FB; --ink: #15223A; --muted: #5B6679;
  --faint: #8A94A6; --line: #E0E4EB; --side: #17253D; --side-ink: #D9DFEA; --side-muted: #8C9AB2;
  --gold: #A9843A; --gold-soft: #F4ECDC; --pos: #2D7654; --neg: #B03F37; --warn: #9A6A12;
  --pos-soft: #E6F2EC; --neg-soft: #F8E7E5; --warn-soft: #F7EEDC;
  --ent-BP: #2A5B8A; --ent-BPM: #2C7163; --ent-BPI: #8E6A28;
  --ent: var(--ent-BP);
  --radius: 10px;
  color-scheme: light;
}
html { scroll-padding-top: env(safe-area-inset-top, 0px); height: 100%; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1522; --surface: #151F31; --surface-2: #1A2539; --ink: #E4E9F1; --muted: #A0ABBD;
    --faint: #6F7B90; --line: #263349; --side: #0B111C; --side-ink: #D9DFEA; --side-muted: #7C8AA3;
    --gold: #D2AF62; --gold-soft: #2E2716; --pos: #5DBB8C; --neg: #E57B72; --warn: #D9A94C;
    --pos-soft: #16302A; --neg-soft: #3A1F20; --warn-soft: #33291A;
    --ent-BP: #6D9ED3; --ent-BPM: #5FB5A2; --ent-BPI: #D2AF62;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1522; --surface: #151F31; --surface-2: #1A2539; --ink: #E4E9F1; --muted: #A0ABBD;
  --faint: #6F7B90; --line: #263349; --side: #0B111C; --side-ink: #D9DFEA; --side-muted: #7C8AA3;
  --gold: #D2AF62; --gold-soft: #2E2716; --pos: #5DBB8C; --neg: #E57B72; --warn: #D9A94C;
  --pos-soft: #16302A; --neg-soft: #3A1F20; --warn-soft: #33291A;
  --ent-BP: #6D9ED3; --ent-BPM: #5FB5A2; --ent-BPI: #D2AF62;
  color-scheme: dark;
}
body[data-entity="BP"] { --ent: var(--ent-BP); }
body[data-entity="BPM"] { --ent: var(--ent-BPM); }
body[data-entity="BPI"] { --ent: var(--ent-BPI); }

* { box-sizing: border-box; }
body {
  margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: "Public Sans", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px; line-height: 1.45; font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100%; }

/* Sidebar */
.side { background: var(--side); color: var(--side-ink); padding: 22px 14px; position: sticky; top: env(safe-area-inset-top, 0px); height: 100vh; overflow-y: auto; }
.brand { padding: 0 10px 22px; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 14px; }
.brand-mark { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-mark span { color: var(--gold); }
.brand-sub { color: var(--side-muted); font-size: 12.5px; margin-top: 2px; }
.nav-group { margin: 16px 0 6px; padding: 0 10px; color: var(--side-muted); font-size: 12px; }
.nav button { display: flex; align-items: center; justify-content: space-between; width: 100%; background: none; border: 0; color: var(--side-ink); text-align: left; padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.nav button:hover { background: rgba(255,255,255,.06); }
.nav button[aria-current="page"] { background: rgba(255,255,255,.1); box-shadow: inset 3px 0 0 var(--gold); }
.nav button.soon { color: var(--side-muted); }
.nav .tag { font-size: 11px; color: var(--side-muted); border: 1px solid rgba(255,255,255,.14); border-radius: 20px; padding: 0 7px; }
.side-foot { margin-top: 24px; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.08); color: var(--side-muted); font-size: 12px; }
.side-foot button { background: none; border: 1px solid rgba(255,255,255,.16); color: var(--side-ink); border-radius: 6px; padding: 4px 9px; cursor: pointer; font-size: 12px; margin-top: 8px; }

/* Top bar */
main { min-width: 0; }
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); padding: 12px 28px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.switch { display: flex; gap: 6px; }
.switch button { display: flex; flex-direction: column; align-items: flex-start; gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 6px 14px 7px; cursor: pointer; min-width: 92px; position: relative; }
.switch button b { font-size: 15px; letter-spacing: .01em; }
.switch button small { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.switch button[aria-pressed="true"] { border-color: var(--sw); box-shadow: inset 0 -3px 0 var(--sw); }
.switch button[aria-pressed="true"] b { color: var(--sw); }
.top .spacer { flex: 1; }
.ctl { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
select, input[type="text"], input[type="number"], input[type="month"] { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; min-height: 34px; }
input[type="number"] { text-align: right; }

/* Content */
.view { padding: 24px 28px 64px; max-width: 1320px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 20px; padding-left: 16px; border-left: 4px solid var(--ent); }
.head h1 { font-size: 26px; line-height: 1.15; margin: 0; letter-spacing: -.015em; font-weight: 700; }
.head p { margin: 4px 0 0; color: var(--muted); }
.timeline { display: grid; grid-template-columns: repeat(12, 38px); gap: 3px; }
.timeline > * { height: 30px; border-radius: 5px; font-size: 11.5px; display: grid; place-items: center; color: var(--muted); border: 1px dashed var(--line); background: none; padding: 0; cursor: pointer; font-weight: 500; }
.timeline > *[disabled] { cursor: default; opacity: .55; }
.timeline > *:not([disabled]):hover { filter: brightness(1.12); }
.timeline .sel { outline: 2px solid var(--ink); outline-offset: 1px; font-weight: 700; }
.linkbtn { background: none; border: 0; color: var(--gold); cursor: pointer; text-decoration: underline; padding: 0; font-size: 12px; }
.viewnote { margin: -8px 0 16px; font-size: 13px; color: var(--muted); }
.chip.gold { color: var(--gold); border-color: var(--gold); background: var(--gold-soft); }
.warnpanel { border-color: var(--warn); background: var(--warn-soft); }
.warnpanel p { margin: 4px 0; }
.section-gap-b { margin-bottom: 16px; }
.timeline .actual { background: var(--ent); color: #fff; border: 0; }
.timeline .forecast { border: 1.5px solid var(--gold); color: var(--gold); background: var(--gold-soft); }
.timeline .gap { border: 1.5px dashed var(--neg); color: var(--neg); }
.tl-legend { font-size: 12px; color: var(--muted); margin-top: 5px; text-align: right; }

.grid { display: grid; gap: 16px; }
.g-kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.g-2 { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.g-2e { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.g-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; min-width: 0; }
.panel h2 { font-size: 15px; margin: 0 0 3px; font-weight: 650; }
.panel .sub { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }
.section-gap { margin-top: 16px; }

.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 25px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 2px; }
.kpi .note { font-size: 12.5px; color: var(--muted); }
.kpi.muted .value { color: var(--faint); font-size: 16px; font-weight: 500; margin: 10px 0 4px; }
.up { color: var(--pos); } .down { color: var(--neg); }
.neg { color: var(--neg); }

.chart { position: relative; height: 290px; }
.chart.sm { height: 230px; }
.legend-note { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* Tables */
.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-weight: 600; font-size: 12.5px; color: var(--muted); background: var(--surface-2); }
td.n, th.n { text-align: right; white-space: nowrap; }
tr.total td { font-weight: 700; border-top: 1.5px solid var(--ink); }
tr.sub td { font-weight: 600; background: var(--surface-2); }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tr.sel td { background: var(--gold-soft); }
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; min-width: 80px; }
.bar i { display: block; height: 100%; background: var(--ent); border-radius: 4px; }

/* Buttons & chips */
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 13px; cursor: pointer; font-weight: 550; min-height: 34px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ent); border-color: var(--ent); color: #fff; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--neg); }
.btn.red { background: var(--neg); border-color: var(--neg); color: #fff; }
.btn.red:hover { filter: brightness(1.08); border-color: var(--neg); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; color: var(--muted); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ent); color: #fff; }
.chip { display: inline-block; font-size: 12px; border-radius: 20px; padding: 1px 9px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.ok { color: var(--pos); border-color: var(--pos); background: var(--pos-soft); }
.chip.bad { color: var(--neg); border-color: var(--neg); background: var(--neg-soft); }
.chip.warn { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

/* Alerts & CFO */
.alerts { display: grid; gap: 8px; }
.alert { border-left: 3px solid var(--line); padding: 8px 12px; background: var(--surface-2); border-radius: 0 7px 7px 0; }
.alert.high { border-color: var(--neg); }
.alert.med { border-color: var(--warn); }
.alert.info { border-color: var(--ent); }
.alert.good { border-color: var(--pos); }
.alert b { display: block; font-weight: 600; }
.alert span { color: var(--muted); font-size: 13px; }
.cfo { border: 1px solid var(--gold); background: linear-gradient(0deg, var(--surface), var(--surface)); }
.cfo h2 { display: flex; align-items: center; gap: 8px; }
.cfo h2::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.cfo .point { padding: 10px 0; border-top: 1px solid var(--line); }
.cfo .point:first-of-type { border-top: 0; }
.cfo .point b { display: block; }
.cfo .fig { font-size: 13px; color: var(--muted); }
.cfo .act { font-size: 13px; margin-top: 2px; }
.cfo .meta { font-size: 12px; color: var(--faint); margin-top: 10px; }
.disclaimer { font-size: 11.5px; color: var(--faint); margin-top: 8px; }

/* Ratios */
.ratio .value { font-size: 22px; font-weight: 700; margin: 4px 0; }
.ratio .expl { font-size: 12.5px; color: var(--muted); }
.ratio .cmp { font-size: 12.5px; margin-top: 6px; }
.ratio svg { display: block; width: 100%; height: 36px; margin-top: 8px; }
.ratio.locked { background: var(--surface-2); }
.ratio.locked .value { color: var(--faint); font-size: 15px; font-weight: 500; }

/* Import */
.drop { display: block; border: 2px dashed var(--line); border-radius: var(--radius); padding: 36px 20px; text-align: center; background: var(--surface); cursor: pointer; }
.drop.over { border-color: var(--ent); background: var(--surface-2); }
.drop p { margin: 6px 0 0; color: var(--muted); }
.steps { display: grid; gap: 16px; }
.pick { display: flex; gap: 8px; flex-wrap: wrap; }
.pick button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 9px 14px; cursor: pointer; text-align: left; }
.pick button[aria-pressed="true"] { border-color: var(--ent); box-shadow: inset 0 0 0 1px var(--ent); }
.pick button[disabled] { opacity: .55; cursor: not-allowed; }
.pick small { display: block; color: var(--muted); font-size: 12px; }
.needs td { background: var(--warn-soft); }
td select { min-width: 190px; }

.savebar { position: sticky; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); margin-top: 16px; background: var(--side); color: #fff; border-radius: 10px; padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; box-shadow: 0 6px 24px rgba(10,20,40,.25); }
.savebar .btn { min-height: 32px; }
.banner { margin: 14px 28px 0; padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--ink); border: 1px solid var(--warn); font-size: 13px; }
.empty { text-align: center; padding: 48px 20px; }
.empty h2 { font-size: 18px; margin: 0 0 6px; }
.empty p { color: var(--muted); margin: 0 auto 16px; max-width: 520px; }
.toast { position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--side); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 20; max-width: 420px; box-shadow: 0 6px 24px rgba(10,20,40,.3); }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
ul.plain { margin: 0; padding-left: 18px; } ul.plain li { margin: 5px 0; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 10px 12px; display: flex; gap: 8px; align-items: center; overflow-x: auto; }
  .brand { border: 0; margin: 0; padding: 0 8px 0 0; white-space: nowrap; }
  .brand-sub, .nav-group, .side-foot { display: none; }
  .nav { display: flex; gap: 4px; }
  .nav button { white-space: nowrap; width: auto; }
  .nav .tag { display: none; }
  .g-2, .g-2e { grid-template-columns: 1fr; }
  .top { padding: 10px 14px; position: static; }
  .view { padding: 18px 14px 56px; }
  .banner { margin: 12px 14px 0; }
  .switch button { min-width: 0; }
  .switch button small { display: none; }
  .timeline { grid-template-columns: repeat(12, minmax(0, 1fr)); width: 100%; }
  .timeline > * { font-size: 10px; }
}

.warn { color: var(--warn); }

.kpi.click { cursor: pointer; }
.kpi.click:hover { border-color: var(--ent); }
tr.subline td { background: var(--surface-2); border-bottom-color: transparent; }

.cfo-compact ul.plain li { margin: 3px 0; color: var(--muted); }
.cfo .row.between b.small { color: var(--muted); font-weight: 600; }

