/* MadDog Fleet — admin portal.
 *
 * Same tokens as the cockpit (style.css), a different instrument. The cockpit
 * is a full-bleed flight surface; this is an operations console: a fixed
 * sidebar, dense tables, numbers in tabular figures where they line up in a
 * column and in proportional figures where they stand alone.
 *
 * Chart colours are their own tokens (--viz-*). The interface palette is
 * deliberately low in chroma, and measured against the dataviz validator it
 * cannot carry four distinguishable series: ok and warn sit at a normal-vision
 * ΔE of 7.3 and read grey. So the chrome keeps the brand palette and the data
 * marks get just enough chroma to be told apart, each value below checked by
 * the validator rather than by eye.
 */

:root {
  --viz-accent: #7FA8B0;           /* single-series marks, 3:1+ on the panel */
  --viz-band: rgba(127, 168, 176, .16);
  --viz-band-key: rgba(127, 168, 176, .55);
  --viz-good: #4FA472;             /* DIRECT */
  --viz-m1: #7A4652;               /* ASSISTED     ordinal, single hue,   */
  --viz-m2: #A4566A;               /* SUPERVISORY  monotone, light end    */
  --viz-m3: #D06E86;               /* SAFE         2.26:1 on the panel    */
  --viz-critical: #D06E86;         /* failed sign-ins */
  --viz-grid: #262B30;
  --viz-base: #3A4148;
  --viz-ink: #C9CFD4;
  --viz-ink-muted: #8A939B;
  --adm-side: #121518;
  --adm-row-hover: #1E2327;
  --adm-sel: rgba(127, 168, 176, .12);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --viz-accent: #1F4A55;
    --viz-band: rgba(31, 74, 85, .12);
    --viz-band-key: rgba(31, 74, 85, .45);
    --viz-good: #2F7A52;
    --viz-m1: #C98A98;
    --viz-m2: #A85A6E;
    --viz-m3: #7E3449;
    --viz-critical: #7E3449;
    --viz-grid: #DCE1E4;
    --viz-base: #A7B0B7;
    --viz-ink: #191D21;
    --viz-ink-muted: #4A535B;
    --adm-side: #E1E5E8;
    --adm-row-hover: #E9ECEE;
    --adm-sel: rgba(31, 74, 85, .09);
  }
}
:root[data-theme="light"] {
  --viz-accent: #1F4A55;
  --viz-band: rgba(31, 74, 85, .12);
  --viz-band-key: rgba(31, 74, 85, .45);
  --viz-good: #2F7A52;
  --viz-m1: #C98A98;
  --viz-m2: #A85A6E;
  --viz-m3: #7E3449;
  --viz-critical: #7E3449;
  --viz-grid: #DCE1E4;
  --viz-base: #A7B0B7;
  --viz-ink: #191D21;
  --viz-ink-muted: #4A535B;
  --adm-side: #E1E5E8;
  --adm-row-hover: #E9ECEE;
  --adm-sel: rgba(31, 74, 85, .09);
}

.admin-body { min-height: 100vh; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── shell ──────────────────────────────────────────────────────────────── */

.adm { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.adm[hidden], .adm-gate[hidden] { display: none; }

.adm-side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 22px;
  padding: 20px 14px 16px;
  background: var(--adm-side); border-right: 1px solid var(--line);
}
.adm-brand { font-weight: 800; letter-spacing: .4px; padding: 0 8px; font-size: 15px; }
.adm-brand span { color: var(--accent); }

.adm-nav { display: grid; gap: 2px; }
.adm-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 7px;
  color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 500;
  transition: background-color .3s var(--ease), color .3s var(--ease);
}
.adm-nav a:hover { color: var(--text); background: var(--adm-row-hover); }
.adm-nav a[aria-current="page"] { color: var(--text); background: var(--adm-sel); }
.adm-badge {
  margin-left: auto; min-width: 20px; padding: 1px 6px; border-radius: 99px;
  font: 600 11px/18px ui-monospace, Consolas, monospace; text-align: center;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
}

.ic {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}

.adm-side-foot { margin-top: auto; display: grid; gap: 12px; padding: 0 4px; }
.adm-exit {
  display: flex; align-items: center; gap: 8px; color: var(--muted);
  text-decoration: none; font-size: 13px;
}
.adm-exit:hover { color: var(--text); }
.adm-me {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px;
}
.adm-link {
  background: none; border: 0; padding: 0; color: var(--muted);
  font-size: 13px; font-weight: 500; cursor: pointer;
}
.adm-link:hover { color: var(--text); }

.adm-main { padding: 28px clamp(16px, 3vw, 40px) 64px; min-width: 0; }
.adm-view { max-width: 1320px; }
.adm-view[hidden] { display: none; }

.adm-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; margin-bottom: 20px;
}
.adm-head h1 { margin: 0; font-size: 25px; letter-spacing: -0.02em; font-weight: 700; }
.adm-sub { margin: 28px 0 10px; font-size: 16px; font-weight: 600; }

/* ── controls ───────────────────────────────────────────────────────────── */

.adm-primary, .adm-ghost, .adm-danger {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 600; border-radius: 8px; padding: 9px 14px;
  cursor: pointer; text-decoration: none; border: 1px solid transparent;
  transition: background-color .3s var(--ease), border-color .3s var(--ease);
}
.adm-primary { background: var(--accent); color: var(--on-ok); }
.adm-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.adm-ghost:hover { border-color: var(--muted); }
.adm-danger { background: var(--bad-fill); color: var(--on-bad-fill); }
.adm-icon {
  display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0;
  background: transparent; border: 1px solid transparent; border-radius: 7px;
  color: var(--muted); cursor: pointer;
}
.adm-icon:hover { color: var(--text); border-color: var(--line); }
.adm-primary:disabled, .adm-ghost:disabled, .adm-danger:disabled { opacity: .45; cursor: not-allowed; }

.adm-filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px 18px;
  margin-bottom: 20px;
}
.adm-filters label { display: grid; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 500; }
.adm-filters select, .adm-filters input, .adm-panel input, .adm-panel textarea {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; min-height: 38px;
}
.adm-filters select { padding-right: 28px; }
.adm-search input { width: min(280px, 70vw); }
.adm-hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.adm-stamp { margin-left: auto; font-size: 12px; color: var(--muted); align-self: center; }

.adm-seg {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: 9px;
  background: var(--panel); border: 1px solid var(--line);
}
.adm-seg button {
  background: transparent; border: 0; color: var(--muted);
  font-size: 13px; font-weight: 500; padding: 6px 12px; border-radius: 6px; cursor: pointer;
}
.adm-seg button[aria-checked="true"] { background: var(--adm-sel); color: var(--text); }

/* ── KPI row ────────────────────────────────────────────────────────────── */

.adm-kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px; margin: 0 0 24px; background: var(--line);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.adm-kpis > div { background: var(--panel); padding: 14px 16px; display: grid; gap: 4px; }
.adm-kpis dt { font-size: 12px; color: var(--muted); font-weight: 500; }
/* Proportional figures: a lone value set in tabular figures looks loose. */
.adm-kpis dd { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.adm-kpis dd small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.adm-kpis .warn dd { color: var(--warn); }

/* ── charts ─────────────────────────────────────────────────────────────── */

.adm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.adm-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 16px 14px; min-width: 0;
}
.adm-card.wide { grid-column: 1 / -1; }
.adm-card > header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  margin-bottom: 12px;
}
.adm-card h2 { margin: 0; font-size: 15px; font-weight: 600; }
.adm-card .adm-card-sub { margin: 3px 0 0; font-size: 12px; color: var(--muted); }
.adm-card-body { position: relative; min-height: 60px; }
.adm-card-body.loading { opacity: .5; transition: opacity .2s var(--ease); }

.viz { width: 100%; }
.viz-svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz-gridline { stroke: var(--viz-grid); stroke-width: 1; }
.viz-base { stroke: var(--viz-base); stroke-width: 1; }
.viz-tick {
  fill: var(--viz-ink-muted); font: 11px/1 ui-monospace, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}
.viz-cat { fill: var(--viz-ink); font: 500 12.5px/1 system-ui, sans-serif; }
.viz-label {
  fill: var(--viz-ink); font: 600 11.5px/1 ui-monospace, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}
.viz-line { fill: none; stroke: var(--viz-accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-band { fill: var(--viz-band); stroke: none; }
.viz-cross { stroke: var(--viz-base); stroke-width: 1; }
.viz-dot { fill: var(--viz-accent); stroke: var(--panel); stroke-width: 2; }
.viz-hit { fill: transparent; cursor: default; outline: none; }
.viz-mark { outline: none; }
.viz-mark path { transition: opacity .2s var(--ease); }
.viz-mark:hover path, .viz-mark:focus path { opacity: .78; }
.viz-mark:focus-visible .viz-hit, .viz-hit:focus-visible {
  stroke: var(--accent); stroke-width: 2;
}
.viz-empty { margin: 18px 0; font-size: 13px; color: var(--muted); }

.viz-legend {
  list-style: none; margin: 14px 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px 22px;
}
.viz-legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.viz-legend strong {
  margin-left: auto; font: 600 12.5px/1 ui-monospace, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}
.viz-swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.viz-key-line { display: inline-block; width: 16px; height: 2px; border-radius: 1px; vertical-align: middle; }
.viz-keys { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.viz-keys span { display: inline-flex; align-items: center; gap: 6px; }

.viz-tip {
  position: absolute; z-index: 60; pointer-events: none;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; min-width: 120px;
  box-shadow: 0 6px 18px -6px rgba(0, 0, 0, .45);
}
.viz-tip-title { color: var(--muted); margin-bottom: 5px; font-size: 11.5px; }
.viz-tip-row { display: flex; align-items: center; gap: 7px; line-height: 1.6; }
.viz-tip-row strong { font: 600 13px/1.4 ui-monospace, Consolas, monospace; color: var(--text); }
.viz-tip-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.viz-tip-label { color: var(--muted); }

.viz-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.viz-table th, .viz-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.viz-table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.viz-table .num { text-align: right; }
.viz-table td.num { font-family: ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; }

/* ── tables ─────────────────────────────────────────────────────────────── */

.adm-table-wrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  overflow-x: auto; min-width: 0;
}
.adm-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.adm-table th {
  position: sticky; top: 0; z-index: 1; background: var(--panel);
  text-align: left; font-size: 12px; font-weight: 500; color: var(--muted);
  padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.adm-table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.adm-table tbody tr:last-child td { border-bottom: 0; }
.adm-table tbody tr:hover { background: var(--adm-row-hover); }
.adm-table tbody tr.selected { background: var(--adm-sel); }
.adm-table .num { text-align: right; white-space: nowrap; }
.adm-table td.num { font-family: ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; }
.adm-table .who { display: grid; gap: 2px; }
.adm-table .who b { font-weight: 600; }
.adm-table .who span { font-size: 12px; color: var(--muted); }
.adm-table .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.adm-table .muted { color: var(--muted); }
.adm-table .actions { text-align: right; white-space: nowrap; }
.adm-table .actions button + button { margin-left: 6px; }
.adm-table .actions button { padding: 6px 11px; font-size: 12.5px; }

.adm-role {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px;
  border-radius: 99px; border: 1px solid var(--line); color: var(--text);
  white-space: nowrap;
}
.adm-role.admin { border-color: var(--accent); color: var(--accent); }
.adm-chip {
  display: inline-block; font-size: 12px; padding: 2px 8px; margin: 2px 4px 2px 0;
  border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line);
  white-space: nowrap;
}
.adm-off { color: var(--bad); font-size: 12px; font-weight: 600; }
.adm-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; background: var(--muted); }
.adm-dot.on { background: var(--ok); }

.adm-empty { margin: 0; padding: 24px 16px; color: var(--muted); font-size: 13.5px; }
.adm-more { margin-top: 14px; }
.adm-log td:last-child { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); max-width: 440px; overflow-wrap: anywhere; }

/* ── account editor ─────────────────────────────────────────────────────── */

.adm-split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.adm-split.editing { grid-template-columns: minmax(0, 1fr) 380px; }
/* With the editor open the list loses a third of its width; drop the two
   columns least needed while editing so the actions stay on screen. */
.adm-split.editing #u-table th:nth-child(4), .adm-split.editing #u-table td:nth-child(4),
.adm-split.editing #u-table th:nth-child(5), .adm-split.editing #u-table td:nth-child(5) { display: none; }

.adm-figure { display: grid; gap: 6px; padding: 18px 0 8px; }
.adm-figure strong { font-size: 44px; font-weight: 600; letter-spacing: -0.03em; line-height: 1; }
.adm-figure span { font-size: 13px; color: var(--muted); }
a.adm-ghost[aria-disabled="true"] { opacity: .45; pointer-events: none; }

.adm-panel {
  position: sticky; top: 16px;
  display: grid; gap: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px;
}
.adm-panel[hidden] { display: none; }
.adm-panel header { display: flex; justify-content: space-between; align-items: center; }
.adm-panel h2 { margin: 0; font-size: 16px; font-weight: 600; }
.adm-panel label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; }
.adm-panel textarea { resize: vertical; min-height: 60px; }
.adm-panel fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.adm-panel legend { font-size: 13px; font-weight: 500; margin-bottom: 6px; padding: 0; }
.adm-roles label {
  display: flex; gap: 10px; align-items: flex-start; font-weight: 400;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.adm-roles label:has(input:checked) { border-color: var(--accent); background: var(--adm-sel); }
.adm-roles input { margin-top: 3px; accent-color: var(--accent); }
.adm-roles span { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.adm-roles b { display: block; color: var(--text); font-size: 13.5px; font-weight: 600; }
.adm-vehicles label {
  display: flex; align-items: center; gap: 9px; font-weight: 400;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.adm-vehicles input { accent-color: var(--accent); width: 16px; height: 16px; }
.adm-vehicles .adm-hint { margin-left: auto; }
.adm-error { color: var(--bad); font-size: 13px; margin: 0; min-height: 1em; }
.adm-panel footer { display: flex; gap: 8px; }

.adm-dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 22px;
  background: var(--panel); color: var(--text); max-width: 420px; width: calc(100% - 32px);
}
.adm-dialog::backdrop { background: rgba(10, 12, 14, .55); }
.adm-dialog h2 { margin: 0 0 8px; font-size: 17px; }
.adm-dialog p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.adm-dialog footer { display: flex; justify-content: flex-end; gap: 8px; }

.adm-gate { display: grid; place-items: center; align-content: center; gap: 16px; min-height: 80vh; text-align: center; }
.adm-gate p { color: var(--muted); margin: 0; }

/* ── narrow screens ─────────────────────────────────────────────────────── */

@media (max-width: 1100px) {
  .adm-split.editing { grid-template-columns: minmax(0, 1fr); }
  .adm-panel { position: static; }
}
@media (max-width: 900px) {
  .adm { grid-template-columns: 1fr; }
  .adm-side {
    position: sticky; top: 0; z-index: 30; height: auto;
    flex-direction: row; align-items: center; gap: 10px;
    padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }
  .adm-brand { display: none; }
  .adm-nav { display: flex; gap: 4px; }
  .adm-nav a { white-space: nowrap; padding: 8px 10px; }
  .adm-side-foot { margin: 0 0 0 auto; display: flex; align-items: center; gap: 12px; }
  .adm-me { border: 0; padding: 0; }
  .adm-me #me-name { display: none; }
  .adm-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .adm-table thead { display: none; }
  .adm-table, .adm-table tbody, .adm-table tr, .adm-table td { display: block; }
  .adm-table tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .adm-table tbody tr:last-child { border-bottom: 0; }
  .adm-table td { padding: 3px 0; border: 0; }
  .adm-table td.num, .adm-table .actions { text-align: left; }
  .adm-table .actions { padding-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
  .adm-table .actions button + button { margin-left: 0; }
  .adm-table td:empty { display: none; }
  .adm-table td[data-label]::before {
    content: attr(data-label) " · "; color: var(--muted);
    font-family: system-ui, sans-serif; font-size: 12px;
  }
  .adm-split.editing #u-table td:nth-child(4),
  .adm-split.editing #u-table td:nth-child(5) { display: block; }
}
@media (max-width: 560px) {
  .adm-nav a { font-size: 0; gap: 0; padding: 9px; }
  .adm-nav a .ic { width: 20px; height: 20px; }
  .adm-badge { font-size: 10px; margin-left: 2px; }
  .adm-exit { font-size: 0; }
  .adm-main { padding: 20px 16px 56px; }
  .adm-head h1 { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  .adm-nav a, .adm-primary, .adm-ghost, .adm-danger, .viz-mark path,
  .adm-card-body.loading { transition: none; }
}
