:root {
  --bg: #0f1420;
  --card: #1b2537;
  --card2: #212d43;
  --line: #2a3550;
  --txt: #e7ecf5;
  --muted: #93a1bd;
  --accent: #4f8cff;
  --good: #2fbf71;
  --warn: #f2a53a;
  --bad: #e5544b;
  --chip: #24304a;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--txt); font-size: 14px; -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* Gate */
.gate { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1c2740, var(--bg)); }
.gate-card { width: 320px; max-width: 90vw; padding: 32px 26px; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.45); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.gate-logo { font-size: 20px; font-weight: 700; }
.gate-sub { color: var(--muted); margin: 0 0 6px; font-size: 13px; }
.gate-input { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  color: var(--txt); font-size: 18px; text-align: center; letter-spacing: 4px; }
.gate-input:focus { outline: none; border-color: var(--accent); }
.gate-btn { padding: 12px 14px; border: 0; border-radius: 10px; cursor: pointer; background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; }
.gate-btn:hover { filter: brightness(1.08); }
.gate-err { color: var(--bad); font-size: 13px; min-height: 16px; }

/* Shell */
.app { max-width: 860px; margin: 0 auto; padding: 20px 18px 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.topbar h1 { margin: 0; font-size: 22px; font-weight: 700; }
.topbar-sub { color: var(--muted); font-size: 13px; }
.topbar-r { display: flex; align-items: center; gap: 8px; }
.updated { color: var(--muted); font-size: 12px; margin-right: 4px; }
.btn-ghost { width: 34px; height: 34px; border-radius: 9px; cursor: pointer; background: var(--chip); border: 1px solid var(--line); color: var(--txt); font-size: 15px; }
.btn-ghost:hover { border-color: var(--accent); }

/* Hero */
.hero { display: grid; grid-template-columns: 1.6fr 1fr 1fr; gap: 12px; margin-bottom: 22px; }
.hero-main { grid-column: 1 / 2; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; }
.hero-main.neg-bg { border-color: rgba(229,84,75,.4); background: linear-gradient(180deg, rgba(229,84,75,.08), var(--card)); }
.hero-main .h-lbl { color: var(--muted); font-size: 12px; margin: 0 0 4px; }
.hero-main .h-big { font-size: 42px; font-weight: 700; line-height: 1.05; letter-spacing: .3px; font-variant-numeric: tabular-nums; }
.hero-main .h-cap { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; line-height: 1.45; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; justify-content: center; }
.kpi .k-lbl { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.kpi .k-lbl .k-note { color: var(--muted); opacity: .7; font-size: 11px; }
.kpi .k-val { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .k-sub { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.pos { color: var(--good); } .neg { color: var(--bad); } .amb { color: var(--warn); }

/* Blocks */
.block { margin-bottom: 22px; }
.block-h { font-size: 15px; font-weight: 650; margin-bottom: 12px; }
.block-note { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 6px; }
.mini-note { color: var(--muted); font-size: 12px; margin-top: 10px; line-height: 1.55; }
.mini-note b { color: var(--txt); font-weight: 600; }

/* OPEX control */
.opexblock { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.opex { display: flex; align-items: center; gap: 16px; margin-top: 4px; }
.opex input[type=range] { flex: 1; accent-color: var(--warn); height: 4px; cursor: pointer; }
.opex-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; white-space: nowrap; }
.opex-inp { display: flex; align-items: center; gap: 6px; }
.opex-inp input { width: 90px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg);
  color: var(--txt); font-size: 16px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.opex-inp input:focus { outline: none; border-color: var(--warn); }
.opex-inp span { color: var(--muted); font-size: 12px; }
.opex-tot { color: var(--muted); font-size: 12.5px; }
.opex-tot b { color: var(--txt); }

/* Waterfall */
.wf { display: block; }
.wf-real { fill: var(--accent); }
.wf-cost { fill: var(--bad); opacity: .82; }
.wf-net { fill: var(--good); }
.wf-netneg { fill: var(--bad); }
.wf-zero { stroke: var(--line); stroke-width: 1; }
.wf-conn { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; opacity: .5; }
.wf-val { fill: var(--txt); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.wf-lbl { fill: var(--txt); font-size: 12px; font-weight: 600; }
.wf-sub { fill: var(--muted); font-size: 10px; }

/* Run-rate + realgap charts */
.rr { display: block; }
.rr-bar { fill: var(--accent); }
.rr-part { fill: var(--accent); opacity: .38; }
.rr-ma { fill: none; stroke: var(--warn); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.rr-v { fill: #fff; font-size: 10px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rr-x { fill: var(--muted); font-size: 10px; }
.rr-ax { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.rr-grid { stroke: var(--line); stroke-width: 1; opacity: .5; }
.rg-fact { fill: var(--chip); stroke: var(--accent); stroke-width: 1; }
.rg-real { fill: var(--good); }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; color: var(--muted); font-size: 11.5px; margin-top: 8px; }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 2px; }
.lg-bar { background: var(--accent); }
.lg-ma { background: var(--warn); }
.lg-part { background: var(--accent); opacity: .38; }
.lg-fact { background: var(--chip); border: 1px solid var(--accent); }
.lg-real { background: var(--good); }

.foot { color: var(--muted); font-size: 12px; margin-top: 8px; line-height: 1.6; }
.foot b { color: #b9c4dc; }
.loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); color: var(--muted); z-index: 40; }

@media (max-width: 680px) {
  .hero { grid-template-columns: 1fr 1fr; }
  .hero-main { grid-column: 1 / 3; }
  .opex { flex-direction: column; align-items: stretch; gap: 10px; }
  .opex-side { align-items: center; flex-direction: row; justify-content: space-between; }
  .topbar h1 { font-size: 19px; }
}
