/* ==========================================================================
   Sentra Tracker — "Mission Control" UI
   Drop-in replacement for public/assets/app.css
   Dark-first telematics console. Light mode included.
   Every legacy class / ID hook from app.js + super_admin.js is styled here.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root,
[data-theme='dark'] {
  --bg:            #080b11;
  --bg-grad:       radial-gradient(1200px 600px at 15% -10%, #12243a 0%, transparent 60%),
                   radial-gradient(900px 500px at 100% 0%, #0d2b30 0%, transparent 55%);
  --surface:       #0e131c;
  --surface-2:     #131a26;
  --surface-3:     #18212f;
  --surface-hi:    #1d2839;
  --border:        #1e2839;
  --border-strong: #2b394f;

  --text:          #e8eef8;
  --text-muted:    #8fa0b8;
  --text-faint:    #5d6b80;
  --text-on-acc:   #04141c;

  --acc:           #38bdf8;
  --acc-2:         #22d3ee;
  --acc-soft:      rgba(56, 189, 248, .14);
  --acc-line:      rgba(56, 189, 248, .32);

  --ok:            #34d399;
  --ok-soft:       rgba(52, 211, 153, .14);
  --warn:          #fbbf24;
  --warn-soft:     rgba(251, 191, 36, .14);
  --danger:        #fb7185;
  --danger-soft:   rgba(251, 113, 133, .14);
  --info:          #a78bfa;
  --info-soft:     rgba(167, 139, 250, .14);

  --shadow-sm:     0 1px 2px rgba(0,0,0,.4);
  --shadow:        0 8px 24px -8px rgba(0,0,0,.6);
  --shadow-lg:     0 24px 60px -20px rgba(0,0,0,.75);
  --glow:          0 0 0 1px var(--acc-line), 0 8px 32px -12px rgba(56,189,248,.5);

  --map-filter:    invert(1) hue-rotate(190deg) brightness(.94) contrast(.9) saturate(.7);
  color-scheme: dark;
}

[data-theme='light'] {
  --bg:            #eef1f6;
  --bg-grad:       radial-gradient(1100px 560px at 12% -10%, #dbe8f7 0%, transparent 60%),
                   radial-gradient(900px 500px at 100% 0%, #d9f0f2 0%, transparent 55%);
  --surface:       #ffffff;
  --surface-2:     #f7f9fc;
  --surface-3:     #eef2f8;
  --surface-hi:    #e5ebf4;
  --border:        #dce3ed;
  --border-strong: #c6d0de;

  --text:          #0d1626;
  --text-muted:    #56657d;
  --text-faint:    #8b98ac;
  --text-on-acc:   #ffffff;

  --acc:           #0b7fc4;
  --acc-2:         #0e8f9e;
  --acc-soft:      rgba(11, 127, 196, .10);
  --acc-line:      rgba(11, 127, 196, .28);

  --ok:            #16855c;
  --ok-soft:       rgba(22, 133, 92, .10);
  --warn:          #b06f00;
  --warn-soft:     rgba(176, 111, 0, .12);
  --danger:        #c22a48;
  --danger-soft:   rgba(194, 42, 72, .10);
  --info:          #6d4bd0;
  --info-soft:     rgba(109, 75, 208, .10);

  --shadow-sm:     0 1px 2px rgba(15,23,42,.06);
  --shadow:        0 10px 28px -14px rgba(15,23,42,.22);
  --shadow-lg:     0 28px 60px -24px rgba(15,23,42,.3);
  --glow:          0 0 0 1px var(--acc-line), 0 8px 28px -14px rgba(11,127,196,.4);

  --map-filter:    saturate(.92) contrast(1.02);
  color-scheme: light;
}

:root {
  --space-1: .25rem;  --space-2: .5rem;   --space-3: .75rem;  --space-4: 1rem;
  --space-5: 1.25rem; --space-6: 1.5rem;  --space-8: 2rem;    --space-10: 2.5rem;
  --space-12: 3rem;   --space-16: 4rem;

  --text-xs:   clamp(.75rem, .72rem + .12vw, .8125rem);
  --text-sm:   clamp(.8125rem, .79rem + .15vw, .875rem);
  --text-base: clamp(.9375rem, .91rem + .18vw, 1rem);
  --text-lg:   clamp(1.0625rem, 1rem + .35vw, 1.25rem);
  --text-xl:   clamp(1.375rem, 1.2rem + .8vw, 1.75rem);

  --r-sm: 8px; --r: 12px; --r-md: 14px; --r-lg: 18px; --r-xl: 24px; --r-full: 999px;

  --sans: 'Satoshi', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --sidebar-w: 264px;
  --rail-w: 320px;
  --topbar-h: 66px;

  --ease: cubic-bezier(.22, .61, .36, 1);
}

/* --------------------------------------------------------------------------
   2. Reset + base
   -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

@media (max-width: 900px) { body { overflow: auto; } }

/* Bootstrap 5.3 ships its own light-mode body/heading/border colours. Point its
   custom properties at our tokens so every Bootstrap component (modals,
   offcanvas, toasts, tables, form controls) inherits the Sentra palette. */
:root,
[data-theme='dark'],
[data-theme='light'] {
  --bs-body-bg: var(--bg);
  --bs-body-color: var(--text);
  --bs-heading-color: var(--text);
  --bs-emphasis-color: var(--text);
  --bs-secondary-color: var(--text-muted);
  --bs-tertiary-color: var(--text-faint);
  --bs-border-color: var(--border);
  --bs-border-color-translucent: var(--border);
  --bs-link-color: var(--acc);
  --bs-link-hover-color: var(--acc-2);
  --bs-font-sans-serif: var(--sans);
  --bs-font-monospace: var(--mono);
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; color: var(--text); }
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-base); }
p  { margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-4) 0; }
a  { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--acc-soft); }

:focus-visible {
  outline: 2px solid var(--acc);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.muted, .text-muted { color: var(--text-muted); font-size: var(--text-sm); }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums lining-nums; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-full);
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }

/* --------------------------------------------------------------------------
   3. App shell
   -------------------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 60;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-5);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }

.brand-mark {
  width: 38px; height: 38px; flex: 0 0 38px;
  display: grid; place-items: center;
  border-radius: 11px;
  color: var(--acc);
  background: linear-gradient(145deg, var(--surface-3), var(--surface-2));
  border: 1px solid var(--border-strong);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 4px 14px -6px rgba(0,0,0,.5);
}
.brand-mark svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; }

.brand-title {
  font-size: var(--text-base); font-weight: 700; letter-spacing: -.02em;
  line-height: 1.15; white-space: nowrap;
}
.brand-subtitle {
  font-size: var(--text-xs); color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 1100px) { .brand-subtitle { display: none; } }
@media (max-width: 560px) {
  .topbar { gap: var(--space-2); padding: 0 var(--space-3); }
  .brand { flex: 1 1 auto; overflow: hidden; }
  .brand-title { font-size: var(--text-sm); overflow: hidden; text-overflow: ellipsis; }
  .brand-mark { width: 32px; height: 32px; flex: 0 0 32px; border-radius: 9px; }
  .brand-mark svg { width: 18px; height: 18px; }
  .topbar-actions { flex: 0 0 auto; }
}

/* Global live status pill in the topbar */
.fleet-pulse {
  display: inline-flex; align-items: center; gap: var(--space-2);
  margin-left: var(--space-4);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border); border-radius: var(--r-full);
  background: var(--surface-2);
  font-size: var(--text-xs); color: var(--text-muted);
  white-space: nowrap;
}
.fleet-pulse b { color: var(--text); font-family: var(--mono); }
.fleet-pulse .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
  animation: pulse 2.4s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .45; transform: scale(.82); }
}
@media (max-width: 1240px) { .fleet-pulse { display: none; } }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

.header-icon-btn {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface-2); color: var(--text-muted);
  cursor: pointer;
  transition: color .16s var(--ease), background .16s var(--ease),
              border-color .16s var(--ease), transform .16s var(--ease);
}
.header-icon-btn svg { width: 19px; height: 19px; fill: currentColor; }
.header-icon-btn:hover {
  color: var(--text); background: var(--surface-hi);
  border-color: var(--border-strong); transform: translateY(-1px);
}
.logout-icon-btn:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

.user-chip {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-1) var(--space-3) var(--space-1) var(--space-1);
  border: 1px solid var(--border); border-radius: var(--r-full);
  background: var(--surface-2);
  font-size: var(--text-sm); font-weight: 500; color: var(--text);
  max-width: 210px;
}
.user-chip .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: var(--text-xs); font-weight: 700; letter-spacing: 0;
  color: var(--text-on-acc);
  background: linear-gradient(140deg, var(--acc), var(--acc-2));
}
.user-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mobile-menu-btn { display: none; }
@media (max-width: 900px) { .mobile-menu-btn { display: grid; } }

/* Below 900px the sidebar becomes the offcanvas menu, which carries its own
   Profile and Sign out buttons at the bottom. Duplicating them in the header
   is redundant on exactly the screens with the least room for them, so the
   header keeps only menu, search and theme. Same breakpoint as
   .mobile-menu-btn above so the two can never disagree. */
@media (max-width: 900px) {
  .user-chip,
  .profile-icon-btn,
  .logout-icon-btn { display: none; }
}

/* Layout grid */
.page-shell { height: calc(100dvh - var(--topbar-h)); }

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100%;
}

/* --------------------------------------------------------------------------
   4. Sidebar
   -------------------------------------------------------------------------- */

.side-menu {
  grid-row: 1 / -1;
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--space-4) var(--space-3) var(--space-5);
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  overflow-y: auto; overscroll-behavior: contain;
}

.side-title {
  font-size: 10.5px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
  color: var(--text-faint);
  padding: var(--space-2) var(--space-3) var(--space-3);
}

.side-link, .module-button {
  position: relative;
  display: grid; grid-template-columns: 22px 1fr auto; align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: 10px var(--space-3);
  border: 0; border-radius: var(--r);
  background: transparent; color: var(--text-muted);
  font: inherit; font-size: var(--text-sm); font-weight: 500;
  text-align: left; cursor: pointer;
  transition: color .15s var(--ease), background .15s var(--ease);
}
.module-icon { display: grid; place-items: center; }
.module-icon svg { width: 18px; height: 18px; fill: currentColor; opacity: .95; }
.module-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.side-link:hover, .module-button:hover { color: var(--text); background: var(--surface-2); }

.side-link.active, .module-button.active {
  color: var(--text);
  background: linear-gradient(90deg, var(--acc-soft), transparent 85%);
  box-shadow: inset 0 0 0 1px var(--border);
}
.side-link.active .module-icon, .module-button.active .module-icon { color: var(--acc); }

.side-link.active::before, .module-button.active::before {
  content: ''; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--acc);
  box-shadow: 0 0 12px var(--acc);
}

.super-admin-module { margin-top: var(--space-2); }
.super-admin-module .module-icon { color: var(--info); }

.side-divider {
  height: 1px; background: var(--border);
  margin: var(--space-3) var(--space-3);
}

.module-count-badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  display: inline-grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--danger); color: #fff;
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.side-foot {
  margin-top: auto; padding: var(--space-3);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2);
  font-size: var(--text-xs); color: var(--text-faint);
}
.side-foot b { display: block; color: var(--text-muted); font-size: var(--text-xs); }

@media (max-width: 900px) {
  .app-layout { grid-template-columns: minmax(0, 1fr); }
  .side-menu { display: none; }
  .page-shell { height: auto; }
}

/* --------------------------------------------------------------------------
   5. Content area + panels
   -------------------------------------------------------------------------- */

.content-stack {
  min-width: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: var(--space-6) clamp(var(--space-4), 2.4vw, var(--space-8)) var(--space-16);
}
@media (max-width: 900px) { .content-stack { overflow: visible; padding: var(--space-4) var(--space-4) var(--space-16); } }

.content-panel { display: none; }
.content-panel.active {
  display: flex; flex-direction: column; gap: var(--space-5);
  animation: panel-in .32s var(--ease);
}
@keyframes panel-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .content-panel.active { animation: none; }
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.card {
  padding: var(--space-5);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: var(--shadow-sm);
}
.card--flush { padding: var(--space-2); }
.card--map { padding: 0; overflow: hidden; }

.section-head {
  display: flex; align-items: flex-start; gap: var(--space-4);
  flex-wrap: wrap; margin-bottom: var(--space-4);
}
.section-head > div:first-child { min-width: 0; flex: 1 1 260px; }
.section-head .muted { margin-top: 4px; max-width: 68ch; }
.section-head > .btn, .section-head > button { margin-left: auto; }

.eyebrow {
  display: block; margin-bottom: 6px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--acc);
}

/* --------------------------------------------------------------------------
   6. Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 40px; padding: 0 var(--space-4);
  border: 1px solid var(--border-strong); border-radius: var(--r);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: var(--text-sm); font-weight: 600; line-height: 1;
  white-space: nowrap; cursor: pointer;
  transition: transform .14s var(--ease), background .14s var(--ease),
              border-color .14s var(--ease), box-shadow .14s var(--ease), color .14s var(--ease);
}
.btn svg { width: 18px; height: 18px; fill: currentColor; flex: 0 0 auto; }
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-primary, .btn.primary {
  background: linear-gradient(140deg, var(--acc), var(--acc-2));
  border-color: transparent; color: var(--text-on-acc);
}
.btn-primary:hover, .btn.primary:hover { box-shadow: var(--glow); filter: brightness(1.06); }

.btn-secondary { background: var(--surface-3); color: var(--text); }
.btn-secondary:hover { background: var(--surface-hi); border-color: var(--acc-line); }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.btn-success { background: var(--ok); border-color: transparent; color: #04231a; }
.btn-danger  { background: var(--danger); border-color: transparent; color: #2b0710; }
.btn-warning { background: var(--warn); border-color: transparent; color: #2a1c00; }
[data-theme='light'] .btn-success,
[data-theme='light'] .btn-danger,
[data-theme='light'] .btn-warning { color: #fff; }

.btn-sm { min-height: 32px; padding: 0 var(--space-3); font-size: var(--text-xs); border-radius: var(--r-sm); }
.btn-sm svg { width: 15px; height: 15px; }
.full-width { width: 100%; }

/* Square icon buttons */
.module-icon-btn, .live-toolbar-btn, .trip-search-btn, .trip-action-btn {
  width: 40px; min-width: 40px; padding: 0;
}
.btn-sm.module-icon-btn, .btn-sm.trip-action-btn { width: 32px; min-width: 32px; }
.action-icon, .trip-action-svg { width: 18px; height: 18px; fill: currentColor; }

/* Segmented action cluster */
.live-toolbar-actions {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: var(--space-2);
}

/* --------------------------------------------------------------------------
   7. Forms
   -------------------------------------------------------------------------- */

label {
  display: block;
  font-size: var(--text-xs); font-weight: 600; letter-spacing: .02em;
  color: var(--text-muted);
}
label > small { display: block; margin-top: 6px; font-weight: 400; }

input:not([type='checkbox']):not([type='radio']),
select, textarea,
.form-control, .form-select {
  width: 100%; margin-top: 6px;
  min-height: 42px; padding: 9px var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--r);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: var(--text-sm);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease);
}
textarea { min-height: 96px; resize: vertical; }

input::placeholder, textarea::placeholder { color: var(--text-faint); }

input:hover, select:hover, textarea:hover { border-color: var(--text-faint); }

input:focus, select:focus, textarea:focus,
.form-control:focus, .form-select:focus {
  outline: 0; border-color: var(--acc);
  background: var(--surface-3);
  box-shadow: 0 0 0 4px var(--acc-soft);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: var(--space-8);
}

input[type='date'] { min-height: 42px; }
input[type='date']::-webkit-calendar-picker-indicator {
  filter: invert(.55); cursor: pointer;
}
[data-theme='light'] input[type='date']::-webkit-calendar-picker-indicator { filter: none; }

input[type='checkbox'], input[type='radio'] {
  width: 18px; height: 18px; margin: 0;
  accent-color: var(--acc); cursor: pointer;
}

.form-label { margin-bottom: 4px; font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); }

.form-grid { display: grid; gap: var(--space-4); }
.form-grid.two-col { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-grid h3 { grid-column: 1 / -1; }
.form-grid .full-width { grid-column: 1 / -1; }

/* Toolbars */
.live-toolbar, .trip-toolbar, .toolbar-group, .table-toolbar, .users-toolbar {
  display: flex; align-items: flex-end; gap: var(--space-3); flex-wrap: wrap;
}
.live-toolbar > label, .trip-toolbar > label, .toolbar-group > label { flex: 1 1 200px; max-width: 300px; }
.live-toolbar input, .live-toolbar select,
.trip-toolbar input, .trip-toolbar select { width: 100% !important; }
.table-toolbar input, .users-toolbar { flex: 1 1 260px; }
.users-toolbar { justify-content: flex-end; margin-bottom: var(--space-4); }
.toolbar-group > .btn { align-self: flex-end; }

.trip-toolbar .trip-search-btn { align-self: flex-end; }

/* Report action button — same shape as the secondary report buttons, green */
.btn-report {
  display: inline-flex; align-items: center; gap: var(--space-2);
  border: 1px solid color-mix(in srgb, var(--ok) 45%, var(--border));
  background: var(--ok-soft, color-mix(in srgb, var(--ok) 14%, transparent));
  color: var(--ok);
  font-weight: 600;
}
.btn-report svg { width: 18px; height: 18px; fill: currentColor; }
.btn-report:hover {
  background: color-mix(in srgb, var(--ok) 22%, transparent);
  border-color: var(--ok); color: var(--ok);
  transform: translateY(-1px);
}
.btn-report:active { transform: none; }
.btn-report:focus-visible { outline: 2px solid var(--ok); outline-offset: 2px; }

/* Icon picker */
.icon-picker { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: 6px; }
/* app.js renders each choice as icon + label, so the tile has to size to its
   content rather than being locked to a square. */
.icon-choice {
  min-width: 68px; padding: var(--space-2) var(--space-3) 6px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 1px solid var(--border-strong); border-radius: var(--r);
  background: var(--surface-2); color: var(--text-muted);
  cursor: pointer; transition: all .15s var(--ease);
}
.icon-choice > span {
  font-size: 11px; font-weight: 600; letter-spacing: .01em; line-height: 1;
  white-space: nowrap;
}
.icon-choice svg, .tracker-svg { width: 24px; height: 24px; fill: currentColor; }
.icon-choice:hover { color: var(--text); border-color: var(--acc-line); transform: translateY(-2px); }
.icon-choice.active, .icon-choice[aria-pressed='true'] {
  color: var(--acc); border-color: var(--acc);
  background: var(--acc-soft); box-shadow: var(--glow);
}

/* Switch rows (alert settings) */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm); color: var(--text);
}
.switch-row:last-child { border-bottom: 0; }
.switch-row input:not([type='checkbox']), .switch-row select { width: auto; min-width: 130px; margin-top: 0; }

.alert-rule-card {
  padding: var(--space-4);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2);
  margin-bottom: var(--space-3);
}
.alert-rule-top {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); margin-bottom: var(--space-2);
  font-weight: 600;
}
.alert-mode-options {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  margin: var(--space-3) 0;
}
.alert-mode-options .alert-radio-option {
  flex: 0 0 auto;
  white-space: nowrap;
}

.alert-radio-option {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--r-full);
  background: var(--surface); font-size: var(--text-xs); cursor: pointer;
}
.alert-radio-option:has(input:checked) {
  border-color: var(--acc); background: var(--acc-soft); color: var(--text);
}
.empty-alert-rules { color: var(--text-muted); font-size: var(--text-sm); }
.sound-select { max-width: 200px; }

.tracker-enabled-row {
  display: flex !important; align-items: center; gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface-2);
  font-size: var(--text-sm); color: var(--text);
}

/* --------------------------------------------------------------------------
   8. Live map panel
   -------------------------------------------------------------------------- */

/* Arm / disarm status banner */
.tracker-status-banner {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface-2);
  font-size: var(--text-sm); font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  color: var(--text-muted);
}
.tracker-status-banner::before {
  content: ''; width: 10px; height: 10px; border-radius: 50%;
  background: currentColor; flex: 0 0 10px;
}
.tracker-status-banner::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, currentColor, transparent 42%); opacity: .09;
}
.tracker-status-banner.disarmed { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.tracker-status-banner.armed    { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.tracker-status-banner.armed::before { animation: pulse 1.6s var(--ease) infinite; }

/* KPI strip */
.stat-grid, .kpi-strip {
  display: grid; gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
/* Two-up KPI tiles on phones so the strip doesn't eat the whole first screen */
@media (max-width: 620px) {
  .stat-grid, .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
  .stat-card, .kpi { padding: var(--space-3); }
  .stat-card .stat-sub, .kpi .kpi-sub { font-size: 11px; }
}
.stat-card, .kpi {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--space-4);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2);
  transition: border-color .16s var(--ease), transform .16s var(--ease);
}
.stat-card:hover, .kpi:hover { border-color: var(--acc-line); transform: translateY(-2px); }
.stat-card .muted, .kpi .kpi-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-faint);
}
.stat-card strong, .kpi-value {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 1.6rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.2;
  color: var(--text);
}
.kpi-value small { font-family: var(--sans); font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); }
.kpi-foot { font-size: var(--text-xs); color: var(--text-muted); }
.kpi::after {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--acc-line);
}
.kpi[data-tone='ok']::after     { background: var(--ok); }
.kpi[data-tone='warn']::after   { background: var(--warn); }
.kpi[data-tone='danger']::after { background: var(--danger); }
.kpi[data-tone='info']::after   { background: var(--info); }

/* Map + fleet rail split */
.live-split {
  display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr);
  gap: var(--space-5); align-items: stretch;
}
@media (max-width: 1180px) { .live-split { grid-template-columns: minmax(0, 1fr); } }

.fleet-rail {
  display: flex; flex-direction: column; min-height: 0;
  padding: var(--space-3);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}
.fleet-rail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-2) var(--space-2) var(--space-3);
}
.fleet-rail-head span {
  font-size: 10.5px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
  color: var(--text-faint);
}
.fleet-rail-list {
  display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto; overscroll-behavior: contain;
  max-height: 520px;
}
.fleet-item {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: var(--space-3);
  width: 100%; padding: var(--space-3);
  border: 1px solid transparent; border-radius: var(--r-md);
  background: transparent; color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.fleet-item:hover { background: var(--surface-2); border-color: var(--border); }
.fleet-item.active {
  background: var(--acc-soft); border-color: var(--acc-line);
}
.fleet-item > span:nth-child(2) { display: block; min-width: 0; }
.fleet-item-icon {
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 10px; background: var(--surface-3); color: var(--text-muted);
  border: 1px solid var(--border);
}
.fleet-item.active .fleet-item-icon { color: var(--acc); border-color: var(--acc-line); }
.fleet-item-icon svg { width: 18px; height: 18px; fill: currentColor; }
.fleet-item-name {
  display: block;
  font-size: var(--text-sm); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fleet-item-sub {
  display: block;
  font-family: var(--mono); font-size: 11px; color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fleet-item-speed {
  flex: 0 0 auto;
  font-family: var(--mono); font-size: var(--text-xs); font-weight: 700;
  color: var(--text-muted); text-align: right; white-space: nowrap;
}
.fleet-item-speed em {
  display: block; font-style: normal; font-size: 10px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
}
.fleet-item[data-state='moving'] .fleet-item-speed { color: var(--ok); }
.fleet-item[data-state='offline'] .fleet-item-speed { color: var(--text-faint); }
.fleet-item[data-state='armed'] .fleet-item-speed { color: var(--danger); }

/* Leaflet map */
#map, #playbackMap {
  height: min(62vh, 640px); min-height: 420px; width: 100%;
  border-radius: var(--r-lg); overflow: hidden;
  background: var(--surface-2);
}
.card--map #map, .card--map #playbackMap { border-radius: calc(var(--r-lg) - 1px); }

.leaflet-container { background: var(--surface-2) !important; font-family: var(--sans) !important; }
.leaflet-tile-pane { filter: var(--map-filter); }

.leaflet-control-zoom a,
.leaflet-bar a {
  background: var(--surface-2) !important; color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-bar { border: 1px solid var(--border) !important; box-shadow: var(--shadow) !important; border-radius: var(--r) !important; overflow: hidden; }
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--surface) 80%, transparent) !important;
  color: var(--text-faint) !important; font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--text-muted) !important; }

.leaflet-popup-content-wrapper {
  background: var(--surface-2) !important; color: var(--text) !important;
  border: 1px solid var(--border-strong) !important; border-radius: var(--r-md) !important;
  box-shadow: var(--shadow-lg) !important;
}
.leaflet-popup-tip { background: var(--surface-2) !important; border: 1px solid var(--border-strong) !important; }
.leaflet-popup-content { margin: var(--space-4) !important; font-size: var(--text-sm) !important; }
.leaflet-popup-close-button { color: var(--text-muted) !important; }

/* Map markers rendered by app.js */
.tracker-map-pin {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 50% 50% 50% 12px;
  transform: rotate(-45deg);
  background: linear-gradient(140deg, var(--acc), var(--acc-2));
  color: var(--text-on-acc);
  border: 2px solid color-mix(in srgb, var(--surface) 70%, transparent);
  box-shadow: 0 6px 18px -6px rgba(0,0,0,.7), 0 0 0 6px var(--acc-soft);
}
.tracker-map-pin svg, .tracker-map-pin .tracker-svg {
  width: 20px; height: 20px; fill: currentColor; transform: rotate(45deg);
}
.tracker-map-label {
  margin-top: 6px; padding: 3px 8px;
  border: 1px solid var(--border-strong); border-radius: var(--r-full);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  color: var(--text); font-size: 11px; font-weight: 700; white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.tracker-popup { min-width: 220px; display: grid; gap: 4px; }
.tracker-popup > div:not(.tracker-popup-head):not(.popup-actions) { font-size: var(--text-xs); color: var(--text-muted); }
.tracker-popup strong { color: var(--text); }
.tracker-popup-head {
  display: flex; align-items: center; gap: var(--space-3);
  padding-bottom: var(--space-3); margin-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}
.tracker-popup-head svg, .tracker-popup-head .tracker-svg {
  width: 32px; height: 32px; padding: 6px; box-sizing: content-box;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-3); color: var(--acc); fill: currentColor;
}
.tracker-popup-head strong { font-size: var(--text-sm); }
.popup-actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); }

/* --------------------------------------------------------------------------
   9. Lists, cards, tables
   -------------------------------------------------------------------------- */

.alert-list { display: grid; gap: var(--space-3); }

.alert-item {
  position: relative;
  display: grid; gap: 4px;
  padding: var(--space-4) var(--space-4) var(--space-4) var(--space-5);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2);
  transition: border-color .16s var(--ease), transform .16s var(--ease);
}
.alert-item:hover { border-color: var(--border-strong); transform: translateX(2px); }
.alert-item::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  border-radius: 3px 0 0 3px; background: var(--text-faint);
}
.alert-item strong { font-size: var(--text-sm); }
.alert-item p { font-size: var(--text-sm); color: var(--text-muted); }
.alert-item .muted { font-family: var(--mono); font-size: 11px; }
.alert-item .btn { justify-self: start; margin-top: var(--space-2); }

.alert-item.critical::before, .alert-item.high::before, .alert-item.danger::before { background: var(--danger); }
.alert-item.warning::before, .alert-item.medium::before { background: var(--warn); }
.alert-item.info::before, .alert-item.low::before { background: var(--info); }
.alert-item.success::before { background: var(--ok); }
.alert-item.unacknowledged { background: color-mix(in srgb, var(--danger-soft) 55%, var(--surface-2)); }
.alert-item.acknowledged { opacity: .72; }

.note-item {
  display: grid; gap: 4px;
  padding: var(--space-4);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2); margin-bottom: var(--space-3);
}
.note-item strong { font-size: var(--text-sm); }
.note-item .muted { font-family: var(--mono); font-size: 11px; }
.note-item .btn { justify-self: start; margin-top: var(--space-2); }

.health-grid {
  display: grid; gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.health-card {
  padding: var(--space-4);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2);
  font-size: var(--text-sm);
  transition: border-color .16s var(--ease), transform .16s var(--ease);
}
.health-card:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.health-card p {
  display: flex; justify-content: space-between; gap: var(--space-3);
  padding: 3px 0; color: var(--text-muted); font-size: var(--text-xs);
}
.health-card p strong { color: var(--text-muted); font-weight: 600; }
.health-card > p:not(:has(strong)) { color: var(--text-muted); }
.health-card hr { margin: var(--space-3) 0; }
.health-card.healthy { border-left: 3px solid var(--ok); }
.health-card.warning { border-left: 3px solid var(--warn); }
.health-card.offline { border-left: 3px solid var(--danger); opacity: .85; }

.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--r-full);
  background: var(--surface-3);
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-muted);
}
.status-pill.status-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); background: var(--ok-soft); }
.status-pill.status-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); background: var(--warn-soft); }
.status-pill.status-bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); background: var(--danger-soft); }
.smart-alert-ack-badge { justify-self: start; margin-top: var(--space-2); }

/* Tables */
.table-wrap, .table-responsive {
  overflow-x: auto; overscroll-behavior-x: contain;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2);
}

.admin-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: var(--text-sm);
}
.admin-table thead th {
  position: sticky; top: 0; z-index: 1;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-3);
  border-bottom: 1px solid var(--border-strong);
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-faint); text-align: left; white-space: nowrap;
}
.admin-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: middle;
}
.admin-table tbody tr:last-child td { border-bottom: 0; }
.admin-table tbody tr { transition: background .14s var(--ease); }
.admin-table tbody tr:hover { background: var(--surface-3); }
.admin-table tbody tr.selected { background: var(--acc-soft); }
.admin-table td:nth-child(n+3) { font-variant-numeric: tabular-nums; }
.table-actions { display: flex; gap: var(--space-2); }
.icon-actions { flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   10. Trips
   -------------------------------------------------------------------------- */

#tripsList { display: grid; gap: var(--space-3); }

.trip-card {
  position: relative;
  padding: var(--space-4);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2);
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}
.trip-card:hover { border-color: var(--acc-line); box-shadow: var(--shadow); }
.trip-card[draggable='true'] { cursor: grab; }
.trip-card.dragging { opacity: .5; }

.trip-card-head {
  display: flex; align-items: flex-start; gap: var(--space-4);
  flex-wrap: wrap;
}
.trip-main-details { flex: 1 1 260px; min-width: 0; display: grid; gap: 6px; }
.trip-main-details > strong { font-size: var(--text-sm); }
.trip-main-details > .muted { font-family: var(--mono); font-size: 11px; }
.trip-card-head .table-actions { margin-left: auto; }

.trip-stats {
  display: flex; flex-wrap: wrap; gap: var(--space-2);
  margin-top: var(--space-2);
}
.trip-stats span {
  padding: 5px 10px;
  border: 1px solid var(--border); border-radius: var(--r-full);
  background: var(--surface-3);
  font-size: var(--text-xs); color: var(--text-muted);
}
.trip-stats span strong { font-family: var(--mono); color: var(--text); }

.trip-odometer {
  display: flex; flex-wrap: wrap; gap: var(--space-4);
  margin-top: var(--space-2);
  font-size: var(--text-xs); color: var(--text-muted);
}
.trip-odometer strong { color: var(--text-faint); font-weight: 600; }

.trip-meta-grid {
  display: grid; gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-top: var(--space-4); padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}
.trip-meta-grid > div { display: grid; gap: 2px; }
.trip-meta-grid .muted {
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-faint);
}
.trip-meta-grid strong { font-size: var(--text-sm); font-weight: 600; }

.trip-merge-select {
  display: inline-flex !important; align-items: center; gap: var(--space-2);
  border: 1px solid var(--border) !important; border-radius: var(--r-full) !important;
  padding: 6px var(--space-3) !important;
  margin-bottom: var(--space-3);
  background: var(--surface-3);
  font-size: var(--text-xs); font-weight: 600; color: var(--text-muted);
  cursor: pointer;
}
.trip-merge-select:has(input:checked) {
  border-color: var(--acc) !important; background: var(--acc-soft); color: var(--text);
}
/* app.js wraps the merge checkbox in an outer div that also carries this class
   and an inline silver border. Collapse the wrapper so only the inner label
   renders as a chip instead of a full-width box. */
.trip-card > .trip-merge-select { display: contents !important; }
.trip-merge-select label.trip-merge-select { justify-self: start; width: fit-content; }

.trip-merge-select label { display: inline-flex; align-items: center; gap: 6px; font-size: inherit; }
.trip-merge-select input { margin: 0; accent-color: var(--acc); }

.trip-manual-merge-actions { display: flex; justify-content: flex-end; margin-top: var(--space-3); }

/* --------------------------------------------------------------------------
   11. Bootstrap component overrides (modals, offcanvas, toasts)
   -------------------------------------------------------------------------- */

.modal-content, .custom-modal-content {
  border: 1px solid var(--border-strong); border-radius: var(--r-xl);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg);
}
.modal-header, .custom-modal-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-5); border-bottom: 1px solid var(--border);
}
.modal-title, .custom-modal-header h2 { font-size: var(--text-lg); font-weight: 700; margin: 0; }
.modal-body { padding: var(--space-5); }
.modal-footer {
  display: flex; justify-content: flex-end; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-xl) var(--r-xl);
}
.modal-backdrop.show { background: #03060b; opacity: .72; }
[data-theme='light'] .modal-backdrop.show { background: #1b2436; opacity: .5; }

.btn-close, .custom-modal-close {
  width: 34px; height: 34px; flex: 0 0 34px; padding: 0;
  display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text-muted);
  font-size: 20px; line-height: 1; opacity: 1; cursor: pointer;
}
.btn-close { background-image: none; }
.btn-close::before { content: '\00d7'; font-size: 20px; }
.btn-close:hover, .custom-modal-close:hover { color: var(--text); background: var(--surface-hi); opacity: 1; }

/* Legacy hand-rolled modals */
.custom-modal {
  position: fixed; inset: 0; z-index: 1080;
  display: grid; place-items: center;
  padding: var(--space-4);
  background: rgba(3, 6, 11, .72);
  backdrop-filter: blur(6px);
  overflow-y: auto;
}
.custom-modal.hidden { display: none; }
.custom-modal-content { width: min(760px, 100%); padding-bottom: var(--space-5); }
.custom-modal-content > form { padding: var(--space-5); }

/* Offcanvas mobile nav */
.offcanvas {
  background: var(--surface) !important; color: var(--text) !important;
  border-right: 1px solid var(--border) !important;
  width: min(320px, 86vw) !important;
}
.offcanvas-header { padding: var(--space-5); border-bottom: 1px solid var(--border); }
.offcanvas-title { font-size: var(--text-base); font-weight: 700; }
.mobile-menu-list { display: flex; flex-direction: column; gap: 4px; padding: var(--space-3); }

.mobile-nav-btn, .mobile-nav-account-btn {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; padding: var(--space-3);
  border: 0; border-radius: var(--r);
  background: transparent; color: var(--text-muted);
  font: inherit; font-size: var(--text-sm); font-weight: 500;
  text-align: left; cursor: pointer;
}
.mobile-nav-btn svg, .mobile-nav-account-btn svg { width: 18px; height: 18px; fill: currentColor; }
.mobile-nav-btn:hover, .mobile-nav-account-btn:hover { background: var(--surface-2); color: var(--text); }
.mobile-nav-btn.active { background: var(--acc-soft); color: var(--text); }
.mobile-nav-btn.active svg { color: var(--acc); }
.mobile-nav-account-actions {
  margin-top: var(--space-4); padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  display: grid; gap: 4px;
}
.mobile-logout-btn:hover { color: var(--danger); background: var(--danger-soft); }

/* Toasts */
.toast {
  border: 1px solid var(--border-strong) !important; border-radius: var(--r-md) !important;
  background: var(--surface) !important; color: var(--text) !important;
  box-shadow: var(--shadow-lg) !important;
}
.toast.text-bg-primary { border-left: 3px solid var(--acc) !important; }
.toast.text-bg-success { border-left: 3px solid var(--ok) !important; }
.toast.text-bg-danger  { border-left: 3px solid var(--danger) !important; }
.toast.text-bg-warning { border-left: 3px solid var(--warn) !important; }
.toast-body { font-size: var(--text-sm); padding: var(--space-4); }
.toast .btn-close-white { filter: none; }

/* Bootstrap grid helpers used by app.js modals */
.row { display: grid; gap: var(--space-4); grid-template-columns: repeat(12, 1fr); }
.row.g-3 { gap: var(--space-4); }
.col-12 { grid-column: span 12; }
.col-md-6 { grid-column: span 12; }
@media (min-width: 768px) { .col-md-6 { grid-column: span 6; } }
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: var(--space-2) !important; }
.mb-3 { margin-bottom: var(--space-3) !important; }
.mt-3 { margin-top: var(--space-3) !important; }
.small { font-size: var(--text-xs); }

/* --------------------------------------------------------------------------
   12. Empty / loading states
   -------------------------------------------------------------------------- */

.empty-state {
  display: grid; place-items: center; gap: var(--space-3);
  padding: var(--space-12) var(--space-5);
  border: 1px dashed var(--border-strong); border-radius: var(--r-lg);
  background: var(--surface-2); text-align: center;
}
.empty-state svg { width: 34px; height: 34px; fill: var(--text-faint); }
.empty-state strong { font-size: var(--text-sm); }
.empty-state p { font-size: var(--text-sm); color: var(--text-muted); max-width: 42ch; }

.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-hi) 40%, var(--surface-2) 80%);
  background-size: 300% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Direct text children used as empty states by app.js */
#alertsList > .muted, #tripsList > .muted, #geofenceList > .muted,
#healthList > .muted, #insightsList > .muted, #trackerDetails > .muted {
  display: block; grid-column: 1 / -1;
  padding: var(--space-8);
  border: 1px dashed var(--border-strong); border-radius: var(--r-md);
  background: var(--surface-2); text-align: center;
}

/* --------------------------------------------------------------------------
   13. Utility
   -------------------------------------------------------------------------- */

.hidden, [hidden] { display: none !important; }

details.drawer {
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  overflow: hidden;
}
details.drawer > summary {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  font-size: var(--text-sm); font-weight: 600; color: var(--text);
  cursor: pointer; list-style: none;
}
details.drawer > summary::-webkit-details-marker { display: none; }
details.drawer > summary::after {
  content: ''; margin-left: auto;
  width: 8px; height: 8px;
  border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg); transition: transform .2s var(--ease);
}
details.drawer[open] > summary::after { transform: rotate(-135deg); }
details.drawer[open] > summary { border-bottom: 1px solid var(--border); }
details.drawer > .drawer-body { padding: var(--space-5); }
details.drawer > summary:hover { background: var(--surface-2); }

/* ==========================================================================
   Driver scores and mileage claims
   Added by scoring.js. Uses only existing tokens, so both themes work with
   no extra work.
   ========================================================================== */

.head-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------- date presets */

.score-toolbar { align-items: flex-end; }

.range-presets {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: var(--r-full);
}
.range-preset {
  appearance: none; border: 0; background: transparent;
  padding: 6px var(--space-4); border-radius: var(--r-full);
  font: inherit; font-size: var(--text-xs); font-weight: 600;
  color: var(--text-muted); cursor: pointer;
  transition: background .16s var(--ease), color .16s var(--ease);
}
.range-preset:hover { color: var(--text); }
.range-preset.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,.25)); }

/* ------------------------------------------------------------ score ring */

.score-ring { position: relative; width: 60px; height: 60px; flex: 0 0 60px; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-ring circle { fill: none; stroke-width: 6; stroke-linecap: round; }
.score-ring-track { stroke: var(--surface-3); }
.score-ring-fill {
  stroke: var(--accent);
  transition: stroke-dashoffset .6s var(--ease);
}
.score-ring-value {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: var(--text-base); font-weight: 700;
  color: var(--text);
}

.band-excellent .score-ring-fill { stroke: var(--ok); }
.band-good      .score-ring-fill { stroke: var(--accent); }
.band-fair      .score-ring-fill { stroke: var(--warn); }
.band-poor      .score-ring-fill { stroke: var(--danger); }
.band-none      .score-ring-fill { stroke: var(--border-strong, var(--border)); }

/* --------------------------------------------------------- fleet summary */

.score-summary { margin-top: var(--space-5); }

.fleet-score-card { display: grid; gap: var(--space-5); }
.fleet-score-main { display: flex; gap: var(--space-4); align-items: center; }
.fleet-score-main .score-ring { width: 76px; height: 76px; flex-basis: 76px; }
.fleet-score-main .score-ring-value { font-size: var(--text-lg); }
.fleet-score-main p { margin: var(--space-2) 0 0; max-width: 56ch; }

.fleet-score-band {
  margin: 2px 0 0; font-size: var(--text-xl); line-height: 1.1;
  text-transform: capitalize;
}
.fleet-score-band.band-excellent { color: var(--ok); }
.fleet-score-band.band-good      { color: var(--accent); }
.fleet-score-band.band-fair      { color: var(--warn); }
.fleet-score-band.band-poor      { color: var(--danger); }

/* ------------------------------------------------------------ trend bars */

.score-subhead {
  margin: var(--space-8) 0 var(--space-4);
  font-size: var(--text-sm); font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted);
}
.trend-wrap { display: grid; gap: var(--space-3); }
.trend-chart {
  position: relative;
  display: flex; align-items: flex-end; gap: 3px;
  height: 120px; padding: 0 2px;
  border-bottom: 1px solid var(--border);
}
/* the 2.0 events target line */
.trend-chart::after {
  content: ''; position: absolute; left: 0; right: 0;
  bottom: var(--trend-target, 50%);
  border-top: 1px dashed var(--border-strong, var(--border));
  pointer-events: none;
}
.trend-bar {
  flex: 1 1 0; min-width: 3px;
  background: var(--warn); border-radius: 3px 3px 0 0;
  opacity: .85; transition: opacity .16s var(--ease), transform .16s var(--ease);
}
.trend-bar.is-good { background: var(--ok); }
.trend-bar:hover { opacity: 1; transform: scaleY(1.03); transform-origin: bottom; }
.trend-axis {
  display: flex; justify-content: space-between; gap: var(--space-3);
  font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted);
}
.trend-target { font-family: var(--sans); }

/* --------------------------------------------------------- driver cards */

.driver-grid {
  margin-top: var(--space-5);
  display: grid; gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
}

.driver-card {
  display: grid; gap: var(--space-4);
  padding: var(--space-5);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-md);
  border-left: 3px solid var(--border);
  transition: border-color .16s var(--ease), transform .16s var(--ease);
}
.driver-card:hover { transform: translateY(-1px); }
.driver-card.band-excellent { border-left-color: var(--ok); }
.driver-card.band-good      { border-left-color: var(--accent); }
.driver-card.band-fair      { border-left-color: var(--warn); }
.driver-card.band-poor      { border-left-color: var(--danger); }
.driver-card.is-unscored    { opacity: .8; }

.driver-card-head { display: flex; align-items: center; gap: var(--space-4); }
.driver-identity { flex: 1 1 auto; min-width: 0; }
.driver-identity h3 {
  margin: 0; font-size: var(--text-base); line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.driver-identity p { margin: 2px 0 0; font-size: var(--text-xs); }

.driver-avatar {
  flex: 0 0 38px; width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--surface-3); border: 1px solid var(--border);
  font-size: var(--text-xs); font-weight: 700; letter-spacing: .04em;
  color: var(--text-muted);
}

.driver-card-meta { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

.band-tag, .rate-tag, .delta-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px var(--space-3); border-radius: var(--r-full);
  font-size: var(--text-xs); font-weight: 600;
  border: 1px solid var(--border); background: var(--surface-3);
  color: var(--text-muted);
}
.band-tag { text-transform: capitalize; }
.band-tag.band-excellent { color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.band-tag.band-good      { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.band-tag.band-fair      { color: var(--warn);   border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.band-tag.band-poor      { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.rate-tag { font-family: var(--mono); }
.delta-up   { color: var(--ok); }
.delta-down { color: var(--danger); }

.event-chip-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.event-chip {
  display: inline-flex; align-items: baseline; gap: 5px;
  padding: 3px var(--space-3); border-radius: var(--r-sm);
  font-size: var(--text-xs); font-weight: 500;
  background: var(--surface-3); border: 1px solid var(--border); color: var(--text-muted);
}
.event-chip b { font-family: var(--mono); font-weight: 700; color: var(--text); }
.event-chip i {
  font-style: normal; font-size: 10px; font-weight: 600;
  color: var(--danger); text-transform: uppercase; letter-spacing: .03em;
}
.chip-speeding    { border-color: color-mix(in srgb, var(--danger) 34%, transparent); }
.chip-harsh_brake { border-color: color-mix(in srgb, var(--warn) 34%, transparent); }
.chip-harsh_accel { border-color: color-mix(in srgb, var(--info) 34%, transparent); }
.chip-harsh_corner{ border-color: color-mix(in srgb, var(--accent) 34%, transparent); }
.chip-clean       { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 34%, transparent); }

.driver-card-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-size: var(--text-xs);
}

/* ------------------------------------------------------- mileage claims */

.claim-totals { margin-bottom: var(--space-5); }

.claim-subhead {
  margin: var(--space-6) 0 var(--space-4);
  font-size: var(--text-sm); font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted);
}

.claim-warning {
  margin-bottom: var(--space-4); padding: var(--space-4) var(--space-5);
  border-radius: var(--r); font-size: var(--text-sm);
  background: color-mix(in srgb, var(--warn) 12%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--warn) 34%, transparent);
  color: var(--text);
}
.claim-warning a { color: inherit; }
.claim-warning-soft {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-muted);
}

.claim-driver-row {
  display: grid; gap: var(--space-3);
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.claim-driver-card {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r);
}
.claim-driver-card > div { flex: 1 1 auto; min-width: 0; }
.claim-driver-card b { font-size: var(--text-sm); }
.claim-driver-card p { margin: 1px 0 0; font-size: var(--text-xs); }
.claim-driver-amount { font-size: var(--text-sm); font-weight: 700; color: var(--text); }

.claim-table tfoot td {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-strong, var(--border));
  background: var(--surface-3);
}
.admin-table td.num, .admin-table th.num { text-align: right; }
.rate-missing { color: var(--warn); font-family: var(--sans); font-size: var(--text-xs); }

/* ------------------------------------------------------ advisory rates */

.rate-grid {
  display: grid; gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.rate-field { display: grid; gap: 6px; font-size: var(--text-xs); color: var(--text-muted); }
.rate-input { position: relative; display: block; }
.rate-input input { width: 100%; padding-right: 58px; font-family: var(--mono); }
.rate-input i {
  position: absolute; right: var(--space-3); top: 50%; transform: translateY(-50%);
  font-style: normal; font-size: var(--text-xs); color: var(--text-muted);
  pointer-events: none;
}
.rate-note { margin: var(--space-4) 0; font-size: var(--text-xs); max-width: 70ch; }
.rate-save-note { margin-left: var(--space-3); font-size: var(--text-xs); }

/* ------------------------------------------- skeletons, empty and error */

.score-skeleton { display: grid; gap: var(--space-3); margin-top: var(--space-4); }
.skeleton-row {
  height: 62px; border-radius: var(--r);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: sentra-shimmer 1.4s linear infinite;
}
@keyframes sentra-shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton-row { animation: none; }
  .score-ring-fill { transition: none; }
}

.score-empty {
  display: grid; justify-items: center; gap: var(--space-3);
  padding: var(--space-10) var(--space-5); text-align: center;
  background: var(--surface-2); border: 1px dashed var(--border);
  border-radius: var(--r-md);
}
.score-empty svg { width: 30px; height: 30px; fill: var(--text-muted); opacity: .7; }
.score-empty h3 { margin: 0; font-size: var(--text-base); }
.score-empty p { margin: 0; max-width: 46ch; font-size: var(--text-sm); color: var(--text-muted); }
.score-error { border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.score-error svg { fill: var(--danger); opacity: 1; }

/* ------------------------------------------------------------- narrow */

@media (max-width: 720px) {
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1 1 auto; justify-content: center; }
  .range-presets { width: 100%; justify-content: space-between; }
  .range-preset { flex: 1 1 auto; text-align: center; }
  .fleet-score-main { align-items: flex-start; }
  .driver-grid { grid-template-columns: 1fr; }
  .trend-chart { height: 96px; }
}

/* ==========================================================================
   Fleet ops — compliance & maintenance, share links, scheduled reports
   Consumed by assets/fleet.js. Additive only; no existing rule is changed.
   ========================================================================== */

/* --------------------------------------------------------------- primitives */

.fleet-muted { color: var(--text-muted); }
.fleet-num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums lining-nums;
}
.fleet-sub {
  display: block;
  margin-top: 3px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.fleet-hint {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--text-muted);
  max-width: 64ch;
  line-height: 1.5;
}
.fleet-subhead {
  margin: var(--space-5) 0 var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: .01em;
}
.fleet-plate {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: var(--text-xs);
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.status-pill.status-muted {
  color: var(--text-muted);
  border-color: var(--border);
  background: var(--surface-3);
}

/* --------------------------------------------------------------------- KPIs */

.fleet-kpis {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  margin: var(--space-5) 0;
}
.fleet-kpi {
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  display: grid;
  gap: 4px;
  align-content: start;
  min-width: 0;
}
.fleet-kpi-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 600;
  line-height: 1.3;
}
.fleet-kpi-value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums lining-nums;
  /* Never wrap a figure mid-digit: clamp it down, then ellipsis if it still
     will not fit. "£1,955.00" breaking to "£1,955.0 / 0" is unreadable. */
  font-size: clamp(1.0625rem, .82rem + .6vw, 1.4rem);
  line-height: 1.2;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fleet-kpi-note {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.45;
}
.fleet-kpi.tone-ok    { border-color: color-mix(in srgb, var(--ok) 34%, var(--border)); }
.fleet-kpi.tone-ok    .fleet-kpi-value { color: var(--ok); }
.fleet-kpi.tone-warn  { border-color: color-mix(in srgb, var(--warn) 34%, var(--border)); }
.fleet-kpi.tone-warn  .fleet-kpi-value { color: var(--warn); }
.fleet-kpi.tone-bad   { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.fleet-kpi.tone-bad   .fleet-kpi-value { color: var(--danger); }
.fleet-kpi.tone-info  { border-color: color-mix(in srgb, var(--info) 34%, var(--border)); }
.fleet-kpi.tone-info  .fleet-kpi-value { color: var(--info); }

/* ------------------------------------------------------------------ toolbar */

.fleet-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-2);
  width: fit-content;
  max-width: 100%;
  margin-bottom: var(--space-4);
}

/* -------------------------------------------------------------------- table */

.fleet-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  -webkit-overflow-scrolling: touch;
}
.fleet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  min-width: 620px;
}
.fleet-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: var(--space-3) var(--space-4);
  text-align: left;
  white-space: nowrap;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-3);
  border-bottom: 1px solid var(--border);
}
.fleet-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.fleet-table tbody tr:last-child td { border-bottom: 0; }
.fleet-table tbody tr[data-fleet-vehicle] { cursor: pointer; }
.fleet-table tbody tr[data-fleet-vehicle]:hover { background: var(--surface-3); }
.fleet-table tbody tr[data-fleet-vehicle]:focus-visible {
  outline: 2px solid var(--acc);
  outline-offset: -2px;
}
/* This class lands on a <td>. It must NOT become a grid or flex container:
   that takes the cell out of table layout and the row's horizontal rules stop
   lining up with the other columns. Stack the children with block display. */
.fleet-cell-vehicle {
  min-width: 0;
  line-height: 1.45;
}
.fleet-cell-vehicle > strong {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  overflow-wrap: anywhere;
}
.fleet-cell-vehicle > .fleet-plate { margin-top: 5px; }

/* ------------------------------------------------- skeleton, empty, error */

.fleet-skeleton { display: grid; gap: var(--space-3); }
.fleet-skeleton-row {
  height: 56px;
  border-radius: var(--r);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: sentra-shimmer 1.4s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .fleet-skeleton-row { animation: none; }
}
.fleet-empty {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-5);
  text-align: center;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
}
/* The inline SVG has no width/height attributes, so without an explicit size
   it fills the whole container. */
.fleet-empty > svg {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  color: var(--text-faint);
}
.fleet-empty h3,
.fleet-empty h4 { margin: 0; font-size: var(--text-base); }
.fleet-empty p {
  margin: 0;
  max-width: 46ch;
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: 1.55;
}
.fleet-empty-error {
  border-style: solid;
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}
.fleet-empty-error h3,
.fleet-empty-error h4 { color: var(--danger); }
.fleet-empty-error > svg { color: var(--danger); }

/* -------------------------------------------------------------------- toast */

.fleet-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 3000;
  max-width: min(420px, calc(100vw - 2 * var(--space-4)));
  padding: var(--space-3) var(--space-5);
  border-radius: var(--r-full);
  border: 1px solid var(--border-strong);
  background: var(--surface-hi);
  color: var(--text);
  font-size: var(--text-sm);
  line-height: 1.4;
  box-shadow: var(--shadow-lg);
  animation: fleet-toast-in .22s cubic-bezier(.2, .8, .3, 1);
}
.fleet-toast-ok    { border-color: color-mix(in srgb, var(--ok) 55%, var(--border)); color: var(--ok); }
.fleet-toast-error { border-color: color-mix(in srgb, var(--danger) 55%, var(--border)); color: var(--danger); }
.fleet-toast-warn  { border-color: color-mix(in srgb, var(--warn) 55%, var(--border)); color: var(--warn); }
@keyframes fleet-toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .fleet-toast { animation: none; }
}

/* ------------------------------------------------------------------- drawer */

.fleet-drawer { position: fixed; inset: 0; z-index: 2400; }
.fleet-drawer[hidden] { display: none; }
.fleet-drawer-scrim {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 12, .6);
  backdrop-filter: blur(2px);
  animation: fleet-fade-in .18s ease;
}
.fleet-drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(520px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  animation: fleet-slide-in .24s cubic-bezier(.2, .8, .3, 1);
}
.fleet-drawer-head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  padding: var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.fleet-drawer-head > div { min-width: 0; flex: 1; }
.fleet-drawer-head h3 {
  margin: 0;
  font-size: var(--text-lg);
  overflow-wrap: anywhere;
}
.fleet-drawer-head p {
  margin: 4px 0 0;
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow-wrap: anywhere;
}
.fleet-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
  -webkit-overflow-scrolling: touch;
}
.fleet-drawer-section + .fleet-drawer-section {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
}
body.fleet-drawer-open,
body.fleet-modal-open { overflow: hidden; }

@keyframes fleet-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fleet-slide-in {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes fleet-pop-in {
  from { opacity: 0; transform: translateY(12px) scale(.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .fleet-drawer-scrim, .fleet-drawer-panel,
  .fleet-modal-scrim, .fleet-modal-panel { animation: none; }
}

/* -------------------------------------------------------------------- modal */

.fleet-modal {
  position: fixed;
  inset: 0;
  z-index: 2500;
  display: grid;
  place-items: center;
  padding: var(--space-4);
}
.fleet-modal[hidden] { display: none; }
.fleet-modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 12, .62);
  backdrop-filter: blur(2px);
  animation: fleet-fade-in .18s ease;
}
.fleet-modal-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: min(86vh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: fleet-pop-in .2s cubic-bezier(.2, .8, .3, 1);
  overflow: hidden;
}
.fleet-modal-head {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.fleet-modal-head h3 {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: var(--text-base);
  overflow-wrap: anywhere;
}
.fleet-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
  -webkit-overflow-scrolling: touch;
}

.fleet-icon-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text-muted);
  cursor: pointer;
  transition: color .16s ease, border-color .16s ease, background .16s ease;
}
.fleet-icon-btn svg { width: 16px; height: 16px; }
.fleet-icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-hi); }
.fleet-icon-btn:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }

/* --------------------------------------------------------------------- form */

/* Two columns where there is room, so a Lat/Lng or From/To pair sits on one
   line and the modal does not become a tall scrolling column. */
.fleet-form {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  align-items: end;
}
/* Date-range filter above the costs and checks tables. This is a plain aligned
   row, not the pill group that `.fleet-toolbar` styles. */
.fleet-filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.fleet-filterbar .fleet-field { flex: 0 1 170px; }
.fleet-filterbar > .btn { flex: 0 0 auto; height: fit-content; }

.fleet-form-inline {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  align-items: end;
}
/* a bare button in an inline row sits on the input baseline rather than
   stretching to the height of the whole grid row */
.fleet-form-inline > .btn,
.fleet-form-inline > button { align-self: end; height: fit-content; }
.fleet-field {
  display: grid;
  gap: 6px;
  min-width: 0;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
}
.fleet-field-wide { grid-column: 1 / -1; }
.fleet-field input,
.fleet-field select,
.fleet-field textarea { width: 100%; font-weight: 400; }
/* a 100%-wide checkbox renders as an enormous empty box */
.fleet-field input[type='checkbox'],
.fleet-field input[type='radio'] { width: auto; }
.fleet-field textarea { min-height: 76px; resize: vertical; }
.fleet-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin-top: var(--space-2);
}
.fleet-form-actions .fleet-hint { flex: 1 1 180px; }
.fleet-section-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: baseline;
  justify-content: space-between;
  margin: var(--space-5) 0 var(--space-3);
}
.fleet-section-head h4 { margin: 0; font-size: var(--text-sm); font-weight: 600; }
.fleet-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.fleet-radio,
.fleet-check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease;
}
.fleet-radio:hover,
.fleet-check:hover { border-color: var(--border-strong); background: var(--surface-3); }
.fleet-radio input,
.fleet-check input {
  margin: 2px 0 0;
  width: auto;
  flex: 0 0 auto;
  accent-color: var(--acc);
}
/* long wrapping labels must shrink inside the flex row, not overflow the modal */
.fleet-radio > span,
.fleet-check > span { min-width: 0; overflow-wrap: anywhere; line-height: 1.5; }
.fleet-radio:focus-within,
.fleet-check:focus-within { border-color: var(--acc); }

/* Keep this as a real table: `display:grid` on a <table> collapses the header
   row and stops the three answer columns lining up with their labels. */
.fleet-check-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  font-size: var(--text-sm);
  margin: var(--space-4) 0;
}
.fleet-check-table th,
.fleet-check-table td { padding: var(--space-2) 0; }
.fleet-check-table thead th {
  position: static;
  font-size: var(--text-xs);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: none;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
/* The three answer columns shrink to their labels so the item name takes the
   slack; nowrap stops "Defect" splitting into "Def / ect". */
.fleet-check-table th:not(:first-child),
.fleet-check-table td { width: 1%; white-space: nowrap; }
.fleet-check-table th:first-child,
.fleet-check-table tbody th { width: auto; white-space: normal; }
.fleet-check-table td { padding-left: var(--space-3); }
.fleet-check-table tbody th {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  text-align: left;
}
.fleet-check-table tbody tr + tr th,
.fleet-check-table tbody tr + tr td { border-top: 1px solid var(--border); }
.fleet-check-table .fleet-radio {
  border: 0;
  background: none;
  padding: 0;
  align-items: center;
}
.fleet-check-table .fleet-radio > span { white-space: nowrap; }
.fleet-check-table .fleet-radio input { margin-top: 0; }

/* ------------------------------------------------------------- schedules */

.fleet-schedule-list { display: grid; gap: var(--space-3); }
.fleet-schedule {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.fleet-schedule-main { min-width: 0; flex: 1 1 160px; display: grid; gap: 4px; }
.fleet-schedule-main strong { font-size: var(--text-sm); overflow-wrap: anywhere; }
/* keep the band pill and the delete button on the same line as the name — a
   wide pill like "13,787 mi left" otherwise pushes the button to its own row */
.fleet-schedule > .status-pill,
.fleet-schedule > .fleet-icon-btn,
.fleet-schedule > .fleet-actions { flex: 0 0 auto; }
@media (min-width: 460px) {
  .fleet-schedule { flex-wrap: nowrap; gap: var(--space-3); }
}

/* --------------------------------------------------------- report schedules */

.fleet-report-grid {
  display: grid;
  gap: var(--space-4);
  /* wide enough that Preview / Send now / Pause / Delete stay on one row */
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
}
.fleet-report-card {
  display: grid;
  gap: var(--space-3);
  align-content: start;
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  min-width: 0;
}
.fleet-report-card.is-paused { opacity: .68; }
.fleet-report-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-start;
  justify-content: space-between;
}
.fleet-report-head h4,
.fleet-report-head strong {
  margin: 0;
  flex: 1 1 130px;
  min-width: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.fleet-report-head > .status-pill { flex: 0 0 auto; }
.fleet-report-when {
  font-family: var(--mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.fleet-report-to {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.fleet-report-error {
  font-size: var(--text-xs);
  color: var(--danger);
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.fleet-report-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* Delete is destructive and rarely wanted, so it is an icon pinned to the far
   right rather than a fourth text button that forces the row to wrap. */
.fleet-report-actions .fleet-icon-btn { margin-left: auto; }

.fleet-icon-btn {
  display: inline-grid;
  place-items: center;
  padding: 0;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
}

.fleet-icon-btn svg { display: block; }

/* --------------------------------------------------------- misc utilities */

.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border));
}
.btn-danger-outline:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}
.btn-danger-outline:focus-visible { outline: 2px solid var(--danger); outline-offset: 2px; }

.fleet-copy-fallback {
  width: 100%;
  margin-top: var(--space-3);
  font-family: var(--mono);
  font-size: var(--text-xs);
}
.fleet-preview-frame {
  width: 100%;
  height: min(60vh, 520px);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: #fff;
}

/* The email preview needs far more room than a form, so the panel goes wide
   and the iframe takes every pixel left over after the subject and footer. */
.fleet-modal-panel.is-preview {
  width: min(880px, 100%);
  max-height: min(92vh, 940px);
}
.fleet-modal-panel.is-preview .fleet-modal-body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: var(--space-4) var(--space-5) var(--space-5);
}
.fleet-preview-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  flex: 1;
  min-height: 0;
}
.fleet-modal-panel.is-preview .fleet-preview-frame {
  flex: 1 1 auto;
  height: auto;
  min-height: 260px;
}
.fleet-preview-wrap .fleet-form-actions {
  align-items: center;
  flex: 0 0 auto;
  margin: 0;
}
.fleet-preview-wrap .fleet-hint { margin: 0; }

/* ------------------------------------------------------------------ narrow */

@media (max-width: 720px) {
  .fleet-kpis { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .fleet-kpi-value { font-size: 1.3rem; }
  .fleet-toolbar { width: 100%; }
  .fleet-toolbar .range-preset { flex: 1 1 auto; text-align: center; }
  .fleet-filterbar .fleet-field { flex: 1 1 140px; }
  .fleet-filterbar > .btn { flex: 1 1 100%; }
  .fleet-drawer-panel { width: 100vw; border-left: 0; }
  .fleet-schedule { align-items: flex-start; }
  .fleet-report-grid { grid-template-columns: 1fr; }
}

@media (max-width: 470px) {
  /* Three pills on one line squeezes "Walkaround checks" onto its own centred
     row, so below this width each tab takes the full row. */
  #panel-compliance .fleet-toolbar[role='tablist'] { flex-direction: column; }
  #panel-compliance .fleet-toolbar[role='tablist'] .range-preset { width: 100%; }
  .fleet-report-card .fleet-report-actions { flex-wrap: wrap; }
}


/* Smart Alerts mobile toolbar: rigid date + settings row for iOS/Safari */
@media (max-width: 620px) {
  #panel-alerts .live-toolbar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) 40px !important;
    align-items: end;
    column-gap: 14px !important;
    row-gap: var(--space-3);
    width: 100%;
  }
  #panel-alerts .live-toolbar > label:first-child {
    grid-column: 1 / -1;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
  }
  #panel-alerts .live-toolbar > label:nth-child(2) {
    grid-column: 1;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    overflow: hidden;
  }
  #panel-alerts .live-toolbar > label:nth-child(2) #alertDate {
    box-sizing: border-box;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }
  #panel-alerts .live-toolbar .live-toolbar-actions {
    grid-column: 2;
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    margin: 0 !important;
    padding: 0 !important;
  }
  #panel-alerts .live-toolbar .module-icon-btn {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    margin: 0 !important;
  }
}

@media (max-width: 575.98px) {
  .alert-mode-options { gap: 6px; }
  .alert-mode-options .alert-radio-option { padding: 6px 8px; font-size: 11px; }
}

/* Alert rules: armed/disarmed behaviour control */
.alert-disarmed-option { margin-top: 12px; gap: 8px; justify-content: flex-start; }
.alert-disarmed-option input[type='checkbox'] { flex: 0 0 auto; }
.alert-disarmed-option span { flex: 0 1 auto; }


/* SentraTracker 2026 brand assets ------------------------------------------------ */
.sentratracker-brand {
  align-items: center;
  min-width: 0;
}
.sentratracker-logo-wrap {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}
.sentratracker-logo {
  display: block;
  width: auto;
  height: 35px;
  max-width: 180px;
  object-fit: contain;
  object-position: left center;
}
.sentratracker-logo-light { display: none; }
.sentratracker-logo-dark { display: block; }
[data-theme='light'] .sentratracker-logo-light { display: block; }
[data-theme='light'] .sentratracker-logo-dark { display: none; }
[data-theme='dark'] .sentratracker-logo-light { display: none; }
[data-theme='dark'] .sentratracker-logo-dark { display: block; }
.sentratracker-brand .brand-subtitle {
  margin-top: 1px;
  padding-left: 3px;
}
.login-brand .sentratracker-logo {
  width: auto;
  height: 58px;
  max-width: min(300px, 78vw);
}
.login-brand .brand-subtitle {
  margin-top: 3px;
  padding-left: 5px;
}
@media (max-width: 1100px) {
  .topbar .sentratracker-logo { height: 32px; max-width: 158px; }
}
@media (max-width: 720px) {
  .topbar .sentratracker-logo { height: 28px; max-width: 138px; }
  .topbar .sentratracker-brand .brand-subtitle { display: none; }
  .login-brand .sentratracker-logo { height: 48px; max-width: min(248px, 78vw); }
}
