:root {
  --bg: #f4f7fb; --surface: #ffffff; --surface-2: #f0f4f9; --line: #e1e7ef; --line-strong: #cbd5e1;
  --text: #0f172a; --muted: #5b6b82; --faint: #8a98ad;
  --accent: #0891b2; --accent-2: #2563eb; --accent-soft: #e0f6fb; --accent-text: #ffffff;
  --eng: #0284c7; --eng-soft: #e0f2fe; --afr: #7c3aed; --afr-soft: #f1eaff;
  --good: #059669; --bad: #dc2626; --warn-bg: #fff7e6; --warn: #92400e;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 6px 20px rgba(15, 23, 42, .05);
  --radius: 14px; --radius-sm: 9px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0b1220; --surface: #111a2c; --surface-2: #16213a; --line: #22304b; --line-strong: #31415f;
  --text: #e6edf7; --muted: #9aabc4; --faint: #6c7d99;
  --accent: #22d3ee; --accent-2: #60a5fa; --accent-soft: #0f2f3d; --accent-text: #04202a;
  --eng: #38bdf8; --eng-soft: #0c2a3e; --afr: #a78bfa; --afr-soft: #241a40;
  --good: #34d399; --bad: #f87171; --warn-bg: #2d2412; --warn: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; }
a { color: var(--accent-2); }
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.n, .big { font-variant-numeric: tabular-nums; }
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot img { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; transform: scale(.94); } }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 14px; display: flex;
  flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand img { width: 34px; height: 34px; }
.brand b { display: block; font-size: 16px; letter-spacing: -.01em; }
.brand span { display: block; font-size: 11.5px; color: var(--muted); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--text); }
.nav a.on svg { color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px 8px 0;
  border-top: 1px solid var(--line); }
.who { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .row { display: flex; gap: 6px; }
main { padding: 26px 32px 60px; min-width: 0; max-width: 1320px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-bottom: 20px; }
.head h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
.head p { margin: 4px 0 0; color: var(--muted); }
.head .tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > h2, .card-h { font-size: 14px; margin: 0; padding: 14px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-h h2 { font-size: 14px; margin: 0; }
.card .body { padding: 16px 18px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.grid-order { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.stack { display: grid; gap: 18px; min-width: 0; }
.grid-order > *, .two > *, .hero > * { min-width: 0; }
.breakdown td:first-child { white-space: normal; }

/* ---------- order hero ---------- */
.hero { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.total { position: relative; padding: 18px 20px 16px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.total::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--c); }
.total.eng { --c: var(--eng); --cs: var(--eng-soft); }
.total.afr { --c: var(--afr); --cs: var(--afr-soft); }
.total .lbl { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-weight: 600;
  font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; }
.total .big { font-size: 46px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; margin: 8px 0 4px; color: var(--text); }
.total .sub { color: var(--muted); font-size: 13px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px;
  background: var(--surface-2); color: var(--muted); font-weight: 500; white-space: nowrap; }
.chip.c { background: var(--cs); color: var(--c); }
.warn { background: var(--warn-bg); color: var(--warn); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13.5px; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600;
  background: var(--surface-2); }
td.n, th.n { text-align: right; }
tr:last-child td { border-bottom: 0; }
tr.sum td { font-weight: 700; background: var(--surface-2); }
td .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.breakdown td.n:last-child, .breakdown th.n:last-child { font-weight: 700; }
.breakdown td:last-child { color: var(--text); }
.formula { font-size: 12.5px; color: var(--muted); padding: 12px 18px; border-top: 1px solid var(--line); line-height: 1.6; }
.formula code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; color: var(--text); }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; }
.field > label, .lab { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--faint); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month], select, textarea {
  width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius-sm);
  padding: 8px 11px; outline: none; transition: border-color .12s, box-shadow .12s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input[type=number] { -moz-appearance: textfield; font-variant-numeric: tabular-nums; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.assume { display: grid; gap: 16px; }
.stepper { display: grid; grid-template-columns: 36px 1fr 36px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--surface); }
.stepper button { border: 0; background: var(--surface-2); cursor: pointer; font-size: 17px; color: var(--muted); }
.stepper button:hover { color: var(--text); background: var(--line); }
.stepper input { border: 0; border-radius: 0; text-align: center; font-weight: 600; box-shadow: none !important; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 4px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; font-size: 13px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.save-note { font-size: 12px; color: var(--faint); min-height: 16px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-radius: var(--radius-sm);
  padding: 8px 14px; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
[data-theme="dark"] .btn { color: #041422; }
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--surface-2); filter: none; }
.btn.danger { background: transparent; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 5px; border-radius: 7px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; }

/* ---------- monthly grid ---------- */
.mgrid input { width: 92px; padding: 6px 8px; text-align: right; border-color: transparent; background: transparent; }
.mgrid input:hover { border-color: var(--line-strong); }
.mgrid input:focus { background: var(--surface); }
.mgrid input.note { width: 100%; min-width: 160px; text-align: left; }
.mgrid td { padding: 3px 6px; }
.mgrid td.mon { padding-left: 14px; font-weight: 600; width: 110px; }
.mgrid tr.future td.mon { color: var(--faint); font-weight: 500; }
.mgrid th.eng { color: var(--eng); } .mgrid th.afr { color: var(--afr); }
.mgrid td.net { text-align: right; padding-right: 14px; font-weight: 600; min-width: 64px; }
.mgrid td.state { width: 34px; text-align: center; }
.mgrid tr.inwin td.mon::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); margin-right: 8px; vertical-align: 2px; }
.ok-tick { color: var(--good); font-size: 13px; }
.year-tabs { display: flex; gap: 6px; }

/* ---------- chart ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--faint); font-size: 10px; font-family: var(--font); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 500px at 15% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent),
              radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--accent-2) 16%, transparent), transparent), var(--bg); }
.auth .card { width: 100%; max-width: 390px; padding: 30px 28px; }
.auth .brand { padding: 0 0 20px; justify-content: center; flex-direction: column; text-align: center; gap: 12px; }
.auth .brand img { width: 56px; height: 56px; }
.auth .brand b { font-size: 22px; }
.auth form { display: grid; gap: 14px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ---------- dialog / toast ---------- */
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(2, 8, 23, .45); backdrop-filter: blur(2px); }
dialog .dh { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
dialog .db { padding: 18px 20px; display: grid; gap: 14px; }
dialog .df { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500; transition: .2s; z-index: 50; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--bad); color: #fff; }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; font-size: 13.5px; }
.kv span:nth-child(odd) { color: var(--muted); }
.kv span:nth-child(even) { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.mobile-nav { display: none; }

/* ---------- print ---------- */
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; }
  .side, .no-print, .head .tools, .mobile-nav { display: none !important; }
  .shell { display: block; } main { padding: 0; max-width: none; }
  .card, .total { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  .grid-order { grid-template-columns: 1fr; }
  .print-only { display: block; }
}

/* ---------- small screens ---------- */
@media (max-width: 1180px) { .grid-order { grid-template-columns: 1fr; } }
@media (max-width: 900px) { .two { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .mobile-nav { display: flex; position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line);
    padding: 8px 10px; gap: 4px; overflow-x: auto; align-items: center; }
  .mobile-nav img { width: 28px; height: 28px; margin-right: 6px; }
  .mobile-nav a { padding: 7px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap; }
  .mobile-nav a.on { background: var(--accent-soft); color: var(--text); }
  main { padding: 18px 14px 60px; }
  .hero { grid-template-columns: 1fr; }
  .total .big { font-size: 40px; }
}
