:root {
  --navy: #0b1f3a;
  --navy-2: #16325c;
  --accent: #2f6fed;
  --accent-dark: #1d4ed8;
  --bg: #f4f6f8;
  --white: #ffffff;
  --line: #d9e1ea;
  --text: #122033;
  --muted: #5c6b7e;
  --zero: #155e75;
  --zero-bg: #ecfeff;
  --missing: #92400e;
  --missing-bg: #fef3c7;
  --holiday: #312e81;
  --holiday-bg: #eef2ff;
  --vacation: #5b21b6;
  --vacation-bg: #f5f3ff;
  --future: #64748b;
  --future-bg: #f8fafc;
  --ok: #065f46;
  --ok-bg: #ecfdf5;
  --error: #9f1239;
  --error-bg: #fff1f2;
  --shadow: 0 10px 30px rgba(11, 31, 58, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Avenir Next", "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}
h1, h2, h3 { font-weight: 650; letter-spacing: -0.02em; margin: 0 0 8px; }
h1 { font-size: 1.7rem; }
p { margin: 0 0 12px; }
a { color: var(--accent-dark); }
button, input, select { font: inherit; }
.skip {
  position: absolute; left: 12px; top: -40px; background: var(--navy); color: white; padding: 8px;
}
.skip:focus { top: 12px; }
.eyebrow {
  margin: 0; text-transform: uppercase; letter-spacing: 0.14em; font-size: 11px; color: var(--accent);
  font-weight: 700;
}
.wordmark {
  font-family: Palatino, "Palatino Linotype", Georgia, serif;
  font-size: 1.45rem; margin: 0; color: var(--navy);
}
.lede, .hint { color: var(--muted); }
.hint { font-size: 0.92rem; }
.kicker {
  margin: 0 0 4px; text-transform: uppercase; letter-spacing: 0.12em;
  font-size: 12px; font-weight: 700; color: var(--accent);
}

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--navy); color: white; padding: 22px 16px;
}
.sidebar .wordmark, .sidebar .eyebrow { color: white; }
.sidebar .eyebrow { color: #9ec1ff; }
.sidenav { display: flex; flex-direction: column; gap: 18px; margin-top: 28px; }
.nav-group { display: flex; flex-direction: column; gap: 4px; }
.nav-label {
  margin: 0 12px 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: #9ec1ff;
}
.sidenav a {
  color: #d7e3f4; text-decoration: none; padding: 10px 12px; border-radius: 8px; font-weight: 650;
}
.sidenav a.active, .sidenav a:hover { background: var(--navy-2); color: white; }
.main { padding: 22px 28px 48px; min-width: 0; }
.topbar, .simple-head, .panel-head, .section-head, .period-nav, .export-row {
  display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap;
}
.topbar { margin-bottom: 18px; }
.simple-wrap { max-width: 520px; margin: 0 auto; padding: 20px 16px 40px; }
.simple-head { align-items: center; margin-bottom: 16px; }

.card, .panel, .chart-card {
  background: var(--white); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px;
  min-width: 0; max-width: 100%;
}
.panel-current { border-top: 4px solid var(--navy); }
.panel-custom { border-top: 4px solid var(--accent); }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack input, .form-grid input, .form-grid select, .filters select, .filters input[type="date"], .inline-form input {
  width: 100%; height: 46px; border: 1px solid #c5d0dc; border-radius: 8px; padding: 0 12px;
  background: white; color: var(--text); font-size: 16px;
}
label { font-size: 13px; font-weight: 700; }
.btn {
  background: var(--accent); color: white; border: 0; border-radius: 8px; min-height: 42px;
  padding: 10px 14px; font-weight: 700; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; cursor: pointer;
}
.btn:hover { background: var(--accent-dark); }
.btn.secondary { background: white; color: var(--navy); border: 1px solid var(--line); }
.btn.secondary:hover { background: var(--bg); }
.btn.full { width: 100%; }
.who { margin-bottom: 4px; }
.banner {
  background: var(--missing-bg); color: var(--missing); padding: 10px 12px; border-radius: 8px;
}
.flashes { margin-bottom: 12px; }
.flash { padding: 10px 12px; border-radius: 8px; margin: 0 0 8px; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--error-bg); color: var(--error); }
.flash-info { background: #eff6ff; color: var(--navy); }

.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: end;
  background: white; border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 180px; }
.tech-picks { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
.tech-picks legend { font-size: 13px; font-weight: 700; width: 100%; margin-bottom: 4px; }
.tech-picks label {
  display: flex; gap: 6px; align-items: center; font-weight: 600; background: var(--bg);
  border-radius: 999px; padding: 6px 10px;
}
.tech-picks input { width: auto; height: auto; }

.switcher { display: flex; flex-wrap: wrap; background: var(--bg); border-radius: 10px; padding: 4px; gap: 4px; }
.switcher a {
  text-decoration: none; color: var(--navy); padding: 8px 12px; border-radius: 8px; font-weight: 700;
}
.switcher a.on { background: var(--navy); color: white; }
.period-nav, .export-row { margin: 0; }
.head-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.period-nav {
  display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: white;
}
.period-nav a {
  text-decoration: none; color: var(--navy); font-weight: 700; padding: 8px 12px;
  border-right: 1px solid var(--line); font-size: 14px;
}
.period-nav a:last-child { border-right: 0; }
.period-nav a:hover { background: var(--bg); }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 8; min-width: 230px;
  background: white; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
  display: flex; flex-direction: column;
}
.menu-panel a {
  text-decoration: none; color: var(--navy); font-weight: 650; padding: 9px 10px; border-radius: 8px;
}
.menu-panel a:hover { background: var(--bg); }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 14px 0 18px; }
.kpi { background: white; border: 1px solid var(--line); border-top: 3px solid var(--navy); border-radius: 12px; padding: 14px; }
.kpi-primary { border-top-color: var(--accent); }
.kpi p { color: var(--muted); font-size: 13px; font-weight: 700; min-height: 34px; margin-bottom: 6px; }
.kpi strong, .overview-card strong, .expense-stats strong {
  display: block; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; color: var(--navy);
}
.kpi strong { font-size: 1.45rem; }
.kpi small { color: var(--muted); display: block; margin-top: 6px; }
.overview { margin-bottom: 18px; }
.overview-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.overview-card {
  background: white; border: 1px solid var(--line); border-radius: 16px; padding: 16px;
  box-shadow: var(--shadow); min-width: 0;
}
.overview-lead { border-top: 3px solid var(--accent); }
.overview-card p { color: var(--muted); font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.overview-card strong { font-size: 1.75rem; line-height: 1.1; }
.overview-card .period { display: block; margin-top: 8px; color: var(--accent-dark); font-size: 13px; font-weight: 700; }
.definition {
  margin-top: 12px; background: white; border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
}
.definition p { margin: 0 0 8px; color: var(--muted); font-size: 0.92rem; }
.definition p:last-child { margin: 0; }
.definition strong { color: var(--navy); }
.section-copy { margin-bottom: 12px; }
.compare-note { margin-top: 4px; }
.chart-stack { display: flex; flex-direction: column; gap: 16px; }
.chart-box { width: 100%; max-width: 100%; min-width: 0; }
.chart-box canvas { display: block; max-width: 100%; }
.chart-box.tall { height: 380px; }
.chart-box.medium { height: 260px; }
.chart-box.rank { height: 280px; }
.chart-box.doughnut { height: 220px; width: 100%; }
.toggle {
  display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--navy);
  background: var(--bg); border-radius: 999px; padding: 8px 12px; white-space: nowrap;
}
.toggle input { width: 16px; height: 16px; }
.expense-panel, .performance { margin-top: 8px; }
.expense-layout {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(220px, 0.8fr); gap: 12px; align-items: center;
}
.expense-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.expense-stats article {
  background: var(--bg); border-radius: 12px; padding: 12px; min-width: 0;
}
.expense-stats p { color: var(--muted); font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.expense-stats strong { font-size: 1.25rem; }
.multi { position: relative; min-width: 240px; }
.multi-toggle {
  width: 100%; height: 46px; border: 1px solid #c5d0dc; border-radius: 8px; background: white;
  text-align: left; padding: 0 12px; font-weight: 650; color: var(--navy); cursor: pointer;
}
.multi-summary { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.multi-panel {
  position: absolute; z-index: 12; top: calc(100% + 6px); left: 0; width: min(320px, 80vw);
  background: white; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 10px;
}
.multi-search { width: 100%; height: 40px; border: 1px solid #c5d0dc; border-radius: 8px; padding: 0 10px; }
.multi-actions { display: flex; gap: 8px; margin: 8px 0; }
.multi-actions button {
  border: 0; background: var(--bg); color: var(--navy); border-radius: 8px; padding: 6px 8px;
  font-weight: 700; cursor: pointer;
}
.multi-list { max-height: 240px; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.multi-list label {
  display: flex; gap: 8px; align-items: center; font-weight: 650; padding: 6px; border-radius: 8px;
}
.multi-list label:hover { background: var(--bg); }
.multi-list input { width: auto; height: auto; }

.legend { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; list-style: none; }
.legend li, .tag {
  border-radius: 999px; padding: 4px 8px; font-size: 12px; font-weight: 700;
}
.tag { background: var(--bg); color: var(--navy); }
.tag-closed { background: var(--missing-bg); color: var(--missing); }
.cell-value { background: white; }
.cell-zero, .legend .cell-zero { background: var(--zero-bg); color: var(--zero); }
.cell-missing, .legend .cell-missing { background: var(--missing-bg); color: var(--missing); }
.cell-holiday, .legend .cell-holiday { background: var(--holiday-bg); color: var(--holiday); }
.cell-vacation, .cell-other, .legend .cell-vacation { background: var(--vacation-bg); color: var(--vacation); }
.cell-future, .legend .cell-future { background: var(--future-bg); color: var(--future); }
.cell-weekend { background: #f8fafc; color: #94a3b8; }
.legend .cell-weekend { background: #f8fafc; color: #475569; }
.cell-inactive, .legend .cell-inactive { background: #f1f5f9; color: #64748b; }

.matrix-wrap, .table-wrap { overflow: auto; background: white; border: 1px solid var(--line); border-radius: 12px; margin: 12px 0 18px; min-width: 0; max-width: 100%; }
.matrix-wrap { max-height: 68vh; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
.matrix { min-width: 860px; border-collapse: separate; border-spacing: 0; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 14px; }
.matrix th, .matrix td { text-align: right; font-variant-numeric: tabular-nums; }
.matrix th:first-child, .matrix td:first-child, .matrix tbody th, .matrix tfoot th {
  text-align: left; position: sticky; left: 0; background: white; z-index: 1; min-width: 168px;
  box-shadow: 1px 0 0 var(--line);
}
.matrix thead th {
  position: sticky; top: 0; z-index: 2; background: #f8fafc;
}
.matrix thead th:first-child { z-index: 3; background: #f8fafc; }
.matrix small { display: block; font-weight: 500; color: var(--muted); }
.matrix .amt, .matrix .tag { display: block; }
.matrix tfoot td, .matrix tfoot th, td.total { font-weight: 750; background: #f8fafc; }
table.sortable th { cursor: pointer; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; min-width: 0; }
.chart-wide { grid-column: 1 / -1; }
.chart-box { height: 280px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; align-items: end; }
.form-grid .wide { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.inline-form input { width: auto; min-width: 140px; }
.history { list-style: none; padding: 0; margin: 0; }
.history li { border-top: 1px solid var(--line); }
.history a { display: flex; flex-direction: column; gap: 2px; padding: 12px 0; text-decoration: none; color: inherit; }
.history-date { font-weight: 750; color: var(--navy); }
.plain-list { padding-left: 18px; }
.checkline { display: flex; gap: 8px; align-items: center; font-weight: 650; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; z-index: 5; padding: 12px;
    width: 100%; max-width: 100%; min-width: 0; overflow: hidden;
  }
  .brand { display: none; }
  .sidenav { flex-direction: row; gap: 14px; margin: 0; max-width: 100%; overflow-x: auto; align-items: center; }
  .nav-group { flex-direction: row; align-items: center; gap: 4px; }
  .nav-label { margin: 0 4px 0 0; white-space: nowrap; }
  .sidenav a { white-space: nowrap; }
  .main { padding: 16px; width: 100%; max-width: 100%; }
  .simple-wrap { padding-top: 12px; }
  .overview-grid, .expense-layout, .expense-stats { grid-template-columns: 1fr; }
  .chart-box.tall { height: 300px; }
  .head-controls { justify-content: flex-start; }
  .menu-panel { right: auto; left: 0; }
}
