:root {
  --bg: #f3f0e8;
  --bg-raise: #fffcf8;
  --card: rgba(255, 252, 248, 0.92);
  --sidebar-bg: rgba(255, 252, 248, 0.9);
  --input: #f7f4ee;
  --surface: rgba(255, 252, 248, 0.72);
  --th-bg: #efeae1;
  --panel: rgba(255, 252, 248, 0.7);
  --modal: #fffcf8;
  --toast: #fffdf9;
  --line: rgba(1, 54, 105, 0.12);
  --line-strong: rgba(1, 54, 105, 0.22);
  --row-line: rgba(1, 54, 105, 0.08);
  --text: #1e2430;
  --muted: #5c6678;
  --faint: #7a8494;
  --gold: #013669;
  --gold-deep: #01284f;
  --on-accent: #f7f5f1;
  --teal: #0f766e;
  --teal-dim: rgba(15, 118, 110, 0.12);
  --rose: #b44955;
  --blue: #013669;
  --shadow: 0 18px 40px rgba(1, 54, 105, 0.08);
  --glow-a: rgba(1, 54, 105, 0.14);
  --glow-b: rgba(1, 54, 105, 0.06);
  --grid: rgba(1, 54, 105, 0.045);
  --mark-from: #3d7eb8;
  --mark-to: #013669;
  --mark-ink: #f7f5f1;
  --btn-from: #1a5a94;
  --btn-to: #013669;
  --accent-dim: rgba(1, 54, 105, 0.1);
  --accent-line: rgba(1, 54, 105, 0.35);
  --focus: rgba(1, 54, 105, 0.18);
  --nav-hover: rgba(1, 54, 105, 0.06);
  --nav-active: rgba(1, 54, 105, 0.12);
  --danger-bg: rgba(180, 73, 85, 0.1);
  --danger-line: rgba(180, 73, 85, 0.28);
  --share-track: #efeae1;
  --share-mark: #013669;
  --page-ink: #f7f5f1;
  --spin: #f7f5f1;
  --modal-back: rgba(30, 36, 48, 0.35);
  --display-from: #013669;
  --radius: 18px;
  --sidebar: 268px;
  --font: "Inter", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
}

html.dark {
  --bg: #070b14;
  --bg-raise: #101624;
  --card: rgba(18, 24, 38, 0.92);
  --sidebar-bg: rgba(8, 12, 22, 0.88);
  --input: #0c111c;
  --surface: rgba(16, 22, 36, 0.7);
  --th-bg: #0e1422;
  --panel: rgba(7, 11, 20, 0.35);
  --modal: #121826;
  --toast: #182033;
  --line: rgba(232, 214, 176, 0.14);
  --line-strong: rgba(232, 214, 176, 0.28);
  --row-line: rgba(255, 255, 255, 0.05);
  --text: #f4f0e6;
  --muted: #9aa3b5;
  --faint: #6d7688;
  --gold: #e4c27a;
  --gold-deep: #b8893d;
  --on-accent: #1c1408;
  --teal: #7ddec3;
  --teal-dim: rgba(125, 222, 195, 0.14);
  --rose: #f0a0a8;
  --blue: #9eb6f0;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --glow-a: rgba(228, 194, 122, 0.16);
  --glow-b: rgba(125, 222, 195, 0.08);
  --grid: rgba(255, 255, 255, 0.025);
  --mark-from: #f0d7a2;
  --mark-to: #a97832;
  --mark-ink: #1a1206;
  --btn-from: #f0d7a2;
  --btn-to: #c99645;
  --accent-dim: rgba(228, 194, 122, 0.1);
  --accent-line: rgba(228, 194, 122, 0.35);
  --focus: rgba(228, 194, 122, 0.15);
  --nav-hover: rgba(255, 255, 255, 0.04);
  --nav-active: rgba(228, 194, 122, 0.16);
  --danger-bg: rgba(240, 160, 168, 0.12);
  --danger-line: rgba(240, 160, 168, 0.3);
  --share-track: #0c111c;
  --share-mark: #fff;
  --page-ink: #1c1408;
  --spin: #1c1408;
  --modal-back: rgba(4, 6, 12, 0.72);
  --display-from: #fff6e4;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 420px at -10% -10%, var(--glow-a), transparent 55%),
    radial-gradient(800px 480px at 110% 0%, var(--glow-b), transparent 50%),
    var(--bg);
  transition: background-color 0.25s ease, color 0.25s ease;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(circle at 20% 0%, #000 0%, transparent 70%);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }

.app { display: flex; min-height: 100%; }
.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px 18px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--sidebar-bg);
  transition: background-color 0.25s ease, border-color 0.25s ease;
  backdrop-filter: blur(16px);
  z-index: 20;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 18px; }
.mark {
  width: 42px; height: 42px; border-radius: 13px;
  display: grid; place-items: center;
  background: linear-gradient(160deg, var(--mark-from), var(--mark-to));
  color: var(--mark-ink); font-family: var(--display); font-size: 24px; font-weight: 640;
}
.brand strong { display: block; letter-spacing: -0.03em; }
.brand span { color: var(--muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-label {
  margin: 16px 10px 6px;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  text-align: left;
  border: 0; background: transparent;
  color: var(--muted);
  border-radius: 12px;
  padding: 10px 12px;
}
.nav-btn[hidden] { display: none !important; }
.nav-btn svg { width: 16px; height: 16px; fill: currentColor; }
.nav-btn:hover { background: var(--nav-hover); color: var(--text); }
.nav-btn.is-active {
  background: linear-gradient(90deg, var(--nav-active), transparent);
  color: var(--gold);
  box-shadow: inset 2px 0 0 var(--gold);
}
.side-note { margin-top: auto; color: var(--faint); font-size: 12px; line-height: 1.5; padding: 12px; }
.backdrop { display: none; }

.main { flex: 1; min-width: 0; padding: 22px 28px 48px; }
.topbar { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.kicker {
  margin: 0 0 2px;
  color: var(--gold);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 11px;
}
.topbar h1 { margin: 0; font-size: 30px; letter-spacing: -0.04em; font-weight: 640; }
.menu-btn { display: none; }
.icon-btn, .btn, .btn-ghost, .btn-danger {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-raise);
  padding: 10px 14px;
}
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; padding: 0; }
.icon-btn svg, .btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 13px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.theme-toggle { margin-left: 0; }
.theme-toggle .sun { display: none; }
html.dark .theme-toggle .moon { display: none; }
html.dark .theme-toggle .sun { display: block; }
.btn {
  background: linear-gradient(180deg, var(--btn-from), var(--btn-to));
  color: var(--on-accent);
  border-color: transparent;
  font-weight: 650;
}
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { border-color: var(--line-strong); }
.btn-danger { background: var(--danger-bg); color: var(--rose); border-color: var(--danger-line); }
.btn-sm { padding: 7px 10px; border-radius: 10px; font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}
.stat b { display: block; font-size: 22px; letter-spacing: -0.04em; }
.stat span { color: var(--muted); font-size: 12px; }

.layout { display: grid; grid-template-columns: minmax(320px, 420px) 1fr; gap: 16px; align-items: start; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card, .stat, .table-wrap, .modal, .field input, .field select, .field textarea, .search, .filter {
  transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}
.card h2 { margin: 0 0 4px; font-size: 18px; letter-spacing: -0.03em; }
.lede { margin: 0 0 16px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.field input, .field select, .field textarea, .search {
  width: 100%;
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input[readonly] {
  color: var(--gold);
  background: var(--accent-dim);
  border-color: var(--accent-line);
  cursor: default;
}
.level-toggle {
  border: 0;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  gap: 8px;
  align-items: center;
}
.level-toggle legend {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  padding: 0;
  margin-right: 4px;
}
.level-toggle label {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.level-toggle input { accent-color: var(--gold); }
.field input:focus, .field select:focus, .field textarea:focus, .search:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--focus);
}
.hint { color: var(--faint); font-size: 12px; line-height: 1.45; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 14px; }
.chip {
  border: 1px dashed var(--line-strong);
  background: transparent;
  color: var(--gold);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
}
.chip:hover { background: var(--accent-dim); }
.form-actions { display: flex; gap: 8px; align-items: center; }
.year-pill {
  margin-left: auto;
  font-size: 12px;
  color: var(--teal);
  background: var(--teal-dim);
  border-radius: 999px;
  padding: 6px 10px;
}

.payable {
  padding: 8px 8px 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.payable span, .muted { color: var(--muted); }
.payable strong {
  display: block;
  font-family: var(--display);
  font-size: clamp(40px, 5vw, 64px);
  font-weight: 560;
  letter-spacing: -0.04em;
  line-height: 1;
  margin: 6px 0;
  background: linear-gradient(90deg, var(--display-from), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.rule-banner {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--accent-line);
  background: var(--accent-dim);
  color: var(--gold);
  line-height: 1.45;
}
.rule-banner strong { display: block; color: var(--text); margin-bottom: 2px; }
.rule-banner.quiet {
  color: var(--muted);
  border-color: var(--line);
  background: var(--surface);
}
.share-meter { margin: 0 0 14px; }
.share-track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: var(--share-track);
  border: 1px solid var(--line);
}
.share-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold));
}
.share-mark {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 16px;
  background: var(--share-mark);
}
.share-meter p { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.formula {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin: 0 0 14px;
}
.breakdown { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: var(--panel);
}
.panel header { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 8px; }
.panel h3 { margin: 0; font-size: 14px; }
.panel .amount { font-variant-numeric: tabular-nums; font-size: 20px; letter-spacing: -0.03em; }
.panel p { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.line {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 13px; padding: 6px 0;
  border-top: 1px solid var(--row-line);
  font-variant-numeric: tabular-nums;
}
.line.off { color: var(--faint); }
.line.on b { color: var(--teal); }
.badge {
  display: inline-flex; align-items: center;
  border-radius: 999px; padding: 3px 8px;
  font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
  background: rgba(255,255,255,0.06); color: var(--muted);
}
.badge.ug { color: var(--blue); background: var(--accent-dim); }
.badge.pg, .badge.final { color: var(--gold); background: var(--accent-dim); }
.badge.second, .badge.active { color: var(--teal); background: var(--teal-dim); }
.badge.first { color: var(--blue); background: var(--accent-dim); }
.badge.none, .badge.inactive { color: var(--faint); }
.badge.warn { color: var(--rose); background: var(--danger-bg); }
.span-2 { grid-column: 1 / -1; }

.empty {
  min-height: 280px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}
.empty strong { color: var(--text); display: block; margin-bottom: 6px; font-size: 18px; }
.ring {
  width: 72px; height: 72px; margin: 0 auto 12px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  display: grid; place-items: center;
  color: var(--gold);
  font-family: var(--display); font-size: 28px;
}

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.search { max-width: 360px; }
.toolbar-actions { margin-left: auto; display: flex; gap: 8px; }
.filter {
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  min-width: 140px;
}
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--row-line); vertical-align: middle; }
th { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); font-weight: 600; background: var(--th-bg); position: sticky; top: 0; }
td { font-size: 14px; }
tr:hover td { background: var(--accent-dim); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-actions { display: flex; gap: 6px; }
.pager { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 13px; }
.pager .pages { display: flex; gap: 4px; margin-left: auto; }
.page-btn { min-width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--text); }
.page-btn.is-active { background: var(--gold); color: var(--page-ink); border-color: transparent; }

.modal-back {
  position: fixed; inset: 0; z-index: 40;
  background: var(--modal-back);
  display: grid; place-items: center;
  padding: 20px;
}
.modal {
  width: min(760px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  background: var(--modal);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 20px;
}
.modal.narrow { width: min(440px, 100%); }
.modal.wide { width: min(980px, 100%); }
.range-table { width: 100%; border-collapse: collapse; margin: 8px 0 12px; }
.range-table th, .range-table td { padding: 6px; border-bottom: 1px solid var(--line); }
.range-table input { width: 100%; background: var(--input); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.range-total { font-variant-numeric: tabular-nums; color: var(--gold); white-space: nowrap; }
.modal h2 { margin: 0 0 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.toast-root { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--toast);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--gold);
  border-radius: 12px;
  padding: 12px 14px;
  min-width: 240px;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.toast.error { border-left-color: var(--rose); }
.skeleton {
  height: 240px; border-radius: 18px;
  background: linear-gradient(90deg, rgba(255,255,255,0.04), rgba(255,255,255,0.09), rgba(255,255,255,0.04));
  background-size: 200% 100%;
  animation: shine 1.2s linear infinite;
}
@keyframes shine { to { background-position: -200% 0; } }
.spin { width: 14px; height: 14px; border: 2px solid color-mix(in srgb, var(--spin) 25%, transparent); border-top-color: var(--spin); border-radius: 50%; display: inline-block; animation: spin 0.7s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

details.rules { margin-top: 14px; color: var(--muted); font-size: 13px; }
details.rules summary { cursor: pointer; color: var(--gold); }
details.rules ol { margin: 8px 0 0; padding-left: 18px; line-height: 1.55; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(440px, 100%); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.login-card h1 { margin: 8px 0 4px; font-family: var(--display); font-weight: 640; letter-spacing: -0.03em; font-size: 32px; }
.login-error { color: var(--rose); font-size: 13px; min-height: 1.2em; margin: 0 0 8px; }
.login-links { margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.login-links a { color: var(--gold); }
.slab-grid { display: grid; gap: 12px; margin-top: 14px; }
.slab-grid .panel h3 { margin: 0 0 4px; }
.slab-grid .table-wrap { margin: 8px 0 4px; }
.login-tools { position: fixed; top: 16px; right: 16px; }
.settings-card { max-width: 520px; }

@media (max-width: 1080px) {
  .layout, .breakdown, .stats { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}
@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 15; }
  .menu-btn { display: grid; }
  .main { padding: 16px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar-actions, .toolbar .btn, .search { width: 100%; max-width: none; margin-left: 0; }
  .toolbar-actions { flex-wrap: wrap; }
  .grid-2 { grid-template-columns: 1fr; }
}
