/* WO DATIN dashboard. Colors are tokens; dark is the default, light under [data-theme="light"].
   Palette = validated reference instance (dataviz): single blue series, blue ordinal ramp for age,
   status colors only with icon + label. */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --base: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;          /* series 1 */
  --accent-ink: #86b6ef;
  --accent-wash: rgba(57, 135, 229, 0.16);
  --track: #262624;
  --age-0: #184f95; --age-1: #256abf; --age-2: #3987e5; --age-3: #6da7ec; --age-4: #9ec5f4;
  --good: #0ca30c; --good-ink: #0ca30c;
  --serious: #ec835a;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
}
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --grid: #e1e0d9;
  --base: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --track: #ecebe6;
  --age-0: #86b6ef; --age-1: #5598e7; --age-2: #2a78d6; --age-3: #1c5cab; --age-4: #104281;
  --good: #0ca30c; --good-ink: #006300;
  --serious: #c2532a;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 var(--font);
}
h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 13px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.eyebrow { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

/* ---------- buttons ---------- */
.btn, .icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  border-radius: 10px; padding: 7px 12px; cursor: pointer; min-height: 36px;
}
.icon-btn { padding: 0; width: 36px; justify-content: center; }
.btn:hover, .icon-btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; justify-content: center; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-block { width: 100%; padding: 10px; }
.link { background: none; border: 0; color: var(--accent-ink); cursor: pointer; padding: 4px 6px; text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[data-theme="light"] .i-moon, [data-theme="dark"] .i-sun { display: none; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  max-width: 1440px; margin: 0 auto; padding: 18px 20px 6px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 22px; letter-spacing: -0.01em; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.src-switch { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); margin-right: auto; margin-left: 18px; }
.src-switch button { border: 0; background: none; padding: 7px 14px; border-radius: 9px; cursor: pointer; font-weight: 700; font-size: 13px; color: var(--ink-2); letter-spacing: 0.02em; }
.src-switch button:hover { color: var(--ink); background: var(--surface-2); }
.src-switch button.on { background: var(--accent); color: #fff; }
.no-bw .col-bw { display: none; }
.updated { margin-right: 4px; }
.acct { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 170px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

.banner {
  max-width: 1400px; margin: 10px auto 0; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--serious); background: color-mix(in srgb, var(--serious) 12%, transparent); color: var(--ink);
}

main { max-width: 1440px; margin: 0 auto; padding: 12px 20px 40px; display: grid; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi { padding: 14px 16px; }
.kpi-label { color: var(--ink-2); font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; margin-top: 4px; }
.kpi-sub { margin-top: 2px; }
.kpi-warn .kpi-label { color: var(--ink); }
.kpi-value, .kpi-sub { display: block; }
.kpi-btn { text-align: left; font: inherit; color: inherit; cursor: pointer; width: 100%; }
.kpi-btn:hover { border-color: var(--accent); }

/* ---------- pivot (Matrix / Status / …) ---------- */
.pivot-card { padding: 6px 0 10px; overflow: hidden; }
.tabs { display: flex; gap: 2px; overflow-x: auto; padding: 0 12px; border-bottom: 1px solid var(--grid); }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 12px; cursor: pointer;
  color: var(--ink-2); font-size: 13.5px; font-weight: 600; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.on { color: var(--accent-ink); border-bottom-color: var(--accent); }
/* margin (not padding): padding would sit inside the scroller and show cells peeking left of the sticky columns */
.pivot-wrap { overflow-x: auto; margin: 12px 12px 0; }
/* separate borders (not collapse): collapsed borders don't travel with position:sticky cells */
.pivot {
  --c1: 92px; --c2: 128px;   /* widths of the sticky REGIONAL / BRANCH columns */
  border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums;
  border-top: 1px solid var(--grid); border-left: 1px solid var(--grid);
}
.pivot th, .pivot td { border: 0; border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); padding: 5px 10px; text-align: center; white-space: nowrap; background: var(--surface); }
.pivot thead th { background: var(--surface-2); color: var(--ink-2); font-size: 11.5px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; padding: 8px 10px; }
.pivot th.reg { background: var(--surface-2); font-weight: 700; }
.pivot th.branch { font-weight: 500; color: var(--ink-2); text-align: center; }
.pivot .tot { font-weight: 700; border-left: 2px solid var(--base); }
.pivot td.dash { color: var(--muted); }
.pivot .subtotal th.branch, .pivot .subtotal td { font-weight: 700; color: var(--ink); border-top: 2px solid var(--base); }
.pivot tfoot th, .pivot tfoot td { font-weight: 800; color: var(--ink); border-top: 2px solid var(--accent); background: var(--surface-2); }
.pivot tfoot th { text-align: right; padding-right: 16px; }
/* REGIONAL + BRANCH stay on screen while the matrix scrolls sideways */
.pivot thead th:nth-child(1), .pivot th.reg { position: sticky; left: 0; z-index: 2; width: var(--c1); min-width: var(--c1); max-width: var(--c1); white-space: normal; }
.pivot thead th:nth-child(2), .pivot th.branch { position: sticky; left: var(--c1); z-index: 2; min-width: var(--c2); box-shadow: inset -2px 0 0 var(--base); }
.pivot tfoot th { position: sticky; left: 0; z-index: 2; box-shadow: inset -2px 0 0 var(--base); }
.cnt {
  min-width: 30px; padding: 1px 8px; border: 0; border-radius: 6px; cursor: pointer;
  background: var(--accent-wash); color: var(--accent-ink); font: inherit; font-weight: 600;
}
.cnt:hover { background: var(--accent); color: #fff; }
.subtotal .cnt, tfoot .cnt { background: none; text-decoration: underline; text-underline-offset: 3px; font-weight: 800; }
.subtotal .cnt:hover, tfoot .cnt:hover { background: var(--accent-wash); color: var(--accent-ink); }
.tot .cnt { background: none; color: var(--ink); font-weight: 700; }
.pivot-note { padding: 8px 14px 0; }
dialog.sheet.wide-sheet { width: min(1180px, calc(100% - 24px)); }
.cell-body { max-height: calc(100vh - 160px); overflow: auto; }
.i-warn { color: var(--serious); flex: none; }

/* ---------- table ---------- */
.table-card { padding: 14px 0 6px; overflow: hidden; }
.table-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 0 16px 12px; }
.table-head h2 { font-size: 16px; }
.count { color: var(--muted); font-weight: 600; margin-left: 4px; }
.search {
  display: flex; align-items: center; gap: 8px; padding: 0 10px; min-height: 38px; min-width: min(340px, 100%);
  border: 1px solid var(--border); border-radius: 10px; background: var(--page); color: var(--muted);
}
.search input { border: 0; outline: 0; background: none; flex: 1; min-width: 0; padding: 8px 0; color: var(--ink); }
.table-wrap { overflow-x: auto; }
.wo-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.wo-table th {
  position: sticky; top: 0; background: var(--surface); text-align: left; font-size: 12px; font-weight: 700; color: var(--ink-2);
  padding: 8px 12px; border-bottom: 1px solid var(--base); cursor: pointer; white-space: nowrap; user-select: none;
}
.wo-table th:hover { color: var(--ink); }
.wo-table th[aria-sort="ascending"]::after { content: " ▲"; color: var(--accent-ink); font-size: 10px; }
.wo-table th[aria-sort="descending"]::after { content: " ▼"; color: var(--accent-ink); font-size: 10px; }
.wo-table td { padding: 9px 12px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.wo-table td.wrap { min-width: 180px; }
.wo-table td.sc { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wo-table tbody tr { cursor: pointer; }
.wo-table tbody tr:hover td { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.age.old { color: var(--ink); font-weight: 700; }
.age .i-warn { margin-right: 4px; vertical-align: -1px; }
.status { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--border); white-space: nowrap; }
.status.st-good { color: var(--good-ink); border-color: var(--good); }
.empty-row td { text-align: center; color: var(--muted); padding: 28px; cursor: default; }
.table-note { padding: 10px 16px 6px; }

/* ---------- dialogs ---------- */
dialog.sheet {
  border: 1px solid var(--border); border-radius: 16px; padding: 0; width: min(720px, calc(100% - 24px)); max-height: calc(100% - 40px);
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
dialog.small-sheet { width: min(420px, calc(100% - 24px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px 10px; border-bottom: 1px solid var(--grid); }
.sheet-head h2 { font-size: 18px; margin-top: 2px; }
.sheet-body { padding: 14px 18px 18px; display: grid; gap: 16px; }
.sheet-body h3 { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.sheet-body dl { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.sheet-body dt { color: var(--ink-2); }
.sheet-body dd { margin: 0; overflow-wrap: anywhere; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- forms / login ---------- */
.field { display: grid; gap: 6px; font-size: 13px; color: var(--ink-2); }
.field input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--base); background: var(--page); color: var(--ink); font-size: 15px;
}
.pw { position: relative; display: block; }
.pw input { padding-right: 44px; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 8px; }
.form-error { color: var(--ink); background: color-mix(in srgb, var(--critical) 14%, transparent); border: 1px solid var(--critical); padding: 8px 10px; border-radius: 8px; font-size: 13.5px; }
.form-ok { color: var(--good-ink); font-weight: 600; font-size: 13.5px; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-wrap { width: min(400px, 100%); }
.login-card { padding: 26px 24px; display: grid; gap: 14px; }
.login-card h1 { font-size: 22px; }
.login-logo { border-radius: 10px; }
.login-theme { position: fixed; top: 14px; right: 14px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .top, main { padding-left: 16px; padding-right: 16px; }
  .updated { flex-basis: 100%; order: 3; }
  .src-switch { margin: 0; order: 2; width: 100%; }
  .src-switch button { flex: 1; }
  .kpi-value { font-size: 28px; }
  .search { min-width: 100%; }
  /* table → cards */
  .wo-table thead { display: none; }
  .wo-table, .wo-table tbody, .wo-table tr, .wo-table td { display: block; width: 100%; }
  .wo-table tr { padding: 10px 16px; border-bottom: 1px solid var(--grid); }
  .wo-table td { border: 0; padding: 2px 0; display: grid; grid-template-columns: 110px 1fr; gap: 10px; text-align: left; }
  .wo-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; }
  .wo-table td.num { text-align: left; }
  .empty-row td { display: block; }
  .empty-row td::before { content: none; }
  .sheet-body dl { grid-template-columns: 1fr; gap: 0 0; }
  .sheet-body dd { margin-bottom: 8px; }
}
