/* Fleet Management design tokens: spec section 14 (brand palette is the source of truth). */
:root {
  --teal-900: #004D5B;
  --teal-700: #0F7A8A;
  --teal-50: #E6F2F4;
  --amber-500: #F59E0B;
  --amber-50: #FEF5E1;
  --charcoal: #1F2937;
  --gray-200: #E5E7EB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-50: #F4F5F7;
  --red: #B91C1C;
  --red-50: #FDECEC;
  --white: #FFFFFF;

  --bg: #EEF0F3;
  --surface: var(--white);
  --text: var(--charcoal);
  --muted: var(--gray-500);
  --border: var(--gray-200);
  --heading: var(--teal-900);
  --link: var(--teal-700);
  --radius: 12px;
  --shadow: 0 1px 2px rgba(31, 41, 55, .05), 0 2px 8px rgba(31, 41, 55, .04);
  --rail: 232px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  font-feature-settings: "tnum" 1, "cv11" 1;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--heading); margin: 0; line-height: 1.25; }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
.icon { flex: none; vertical-align: -3px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Application shell ---------- */
.shell { display: flex; min-height: 100vh; }
.rail {
  width: var(--rail); flex: none; background: var(--teal-900); color: var(--white);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 24px; font-weight: 700; font-size: 16px; letter-spacing: .01em; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--amber-500); color: var(--charcoal); display: grid; place-items: center; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; flex: 1; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; opacity: .6; padding: 16px 12px 6px; }
.nav a {
  color: rgba(255,255,255,.86); display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 8px; position: relative; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: var(--white); }
.nav a.active { background: rgba(255,255,255,.12); color: var(--white); }
.nav a.active::before { content: ""; position: absolute; left: -10px; top: 6px; bottom: 6px; width: 4px; border-radius: 0 4px 4px 0; background: var(--amber-500); }
.nav .count { margin-left: auto; background: var(--amber-500); color: var(--charcoal); font-size: 11px; font-weight: 700; border-radius: 999px; padding: 0 7px; }
.rail-foot { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; }
.rail-foot a { color: rgba(255,255,255,.8); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--white); border-bottom: 1px solid var(--border); height: 60px;
  display: flex; align-items: center; gap: 16px; padding: 0 28px; position: sticky; top: 0; z-index: 5;
}
.menu-btn { display: none; background: none; border: 0; color: var(--teal-900); padding: 6px; cursor: pointer; }
.search { flex: 1; min-width: 0; max-width: 460px; position: relative; }
.search .icon { position: absolute; left: 11px; top: 10px; color: var(--gray-400); }
.search input { width: 100%; padding: 8px 12px 8px 36px; border: 1px solid var(--border); border-radius: 8px; background: var(--gray-50); font: inherit; }
.search input:focus { outline: 2px solid var(--teal-700); outline-offset: -1px; background: var(--white); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 18px; }
.bell { position: relative; color: var(--teal-900); display: inline-flex; }
.bell .dot { position: absolute; top: -6px; right: -9px; background: var(--red); color: var(--white); font-size: 10px; font-weight: 700; border-radius: 999px; padding: 0 5px; line-height: 16px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--teal-700); color: var(--white); display: grid; place-items: center; font-weight: 600; font-size: 13px; }

.content { padding: 28px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.eyebrow { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--teal-700); margin-bottom: 6px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Cards and grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 12px; }
.card-body { padding: 18px 20px; }
.card-foot { padding: 12px 20px; border-top: 1px solid var(--border); font-size: 13px; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 20px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { padding: 16px 18px; position: relative; overflow: hidden; }
.kpi-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--teal-900); margin-top: 6px; letter-spacing: -.01em; }
.kpi-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kpi.accent::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--amber-500); }
.kpi.danger .kpi-value { color: var(--red); }

/* Status bar (fleet status breakdown) */
.statusbar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--gray-200); margin: 4px 0 16px; }
.statusbar span { display: block; height: 100%; }
.legend { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px 16px; font-size: 13px; }
.legend div { display: flex; align-items: center; gap: 8px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend b { margin-left: auto; color: var(--teal-900); }
.tone-teal { background: var(--teal-700); }
.tone-navy, .tone-navy-outline { background: var(--teal-900); }
.tone-amber { background: var(--amber-500); }
.tone-red { background: var(--red); }
.tone-gray { background: var(--gray-400); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--teal-900); background: var(--gray-50); padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #FAFBFB; }
td.right, th.right { text-align: right; }
.cell-main { font-weight: 600; color: var(--teal-900); }
.cell-sub { font-size: 12.5px; color: var(--muted); }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 2px 9px 2px 7px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent;
}
.badge-teal { background: var(--teal-50); color: var(--teal-900); }
.badge-teal .icon { color: var(--teal-700); }
.badge-navy { background: var(--teal-900); color: var(--white); }
.badge-navy-outline { background: var(--white); color: var(--teal-900); border-color: var(--teal-900); }
.badge-amber { background: var(--amber-500); color: var(--charcoal); } /* charcoal on amber, never white (spec 14.2) */
.badge-red { background: var(--red-50); color: var(--red); }
.badge-gray { background: var(--gray-50); color: #4B5563; border-color: var(--gray-200); }

/* ---------- Buttons and forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; font: inherit; font-weight: 600; font-size: 13.5px;
  border-radius: 8px; padding: 8px 14px; border: 1px solid transparent; cursor: pointer; white-space: nowrap; line-height: 1.3;
}
.btn:hover { text-decoration: none; filter: brightness(.96); }
.btn-primary { background: var(--teal-700); color: var(--white); }
.btn-accent { background: var(--amber-500); color: var(--charcoal); }
.btn-outline { background: var(--white); color: var(--teal-700); border-color: var(--teal-700); }
.btn-ghost { background: transparent; color: var(--teal-900); border-color: var(--border); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn:focus-visible, .input:focus, .nav a:focus-visible { outline: 2px solid var(--amber-500); outline-offset: 2px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); align-items: center; }
.filters .input { width: auto; min-width: 150px; }
.filters .grow { flex: 1; min-width: 200px; }

.input {
  width: 100%; font: inherit; color: var(--text); padding: 8px 11px; border: 1px solid #D1D5DB;
  border-radius: 8px; background: var(--white);
}
.input:focus { border-color: var(--teal-700); outline-offset: 0; outline: 2px solid rgba(15,122,138,.25); }
select.input { padding-right: 28px; }
textarea.input { resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px 20px; }
.form-section { padding: 20px; border-bottom: 1px solid var(--border); }
.form-section:last-of-type { border-bottom: 0; }
.form-section h2 { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--teal-900); margin-bottom: 5px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.field .error, .errorlist { color: var(--red); font-size: 12.5px; margin: 4px 0 0; padding: 0; list-style: none; }
.field.wide { grid-column: 1 / -1; }
.field.has-error .input { border-color: var(--red); }
.form-actions { display: flex; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--border); background: var(--gray-50); border-radius: 0 0 var(--radius) var(--radius); }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1; min-width: 140px; }

/* ---------- Messages ---------- */
.messages { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.messages li { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--white); display: flex; gap: 8px; align-items: center; }
.messages .success { border-color: #B6DCE2; background: var(--teal-50); color: var(--teal-900); }
.messages .error { border-color: #F3C2C2; background: var(--red-50); color: var(--red); }
.messages .info, .messages .warning { border-color: #F7D48A; background: var(--amber-50); color: var(--charcoal); }

/* ---------- Vehicle 360 ---------- */
.hero { display: flex; gap: 20px; align-items: center; padding: 20px; }
.hero-photo { width: 120px; height: 84px; border-radius: 10px; background: var(--teal-50); color: var(--teal-700); display: grid; place-items: center; overflow: hidden; flex: none; }
.hero-photo img { width: 100%; height: 100%; object-fit: cover; }
.hero-title { font-size: 24px; font-weight: 700; color: var(--teal-900); }
.hero-meta { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); margin-top: 6px; font-size: 13px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px 20px; }
.fact dt { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.fact dd { margin: 2px 0 0; font-weight: 500; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 12px; overflow-x: auto; }
.tabs a { padding: 12px 12px; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--teal-900); text-decoration: none; }
.tabs a.active { color: var(--teal-900); border-bottom-color: var(--amber-500); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); min-width: 110px; }

/* ---------- Work-order board ---------- */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 16px; overflow-x: auto; }
.column { background: #E4E8EC; border-radius: var(--radius); padding: 10px; min-height: 200px; }
.column-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 10px; font-weight: 600; color: var(--teal-900); }
.ticket { display: block; background: var(--white); border-radius: 10px; padding: 12px; margin-bottom: 10px; border: 1px solid var(--border); color: var(--text); box-shadow: var(--shadow); }
.ticket:hover { text-decoration: none; border-color: var(--teal-700); }
.ticket .t-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.ticket .t-title { font-weight: 600; color: var(--teal-900); margin-bottom: 8px; }
.ticket .t-foot { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side { background: var(--teal-900); color: var(--white); padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side h2 { color: var(--white); font-size: 32px; font-weight: 700; max-width: 420px; line-height: 1.2; }
.auth-side p { opacity: .8; max-width: 420px; }
.auth-main { display: grid; place-items: center; padding: 32px; background: var(--white); }
.auth-card { width: 100%; max-width: 360px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card .field { margin-top: 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-main, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .rail { position: fixed; left: 0; z-index: 20; transform: translateX(-100%); transition: transform .18s ease; }
  body.nav-open .rail { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-btn { display: inline-flex; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .kpi-value { font-size: 24px; }
  .page-head .actions { width: 100%; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .hero { flex-direction: column; align-items: flex-start; }
  h1 { font-size: 22px; }
}

@media print {
  .rail, .topbar, .actions, .filters { display: none !important; }
  .content { padding: 0; }
}

/* ---------- Accounts, organization ---------- */
.auth-submit { width: 100%; justify-content: center; margin-top: 22px; padding: 10px; }
.auth-links { margin-top: 18px; font-size: 13px; color: var(--muted, #6B7280); }
.auth-card form + form { margin-top: 12px; }
.org-switch select, .org-name { width: 100%; margin-bottom: 12px; background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.2); border-radius: 6px; padding: 6px 8px; font: inherit; font-size: 13px; }
.org-name { border-color: transparent; background: transparent; padding: 0; opacity: .85; }
.org-switch option { color: #1F2937; }
.two-factor { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 24px; align-items: start; }
.qr { background: #fff; border: 1px solid #E5E7EB; border-radius: 8px; padding: 8px; }
.secret { word-break: break-all; font-size: 13px; }
.recovery-codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 16px 0 20px; }
.recovery-codes code { font-size: 15px; letter-spacing: .04em; }
nav.tabs { margin-bottom: 16px; }

/* ---------- Billing ---------- */
.billing-notice { border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; border: 1px solid; }
.billing-notice.info { background: #E6F2F4; border-color: #B7DCE2; color: var(--teal-900); }
.billing-notice.warning { background: #FEF3C7; border-color: #FCD34D; color: #78350F; }
.billing-notice.error { background: #FEE2E2; border-color: #FCA5A5; color: var(--red); }
.billing-notice a { font-weight: 600; margin-left: 6px; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 12px; }
.plan-option { display: block; border: 1px solid var(--border); border-radius: 10px; padding: 14px; cursor: pointer; }
.plan-option:has(input:checked) { border-color: var(--teal-700); box-shadow: 0 0 0 2px rgba(15,122,138,.15); }
.plan-option .price { font-size: 20px; font-weight: 700; color: var(--teal-900); }
.radio-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.radio-list label { display: flex; gap: 10px; align-items: center; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; cursor: pointer; font-weight: 500; }
.radio-list label:has(input:checked) { border-color: var(--teal-700); background: #F0F8F9; }
.pay-wait { text-align: center; padding: 28px 16px; }
.amount-due { font-size: 28px; font-weight: 700; color: var(--teal-900); }

/* ---------- GPS tracking ---------- */
.map-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: stretch; }
.map-canvas { height: min(72vh, 720px); min-height: 380px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--gray-50); z-index: 0; }
.map-canvas.small { height: 360px; min-height: 300px; }
.map-side { display: flex; flex-direction: column; min-height: 0; max-height: min(72vh, 720px); }
.map-side .card-body { overflow: auto; padding: 8px; flex: 1; }
.vehicle-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.vehicle-row { width: 100%; display: flex; gap: 10px; align-items: center; text-align: left; background: none; border: 1px solid transparent; border-radius: 8px; padding: 8px 10px; font: inherit; color: inherit; cursor: pointer; }
.vehicle-row:hover:not(:disabled), .vehicle-row:focus-visible { background: var(--gray-50); border-color: var(--border); }
.vehicle-row:disabled { cursor: default; opacity: .65; }
.vehicle-row-body { display: flex; flex-direction: column; min-width: 0; }
.vehicle-row-body .muted { font-size: 12.5px; }
.state-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--gray-400); }
.state-moving .state-dot, .state-dot.moving { background: var(--teal-700); }
.state-idle .state-dot, .state-dot.idle { background: var(--amber-500); }
.state-parked .state-dot, .state-dot.parked { background: var(--teal-900); }
.state-counts { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); }
.state-counts span { display: inline-flex; align-items: center; gap: 6px; }
.state-counts b { color: var(--text); }
.vehicle-marker { background: none; border: 0; }
.vehicle-marker svg { display: block; filter: drop-shadow(0 1px 2px rgba(0,0,0,.35)); }
.vehicle-marker span { position: absolute; left: 26px; top: 4px; white-space: nowrap; background: rgba(255,255,255,.92); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; font: 600 11px/16px Inter, system-ui, sans-serif; color: var(--charcoal); }
.map-popup { display: grid; gap: 2px; font: 13px/1.4 Inter, system-ui, sans-serif; min-width: 180px; }
.map-popup strong { font-size: 14px; color: var(--heading); }
.map-popup-links { display: flex; gap: 12px; margin-top: 6px; font-weight: 600; }
.trip-row { cursor: pointer; }
.trip-row:hover, .trip-row:focus-visible { background: var(--gray-50); }
.setup-steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.setup-steps code, .protocol-table code { background: var(--gray-50); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 13px; }
@media (max-width: 900px) {
  .map-layout { grid-template-columns: 1fr; }
  .map-side { max-height: 320px; order: 2; }
  .map-canvas { height: 62vh; }
}
