:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --border: #e3e7ed;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --row-hover: #f2f6ff;
  --mismatch: #fff4e5;
  --error: #b42318;
  --error-bg: #fef3f2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #171d24;
    --text: #e6e9ee;
    --muted: #97a1af;
    --border: #2a323d;
    --accent: #5b8def;
    --accent-text: #0f1419;
    --row-hover: #1e2733;
    --mismatch: #33270f;
    --error: #ff8a80;
    --error-bg: #3a1714;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
main { max-width: 1400px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 8px 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 6px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sub { color: var(--muted); font-size: 12px; }
.error { color: var(--error); background: var(--error-bg); padding: 10px 12px; border-radius: 8px; }

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); }
.topbar nav a.active, .topbar nav a:hover { background: var(--row-hover); color: var(--text); text-decoration: none; }
.logout { color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 2px; color: var(--text);
}
a.tile:hover { text-decoration: none; border-color: var(--accent); }
.tile-label { color: var(--muted); font-size: 12px; }
.tile-value { font-size: 22px; font-weight: 650; }
.tile-value.small { font-size: 15px; }
.tile-note { color: var(--muted); font-size: 12px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; }
details.panel summary { cursor: pointer; font-weight: 600; }

.health { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.health ul { list-style: none; margin: 0; padding: 0; }
.health li { display: grid; grid-template-columns: 22px 1fr; column-gap: 6px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.health li .sub { grid-column: 2; }

.filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: end;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px;
}
.filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
.filters label.check { flex-direction: row; align-items: center; gap: 6px; }
input, select, button {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; min-height: 36px;
}
input[type="search"] { min-width: 220px; flex: 1; }
input[type="number"] { width: 110px; }
button { background: var(--accent); color: var(--accent-text); border-color: var(--accent); cursor: pointer; font-weight: 600; }
button:hover { filter: brightness(1.08); }
.download { margin: 0 0 16px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.panel .table-wrap { border: none; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
#grid th { cursor: pointer; user-select: none; }
#grid th.sorted { color: var(--text); }
#grid th[data-dir="asc"]::after { content: " ▲"; }
#grid th[data-dir="desc"]::after { content: " ▼"; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: var(--row-hover); }
tr.mismatch { background: var(--mismatch); }
td:first-child { min-width: 240px; max-width: 420px; }

.login-card {
  max-width: 360px; margin: 12vh auto 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 24px;
}
.login-card h1 { margin-top: 0; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

@media (max-width: 640px) {
  main { padding: 12px; }
  .topbar { gap: 8px; }
  .tile-value { font-size: 19px; }
  input[type="search"] { min-width: 100%; }
}
