:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5d6878;
  --border: #dde2e8;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --ok: #1e7a46;
  --amber: #a86400;
  --red: #b42318;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }

.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: 0.6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 600; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { color: var(--muted); text-decoration: none; }
.topbar nav a:hover { color: var(--accent); }
.logout { display: flex; align-items: center; gap: 0.5rem; margin: 0; }
.who { color: var(--muted); font-size: 0.9rem; }

.container { max-width: 1440px; margin: 0 auto; padding: 1.5rem 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; }
.narrow { max-width: 28rem; }
.muted { color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field label { font-weight: 500; }
.field input, .field select { padding: 0.45rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
.help { color: var(--muted); }
.error { color: var(--red); }

button { font: inherit; cursor: pointer; }
button.primary {
  align-self: flex-start; padding: 0.5rem 1rem; border: 0; border-radius: 6px;
  background: var(--accent); color: var(--accent-text);
}
button.link { background: none; border: 0; padding: 0; color: var(--accent); }

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { padding: 0.5rem 0.75rem; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); }
.messages li.success { border-color: var(--ok); color: var(--ok); }
.messages li.error { border-color: var(--red); color: var(--red); }

h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.5rem; }
a { color: var(--accent); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: 1.25rem 0 0.75rem; }
.page-head h1, .page-head h2 { margin: 0; }
.status-line { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; color: var(--muted); font-size: 0.9rem; }
.status-line form { margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.cards.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.card + .card, .cards + .card { margin-top: 1rem; }
.card.warn { border-color: var(--amber); }
.card.warn p { margin: 0.25rem 0; }
.stat h2 { color: var(--muted); font-weight: 500; font-size: 0.9rem; margin: 0; }
.stat .big { font-size: 1.6rem; font-weight: 600; margin: 0.25rem 0; font-variant-numeric: tabular-nums; }
.stat p { margin: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th, .table td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.inactive td { color: var(--muted); }
.card { overflow-x: auto; }
.badge { display: inline-block; padding: 0 0.4rem; border-radius: 4px; font-size: 0.78rem; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.badge.amber, .badge.partial { color: var(--amber); border-color: var(--amber); }
.badge.red, .badge.failed { color: var(--red); border-color: var(--red); }
.badge.success { color: var(--ok); border-color: var(--ok); }
form.inline { display: inline; }
.actions { white-space: nowrap; text-align: right; }
.actions > * + * { margin-left: 0.5rem; }
.nowrap { white-space: nowrap; }
.field.checkbox label { font-weight: 400; display: flex; gap: 0.5rem; align-items: center; }
a.button, button.secondary { display: inline-block; padding: 0.45rem 0.9rem; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; font-size: 0.92rem; }
a.button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: 0.25rem 0; }
dl.pairs { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 0; }
dl.pairs dt { color: var(--muted); }
dl.pairs dd { margin: 0; }
pre.error { white-space: pre-wrap; margin: 0.25rem 0 0; font-size: 0.8rem; }
.messages li.warning { border-color: var(--amber); color: var(--amber); }

.state-amber { color: var(--amber); font-weight: 600; }
.state-red { color: var(--red); font-weight: 600; }
.state-card-amber { border-color: var(--amber); }
.state-card-red { border-color: var(--red); }
.chart-wrap { position: relative; height: 260px; }
.page-head.tight { margin: 0 0 0.75rem; }
.table.grid { font-size: 0.85rem; }
.table.grid th:first-child { position: sticky; left: 0; background: var(--surface); min-width: 12rem; }
.table.grid td a { text-decoration: none; }
.table.grid tr.section th { background: var(--bg); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.04em; }
.table.grid tr.row-total th, .table.grid tr.row-total td { font-weight: 600; }
.table.grid tr.row-ending th, .table.grid tr.row-ending td { font-weight: 700; border-top: 2px solid var(--border); }
.table.grid tr.row-sub th { padding-left: 1.5rem; font-weight: 400; color: var(--muted); }
.table.grid tr.row-muted th, .table.grid tr.row-muted td { color: var(--muted); }
.drill { margin-top: 1rem; border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; }
.drill-head { display: flex; gap: 1rem; align-items: baseline; margin-bottom: 0.5rem; }
.drill-head button { margin-left: auto; }
.occ { display: flex; gap: 0.4rem; align-items: center; }
.occ form { margin: 0; display: inline; }
.danger-zone { margin-top: 1.5rem; }
.cards > .card { margin-top: 0; }
.table.grid th, .table.grid td { padding: 0.35rem 0.4rem; }
.table.grid th:first-child { min-width: 10.5rem; }
.card + h2, .cards + h2 { margin-top: 1.75rem; }
.table.compact td, .table.compact th { padding-top: 0.3rem; padding-bottom: 0.3rem; font-size: 0.9rem; }
.match-bar { position: sticky; top: 0; z-index: 2; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.match-bar button { margin-left: auto; }
.neg { color: var(--red); }
.aging { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.5rem; margin: 0.5rem 0 1rem; }
.aging-cell { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.75rem; display: flex; flex-direction: column; gap: 0.15rem; }
.aging-cell.late strong { color: var(--red); }
.aging-cell.total { border-color: var(--accent); }
@media (max-width: 800px) { .aging { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
form.override input[type=date] { width: 9.5rem; }
form.override input[type=text] { width: 8rem; }
.tabs a { margin: 0 0.25rem; }
