/* ═══════════════════════════════════════════
   BASE & DESIGN TOKENS
   ═══════════════════════════════════════════ */
:root, [data-theme="light"] {
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.9rem  + 0.5vw,  1.125rem);
  --text-lg:   clamp(1.125rem, 0.95rem + 0.85vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1rem    + 1.5vw,  2.25rem);
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --shadow-sm: 0 1px 2px oklch(0.2 0.01 80 / 0.06);
  --shadow-md: 0 4px 12px oklch(0.2 0.01 80 / 0.08);
  --shadow-lg: 0 12px 32px oklch(0.2 0.01 80 / 0.12);

  /* Surfaces */
  --color-bg: #f7f6f2;
  --color-surface: #f9f8f5;
  --color-surface-2: #fbfbf9;
  --color-surface-offset: #f3f0ec;
  --color-surface-offset-2: #edeae5;
  --color-surface-dynamic: #e6e4df;
  --color-divider: #dcd9d5;
  --color-border: #d4d1ca;

  /* Text */
  --color-tx: #28251d;
  --color-tx-muted: #7a7974;
  --color-tx-faint: #bab9b4;
  --color-tx-inverse: #f9f8f4;

  /* Primary (Hydra Teal) */
  --color-primary: #01696f;
  --color-primary-hover: #0c4e54;
  --color-primary-active: #0f3638;
  --color-primary-hl: #cedcd8;

  /* Semantic */
  --color-error: #a12c7b;
  --color-error-hl: #e0ced7;
  --color-success: #437a22;
  --color-success-hl: #d4dfcc;
  --color-warning: #964219;
  --color-warning-hl: #ddcfc6;
  --color-blue: #006494;
  --color-blue-hl: #c6d8e4;
  --color-orange: #da7101;
  --color-orange-hl: #e7d7c4;
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  text-size-adjust: none;
  -webkit-text-size-adjust: none;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--color-tx);
  background: var(--color-bg);
  line-height: 1.5;
}

/* Dark mode */
[data-theme="dark"] {
  --color-bg: #171614;
  --color-surface: #1c1b19;
  --color-surface-2: #201f1d;
  --color-surface-offset: #1d1c1a;
  --color-surface-offset-2: #22211f;
  --color-surface-dynamic: #2d2c2a;
  --color-divider: #262523;
  --color-border: #393836;
  --color-tx: #cdccca;
  --color-tx-muted: #797876;
  --color-tx-faint: #5a5957;
  --color-tx-inverse: #2b2a28;
  --color-primary: #4f98a3;
  --color-primary-hover: #227f8b;
  --color-primary-active: #1a626b;
  --color-primary-hl: #313b3b;
  --color-error: #d163a7;
  --color-error-hl: #4c3d46;
  --color-success: #6daa45;
  --color-success-hl: #3a4435;
  --color-warning: #bb653b;
  --color-warning-hl: #564942;
  --color-blue: #5591c7;
  --color-blue-hl: #3a4550;
  --color-orange: #fdab43;
  --color-orange-hl: #564b3e;
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.2);
  --shadow-md: 0 4px 12px oklch(0 0 0 / 0.3);
  --shadow-lg: 0 12px 32px oklch(0 0 0 / 0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #171614;
    --color-surface: #1c1b19;
    --color-surface-2: #201f1d;
    --color-surface-offset: #1d1c1a;
    --color-surface-offset-2: #22211f;
    --color-surface-dynamic: #2d2c2a;
    --color-divider: #262523;
    --color-border: #393836;
    --color-tx: #cdccca;
    --color-tx-muted: #797876;
    --color-tx-faint: #5a5957;
    --color-tx-inverse: #2b2a28;
    --color-primary: #4f98a3;
    --color-primary-hover: #227f8b;
    --color-primary-active: #1a626b;
    --color-primary-hl: #313b3b;
    --color-error: #d163a7;
    --color-error-hl: #4c3d46;
    --color-success: #6daa45;
    --color-success-hl: #3a4435;
    --color-warning: #bb653b;
    --color-warning-hl: #564942;
    --color-blue: #5591c7;
    --color-blue-hl: #3a4550;
    --color-orange: #fdab43;
    --color-orange-hl: #564b3e;
    --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.2);
    --shadow-md: 0 4px 12px oklch(0 0 0 / 0.3);
    --shadow-lg: 0 12px 32px oklch(0 0 0 / 0.4);
  }
}

/* Tabular nums for all data */
.tabular-nums { font-variant-numeric: tabular-nums lining-nums; }

/* Focus visible */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

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

button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
table { border-collapse: collapse; width: 100%; }

/* Screen reader only */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ═══════════════════════════════════════════
   LAYOUT — DASHBOARD SHELL
   ═══════════════════════════════════════════ */
html, body { height: 100%; overflow: hidden; margin: 0; }

#app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 56px 1fr;
  height: 100dvh;
  background: var(--color-bg);
}

#app-shell.sidebar-collapsed {
  grid-template-columns: 64px 1fr;
}

/* Sidebar */
#sidebar {
  grid-row: 1 / -1;
  grid-column: 1;
  background: var(--color-surface);
  border-right: 1px solid var(--color-divider);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  transition: width var(--transition-interactive);
  z-index: 30;
}

/* Header */
#top-header {
  grid-column: 2;
  grid-row: 1;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 0.75rem;
  z-index: 20;
}

/* Main content */
#main-content {
  grid-column: 2;
  grid-row: 2;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.5rem;
  background: var(--color-bg);
}

/* Mobile responsive */
@media (max-width: 768px) {
  #app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr 56px;
  }
  #sidebar {
    grid-row: 3;
    grid-column: 1;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--color-divider);
    overflow-x: auto;
    overflow-y: hidden;
    justify-content: space-around;
    padding: 0 0.25rem;
  }
  #sidebar .sidebar-brand,
  #sidebar .sidebar-footer,
  #sidebar .nav-label { display: none; }
  #sidebar nav { display: flex; flex-direction: row; gap: 0; width: 100%; justify-content: space-around; }
  #sidebar nav a { flex-direction: column; padding: 0.5rem; font-size: 0.65rem; gap: 0.125rem; min-width: 44px; min-height: 44px; justify-content: center; align-items: center; }
  #sidebar nav a svg { width: 20px; height: 20px; }
  #top-header { grid-column: 1; }
  #main-content { grid-column: 1; padding: 1rem; }
}

/* Sidebar link styles */
#sidebar nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-tx-muted);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all var(--transition-interactive);
  min-height: 44px;
}
#sidebar nav a:hover { background: var(--color-surface-offset); color: var(--color-tx); }
#sidebar nav a.active { background: var(--color-primary-hl); color: var(--color-primary); }
#sidebar nav a svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-collapsed #sidebar nav a .nav-label { display: none; }
.sidebar-collapsed #sidebar nav a { justify-content: center; padding: 0.5rem; }
.sidebar-collapsed #sidebar .sidebar-brand span { display: none; }
.sidebar-collapsed #sidebar .sidebar-brand { justify-content: center; }

/* Nav group (Admin Inputs collapsible) */
.nav-group { margin: 0.25rem 0; }
.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-tx-muted);
  border-radius: var(--radius-md);
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-interactive);
  min-height: 44px;
  background: none;
  border: none;
}
.nav-group-toggle:hover { background: var(--color-surface-offset); color: var(--color-tx); }
.nav-group-toggle svg:first-child { width: 18px; height: 18px; flex-shrink: 0; }
.nav-group-arrow {
  margin-left: auto;
  flex-shrink: 0;
  transition: transform 0.2s ease;
  opacity: 0.5;
}
.nav-group.open .nav-group-arrow { transform: rotate(180deg); }
.nav-group-items {
  display: none;
  padding-left: 0.75rem;
}
.nav-group.open .nav-group-items { display: block; }
.nav-group-items a { font-size: var(--text-xs); min-height: 38px; padding: 0.375rem 1rem; }
.sidebar-collapsed .nav-group-toggle .nav-label,
.sidebar-collapsed .nav-group-arrow { display: none; }
.sidebar-collapsed .nav-group-toggle { justify-content: center; padding: 0.5rem; }
.sidebar-collapsed .nav-group-items { padding-left: 0; }
.sidebar-collapsed .nav-group-items a .nav-label { display: none; }
.sidebar-collapsed .nav-group-items a { justify-content: center; padding: 0.5rem; }

/* ═══════════════════════════════════════════
   COMPONENTS
   ═══════════════════════════════════════════ */

/* KPI Card */
.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: box-shadow var(--transition-interactive);
}
.kpi-card:hover { box-shadow: var(--shadow-md); }
.kpi-card .kpi-label { font-size: var(--text-xs); color: var(--color-tx-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-card .kpi-value { font-size: var(--text-xl); font-weight: 700; margin-top: 0.5rem; }
.kpi-card .kpi-delta { font-size: var(--text-xs); font-weight: 500; margin-top: 0.25rem; display: flex; align-items: center; gap: 0.25rem; }
.kpi-delta.up { color: var(--color-success); }
.kpi-delta.down { color: var(--color-error); }

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  font-size: var(--text-xs);
  font-weight: 500;
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.badge-delivered, .badge-active { background: var(--color-success-hl); color: var(--color-success); }
.badge-transit, .badge-dispatched { background: var(--color-orange-hl); color: var(--color-orange); }
.badge-ordered { background: #f0e6ff; color: #7c3aed; }
.badge-pending { background: var(--color-surface-dynamic); color: var(--color-tx-muted); }
.badge-scheduled { background: var(--color-blue-hl); color: var(--color-blue); }
.badge-in-route { background: #dbeafe; color: #2563eb; }
.badge-cancelled, .badge-inactive { background: var(--color-error-hl); color: var(--color-error); }
.badge-blue { background: var(--color-blue-hl); color: var(--color-blue); }

/* Data Table */
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table thead { position: sticky; top: 0; z-index: 1; }
.data-table th {
  text-align: left;
  padding: 0.625rem 0.75rem;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-tx-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--color-surface-offset);
  border-bottom: 1px solid var(--color-divider);
}
.data-table td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--color-divider);
  color: var(--color-tx);
}
.data-table tbody tr { transition: background var(--transition-interactive); }
.data-table tbody tr:hover { background: var(--color-surface-offset); }

/* Button */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: all var(--transition-interactive);
  min-height: 44px;
  cursor: pointer;
  border: none;
}
.btn-primary { background: var(--color-primary); color: var(--color-tx-inverse); }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: var(--color-surface-offset); color: var(--color-tx); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: var(--color-surface-dynamic); }
.btn-ghost { background: transparent; color: var(--color-tx-muted); }
.btn-ghost:hover { background: var(--color-surface-offset); color: var(--color-tx); }
.btn-sm { padding: 0.25rem 0.625rem; min-height: 32px; font-size: var(--text-xs); }

/* Input */
.input-field {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-tx);
  transition: border-color var(--transition-interactive);
  min-height: 44px;
}
.input-field:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-hl); }
.input-field::placeholder { color: var(--color-tx-faint); }

/* Select */
.select-field {
  appearance: none;
  width: 100%;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  background: var(--color-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237a7974' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 0.75rem center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-tx);
  min-height: 44px;
  cursor: pointer;
}

/* Modal overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 0.4);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-interactive);
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal-panel {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: contain;
  transform: scale(0.95) translateY(8px);
  transition: transform var(--transition-interactive);
}
.modal-body {
  overflow-y: auto;
  flex: 1 1 auto;
}
.modal-overlay.active .modal-panel { transform: scale(1) translateY(0); }

/* Sheet (slide-in from right) */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 0.4);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-interactive);
}
.sheet-overlay.active { opacity: 1; pointer-events: auto; }
.sheet-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 420px;
  max-width: 90vw;
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translateX(100%);
  transition: transform var(--transition-interactive);
  z-index: 51;
}
.sheet-overlay.active .sheet-panel { transform: translateX(0); }

/* Chart container */
.chart-box {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}
.chart-box h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-tx);
  margin-bottom: 1rem;
}

/* Driver card */
.driver-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: all var(--transition-interactive);
}
.driver-card:hover { box-shadow: var(--shadow-md); border-color: var(--color-primary-hl); }

/* Tabs */
.tab-list {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-divider);
  margin-bottom: 1.5rem;
}
.tab-btn {
  padding: 0.75rem 1rem;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-tx-muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-interactive);
  min-height: 44px;
}
.tab-btn:hover { color: var(--color-tx); }
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* Reports & Settings panel visibility */
.reports-panel { display: block; }
.settings-panel { display: block; }
.locations-panel { display: block; }

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--color-surface-offset) 25%, var(--color-surface-dynamic) 50%, var(--color-surface-offset) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Search overlay (Cmd+K) */
.search-overlay {
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 0.4);
  z-index: 60;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20vh;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-interactive);
}
.search-overlay.active { opacity: 1; pointer-events: auto; }
.search-box {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  overflow: hidden;
  transform: scale(0.95) translateY(-8px);
  transition: transform var(--transition-interactive);
}
.search-overlay.active .search-box { transform: scale(1) translateY(0); }

/* Page transitions */
.view { display: none; }
.view.active { display: block; animation: fadeIn 200ms cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Avatar */
.avatar {
  width: 32px; height: 32px;
  border-radius: var(--radius-full);
  background: var(--color-primary-hl);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs); font-weight: 600; color: var(--color-primary);
  flex-shrink: 0;
}
.avatar-lg { width: 48px; height: 48px; font-size: var(--text-sm); }

/* Integration card */
.integration-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Notification dot */
.notif-dot {
  width: 8px; height: 8px;
  background: var(--color-error);
  border-radius: var(--radius-full);
  position: absolute; top: 4px; right: 4px;
}

/* Footer */
.app-footer {
  font-size: var(--text-xs);
  color: var(--color-tx-faint);
  text-align: center;
  padding: 1.5rem 0 0.5rem;
}
.app-footer a {
  color: var(--color-tx-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.app-footer a:hover { color: var(--color-primary); }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  justify-content: center;
  padding: 1rem 0 0;
}
.page-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-tx-muted);
  transition: all var(--transition-interactive);
  cursor: pointer;
  min-width: 44px; min-height: 44px;
}
.page-btn:hover { background: var(--color-surface-offset); color: var(--color-tx); }
.page-btn.active { background: var(--color-primary); color: var(--color-tx-inverse); }

/* Login page */
#login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  padding: 1rem;
}

/* Status dot */
.status-dot {
  width: 8px; height: 8px;
  border-radius: var(--radius-full);
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.available { background: var(--color-success); }
.status-dot.on-route { background: var(--color-orange); }
.status-dot.off-duty { background: var(--color-tx-faint); }

/* User menu dropdown */
.user-menu {
  position: relative;
}
.user-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  padding: 0.25rem;
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: all var(--transition-interactive);
}
.user-dropdown.active { opacity: 1; pointer-events: auto; transform: translateY(0); }
.user-dropdown a, .user-dropdown button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: var(--text-sm);
  color: var(--color-tx-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all var(--transition-interactive);
  min-height: 44px;
  text-align: left;
}
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--color-surface-offset); color: var(--color-tx); }

/* ═══════════════════════════════════════════
   AUTH STYLES
   ═══════════════════════════════════════════ */

/* Auth error message */
.auth-error {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--color-error-hl);
  color: var(--color-error);
  font-size: var(--text-xs);
  font-weight: 500;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  line-height: 1.4;
}
.auth-error svg { flex-shrink: 0; margin-top: 1px; }

/* Auth success message */
.auth-success {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--color-success-hl);
  color: var(--color-success);
  font-size: var(--text-xs);
  font-weight: 500;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  line-height: 1.4;
}
.auth-success svg { flex-shrink: 0; margin-top: 1px; }

/* Sign-up field animation */
.auth-signup-field {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  margin-bottom: 0;
  transition: max-height 250ms cubic-bezier(0.16, 1, 0.3, 1),
              opacity 200ms cubic-bezier(0.16, 1, 0.3, 1),
              margin-bottom 250ms cubic-bezier(0.16, 1, 0.3, 1);
}
.auth-signup-field.visible {
  max-height: 80px;
  opacity: 1;
  margin-bottom: 1rem;
}

/* Auth button loading state */
#auth-submit-btn.loading {
  opacity: 0.7;
  pointer-events: none;
  cursor: not-allowed;
}
#auth-submit-btn.loading #auth-btn-text {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

/* Spinner for auth button */
.auth-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: auth-spin 0.6s linear infinite;
}
@keyframes auth-spin {
  to { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════
   CRUD ADDITIONS — Toast, Status Dropdown, Confirm
   ═══════════════════════════════════════════ */

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-tx);
  min-width: 280px;
  max-width: 420px;
  animation: toast-in 300ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.toast.toast-removing {
  animation: toast-out 200ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.toast-success .toast-icon { color: var(--color-success); }
.toast-error .toast-icon { color: var(--color-error); }
.toast-info .toast-icon { color: var(--color-blue); }
.toast-close {
  margin-left: auto;
  width: 18px;
  height: 18px;
  color: var(--color-tx-faint);
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--transition-interactive);
}
.toast-close:hover { color: var(--color-tx); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to { opacity: 0; transform: translateX(40px) scale(0.95); }
}

/* Status Dropdown */
.status-dropdown-wrap {
  position: relative;
  display: inline-block;
}
.status-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0.25rem;
  z-index: 45;
  min-width: 150px;
  animation: dropdown-in 150ms cubic-bezier(0.16, 1, 0.3, 1);
}
.status-dropdown button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-tx-muted);
  border-radius: var(--radius-sm);
  transition: all var(--transition-interactive);
  min-height: 36px;
  text-align: left;
  white-space: nowrap;
}
.status-dropdown button:hover {
  background: var(--color-surface-offset);
  color: var(--color-tx);
}
.status-dropdown button.current {
  background: var(--color-primary-hl);
  color: var(--color-primary);
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-4px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Badge clickable (status) */
.badge-clickable {
  cursor: pointer;
  transition: all var(--transition-interactive);
}
.badge-clickable:hover {
  filter: brightness(0.92);
  box-shadow: 0 0 0 2px var(--color-primary-hl);
}

/* Action buttons in table */
.btn-ghost.btn-sm {
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-danger-ghost {
  background: transparent;
  color: var(--color-tx-faint);
  transition: all var(--transition-interactive);
}
.btn-danger-ghost:hover {
  background: var(--color-error-hl);
  color: var(--color-error);
}

/* Delivery modal loading */
#delivery-modal-submit.loading {
  opacity: 0.7;
  pointer-events: none;
  cursor: not-allowed;
}
.modal-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: auth-spin 0.6s linear infinite;
}

/* ═══════════════════════════════════════════
   DISPATCH COMMAND CENTER
   ═══════════════════════════════════════════ */

/* Responsive responsive reports layout */
@media (max-width: 768px) {
  #view-reports div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}
/* ═══════════════════════════════════════════
   PHASE 2: SETTINGS & RBAC STYLES
   ═══════════════════════════════════════════ */

/* Field Label */
.field-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-tx-muted);
  margin-bottom: 0.375rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Notification Row */
.notif-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-divider);
}
.notif-row:last-child {
  border-bottom: none;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--color-surface-dynamic);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition-interactive);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition-interactive);
  box-shadow: 0 1px 3px oklch(0 0 0 / 0.25);
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--color-primary);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}
.toggle-switch input:focus-visible + .toggle-slider {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Role Badges */
.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  white-space: nowrap;
  text-transform: capitalize;
}
.role-admin {
  background: var(--color-error-hl);
  color: var(--color-error);
}
.role-dispatcher {
  background: var(--color-blue-hl);
  color: var(--color-blue);
}
.role-driver {
  background: var(--color-orange-hl);
  color: var(--color-orange);
}
.role-viewer {
  background: var(--color-surface-dynamic);
  color: var(--color-tx-muted);
}

/* Audit Action Badges */
.audit-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  white-space: nowrap;
  text-transform: capitalize;
}
.audit-create {
  background: var(--color-success-hl);
  color: var(--color-success);
}
.audit-update {
  background: var(--color-blue-hl);
  color: var(--color-blue);
}
.audit-delete {
  background: var(--color-error-hl);
  color: var(--color-error);
}

/* ═══════════════════════════════════════════
   PHASE 3: DELIVERY OPERATIONS
   ═══════════════════════════════════════════ */

/* Modal dialog (alternative small modal wrapper) */
.modal-dialog {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
}
.modal-title {
  font-size: var(--text-base);
  font-weight: 600;
}
.modal-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-tx-muted);
  font-size: 1.25rem;
  line-height: 1;
  min-width: 44px; min-height: 44px;
  transition: background var(--transition-interactive);
}
.modal-close:hover { background: var(--color-surface-offset); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--color-divider);
  flex-shrink: 0;
}

/* Pending Queue Cards */
.pending-queue-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: all var(--transition-interactive);
}
.pending-queue-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary-hl);
}
.pending-queue-card .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.pending-queue-card .card-id {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-tx-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.pending-queue-card .card-customer {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-tx);
  margin-bottom: 0.25rem;
}
.pending-queue-card .card-detail {
  font-size: var(--text-xs);
  color: var(--color-tx-muted);
  margin-bottom: 0.125rem;
  display: flex;
  align-items: flex-start;
  gap: 0.375rem;
}
.pending-queue-card .card-assign-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  align-items: center;
}
.pending-queue-card .card-assign-row select {
  flex: 1;
}

/* Delivery Timeline */
.delivery-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.timeline-item {
  display: flex;
  gap: 0.75rem;
  position: relative;
}
.timeline-item:not(:last-child) .timeline-line {
  position: absolute;
  left: 7px;
  top: 20px;
  bottom: -12px;
  width: 2px;
  background: var(--color-divider);
}
.timeline-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-surface-dynamic);
  border: 2px solid var(--color-divider);
  flex-shrink: 0;
  margin-top: 2px;
}
.timeline-dot.dot-create { background: var(--color-success); border-color: var(--color-success); }
.timeline-dot.dot-update { background: var(--color-blue); border-color: var(--color-blue); }
.timeline-dot.dot-delete { background: var(--color-error); border-color: var(--color-error); }
.timeline-content {
  flex: 1;
  padding-bottom: 1rem;
}
.timeline-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-tx);
}
.timeline-meta {
  font-size: var(--text-xs);
  color: var(--color-tx-faint);
  margin-top: 0.125rem;
}
.timeline-detail {
  font-size: var(--text-xs);
  color: var(--color-tx-muted);
  margin-top: 0.25rem;
  line-height: 1.5;
}

/* Attachment items */
.attachment-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  background: var(--color-surface-offset);
  border-radius: var(--radius-md);
  transition: background var(--transition-interactive);
}
.attachment-item:hover { background: var(--color-surface-dynamic); }
.attachment-icon {
  width: 36px; height: 36px;
  background: var(--color-primary-hl);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--color-primary);
}
.attachment-info { flex: 1; min-width: 0; }
.attachment-name {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-tx);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attachment-meta {
  font-size: var(--text-xs);
  color: var(--color-tx-faint);
  margin-top: 0.125rem;
}

/* Drop zone */
.attachment-drop-zone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-interactive);
}
.attachment-drop-zone:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-hl);
}
.attachment-drop-zone.drag-over {
  border-color: var(--color-primary);
  background: var(--color-primary-hl);
}

/* Progress bar */
.progress-bar-track {
  width: 100%;
  height: 6px;
  background: var(--color-surface-dynamic);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width 300ms ease;
}

/* Invoice status badges */
.badge-draft { background: var(--color-surface-dynamic); color: var(--color-tx-muted); }
.badge-sent { background: var(--color-blue-hl); color: var(--color-blue); }
.badge-paid { background: var(--color-success-hl); color: var(--color-success); }
.badge-overdue { background: var(--color-error-hl); color: var(--color-error); }

/* CSV preview validation */
.csv-row-valid { background: var(--color-success-hl); }
.csv-row-error { background: var(--color-error-hl); }
.csv-cell-error { color: var(--color-error); font-weight: 500; }

/* Delivery checkbox in invoice modal */
.invoice-delivery-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-divider);
  transition: background var(--transition-interactive);
  cursor: pointer;
}
.invoice-delivery-item:last-child { border-bottom: none; }
.invoice-delivery-item:hover { background: var(--color-surface-offset); }
.invoice-delivery-item input[type="checkbox"] { flex-shrink: 0; }
.invoice-delivery-info { flex: 1; }
.invoice-delivery-id { font-size: var(--text-xs); font-weight: 600; color: var(--color-primary); }
.invoice-delivery-addr { font-size: var(--text-xs); color: var(--color-tx-muted); margin-top: 0.125rem; }
.invoice-delivery-amount { font-size: var(--text-sm); font-weight: 600; color: var(--color-tx); }

/* Responsive pending queue */
@media (max-width: 768px) {
  #pending-queue-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ═══════════════════════════════════════════
   PHASE 3 REVISIONS: VEHICLES & ROUTES
   ═══════════════════════════════════════════ */

/* Vehicle Cards */
.vehicle-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: all var(--transition-interactive);
}
.vehicle-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary-hl);
}
.vehicle-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.vehicle-card-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-tx);
}
.vehicle-card-meta {
  font-size: var(--text-xs);
  color: var(--color-tx-muted);
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}
.vehicle-card-actions {
  display: flex;
  gap: 0.375rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-divider);
}

/* Vehicle type badge */
.badge-vehicle-van { background: var(--color-blue-hl); color: var(--color-blue); }
.badge-vehicle-truck { background: var(--color-orange-hl); color: var(--color-orange); }
.badge-vehicle-car { background: var(--color-success-hl); color: var(--color-success); }
.badge-vehicle-suv { background: var(--color-primary-hl); color: var(--color-primary); }
.badge-maintenance { background: var(--color-warning-hl); color: var(--color-warning); }

/* Route Cards */
.route-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  cursor: pointer;
  transition: all var(--transition-interactive);
}
.route-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}
.route-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.route-card-id {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.route-card-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-tx);
  margin-top: 0.25rem;
}
.route-card-stats {
  display: flex;
  gap: 1rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-divider);
}
.route-stat {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}
.route-stat-label {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--color-tx-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.route-stat-value {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-tx);
}

/* Route Detail View */
.route-detail-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.route-detail-section {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.route-detail-section-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-tx-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: space-between;
}

/* Crew member row */
.crew-member-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--color-divider);
}
.crew-member-row:last-child {
  border-bottom: none;
}

/* Stop row in route detail */
.stop-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--color-divider);
  font-size: var(--text-xs);
}
.stop-row:last-child {
  border-bottom: none;
}
.stop-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary-hl);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* Route manifest action bar */
.route-action-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-divider);
}

@media (max-width: 768px) {
  #vehicles-grid,
  #routes-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ═══ Dispatch route card accordion ═══ */
.dispatch-route-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.dispatch-route-card.drag-over {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-hl), 0 0 12px rgba(1, 105, 111, 0.25), var(--shadow-lg);
  transform: scale(1.01);
  background: var(--color-primary-hl);
  transition: box-shadow 0.15s ease, border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}
.dispatch-route-header {
  padding: 0.75rem 1rem;
  background: var(--color-surface-offset);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.dispatch-route-header:hover {
  background: var(--color-surface-offset-2);
}
.dispatch-expand-arrow {
  transition: transform 0.2s ease;
  flex-shrink: 0;
  color: var(--color-tx-muted);
}
.dispatch-expand-arrow.expanded {
  transform: rotate(180deg);
}
.dispatch-route-body {
  display: none;
  padding: 0.625rem 1rem;
  border-top: 1px solid var(--color-divider);
}
.dispatch-route-body.expanded {
  display: block;
}
.dispatch-route-actions {
  display: none;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--color-divider);
  gap: 0.5rem;
  flex-wrap: wrap;
}
.dispatch-route-actions.expanded {
  display: flex;
}

/* ═══ Drag and drop ═══ */
.dispatch-order-card {
  cursor: grab;
  transition: opacity 0.2s ease, transform 0.15s ease;
}
.dispatch-order-card:active {
  cursor: grabbing;
}
.dispatch-order-card.dragging {
  opacity: 0.5;
  transform: scale(0.97);
}
.drop-indicator {
  display: none;
  padding: 0.5rem;
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-primary);
  font-weight: 500;
  border: 2px dashed var(--color-primary);
  border-radius: var(--radius-md);
  background: var(--color-primary-hl);
  margin: 0.375rem 1rem;
}
.dispatch-route-card.drag-over .drop-indicator {
  display: block;
}
/* Active route card highlight (map is showing this route) */
.dispatch-route-card.map-active {
  border-left: 3px solid var(--color-primary);
  background: var(--color-primary-hl);
}
