/* ============================================================
   QRAALYS Fleet Management — Apple HIG Design System
   ============================================================ */

/* ── Google Fonts (SF Pro substitute) ─────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;

  --text-large-title:  2.125rem; /* 34px */
  --text-title1:       1.75rem;  /* 28px */
  --text-title2:       1.375rem; /* 22px */
  --text-title3:       1.25rem;  /* 20px */
  --text-headline:     1.0625rem;/* 17px 600 */
  --text-body:         1.0625rem;/* 17px */
  --text-callout:      1rem;     /* 16px */
  --text-subhead:      0.9375rem;/* 15px */
  --text-footnote:     0.8125rem;/* 13px */
  --text-caption1:     0.75rem;  /* 12px */
  --text-caption2:     0.6875rem;/* 11px */

  /* System Colors — Light */
  --blue:    #007AFF;
  --green:   #34C759;
  --red:     #FF3B30;
  --orange:  #FF9500;
  --yellow:  #FFCC00;
  --purple:  #AF52DE;
  --teal:    #5AC8FA;
  --indigo:  #5856D6;

  --blue-tint:   rgba(0, 122, 255, 0.12);
  --green-tint:  rgba(52, 199, 89, 0.12);
  --red-tint:    rgba(255, 59, 48, 0.12);
  --orange-tint: rgba(255, 149, 0, 0.12);
  --yellow-tint: rgba(255, 204, 0, 0.15);
  --purple-tint: rgba(175, 82, 222, 0.12);

  /* Label Colors */
  --label:             #000000;
  --label-secondary:   rgba(60, 60, 67, 0.60);
  --label-tertiary:    rgba(60, 60, 67, 0.30);
  --label-quaternary:  rgba(60, 60, 67, 0.18);

  /* Backgrounds */
  --bg-system:          #F2F2F7;
  --bg-secondary:       #FFFFFF;
  --bg-tertiary:        #F2F2F7;
  --bg-grouped:         #F2F2F7;
  --bg-grouped-secondary: #FFFFFF;
  --bg-elevated:        #FFFFFF;

  /* Separator */
  --separator:          rgba(60, 60, 67, 0.29);
  --separator-opaque:   #C6C6C8;

  /* System Grays */
  --gray1: #8E8E93;
  --gray2: #AEAEB2;
  --gray3: #C7C7CC;
  --gray4: #D1D1D6;
  --gray5: #E5E5EA;
  --gray6: #F2F2F7;

  /* Fill Colors */
  --fill1: rgba(120, 120, 128, 0.20);
  --fill2: rgba(120, 120, 128, 0.16);
  --fill3: rgba(120, 120, 128, 0.12);
  --fill4: rgba(120, 120, 128, 0.08);

  /* Spacing (8pt grid) */
  --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-11: 44px;
  --space-12: 48px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-xs: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.10), 0 2px 6px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.08);

  /* Sidebar */
  --sidebar-width: 240px;

  /* Transitions */
  --spring: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --spring-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Dark Mode ─────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --label:             #FFFFFF;
    --label-secondary:   rgba(235, 235, 245, 0.60);
    --label-tertiary:    rgba(235, 235, 245, 0.30);
    --label-quaternary:  rgba(235, 235, 245, 0.18);

    --bg-system:          #000000;
    --bg-secondary:       #1C1C1E;
    --bg-tertiary:        #2C2C2E;
    --bg-grouped:         #000000;
    --bg-grouped-secondary: #1C1C1E;
    --bg-elevated:        #2C2C2E;

    --separator:          rgba(84, 84, 88, 0.60);
    --separator-opaque:   #38383A;

    --gray1: #8E8E93;
    --gray2: #636366;
    --gray3: #48484A;
    --gray4: #3A3A3C;
    --gray5: #2C2C2E;
    --gray6: #1C1C1E;

    --fill1: rgba(120, 120, 128, 0.36);
    --fill2: rgba(120, 120, 128, 0.32);
    --fill3: rgba(120, 120, 128, 0.24);
    --fill4: rgba(120, 120, 128, 0.18);

    --shadow-xs: 0 1px 3px rgba(0,0,0,0.30);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.30);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.40);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.50);
  }
}

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

html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.5;
  color: var(--label);
  background: var(--bg-grouped);
  min-height: 100vh;
}

/* ============================================================
   LAYOUT
   ============================================================ */

.main-container {
  margin-left: var(--sidebar-width);
  padding: var(--space-6) var(--space-6) var(--space-12);
  min-height: 100vh;
  transition: margin-left 0.3s var(--spring);
}

.main-container.sidebar-collapsed {
  margin-left: 0;
}

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
}

.page-title {
  font-size: var(--text-title1);
  font-weight: 700;
  color: var(--label);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.page-subtitle {
  font-size: var(--text-subhead);
  color: var(--label-secondary);
  margin-top: var(--space-1);
}

/* Config card (main content wrapper) */
.config-card {
  background: transparent;
  padding: 0;
  border: none;
  box-shadow: none;
}

/* ── Page-level notification banner (Pesapal-style) ── */
.page-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-5);
  font-size: var(--text-subhead);
  font-weight: 500;
  border: 1px solid transparent;
  line-height: 1.4;
}

.page-banner.success {
  background: var(--green-tint);
  color: var(--green);
  border-color: rgba(52, 199, 89, 0.30);
}

.page-banner.error {
  background: var(--red-tint);
  color: var(--red);
  border-color: rgba(255, 59, 48, 0.30);
}

.page-banner.info {
  background: var(--blue-tint);
  color: var(--blue);
  border-color: rgba(0, 122, 255, 0.25);
}

.page-banner.warning {
  background: var(--orange-tint);
  color: var(--orange);
  border-color: rgba(255, 149, 0, 0.30);
}

.page-banner-close {
  background: none;
  border: none;
  cursor: pointer;
  color: currentColor;
  opacity: 0.55;
  padding: 2px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  transition: opacity 0.15s;
}

.page-banner-close:hover { opacity: 1; }
.page-banner-close svg { width: 16px; height: 16px; }

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar-nav {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: #FFFFFF;
  border-right: 1px solid var(--separator-opaque);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s var(--spring);
}

@media (prefers-color-scheme: dark) {
  .sidebar-nav {
    background: #1C1C1E;
    border-right-color: var(--separator-opaque);
  }
}

.sidebar-nav.collapsed {
  transform: translateX(-100%);
}

/* Sidebar header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--separator);
  min-height: 72px;
  flex-shrink: 0;
}

.sidebar-logo {
  width: 130px;
  height: auto;
  max-height: 36px;
  object-fit: contain;
}

/* Org name strip (injected dynamically by navigation.js) */
.sidebar-org-section {
  flex-shrink: 0;
  padding: var(--space-2) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--separator);
}

.sidebar-org-name {
  font-size: var(--text-footnote);
  font-weight: 600;
  color: var(--label);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-org-label {
  font-size: var(--text-caption2);
  font-weight: 500;
  color: var(--label-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.sidebar-close {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  background: var(--fill3);
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--label-secondary);
  transition: background 0.15s;
}

.sidebar-close:hover { background: var(--fill2); }
.sidebar-close svg { width: 14px; height: 14px; }

/* Sidebar menu scroll area */
.sidebar-menu {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-3) 0;
  scrollbar-width: none;
}
.sidebar-menu::-webkit-scrollbar { display: none; }

/* Section headers */
.sidebar-section-header {
  padding: var(--space-3) var(--space-4) var(--space-1);
  font-size: var(--text-caption1);
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--label-tertiary);
  text-transform: uppercase;
  cursor: default;
  user-select: none;
  margin-top: var(--space-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-section-header:first-child { margin-top: 0; }

.section-chevron {
  width: 12px;
  height: 12px;
  transition: transform 0.2s var(--spring);
  color: var(--label-tertiary);
}

.sidebar-section-header.collapsed .section-chevron {
  transform: rotate(-90deg);
}

/* Nav items */
.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  margin: 1px var(--space-2);
  border-radius: var(--radius-md);
  color: var(--label);
  font-size: var(--text-subhead);
  font-weight: 500;
  text-decoration: none;
  border: none;
  background: none;
  width: calc(100% - var(--space-4));
  text-align: left;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  border-left: none;
  line-height: 1.3;
  min-height: 34px;
}

.sidebar-nav-item:hover {
  background: var(--fill3);
  color: var(--label);
}

.sidebar-nav-item.active {
  background: var(--blue-tint);
  color: var(--blue);
  font-weight: 600;
}

.sidebar-nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.sidebar-nav-item.active svg {
  opacity: 1;
}

/* Submenu */
.sidebar-nav-item.has-submenu::after {
  content: '';
  width: 0;
  height: 0;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-top: 4.5px solid currentColor;
  margin-left: auto;
  opacity: 0.4;
  transition: transform 0.2s var(--spring);
  flex-shrink: 0;
}

.sidebar-nav-item.has-submenu.open::after { transform: rotate(180deg); }

.sidebar-submenu {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s var(--spring);
}

.sidebar-submenu.open { max-height: 400px; }

.sidebar-submenu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  margin: 1px var(--space-2) 1px calc(var(--space-2) + 18px + var(--space-3));
  border-radius: var(--radius-md);
  color: var(--label-secondary);
  font-size: var(--text-footnote);
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  border-left: none;
  min-height: 32px;
}

.sidebar-submenu-item:hover { background: var(--fill3); color: var(--label); }
.sidebar-submenu-item.active { color: var(--blue); background: var(--blue-tint); font-weight: 600; }
.sidebar-submenu-item svg { width: 15px; height: 15px; flex-shrink: 0; }

/* Nav badge */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--red);
  color: white;
  border-radius: 9px;
  font-size: var(--text-caption2);
  font-weight: 700;
  margin-left: auto;
}

/* Sidebar user chip (bottom) */
.sidebar-user-info {
  flex-shrink: 0;
  padding: var(--space-3) var(--space-3);
  border-top: 1px solid var(--separator);
}

.sidebar-user-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: default;
}

.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--blue);
  color: white;
  font-size: var(--text-caption1);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}

.sidebar-user-detail {
  min-width: 0;
}

.sidebar-user-name {
  font-size: var(--text-footnote);
  font-weight: 600;
  color: var(--label);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: var(--text-caption1);
  color: var(--label-secondary);
}

/* Sidebar date */
.sidebar-date {
  display: none; /* folded into user chip */
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 999;
}

.sidebar-overlay.show { display: block; }

/* Mobile menu button — both class names accepted */
.mobile-menu-btn, .sidebar-toggle {
  display: none;
  position: fixed;
  top: var(--space-4);
  left: var(--space-4);
  z-index: 1001;
  background: var(--bg-elevated);
  border: none;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  color: var(--label);
}

.mobile-menu-btn svg, .sidebar-toggle svg { width: 22px; height: 22px; }

/* Sidebar divider (legacy — hidden) */
.sidebar-divider { display: none; }

/* ============================================================
   CARDS
   ============================================================ */

.card {
  background: var(--bg-grouped-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--separator);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--separator);
}

.card-title {
  font-size: var(--text-headline);
  font-weight: 600;
  color: var(--label);
}

.card-body { padding: var(--space-5); }

/* Section card (alias used in billing/admin pages) */
.section-card {
  background: var(--bg-grouped-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--separator);
  box-shadow: var(--shadow-xs);
  overflow: visible;
  margin-bottom: var(--space-5);
  padding: var(--space-5);
}

.sc-head, .section-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--separator);
}

.sc-head h2, .section-card-header h2 {
  font-size: var(--text-headline);
  font-weight: 600;
  color: var(--label);
  margin: 0;
}

.sc-body, .section-card-body { padding: var(--space-5); }

/* Stat / metric cards */
.summary-card {
  background: var(--bg-grouped-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--separator);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-xs);
}

.summary-card .lbl,
.summary-card .label {
  font-size: var(--text-footnote);
  font-weight: 500;
  color: var(--label-secondary);
  margin-bottom: var(--space-1);
  text-transform: none;
  letter-spacing: 0;
}

.summary-card .val,
.summary-card .value {
  font-size: var(--text-title2);
  font-weight: 700;
  color: var(--label);
  line-height: 1.2;
  margin-top: var(--space-1);
}

.val.green,  .value.green  { color: var(--green); }
.val.blue,   .value.blue   { color: var(--blue); }
.val.yellow, .value.yellow { color: var(--orange); }
.val.red,    .value.red    { color: var(--red); }

/* Summary grid */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

/* ============================================================
   BUTTONS
   ============================================================ */

/* Base */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 36px;
  font-family: var(--font-sans);
  font-size: var(--text-subhead);
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s, transform 0.1s var(--spring), box-shadow 0.15s;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.3; pointer-events: none; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* Sizes */
.btn-sm { height: 28px; padding: 0 var(--space-3); font-size: var(--text-footnote); border-radius: var(--radius-sm); }
.btn-lg { height: 44px; padding: 0 var(--space-6); font-size: var(--text-callout); border-radius: var(--radius-lg); }

/* ── Base styles shared by all semantic variants ── */
.btn-primary, .btn-filled,
.btn-tinted,
.btn-gray, .btn-secondary,
.btn-plain,
.btn-destructive, .btn-danger,
.btn-destructive-filled,
.btn-success {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 36px;
  font-family: var(--font-sans);
  font-size: var(--text-subhead);
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s, transform 0.1s var(--spring), box-shadow 0.15s;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}
.btn-primary:active, .btn-filled:active,
.btn-tinted:active, .btn-gray:active, .btn-secondary:active,
.btn-destructive:active, .btn-danger:active,
.btn-destructive-filled:active, .btn-success:active { transform: scale(0.97); }
.btn-primary:disabled, .btn-tinted:disabled, .btn-gray:disabled,
.btn-destructive:disabled, .btn-success:disabled { opacity: 0.3; pointer-events: none; }
.btn-primary svg, .btn-tinted svg, .btn-gray svg, .btn-secondary svg,
.btn-destructive svg, .btn-danger svg, .btn-success svg,
.btn-plain svg { width: 16px; height: 16px; flex-shrink: 0; }

/* Filled (primary) */
.btn-primary, .btn-filled {
  background: var(--blue);
  color: #fff;
}
.btn-primary:hover, .btn-filled:hover { opacity: 0.88; }

/* Tinted (secondary) */
.btn-tinted {
  background: var(--blue-tint);
  color: var(--blue);
}
.btn-tinted:hover { opacity: 0.80; }

/* Gray (tertiary) */
.btn-gray, .btn-secondary {
  background: var(--fill2);
  color: var(--label);
}
.btn-gray:hover, .btn-secondary:hover { background: var(--fill1); }

/* Plain */
.btn-plain {
  background: none;
  color: var(--blue);
  padding: 0 var(--space-2);
  display: inline-flex; align-items: center; gap: var(--space-2);
  border: none; cursor: pointer; font-family: var(--font-sans);
  font-size: var(--text-subhead); font-weight: 600;
  transition: opacity 0.15s;
}
.btn-plain:hover { opacity: 0.7; }

/* Destructive */
.btn-destructive, .btn-danger {
  background: var(--red-tint);
  color: var(--red);
}
.btn-destructive:hover, .btn-danger:hover { opacity: 0.80; }

.btn-destructive-filled {
  background: var(--red);
  color: #fff;
}
.btn-destructive-filled:hover { opacity: 0.88; }

/* Success */
.btn-success {
  background: var(--green);
  color: #fff;
}
.btn-success:hover { opacity: 0.88; }

/* Ghost (legacy alias) */
.btn-ghost {
  background: none;
  border: none;
  color: var(--blue);
  font-size: var(--text-footnote);
  font-weight: 600;
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  transition: opacity 0.15s;
}
.btn-ghost:hover { opacity: 0.7; }

/* ============================================================
   FORM CONTROLS
   ============================================================ */

.form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: var(--space-4);
}

.form-group label {
  font-size: var(--text-footnote);
  font-weight: 500;
  color: var(--label-secondary);
  margin-bottom: var(--space-1);
}

.form-group input,
.form-group select,
.form-group textarea,
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="date"],
select,
textarea {
  background: var(--bg-grouped-secondary);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-sans);
  font-size: var(--text-callout);
  color: var(--label);
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  min-height: 40px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.18);
}

.form-group .hint {
  font-size: var(--text-caption1);
  color: var(--label-tertiary);
  margin-top: var(--space-1);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

/* Inset grouped form rows */
.form-inset-group {
  background: var(--bg-grouped-secondary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
  margin-bottom: var(--space-5);
}

.form-inset-row {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--separator);
  gap: var(--space-4);
}

.form-inset-row:last-child { border-bottom: none; }

.form-inset-label {
  font-size: var(--text-callout);
  font-weight: 500;
  color: var(--label);
  flex: 1;
  white-space: nowrap;
}

.form-inset-row input,
.form-inset-row select {
  border: none;
  background: none;
  text-align: right;
  color: var(--label-secondary);
  font-size: var(--text-callout);
  padding: 0;
  min-height: unset;
  width: auto;
  flex: 1;
  box-shadow: none !important;
}

/* Segmented control */
.segmented-control {
  display: inline-flex;
  background: var(--fill3);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 1px;
}

.segmented-control button {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border: none;
  background: none;
  font-family: var(--font-sans);
  font-size: var(--text-footnote);
  font-weight: 500;
  color: var(--label-secondary);
  border-radius: calc(var(--radius-md) - 2px);
  cursor: pointer;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s;
  white-space: nowrap;
}

.segmented-control button.active {
  background: var(--bg-grouped-secondary);
  color: var(--label);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--gray4);
  border-radius: 31px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-track::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: transform 0.22s var(--spring-bounce);
}

.toggle-switch input:checked + .toggle-track { background: var(--green); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(20px); }

/* ============================================================
   TABLES & LISTS
   ============================================================ */

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  background: var(--bg-grouped);
  font-size: var(--text-caption1);
  font-weight: 600;
  color: var(--label-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--separator);
}

.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--separator);
  font-size: var(--text-subhead);
  color: var(--label);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: var(--fill4); }

.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--label-tertiary);
  font-size: var(--text-subhead);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding: 0 var(--space-1);
}

/* ============================================================
   BADGES / STATUS PILLS
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: 9999px;
  font-size: var(--text-caption1);
  font-weight: 600;
  white-space: nowrap;
}

.badge-active,
.badge-paid      { background: var(--green-tint);  color: var(--green);  }
.badge-pending   { background: var(--yellow-tint); color: #B8860B;       }
.badge-overdue   { background: var(--red-tint);    color: var(--red);    }
.badge-cancelled,
.badge-inactive  { background: var(--fill3);       color: var(--label-secondary);  }
.badge-warning   { background: var(--orange-tint); color: var(--orange); }

/* Colour-named badges */
.badge-green     { background: var(--green-tint);  color: var(--green);  }
.badge-red       { background: var(--red-tint);    color: var(--red);    }
.badge-blue      { background: var(--blue-tint);   color: var(--blue);   }
.badge-orange    { background: var(--orange-tint); color: var(--orange); }
.badge-yellow    { background: var(--yellow-tint); color: #B8860B;       }
.badge-purple    { background: var(--purple-tint); color: var(--purple); }

/* Pill (vehicle type) */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px var(--space-2);
  border-radius: 9999px;
  font-size: var(--text-caption1);
  font-weight: 600;
}

.pill-saloon { background: var(--blue-tint);   color: var(--blue);   }
.pill-heavy  { background: var(--purple-tint); color: var(--purple); }

/* ============================================================
   MODALS / SHEETS
   ============================================================ */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.40);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal.show { display: flex; }

.modal-content {
  background: var(--bg-elevated);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: sheet-in 0.28s var(--spring-bounce);
}

@keyframes sheet-in {
  from { opacity: 0; transform: scale(0.94) translateY(16px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);    }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--separator);
}

.modal-header h2 {
  font-size: var(--text-headline);
  font-weight: 700;
  color: var(--label);
  margin: 0;
}

.close-btn, .modal-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--fill3);
  color: var(--label-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  transition: background 0.15s;
}
.close-btn:hover, .modal-close:hover { background: var(--fill2); }

.modal-body { padding: var(--space-5); }

.modal-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--separator);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* ============================================================
   TOAST / NOTIFICATION BANNER
   ============================================================ */

.toast {
  position: fixed;
  top: var(--space-5);
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  min-width: 320px;
  max-width: 400px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-3) var(--space-4);
  display: none;
  align-items: center;
  gap: var(--space-3);
  z-index: 3000;
  font-size: var(--text-subhead);
  font-weight: 500;
  color: var(--label);
  border: 1px solid var(--separator);
  animation: banner-in 0.3s var(--spring-bounce) forwards;
}

.toast.show {
  display: flex;
  transform: translateX(-50%) translateY(0);
}

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

.toast::before {
  content: '';
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  background-size: 20px;
  background-repeat: no-repeat;
  background-position: center;
}

.toast.success::before {
  background-color: var(--green);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='white'%3E%3Cpath d='M16.7 5.3a1 1 0 010 1.4l-8 8a1 1 0 01-1.4 0l-4-4a1 1 0 011.4-1.4L8 12.58l7.3-7.28a1 1 0 011.4 0z'/%3E%3C/svg%3E");
}

.toast.error::before {
  background-color: var(--red);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='white'%3E%3Cpath d='M10 8.586L4.707 3.293 3.293 4.707 8.586 10l-5.293 5.293 1.414 1.414L10 11.414l5.293 5.293 1.414-1.414L11.414 10l5.293-5.293-1.414-1.414L10 8.586z'/%3E%3C/svg%3E");
}

/* ============================================================
   FILTER ROW
   ============================================================ */

.filter-row {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  align-items: center;
}

.filter-row select,
.filter-row input {
  height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-md);
  background: var(--bg-grouped-secondary);
  font-family: var(--font-sans);
  font-size: var(--text-subhead);
  color: var(--label);
  min-height: unset;
}

/* ============================================================
   STATUS / UTILITY
   ============================================================ */

.loading {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--fill2);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-4);
  gap: var(--space-3);
  color: var(--label-secondary);
  font-size: var(--text-subhead);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.hidden { display: none !important; }

.status-message {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  margin: var(--space-4) 0;
  font-weight: 500;
  font-size: var(--text-subhead);
  display: none;
}

.status-success { background: var(--green-tint);  color: var(--green); }
.status-error   { background: var(--red-tint);    color: var(--red);   }
.status-info    { background: var(--blue-tint);   color: var(--blue);  }

/* ============================================================
   LEGACY / COMPAT
   ============================================================ */

/* Header card (replaced by page-title pattern, kept for compat) */
.header-card { display: none; }

/* Nav menu / tabs (legacy — hidden in favour of sidebar) */
.nav-menu, .nav-tabs, .nav-tab { display: none; }

/* search-input — used in device/driver search bars */
.search-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--separator);
  border-radius: var(--radius-md);
  background: var(--bg-grouped-secondary);
  color: var(--label);
  font-size: var(--text-callout);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-tint);
}

/* action-buttons */
.action-buttons {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* welcome-message */
.welcome-message {
  text-align: center;
  color: var(--label-secondary);
  font-size: var(--text-callout);
  margin: var(--space-8) 0;
}

/* form-section-title */
.form-section-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-title3);
  font-weight: 600;
  color: var(--label);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--separator);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
  .main-container {
    margin-left: 0;
    padding: var(--space-4) var(--space-4) var(--space-12);
    padding-top: calc(44px + var(--space-6));
  }

  .mobile-menu-btn, .sidebar-toggle { display: flex; }

  .sidebar-nav {
    width: 280px;
    transform: translateX(-100%);
  }

  .sidebar-nav.open {
    transform: translateX(0);
  }

  .sidebar-close { display: flex; }

  .page-title { font-size: var(--text-title2); }

  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-row { grid-template-columns: 1fr; }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .modal-content {
    max-width: 100%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 92vh;
  }

  .modal {
    align-items: flex-end;
    padding: 0;
  }

  .data-table th,
  .data-table td {
    padding: var(--space-3);
    font-size: var(--text-caption1);
  }
}
