:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --surface-3: #e9ecf1;
  --border: #e4e7ec;
  --text: #101828;
  --text-2: #475467;
  --muted: #667085;
  --accent: #2a78d6;
  --accent-soft: #e8f1fc;
  --accent-ink: #1c5cab;
  --bar: #2a78d6;
  --bar-hover: #1c5cab;
  --good: #0a7d0a;
  --bad: #c22f2f;
  --warn-bg: #fff6e0;
  --warn-border: #f5d48a;
  --sidebar: #0f1729;
  --sidebar-text: #c6cbd6;
  --sidebar-muted: #8b93a5;
  --sidebar-active: #1d2840;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c0f14;
    --surface: #141821;
    --surface-2: #1a1f2a;
    --surface-3: #232937;
    --border: #262c39;
    --text: #eef0f4;
    --text-2: #c3c8d2;
    --muted: #8e96a6;
    --accent: #3987e5;
    --accent-soft: #16243a;
    --accent-ink: #86b6ef;
    --bar: #3987e5;
    --bar-hover: #6da7ec;
    --good: #3fbf6f;
    --bad: #f07171;
    --warn-bg: #2a2212;
    --warn-border: #5a4718;
    --sidebar: #0a0d12;
    --sidebar-active: #18202e;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
a { color: inherit; text-decoration: none; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 24px;
  padding: 20px 14px; background: var(--sidebar); color: var(--sidebar-text);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; color: #fff; padding: 0 8px; }
.logo { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--accent); color: #fff; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--sidebar-text); font-weight: 500; }
.nav a:hover { background: var(--sidebar-active); color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; }
.nav a.active svg { color: #86b6ef; }
.sidebar-foot { margin-top: auto; }
.sync-card { display: grid; gap: 8px; padding: 12px; border-radius: 10px; background: var(--sidebar-active); font-size: 13px; }
.sync-card .muted { color: var(--sidebar-muted); }
.sync-row { display: flex; align-items: center; gap: 8px; color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sidebar-muted); flex: none; }
.dot.ok { background: #3fbf6f; }
.dot.bad { background: #f07171; }

.main { min-width: 0; display: flex; flex-direction: column; }
.header {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 24px 32px 16px;
}
.crumbs { font-size: 13px; color: var(--muted); min-height: 18px; display: flex; gap: 6px; align-items: center; }
.crumbs a:hover { color: var(--text); }
.range { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.seg { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 3px; box-shadow: var(--shadow); }
.seg button {
  border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: 13px; font-weight: 500;
  padding: 6px 11px; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--accent-soft); color: var(--accent-ink); }
.dates { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 3px 8px; box-shadow: var(--shadow); }
.dates input { border: 0; background: transparent; color: var(--text); font: inherit; font-size: 13px; padding: 5px 2px; }

.banner {
  margin: 0 32px 4px; padding: 10px 14px; border-radius: 10px; font-size: 13px;
  background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--text-2);
}
.view { padding: 12px 32px 48px; display: grid; gap: 16px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-sm { padding: 7px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.sync-card .btn { background: transparent; border-color: #34405a; color: #fff; }
.sync-card .btn:hover { background: #26324b; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn:disabled svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(190px, 46%), 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.kpi.hero { background: linear-gradient(180deg, var(--accent-soft), var(--surface) 70%); border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 24px; font-weight: 600; margin-top: 6px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .value small { font-size: 15px; color: var(--muted); font-weight: 500; margin-left: 2px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

/* ---------- Cards ---------- */
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
.grid-2 > * { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; display: flex; flex-direction: column; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 16px 18px 0; }
.card-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.card-body { padding: 16px 18px 18px; flex: 1; }
.card-body.flush { padding: 12px 0 0; }

/* Chart */
.chart { position: relative; width: 100%; height: 100%; min-height: 260px; }
.chart svg { width: 100%; height: 100%; stroke: none; display: block; overflow: visible; }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .bar { fill: var(--bar); }
.chart .bar.on { fill: var(--bar-hover); }
.chart .hit { fill: transparent; cursor: default; }
.chart-empty { height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 13px; }

/* Breakdown lists */
.blist { display: grid; gap: 14px; align-content: start; }
.brow { display: grid; gap: 6px; }
.brow .top { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.brow .top b { font-weight: 600; font-variant-numeric: tabular-nums; }
.brow .top span { color: var(--text-2); }
.brow .top em { font-style: normal; color: var(--muted); font-size: 12px; margin-left: 6px; font-variant-numeric: tabular-nums; }
.meter { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--bar); border-radius: 3px; }
.section-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 4px 0 -4px; }
.divider { height: 1px; background: var(--border); margin: 2px 0; }

/* ---------- Tables ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search input {
  font: inherit; font-size: 13px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px 7px 32px; width: 220px;
}
.search input:focus, .dates input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 1px; }
select.select { font: inherit; font-size: 13px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; }

.table-wrap { overflow: auto; }
.table-wrap.tall { max-height: 640px; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; font-size: 13px; }
.table th, .table td { padding: 11px 14px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
.table th:first-child, .table td:first-child { padding-left: 18px; }
.table th:last-child, .table td:last-child { padding-right: 18px; }
.table thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2);
  color: var(--muted); font-size: 12px; font-weight: 600;
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th .arrow { margin-left: 3px; color: var(--accent); }
.table .r { text-align: right; }
.table tbody tr.link { cursor: pointer; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tfoot td { position: sticky; bottom: 0; background: var(--surface-2); font-weight: 600; border-bottom: 0; }
/* Totals row moved under the header by liftTotals(); "top" is set inline */
.table thead tr.total-row td {
  position: sticky; z-index: 1; background: var(--accent-soft); color: var(--text);
  font-weight: 600; border-bottom: 2px solid color-mix(in srgb, var(--accent) 35%, var(--border));
}
.table .zero { color: var(--muted); }
.table .strong { font-weight: 600; }
.name-cell { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; font-size: 12px;
}
.name-cell .t { display: grid; line-height: 1.3; }
.name-cell .t span { font-size: 12px; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; color: var(--text-2); }
.badge.bad { color: var(--bad); }
.badge.bad::before { content: "!"; font-weight: 700; }
.status-working { color: var(--good); }
.status-fired, .status-not_working { color: var(--muted); }
.table-foot { padding: 10px 18px; font-size: 12px; color: var(--muted); }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

/* Tooltip, toast */
.tooltip {
  position: fixed; z-index: 20; pointer-events: none; min-width: 170px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font-size: 12.5px; box-shadow: 0 8px 24px rgba(16, 24, 40, .14);
}
.tooltip .tt-title { font-weight: 600; margin-bottom: 6px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 16px; color: var(--text-2); }
.tooltip .tt-row b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 30; max-width: calc(100% - 40px);
  background: var(--text); color: var(--surface); padding: 11px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar, .nav { min-width: 0; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 12px; padding: 12px 16px; }
  .nav { display: flex; gap: 4px; width: 100%; overflow-x: auto; order: 3; }
  .nav a { flex: none; white-space: nowrap; }
  .sidebar-foot { width: 100%; margin: 0; }
  .sync-card { grid-template-columns: 1fr auto auto; align-items: center; }
  .sync-card .sync-row, .sync-card > .muted { grid-column: 1; }
  .sync-card .btn { width: auto; grid-row: 1 / span 2; }
  .header { padding: 16px 16px 8px; }
  .banner { margin: 0 16px 4px; }
  .view { padding: 8px 16px 32px; }
  .range, .seg, .dates { width: 100%; }
  .seg { overflow-x: auto; }
  .seg button { flex: 1; }
  .dates input { flex: 1; min-width: 0; }
  .search, .search input { width: 100%; }
  .toolbar { width: 100%; }
}

/* ---------- Forms (Parks page) ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 14px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field label em { font-style: normal; color: var(--muted); font-weight: 400; }
.field input {
  font: inherit; font-size: 13px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; width: 100%;
}
.field input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 1px; }
.field .hint { font-size: 12px; color: var(--muted); }
.form-actions { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.icon { padding: 6px 8px; }
.form-error { color: var(--bad); font-size: 13px; margin-right: auto; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--text-2); }
.state-ok { color: var(--good); }
.state-bad { color: var(--bad); }
.empty-state { padding: 56px 24px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.empty-state h2 { font-size: 17px; }
.empty-state p { margin: 0; color: var(--muted); max-width: 460px; }
.table input.inline { font: inherit; font-size: 13px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; width: 100%; min-width: 90px; }

/* ---------- Report (Excel layout) ---------- */
.table.report thead tr.group th { text-align: center; border-bottom: 1px solid var(--border); }
.table.report thead tr.group th.span { border-left: 1px solid var(--border); }
.table.report td.sep, .table.report th.sep { border-left: 1px solid var(--border); }
.table.report td.total { font-weight: 600; }
.table .idx { color: var(--muted); width: 44px; }
.legend-note { padding: 0 18px 16px; font-size: 12px; color: var(--muted); }
.legend-note b { color: var(--text-2); font-weight: 600; }

.table.report th.span.neg { color: var(--bad); }
.table.report th.span.pos { color: var(--good); }
.table td.neg, .kpi .neg { color: var(--bad); }
.table td.pos, .kpi .pos { color: var(--good); }
.month-pick { box-shadow: var(--shadow); border-radius: 9px; padding: 8px 10px; }
@media (max-width: 860px) { .month-pick { width: 100%; } }

/* Parks table: keep Edit / Delete visible while the table scrolls sideways */
#parks-table th.actions, #parks-table td.actions { position: sticky; right: 0; background: var(--surface); box-shadow: -8px 0 8px -8px rgba(16, 24, 40, .15); }
#parks-table thead th.actions { background: var(--surface-2); z-index: 2; }
#parks-table tbody tr:hover td.actions { background: var(--surface-2); }
.danger-zone .card-body { display: none; }
.danger-zone .card-head { padding-bottom: 16px; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: color-mix(in srgb, var(--bad) 10%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }

.field .select, .field input[type=date], .field input[type=file] { width: 100%; }
.field input[type=file] { padding: 6px 8px; }
#import-form .hint { margin: 12px 0 0; }
#imports-table th.actions, #imports-table td.actions { position: sticky; right: 0; background: var(--surface); }
#imports-table thead th.actions { background: var(--surface-2); }
.banner a { color: var(--accent-ink); text-decoration: underline; }

.pay-tabs { width: fit-content; max-width: 100%; overflow-x: auto; }
.legend-note a { color: var(--accent-ink); }

/* Signed-in user in the sidebar */
.user-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px 2px; border-top: 1px solid #2a3550; margin-top: 4px; color: #fff; }
.user-row:hover b { text-decoration: underline; }
.user-row .avatar { background: #26324b; color: #c6d4f0; }
.user-row .t { display: grid; line-height: 1.25; min-width: 0; }
.user-row .t b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row .t span { font-size: 12px; color: var(--sidebar-muted); }
.role-badge.admin { color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
@media (max-width: 860px) { .user-row { grid-column: 1 / -1; border-top: 0; } }

/* Date + time range */
.dates input[type=time] { width: 88px; color: var(--text-2); }
@media (max-width: 860px) {
  .dates { flex-wrap: wrap; row-gap: 2px; }
  .dates input[type=date] { flex: 1 1 55%; }
  .dates input[type=time] { flex: 1 1 30%; width: auto; }
  .dates .muted { flex-basis: 100%; height: 0; overflow: hidden; }
}

/* Park / Fleet kind badges */
.badge.kind { font-size: 11px; padding: 1px 7px; font-weight: 600; vertical-align: 1px; }
.badge.kind-park { color: var(--accent-ink); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.badge.kind-fleet { color: var(--text-2); }
.badge.kind-none { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.banner.warn-inline { margin: 0; }

/* ⓘ formula button in table headers */
.th-label { display: inline-flex; align-items: center; gap: 4px; justify-content: flex-end; }
.info-btn { display: inline-grid; place-items: center; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); cursor: help; flex: none; }
.info-btn:hover, .info-btn:focus-visible { color: var(--accent); background: var(--accent-soft); outline: none; }
.info-btn svg { width: 15px; height: 15px; }
.tooltip { max-width: 280px; }
