/* =====================================================================
   MAADI TRANSPORTATION — Design System
   =====================================================================
   Layers:
   1) Design tokens (color / typography / spacing / radius / elevation / motion)
   2) Reset & base
   3) Layout & grid
   4) Topbar & navigation (responsive + accessible)
   5) Buttons & interaction states
   6) Forms & inputs
   7) Tables
   8) Cards, page head & stats
   9) Badges
   10) Alerts, flash & state patterns
   11) Info grid & clean lists
   12) Filters & search
   13) Maps (mini / full / fleet)
   14) Photos & lightbox (accessible dialog)
   15) Tabs
   16) Charts & dashboard bars
   17) Users & roles
   18) Maintenance parts & store
   19) Login
   20) Utilities & helpers
   ===================================================================== */


/* =====================================================================
   1) DESIGN TOKENS
   ===================================================================== */
:root {
  color-scheme: light;

  /* --- Brand (teal) --- */
  --brand-50: #f0fdfa;
  --brand-100: #ccfbf1;
  --brand-200: #99f6e4;
  --brand-300: #5eead4;
  --brand-400: #2dd4bf;
  --brand-500: #14b8a6;
  --brand-600: #0d9488;
  --brand-700: #0f766e;
  --brand-800: #115e59;
  --brand-900: #134e4a;

  /* --- Neutral (slate) --- */
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;

  /* --- Semantic (AA-compliant text + button tones) --- */
  --ok: #15803d;        /* green-700 — white text 5.0:1, on green-100 4.6:1 */
  --ok-soft: #dcfce7;   /* green-100 */
  --ok-border: #86efac;
  --warn: #b45309;      /* amber-700 — on amber-100 4.6:1 */
  --warn-soft: #fef3c7; /* amber-100 */
  --warn-border: #fcd34d;
  --off: #b91c1c;       /* red-700 — white text 5.1:1, on red-100 4.6:1 */
  --off-soft: #fee2e2;  /* red-100 */
  --off-border: #fca5a5;
  --info: #0369a1;      /* sky-700 — on sky-100 4.9:1 */
  --info-soft: #e0f2fe; /* sky-100 */
  --info-border: #7dd3fc;

  /* --- Surfaces & text (AA on both --bg and --surface) --- */
  --bg: var(--gray-100);
  --surface: #ffffff;
  --surface-2: var(--gray-50);
  --surface-3: #eef2f7;
  --border: var(--gray-200);
  --border-strong: var(--gray-300);
  --text: var(--gray-900);
  --text-2: var(--gray-700);
  --muted: #5b6472;     /* ~6:1 on white, ~5.7:1 on --bg */

  /* --- Primary aliases --- */
  --primary: var(--brand-700);
  --primary-hover: var(--brand-800);
  --primary-active: var(--brand-900);
  --primary-soft: var(--brand-100);
  --on-primary: #ffffff;
  --on-ok: #ffffff;
  --on-off: #ffffff;
  --neutral: var(--gray-500);
  --neutral-soft: var(--gray-200);

  /* --- Typography --- */
  --font: "Segoe UI", Tahoma, "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
  --font-mono: Consolas, "Cascadia Mono", "Courier New", monospace;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 15px;
  --text-lg: 17px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-3xl: 28px;
  --leading-tight: 1.3;
  --leading: 1.6;
  --font-regular: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
  --font-extrabold: 800;

  /* --- Spacing (4px base) --- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* --- Radius --- */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 999px;

  /* --- Elevation --- */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 2px 8px rgba(15, 23, 42, .05);
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --shadow-lg: 0 8px 24px rgba(2, 6, 23, .14);
  --shadow-xl: 0 24px 60px rgba(2, 6, 23, .35);

  /* --- Focus ring --- */
  --focus-ring: 0 0 0 3px rgba(15, 118, 110, .35);

  /* --- Motion --- */
  --dur-fast: 120ms;
  --dur: 180ms;
  --ease: cubic-bezier(.2, .7, .3, 1);

  /* --- Breakpoints --- */
  --bp-sm: 640px;
  --bp-md: 768px;
  --bp-lg: 900px;
}

html[data-theme="dark"] {
  color-scheme: dark;

  --bg: var(--gray-900);
  --surface: var(--gray-800);
  --surface-2: #243244;
  --surface-3: #1a2536;
  --border: var(--gray-700);
  --border-strong: var(--gray-600);
  --text: #e6edf7;
  --text-2: var(--gray-300);
  --muted: #9aa8bc;

  --primary: #14b8a6;
  --primary-hover: #2dd4bf;
  --primary-active: #5eead4;
  --primary-soft: #134e4a;
  --on-primary: #0f172a;
  --on-ok: #052e16;
  --on-off: #450a0a;

  --ok: #4ade80;
  --ok-soft: #14532d;
  --ok-border: #15803d;
  --warn: #fbbf24;
  --warn-soft: #78350f;
  --warn-border: #b45309;
  --off: #f87171;
  --off-soft: #7f1d1d;
  --off-border: #b91c1c;
  --info: #7dd3fc;
  --info-soft: #0c4a6e;
  --info-border: #0369a1;

  --neutral: var(--gray-400);
  --neutral-soft: var(--gray-600);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .25);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, .5);
  --shadow-xl: 0 24px 60px rgba(0, 0, 0, .6);

  --focus-ring: 0 0 0 3px rgba(45, 212, 191, .45);
}


/* =====================================================================
   2) RESET & BASE
   ===================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: var(--leading);
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
}

::selection { background: var(--primary-soft); color: var(--primary); }

/* Skip link — visible on focus only */
.skip-link {
  position: absolute;
  inset-inline-start: var(--space-3);
  top: -60px;
  z-index: 2000;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: var(--font-bold);
  padding: var(--space-2) var(--space-4);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  transition: top var(--dur-fast) var(--ease);
}
.skip-link:focus-visible {
  top: 0;
  box-shadow: var(--focus-ring);
  text-decoration: none;
}


/* =====================================================================
   3) LAYOUT & GRID
   ===================================================================== */
.container { max-width: 1180px; margin: 0 auto; padding: var(--space-5) var(--space-4) var(--space-12); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2 .card { margin-bottom: 0; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-3 .card { margin-bottom: 0; }

@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } .grid-3 { grid-template-columns: 1fr; } }


/* =====================================================================
   4) TOPBAR & NAVIGATION
   ===================================================================== */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 900;
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--space-4);
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--primary);
  font-weight: var(--font-extrabold);
  font-size: var(--text-lg);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.nav { display: flex; gap: 4px; flex: 1; }
.nav-link {
  padding: var(--space-2) 14px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: var(--font-semibold);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--primary-soft); color: var(--primary); }
.nav-link:focus-visible { box-shadow: var(--focus-ring); }

.topbar-user { display: flex; align-items: center; gap: var(--space-2); margin-inline-start: auto; }
.user-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
  font-weight: var(--font-bold);
}
.user-chip small { color: var(--muted); font-weight: var(--font-medium); }

/* Mobile nav toggle (hamburger) — hidden ≥ md */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}
.nav-toggle:hover { color: var(--primary); border-color: var(--primary); }
.nav-toggle svg { width: 22px; height: 22px; }
.nav-toggle[aria-expanded="true"] { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.theme-toggle:hover { color: var(--primary); border-color: var(--primary); }
.theme-toggle svg { width: 18px; height: 18px; display: none; }
html[data-theme="dark"] .theme-toggle .ico-moon { display: block; }
html:not([data-theme="dark"]) .theme-toggle .ico-sun { display: block; }

@media (max-width: 767px) {
  .topbar-inner { gap: var(--space-2); padding: 8px var(--space-3); }
  .brand { font-size: var(--text-md); }
  .user-chip { display: none; }
  .nav {
    display: none;
    flex: 1 1 100%;
    order: 5;
    flex-direction: column;
    padding: var(--space-2) 0 var(--space-3);
    border-top: 1px solid var(--border);
    margin-top: var(--space-2);
    gap: 2px;
  }
  .nav.is-open { display: flex; }
  .nav-link { padding: 10px var(--space-3); border-radius: var(--radius-sm); min-height: 44px; display: flex; align-items: center; }
  .nav-toggle { display: inline-flex; order: -1; }
  .topbar-user { margin-inline-start: auto; }
}


/* =====================================================================
   5) BUTTONS & INTERACTION STATES
   ===================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: var(--font-bold);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease), transform .05s var(--ease), box-shadow var(--dur-fast) var(--ease);
  white-space: nowrap;
  line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { box-shadow: var(--focus-ring); outline: none; }

.btn:disabled, .btn[aria-disabled="true"] {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
  filter: saturate(.6);
}
.btn.is-loading { position: relative; pointer-events: none; }
.btn.is-loading > * { visibility: hidden; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px; height: 18px;
  border: 2px solid currentColor;
  border-inline-end-color: transparent;
  border-radius: 50%;
  animation: btn-spin .7s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); color: var(--on-primary); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--neutral-soft); color: var(--text); }
.btn-danger { background: var(--off); color: var(--on-off); }
.btn-danger:hover { filter: brightness(.88); color: var(--on-off); }
.btn-success { background: var(--ok); color: var(--on-ok); }
.btn-success:hover { filter: brightness(.88); color: var(--on-ok); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 11px; min-height: 34px; font-size: var(--text-sm); }
.btn-xs { padding: 3px 9px; min-height: 28px; font-size: var(--text-xs); }
.btn-row { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }

/* Loading skeleton for async content */
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: skeleton-load 1.4s ease infinite;
  color: transparent;
  user-select: none;
}
@keyframes skeleton-load {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}


/* =====================================================================
   6) FORMS & INPUTS
   ===================================================================== */
.input, select.input, textarea.input {
  font-family: inherit;
  font-size: var(--text-base);
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input:focus, select.input:focus, textarea.input:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
.input-sm { padding: 5px 9px; font-size: var(--text-sm); border-radius: 6px; }
.input::placeholder { color: var(--muted); opacity: .85; }
.input:disabled, select.input:disabled, textarea.input:disabled { opacity: .6; cursor: not-allowed; background: var(--surface-2); }

.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field span { font-size: var(--text-sm); font-weight: var(--font-bold); color: var(--muted); }
.field input, .field textarea, .field select {
  font-family: inherit;
  font-size: var(--text-base);
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
.field input:disabled, .field select:disabled { opacity: .6; background: var(--surface-2); cursor: not-allowed; }
.field input[readonly] { background: var(--surface-2); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3) 18px; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }
.form-grid .field.span-2 { grid-column: span 2; }
@media (max-width: 720px) { .form-grid .field.span-2 { grid-column: span 1; } }
.form-actions { margin-top: var(--space-4); }
.edit-form h2.card-title { margin-top: 6px; }

.radio-inline, .check-inline {
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; font-size: var(--text-sm); white-space: nowrap;
}
.radio-inline input, .check-inline input { margin: 0; accent-color: var(--primary); }
.check-item { display: flex; align-items: center; gap: 6px; font-size: var(--text-base); cursor: pointer; }
.check-item input { accent-color: var(--primary); width: 17px; height: 17px; }
.check-row { display: flex; flex-wrap: wrap; gap: var(--space-2) 14px; padding: var(--space-2) 0; }

/* Site picker autocomplete */
.site-pick { position: relative; }
.suggest-box {
  position: absolute;
  top: calc(100% + 4px);
  inset-inline-start: 0;
  inset-inline-end: 0;
  z-index: 700;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}
.suggest-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 9px var(--space-3);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  font: inherit;
  font-size: var(--text-sm);
  color: var(--text);
  cursor: pointer;
  text-align: start;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover, .suggest-item:focus-visible { background: var(--primary-soft); outline: none; }
.suggest-item strong { font-weight: var(--font-bold); }
.suggest-item span { color: var(--muted); font-size: var(--text-xs); }


/* =====================================================================
   7) TABLES
   ===================================================================== */
.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
.table-wrap { overflow-x: auto; }

.table, .ops-table {
  width: 100%;
  border-collapse: collapse;
}
.table th, .table td, .ops-table th, .ops-table td {
  padding: 10px 14px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
.table th, .ops-table th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--text-sm);
  white-space: nowrap;
  font-weight: var(--font-bold);
}
.table tbody tr:hover, .ops-table tbody tr:hover { background: var(--surface-2); }
.cell-main { font-weight: var(--font-bold); }
.row-link { cursor: pointer; }
.nowrap { white-space: nowrap; }

.trip-id {
  direction: ltr;
  display: inline-block;
  font-variant-numeric: tabular-nums;
  font-weight: var(--font-bold);
  font-size: var(--text-sm);
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 6px;
  padding: 1px 8px;
  white-space: nowrap;
}
.trip-id:hover { text-decoration: none; background: var(--primary); color: var(--on-primary); }

.totals-row td { font-weight: var(--font-extrabold); background: var(--surface-2); border-top: 2px solid var(--border-strong); }

.pager { display: flex; align-items: center; gap: 10px; justify-content: center; margin-top: var(--space-4); }
.pager-info { color: var(--muted); font-size: var(--text-base); }

/* Mobile card-style tables */
@media (max-width: 640px) {
  .ops-table thead { display: none; }
  .ops-table, .ops-table tbody, .ops-table tr, .ops-table td { display: block; width: 100%; }
  .ops-table tr { border-bottom: 1px solid var(--border); padding: 10px 6px; }
  .ops-table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    padding: 7px 4px;
    border: none;
  }
  .ops-table td::before { content: attr(data-label); color: var(--muted); font-size: var(--text-xs); font-weight: var(--font-bold); flex-shrink: 0; }
  .ops-table td.empty { display: block; text-align: center; }
  .ops-table .truncate { max-width: 56vw; }
}


/* =====================================================================
   8) CARDS, PAGE HEAD & STATS
   ===================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card-title { margin: 0 0 14px; font-size: var(--text-lg); font-weight: var(--font-extrabold); color: var(--text); }
.card-title.sub { font-size: var(--text-base); margin-top: var(--space-4); }
.section-card { display: flex; flex-direction: column; gap: var(--space-2); }
.section-card h3 { margin: 0; font-size: var(--text-lg); }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head h1 { margin: 2px 0 2px; font-size: var(--text-2xl); line-height: var(--leading-tight); }
.back-link { display: inline-block; margin-bottom: 4px; font-size: var(--text-sm); color: var(--muted); }
.back-link:hover { color: var(--primary); }

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-3);
  margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: var(--shadow);
}
.stat-num { font-size: 26px; font-weight: var(--font-extrabold); color: var(--primary); font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: var(--text-sm); }
.stat-link { text-decoration: none; transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
.stat-link:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); transform: translateY(-1px); text-decoration: none; }
.stat-link .stat-num { color: var(--primary); }


/* =====================================================================
   9) BADGES
   ===================================================================== */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  line-height: 1.6;
  white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-off { background: var(--off-soft); color: var(--off); }
.badge-neutral { background: var(--neutral-soft); color: var(--muted); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: var(--neutral-soft); color: var(--muted); }
.badge-danger { background: var(--off); color: var(--on-off); }
.badge-late { background: var(--off); color: var(--on-off); }
.badge-danger:hover, .badge-late:hover { text-decoration: none; }


/* =====================================================================
   10) ALERTS, FLASH & STATE PATTERNS
   ===================================================================== */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-weight: var(--font-semibold); }
.alert-error { background: var(--off-soft); color: var(--off); border: 1px solid var(--off-border); }
.alert-info { background: var(--neutral-soft); color: var(--text); border: 1px solid var(--border); }
.alert-ok { background: var(--ok-soft); color: var(--ok); border: 1px solid var(--ok-border); }
.alert-warn { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-border); }
.alert-warn ul, .avail-warn ul { margin: 6px 0 0; padding-inline-start: 20px; font-weight: var(--font-medium); }
.alert-warn li, .avail-warn li { margin: 3px 0; }

.flash {
  max-width: 1180px;
  margin: var(--space-3) auto 0;
  padding: 10px var(--space-4);
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid var(--ok-border);
  border-radius: var(--radius);
  font-weight: var(--font-bold);
}

/* State pattern: empty */
.empty { color: var(--muted); text-align: center; padding: 26px; }
.empty-icon { font-size: 2rem; display: block; margin-bottom: var(--space-2); opacity: .7; }

/* State pattern: loading row / message */
.is-loading-row { opacity: .6; }

/* State pattern: inline error text */
.text-danger { color: var(--off); font-weight: var(--font-semibold); }
.text-warn { color: var(--warn); font-weight: var(--font-semibold); }
.text-ok { color: var(--ok); font-weight: var(--font-semibold); }


/* =====================================================================
   11) INFO GRID & CLEAN LISTS
   ===================================================================== */
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; }
@media (max-width: 720px) { .info-grid { grid-template-columns: 1fr; } }
.info-item { border-bottom: 1px dashed var(--border); padding-bottom: 8px; }
.info-item dt { color: var(--muted); font-size: var(--text-xs); font-weight: var(--font-bold); }
.info-item dd { margin: 2px 0 0; font-size: var(--text-base); }

.clean-list { list-style: none; margin: 0; padding: 0; }
.clean-list li {
  padding: var(--space-2) 0;
  border-bottom: 1px dashed var(--border);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.clean-list li:last-child { border-bottom: none; }
.overdue-item { background: var(--off-soft); border-radius: var(--radius-sm); padding: var(--space-2) 10px !important; margin: var(--space-1) 0; }

.alerts-list { display: flex; flex-direction: column; gap: 6px; }
.alert-row {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  background: var(--off-soft);
  border: 1px solid var(--off-border);
  color: var(--text);
}
.alert-row small { display: block; color: var(--muted); margin-top: 2px; }


/* =====================================================================
   12) FILTERS & SEARCH
   ===================================================================== */
.filter-bar { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); align-items: center; }
.filter-bar .input { flex: 1; min-width: 200px; }
.filter-bar input, .filter-bar select {
  flex: 1;
  min-width: 180px;
  font-family: inherit;
  font-size: var(--text-base);
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--primary); box-shadow: var(--focus-ring); }


/* =====================================================================
   13) MAPS
   ===================================================================== */
.mini-map { height: 320px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.map-actions { display: flex; gap: var(--space-2); margin-top: 10px; flex-wrap: wrap; }
.fullmap-wrap { position: relative; height: calc(100vh - 58px); }
.full-map { position: absolute; inset: 0; }
.map-overlay {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 500;
  width: 300px;
  padding: var(--space-3);
  margin: 0;
  box-shadow: var(--shadow-lg);
}
.map-overlay .input { width: 100%; }
.map-stats { margin-top: var(--space-2); font-size: var(--text-xs); color: var(--muted); }
@media (max-width: 640px) { .map-overlay { right: var(--space-2); left: var(--space-2); width: auto; } }

/* Fleet live */
.fleet-wrap { position: relative; height: 320px; margin-bottom: 1.25rem; }
.fleet-wrap .full-map { position: absolute; inset: 0; border-radius: var(--radius); }
.fleet-summary { top: 12px; right: 12px; width: auto; max-width: 420px; }
.fleet-summary .stats-row { grid-template-columns: repeat(4, 1fr); gap: var(--space-2); }
.fleet-summary .stat-card { padding: 6px 8px; }
.fleet-summary .stat-label { font-size: 11px; }
@media (max-width: 640px) {
  .fleet-wrap { height: 260px; }
  .fleet-summary { top: var(--space-2); right: var(--space-2); left: var(--space-2); width: auto; max-width: none; }
  .fleet-summary .stats-row { grid-template-columns: repeat(2, 1fr); }
  .fleet-label { display: none; }
}
.fleet-dot {
  position: relative;
  display: block;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--neutral);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.fleet-dot.moving { background: var(--ok); }
.fleet-dot.idle { background: var(--gray-400); }
.fleet-dot.stale { background: var(--warn); border-style: dashed; }
.fleet-dot.over { background: var(--off); animation: fleet-pulse 1.2s infinite; }
.fleet-label {
  position: absolute;
  top: 50%;
  right: 18px;
  transform: translateY(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 11px;
  font-style: normal;
  white-space: nowrap;
  color: var(--text);
  box-shadow: var(--shadow-xs);
}
@keyframes fleet-pulse {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .5); }
  70% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

.leaflet-container { font-family: var(--font); }


/* =====================================================================
   14) PHOTOS & LIGHTBOX
   ===================================================================== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.photo-thumb {
  display: block;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--gray-900);
  aspect-ratio: 4 / 3;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.admin-photo { position: relative; margin: 0; cursor: pointer; aspect-ratio: auto; overflow: visible; }
.admin-photo img { height: auto; aspect-ratio: 4 / 3; }
.admin-photo figcaption { padding: 6px 8px; font-size: var(--text-xs); word-break: break-all; background: var(--surface-2); }
.admin-photo figcaption small { color: var(--muted); }
.admin-photo form { padding: 0 8px 8px; }

.photo-toolbar { display: flex; align-items: center; gap: 14px; padding: 0 0 var(--space-3); flex-wrap: wrap; }
.photo-check-all { font-weight: var(--font-bold); color: var(--text); }

.photo-check {
  position: absolute;
  top: var(--space-2);
  inset-inline-start: var(--space-2);
  z-index: 3;
  background: rgba(15, 23, 42, .55);
  border-radius: 6px;
  padding: 2px;
  display: inline-flex;
}
.photo-check input { display: none; }
.photo-check span {
  width: 20px; height: 20px;
  border: 2px solid var(--gray-200);
  border-radius: 5px;
  display: block;
  background: rgba(255, 255, 255, .15);
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.photo-check input:checked + span { background: var(--primary); border-color: var(--primary); position: relative; }
.photo-check input:checked + span::after {
  content: '✓';
  color: var(--on-primary);
  font-size: var(--text-base);
  font-weight: var(--font-bold);
  position: absolute;
  inset: -2px 0 0 0;
  text-align: center;
  line-height: 20px;
}

.photo-actions { display: flex; flex-wrap: wrap; gap: var(--space-1); padding: 0 8px 8px; }
.photo-actions form { padding: 0; margin: 0; }

.edit-thumbs { display: flex; gap: 6px; align-items: center; }
.edit-thumbs img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

/* Accessible lightbox (dialog) */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, .94);
  z-index: 1200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}
.lightbox.is-open { display: flex; }
.lightbox-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
}
.lightbox-figure img {
  max-width: 100%;
  max-height: 82vh;
  border-radius: 10px;
  box-shadow: var(--shadow-xl);
}
.lightbox-cap {
  color: var(--gray-300);
  margin-top: 14px;
  font-size: var(--text-base);
  word-break: break-all;
  text-align: center;
  max-width: 92vw;
}
.lightbox-close {
  position: absolute;
  top: 14px;
  right: 20px;
  width: 44px; height: 44px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 50%;
  color: #e2e8f0;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  z-index: 2;
  transition: background var(--dur-fast) var(--ease);
}
.lightbox-close:hover { background: rgba(255, 255, 255, .2); }
.lightbox-close:focus-visible { box-shadow: var(--focus-ring); outline: none; }
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px; height: 68px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: var(--radius);
  color: #e2e8f0;
  font-size: 34px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-fast) var(--ease);
}
.lightbox-nav:hover { background: rgba(255, 255, 255, .2); }
.lightbox-nav:disabled { opacity: .25; cursor: default; }
.lightbox-nav:focus-visible { box-shadow: var(--focus-ring); outline: none; }
.lb-prev { left: 14px; }
.lb-next { right: 14px; }
.lightbox-counter {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, .45);
  color: #e2e8f0;
  font-size: var(--text-sm);
  padding: 4px 14px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  z-index: 2;
}
@media (max-width: 720px) {
  .lightbox-nav { width: 40px; height: 56px; font-size: 28px; }
  .lb-prev { left: 6px; }
  .lb-next { right: 6px; }
  .lightbox-close { top: 10px; right: 14px; width: 40px; height: 40px; }
  .lightbox-figure img { max-height: 74vh; }
}


/* =====================================================================
   15) TABS
   ===================================================================== */
.tabs { display: flex; gap: var(--space-2); margin-bottom: var(--space-4); flex-wrap: wrap; }
.tab {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--text-base);
  transition: all var(--dur-fast) var(--ease);
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab-active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.tab-active:hover { background: var(--primary-hover); color: var(--on-primary); text-decoration: none; }


/* =====================================================================
   16) CHARTS & DASHBOARD BARS
   ===================================================================== */
.chart { display: grid; gap: 6px; margin-top: var(--space-2); }
.chart-row { display: grid; grid-template-columns: 52px 1fr 96px; align-items: center; gap: 10px; }
.chart-label { font-size: var(--text-xs); color: var(--muted); white-space: nowrap; }
.chart-track { height: 18px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.chart-bar { height: 100%; background: var(--primary); border-radius: 6px; min-width: 3px; transition: width var(--dur) var(--ease); }
.chart-bar.neg { background: var(--off); }
.chart-val { font-size: var(--text-sm); font-weight: var(--font-bold); text-align: left; white-space: nowrap; }
.chart-val.neg { color: var(--off); }
@media (max-width: 600px) {
  .chart-row { grid-template-columns: 46px 1fr 80px; gap: 6px; }
  .chart-val { font-size: var(--text-xs); }
}

.mini-bars { display: flex; flex-direction: column; gap: var(--space-2); }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { width: 90px; font-size: var(--text-sm); font-weight: var(--font-semibold); }
.bar-track { flex: 1; background: var(--surface-2); border-radius: var(--radius-full); height: 10px; overflow: hidden; }
.bar-fill { background: var(--primary); height: 100%; border-radius: var(--radius-full); transition: width var(--dur) var(--ease); }
.bar-val { width: 60px; text-align: left; font-size: var(--text-sm); color: var(--muted); font-variant-numeric: tabular-nums; }


/* =====================================================================
   17) USERS & ROLES
   ===================================================================== */
.inline-details summary { cursor: pointer; color: var(--primary); font-size: var(--text-sm); font-weight: var(--font-bold); }
.inline-form { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: flex-end; margin-top: var(--space-2); }

.user-cell { display: flex; align-items: center; gap: var(--space-2); }
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}
.edit-user-form {
  display: block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-top: 10px;
}
.edit-user-form .form-grid { grid-template-columns: 1fr 1fr; }
@media (max-width: 720px) { .edit-user-form .form-grid { grid-template-columns: 1fr; } }

.edit-select { accent-color: var(--primary); width: 17px; height: 17px; cursor: pointer; }


/* =====================================================================
   18) MAINTENANCE PARTS & STORE
   ===================================================================== */
.part-row {
  display: grid;
  grid-template-columns: 1fr 90px 110px 70px 34px;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-2);
}
@media (max-width: 720px) { .part-row { grid-template-columns: 1fr 70px; } }
.part-row input { width: 100%; }
.p-name { font-weight: var(--font-medium); }
.p-qty, .p-cost { text-align: left; font-variant-numeric: tabular-nums; }
.p-del { justify-self: center; }
.p-total { text-align: left; font-weight: var(--font-bold); }

.low-stock-row { background: var(--off-soft); }
.mat-item-line { font-size: var(--text-sm); padding: 1px 0; }

/* Worker picker (select + add + chips) */
.worker-pick { display: flex; gap: var(--space-2); align-items: center; }
.worker-pick select { flex: 1; min-width: 0; }
.worker-pick .btn { white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius-full);
  padding: 4px 10px 4px 4px;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
}
.chip-label { line-height: 1.5; }
.chip-x {
  width: 22px; height: 22px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--primary);
  font-size: var(--text-md);
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.chip-x:hover { background: var(--off); color: var(--on-off); }
.chip-x:focus-visible { box-shadow: var(--focus-ring); outline: none; }
@media (max-width: 480px) { .worker-pick { flex-direction: column; align-items: stretch; } }


/* =====================================================================
   19) LOGIN
   ===================================================================== */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, var(--brand-700) 0%, var(--brand-900) 60%, var(--gray-900) 100%);
}
.login-wrap { width: 100%; max-width: 400px; padding: var(--space-5); }
.login-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 34px 30px;
  box-shadow: var(--shadow-xl);
}
.login-logo { color: var(--primary); display: flex; justify-content: center; margin-bottom: 6px; }
.login-card h1 { margin: 0 0 2px; font-size: var(--text-2xl); text-align: center; }
.login-sub { color: var(--muted); text-align: center; margin: 0 0 var(--space-5); }


/* =====================================================================
   20) UTILITIES & HELPERS
   ===================================================================== */
.muted { color: var(--muted); }
.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.gps-link { direction: ltr; display: inline-block; font-variant-numeric: tabular-nums; }
.gps-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  color: var(--primary);
  margin-inline-start: 5px;
}
.gps-badge svg { display: block; }

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.w-full { width: 100%; }
.text-center { text-align: center; }
.text-end { text-align: end; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
