:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #1f2937; --muted: #6b7280; --line: #e5e7eb; --line2: #d1d5db;
  --brand: #1d4ed8; --brand-soft: #e8efff; --ok: #15803d; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fff4e0;
  --bad: #b91c1c; --bad-soft: #fdecec; --edit: #fffbea; --locked: #f1f1f1; --nav: #0f1e3d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 13px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 11.5px; } .err { color: var(--bad); min-height: 1em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--ok); } .neg { color: var(--bad); }

.login { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(135deg, #0f1e3d, #1d4ed8); }
.login-card { background: #fff; padding: 28px 32px; border-radius: 12px; width: 340px; display: grid; gap: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.login-card h1 { margin: 0; font-size: 20px; }
label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--line2); border-radius: 6px; background: #fff; color: var(--ink); }
textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

.app { display: grid; grid-template-columns: 196px 1fr; height: 100vh; }
.nav { background: var(--nav); color: #cbd5e1; display: flex; flex-direction: column; padding: 12px 0; overflow-y: auto; }
.nav .brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 18px 14px; }
.nav a { color: #cbd5e1; text-decoration: none; padding: 8px 18px; border-left: 3px solid transparent; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; border-left-color: #60a5fa; }
.nav-sep { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 14px 18px 4px; }
main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.page-title { font-size: 17px; font-weight: 600; }
.top-right { display: flex; gap: 12px; align-items: center; }
.content { padding: 16px 20px; overflow: auto; flex: 1; }

.btn { font: inherit; border: 1px solid var(--line2); background: #fff; color: var(--ink); padding: 6px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn { text-decoration: none; display: inline-block; }
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); color: #fff; }
.btn.danger { color: var(--bad); border-color: #f3c0c0; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; font-size: 14px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.tile .k { font-size: 11.5px; color: var(--muted); } .tile .v { font-size: 20px; font-weight: 600; margin-top: 4px; } .tile .d { font-size: 12px; margin-top: 2px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-size: 11.5px; font-weight: 600; }
.badge.Approved, .badge.Published, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.Proposed, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.Draft, .badge.Open { background: #eef2f7; color: #475569; }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: none; background: none; padding: 8px 12px; cursor: pointer; font: inherit; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

table.t { border-collapse: separate; border-spacing: 0; width: 100%; background: #fff; }
table.t th, table.t td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.t th { position: sticky; top: 0; background: #f8fafc; font-weight: 600; font-size: 12px; color: #374151; z-index: 2; }
table.t tr:hover td { background: #fafcff; }
.tablewrap { overflow: auto; max-height: 62vh; border: 1px solid var(--line); border-radius: 8px; }
table.t td.click { cursor: pointer; color: var(--brand); }

/* forecast grid */
.fgrid { border-collapse: separate; border-spacing: 0; font-size: 12px; }
.fgrid th, .fgrid td { padding: 4px 6px; border-bottom: 1px solid var(--line); border-right: 1px solid #f1f3f6; min-width: 68px; }
.fgrid th { position: sticky; top: 0; background: #f8fafc; z-index: 3; text-align: right; font-weight: 600; }
.fgrid .lbl { position: sticky; left: 0; background: #fff; z-index: 2; box-shadow: 1px 0 0 var(--line2); min-width: 230px; max-width: 320px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fgrid th.lbl { z-index: 4; background: #f8fafc; }
.fgrid td.cell { text-align: right; font-variant-numeric: tabular-nums; }
.fgrid td.ed { background: var(--edit); cursor: cell; }
.fgrid td.ed:hover { outline: 1px solid #f0c040; }
.fgrid td.sel { outline: 2px solid var(--brand) !important; outline-offset: -2px; }
.fgrid td.past { color: #4b5563; }
.fgrid tr.total td { font-weight: 700; border-top: 2px solid var(--line2); }
.fgrid tr.arch td { color: #7c3aed; }
.fgrid tr.child td.lbl { padding-left: 22px; }
.fgrid tr.child td.lbl a { color: var(--brand); cursor: pointer; text-decoration: none; }
.fgrid tr.section td { background: #f3f6fb; font-weight: 600; color: #334155; }
.fgrid td input { width: 100%; border: none; padding: 0; text-align: right; background: #fff; font: inherit; outline: none; }
.fgrid .curcol { box-shadow: inset 2px 0 0 #93c5fd; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

/* perimeter picker */
.perim { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-flex; gap: 6px; align-items: center; background: var(--brand-soft); color: var(--brand); padding: 3px 4px 3px 10px; border-radius: 999px; font-size: 12px; }
.chip button { border: none; background: transparent; color: inherit; cursor: pointer; font-size: 13px; padding: 0 4px; }
.picker { position: relative; }
.picker .dd { position: absolute; top: 100%; left: 0; width: 460px; max-height: 340px; overflow: auto; background: #fff; border: 1px solid var(--line2); border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.12); z-index: 20; }
.picker .dd div { padding: 6px 10px; cursor: pointer; border-bottom: 1px solid #f3f4f6; }
.picker .dd div:hover { background: var(--brand-soft); }
.picker .dd small { color: var(--muted); }

.toast { position: fixed; right: 20px; bottom: 20px; background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 480px; z-index: 100; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.error { background: var(--bad); }
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 90; }
.modal-card { background: #fff; border-radius: 12px; padding: 18px 20px; width: min(620px, 94vw); max-height: 88vh; overflow: auto; display: grid; gap: 10px; }
.modal-card h3 { margin: 0; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 10px; }
.chart { width: 100%; height: 300px; }
.breadcrumb a { color: var(--brand); cursor: pointer; } .breadcrumb span.sep { color: var(--muted); margin: 0 6px; }
.progress { height: 10px; background: #eef2f7; border-radius: 99px; overflow: hidden; } .progress > div { height: 100%; background: var(--ok); }

.quick { display: inline-flex; gap: 4px; margin-right: 6px; }
.month-range { display: inline-flex; gap: 6px; align-items: flex-end; }
table.t td.dirty { background: #fff4d6; }
table.t td.edit input { width: 100%; min-width: 80px; border: 1px solid var(--line2); border-radius: 4px; padding: 3px 5px; font-size: 12px; }
table.t tr.newrow td { background: #eefbf1; }
table.t tr.delrow td { text-decoration: line-through; color: var(--muted); background: #fdecec; }
table.t thead tr.filters th { top: 30px; background: #fff; padding: 3px 4px; }
table.t thead tr.filters input { width: 100%; min-width: 60px; font-size: 11.5px; padding: 3px 5px; }
.flag { display: inline-block; font-size: 11px; padding: 1px 6px; margin: 1px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); white-space: nowrap; }
.flag.bad { background: var(--bad-soft); color: var(--bad); }

.dd-panel { position: absolute; top: 100%; left: 0; z-index: 30; background: #fff; border: 1px solid var(--line2); border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.12); padding: 10px 12px; min-width: 300px; max-height: 420px; overflow: auto; color: var(--ink); font-size: 13px; }
.dd-panel .chk { display: flex; align-items: center; gap: 6px; padding: 3px 0; color: var(--ink); font-size: 13px; cursor: pointer; }
.fgrid tr.calc td { color: #0f766e; font-style: italic; background: #f6fbfa; }
.fgrid tr.calc td.lbl { background: #f6fbfa; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; margin: 1px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); }
code.f { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 12px; }

.fgrid tr.virt td { color: #0e7490; background: #f3fafc; }
.fgrid tr.virt td.lbl { background: #f3fafc; font-weight: 600; }
.month-range input[type=month] { min-width: 175px; }
