/* ═══════════════════════════════════════════
   DESIGN TOKENS — NavioData Dark Operations
   ═══════════════════════════════════════════ */
:root {
  /* Sidebar */
  --sb-bg: #060B18;
  --sb-border: rgba(255,255,255,0.06);
  --sb-text: rgba(255,255,255,0.42);
  --sb-text-active: #fff;
  --sb-active-bg: rgba(37,99,235,0.15);
  --sb-hover-bg: rgba(255,255,255,0.05);

  /* Page surfaces */
  --page-bg: #08101F;
  --surface: #0D1A2E;
  --surface-2: #0A1424;
  --surface-3: #111F35;

  /* Brand & accents */
  --brand: #3B82F6;
  --brand-dark: #2563EB;
  --brand-glow: rgba(59,130,246,0.2);
  --green: #10B981;
  --green-glow: rgba(16,185,129,0.15);
  --amber: #F59E0B;
  --red: #EF4444;
  --purple: #8B5CF6;
  --cyan: #06B6D4;

  /* Text */
  --text-1: #E8F0FE;
  --text-2: #7A9BBF;
  --text-3: #3D5A7A;
  --border: rgba(255,255,255,0.07);
  --border-bright: rgba(255,255,255,0.12);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px rgba(59,130,246,0.12);

  /* Geometry */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;

  /* Typography */
  --font-display: 'Syne', sans-serif;
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Layout */
  --sidebar-w: 240px;
  --topbar-h: 60px;
}

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

body {
  font-family: var(--font-body);
  background: var(--page-bg);
  color: var(--text-1);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse 60% 40% at 70% 20%, rgba(37,99,235,0.04) 0%, transparent 60%),
    radial-gradient(ellipse 40% 30% at 20% 80%, rgba(16,185,129,0.03) 0%, transparent 60%);
}

/* ═══════════════════════════════════════════
   APP SHELL
   ═══════════════════════════════════════════ */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ─── SIDEBAR ─── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sb-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  position: relative;
  overflow: hidden;
  transition: transform 0.25s ease;
  border-right: 1px solid var(--sb-border);
}

.sidebar::before {
  content: '';
  position: absolute;
  top: -80px; left: -80px;
  width: 260px; height: 260px;
  background: radial-gradient(circle, rgba(37,99,235,0.12) 0%, transparent 70%);
  pointer-events: none;
}
.sidebar::after {
  content: '';
  position: absolute;
  bottom: 0; right: 0;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(16,185,129,0.05) 0%, transparent 70%);
  pointer-events: none;
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--sb-border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-logo {
  height: 72px;
  width: auto;
  object-fit: contain;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.625rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.875rem;
  border-radius: var(--radius-sm);
  color: var(--sb-text);
  font-size: 0.845rem;
  font-weight: 500;
  transition: all 0.15s ease;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  position: relative;
  letter-spacing: 0.01em;
}
.nav-item i { font-size: 1rem; width: 18px; text-align: center; flex-shrink: 0; }
.nav-item:hover {
  background: var(--sb-hover-bg);
  color: rgba(255,255,255,0.75);
}
.nav-item.active {
  background: var(--sb-active-bg);
  color: var(--text-1);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--brand);
}
.nav-item.active i { color: var(--brand); }

.nav-badge {
  margin-left: auto;
  background: rgba(59,130,246,0.2);
  color: var(--brand);
  border: 1px solid rgba(59,130,246,0.25);
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 20px;
  font-family: var(--font-mono);
}

.sidebar-live {
  margin: 0 0.625rem 0.75rem;
  padding: 0.6rem 0.875rem;
  background: var(--green-glow);
  border: 1px solid rgba(16,185,129,0.2);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.live-dot {
  width: 7px; height: 7px;
  background: var(--green);
  border-radius: 50%;
  flex-shrink: 0;
  animation: pulse-green 2s ease-in-out infinite;
}
@keyframes pulse-green {
  0%,100% { box-shadow: 0 0 0 0 rgba(16,185,129,0.6); }
  50% { box-shadow: 0 0 0 5px rgba(16,185,129,0); }
}
.live-label { font-size: 0.68rem; color: var(--green); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.live-count { margin-left: auto; font-family: var(--font-mono); font-size: 0.7rem; color: var(--green); font-weight: 600; }

.sidebar-footer {
  padding: 0.875rem 1rem 1rem;
  border-top: 1px solid var(--sb-border);
}

/* ─── MAIN ─── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* ─── TOPBAR ─── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 0.875rem;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.topbar-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.02em;
}
.topbar-sub { font-size: 0.7rem; color: var(--text-3); letter-spacing: 0.02em; }
.topbar-sep { flex: 1; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.7rem;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 700;
  font-family: var(--font-mono);
  white-space: nowrap;
  border: 1px solid transparent;
}
.chip.green {
  background: rgba(16,185,129,0.1);
  color: #10B981;
  border-color: rgba(16,185,129,0.2);
}
.chip.amber {
  background: rgba(245,158,11,0.1);
  color: var(--amber);
  border-color: rgba(245,158,11,0.2);
}
.chip i { font-size: 0.65rem; }

.topbar-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.15s;
}
.topbar-btn:hover { background: var(--surface-2); color: var(--brand); border-color: var(--brand-glow); }

.topbar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3B82F6, #8B5CF6);
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 0 12px rgba(59,130,246,0.3);
}

/* ═══════════════════════════════════════════
   CONTENT AREA
   ═══════════════════════════════════════════ */
#page-content { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.content-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 1.5rem; }
.content-scroll::-webkit-scrollbar { width: 4px; }
.content-scroll::-webkit-scrollbar-track { background: transparent; }
.content-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }
.content-scroll::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

/* ═══════════════════════════════════════════
   DASHBOARD
   ═══════════════════════════════════════════ */
.dashboard { flex: 1; display: flex; overflow: hidden; position: relative; }

.map-canvas {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #060E1C;
}
#dash-map { height: 100%; width: 100%; }

.kpi-overlay {
  position: absolute;
  top: 14px; left: 14px;
  display: flex; gap: 8px;
  z-index: 10;
}
.kpi-tile {
  padding: 10px 16px;
  background: rgba(6,11,24,0.88);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  min-width: 90px;
}
.kpi-val {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 600;
  color: white;
  line-height: 1;
}
.kpi-lbl { font-size: 0.58rem; color: rgba(255,255,255,0.35); text-transform: uppercase; letter-spacing: 0.1em; margin-top: 4px; }

/* Vehicle panel */
.panel {
  width: 300px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.panel-head {
  padding: 1rem 1.125rem 0.875rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-title {
  font-family: var(--font-display);
  font-size: 0.825rem;
  font-weight: 700;
  color: var(--text-1);
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 0.625rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.panel-badge {
  background: rgba(59,130,246,0.15);
  color: var(--brand);
  border: 1px solid rgba(59,130,246,0.25);
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  font-family: var(--font-mono);
}
.panel-search {
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  font-size: 0.78rem;
  color: var(--text-3);
  transition: border-color 0.15s;
}
.panel-search:focus-within { border-color: rgba(59,130,246,0.4); }
.panel-search input {
  border: none; background: none; outline: none;
  font-size: 0.78rem; color: var(--text-1); width: 100%;
  font-family: var(--font-body);
}
.panel-search input::placeholder { color: var(--text-3); }
.vlist { flex: 1; overflow-y: auto; }
.vlist::-webkit-scrollbar { width: 3px; }
.vlist::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

.vcard {
  padding: 0.875rem 1.125rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}
.vcard:hover { background: rgba(59,130,246,0.05); }
.vcard.sel {
  background: rgba(59,130,246,0.08);
  border-left: 3px solid var(--brand);
  padding-left: calc(1.125rem - 3px);
}
.vcard-top { display: flex; align-items: center; gap: 0.625rem; margin-bottom: 0.5rem; }
.vcard-icon {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.vcard-name { font-weight: 600; font-size: 0.845rem; color: var(--text-1); }
.vcard-id { font-size: 0.65rem; color: var(--text-3); font-family: var(--font-mono); letter-spacing: 0.03em; }
.vcard-status { margin-left: auto; display: flex; align-items: center; gap: 4px; font-size: 0.67rem; font-weight: 600; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; }
.status-dot.moving { background: var(--green); animation: pulse-green 1.8s ease-in-out infinite; }
.status-dot.online { background: var(--brand); }
.status-dot.offline { background: var(--text-3); }

.vcard-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 0.5rem; }
.vs-val { font-family: var(--font-mono); font-size: 0.8rem; font-weight: 600; color: var(--text-1); text-align: center; }
.vs-lbl { font-size: 0.58rem; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; text-align: center; }

/* ═══════════════════════════════════════════
   COMMON PAGE ELEMENTS
   ═══════════════════════════════════════════ */
.page-h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-1);
  margin-bottom: 0.25rem;
}
.page-sub { font-size: 0.8rem; color: var(--text-3); margin-bottom: 1.375rem; letter-spacing: 0.01em; overflow-wrap: break-word; }

.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 1rem; margin-bottom: 1.375rem; }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-width: 0;
}
.kpi-card:hover {
  border-color: var(--border-bright);
  box-shadow: var(--shadow-md);
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  border-radius: 12px 12px 0 0;
}
.kpi-card.c-green::before { background: linear-gradient(90deg, var(--green), #34D399); }
.kpi-card.c-blue::before  { background: linear-gradient(90deg, var(--brand), #60A5FA); }
.kpi-card.c-amber::before { background: linear-gradient(90deg, var(--amber), #FCD34D); }
.kpi-card.c-purple::before{ background: linear-gradient(90deg, var(--purple), #A78BFA); }
.kpi-card.c-red::before   { background: linear-gradient(90deg, var(--red), #F87171); }
.kc-val { font-family: var(--font-mono); font-size: 2rem; font-weight: 600; color: var(--text-1); line-height: 1; }
.kc-unit { font-size: 0.9rem; font-weight: 400; color: var(--text-3); }
.kc-lbl { font-size: 0.72rem; color: var(--text-2); font-weight: 500; margin-top: 6px; letter-spacing: 0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kc-icon { position: absolute; right: 1rem; top: 1.1rem; font-size: 1.6rem; opacity: 0.08; }
.kc-sub { font-size: 0.68rem; color: var(--text-3); margin-top: 6px; }

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.table-head {
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem;
  flex-wrap: wrap;
}
.table-title { font-family: var(--font-display); font-size: 0.825rem; font-weight: 700; color: var(--text-1); letter-spacing: 0.03em; text-transform: uppercase; }
.table-count { font-size: 0.7rem; color: var(--text-3); font-family: var(--font-mono); }
.search-box {
  margin-left: auto;
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.38rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  color: var(--text-3);
  transition: border-color 0.15s;
}
.search-box:focus-within { border-color: rgba(59,130,246,0.4); }
.search-box input {
  border: none; background: none; outline: none;
  font-size: 0.78rem; color: var(--text-1);
  font-family: var(--font-body);
  width: 140px;
}
.search-box input::placeholder { color: var(--text-3); }

.table-scroll-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll-wrap::-webkit-scrollbar { height: 3px; }
.table-scroll-wrap::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 0.7rem 1.25rem;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  background: var(--surface-2);
  text-align: left;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr.tr-clickable { cursor: pointer; transition: background 0.1s; }
tbody tr.tr-clickable:hover { background: rgba(59,130,246,0.05); }
td { padding: 0.875rem 1.25rem; font-size: 0.845rem; vertical-align: middle; }

.dev-cell { display: flex; align-items: center; gap: 0.75rem; }
.dev-icon {
  width: 36px; height: 36px;
  background: rgba(59,130,246,0.1);
  border: 1px solid rgba(59,130,246,0.15);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--brand); font-size: 1rem;
  flex-shrink: 0;
}
.dev-name { font-weight: 600; color: var(--text-1); }
.dev-id { font-size: 0.65rem; color: var(--text-3); font-family: var(--font-mono); letter-spacing: 0.03em; }

.gps-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 20px;
  font-size: 0.67rem; font-weight: 700;
  border: 1px solid transparent;
}
.gps-badge.moving  { background: rgba(59,130,246,0.1); color: var(--brand); border-color: rgba(59,130,246,0.2); }
.gps-badge.online  { background: rgba(16,185,129,0.1); color: var(--green); border-color: rgba(16,185,129,0.2); }
.gps-badge.offline { background: rgba(255,255,255,0.04); color: var(--text-3); border-color: var(--border); }
.gps-badge i { font-size: 0.55rem; }

.coord { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-2); }
.spd { font-family: var(--font-mono); font-weight: 600; color: var(--text-1); }
.spd-u { font-size: 0.65rem; color: var(--text-3); margin-left: 2px; }

/* Action buttons */
.btn-primary {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 1.1rem;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  transition: all 0.15s;
  box-shadow: 0 0 12px rgba(59,130,246,0.25);
}
.btn-primary:hover { background: var(--brand-dark); box-shadow: 0 0 20px rgba(59,130,246,0.4); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.4rem 0.875rem;
  background: var(--surface-3);
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  transition: all 0.15s;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text-1); border-color: var(--border-bright); }

.btn-icon {
  width: 30px; height: 30px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface-3);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-2);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}
.btn-icon:hover { background: rgba(59,130,246,0.1); color: var(--brand); border-color: rgba(59,130,246,0.3); }

/* ═══════════════════════════════════════════
   DEVICES PAGE
   ═══════════════════════════════════════════ */
.action-row {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════════
   DEVICE DETAIL PAGE
   ═══════════════════════════════════════════ */
.dd-cards-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}
.dd-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.dd-card-head {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.72rem;
  color: var(--text-3);
  display: flex; align-items: center; gap: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.dd-card-head i { color: var(--brand); }
.dd-field {
  display: flex; align-items: baseline;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.dd-field:last-child { border-bottom: none; }
.dd-label { font-size: 0.62rem; color: var(--text-3); font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; flex-shrink: 0; }
.dd-val { font-size: 0.8rem; color: var(--text-1); font-weight: 500; text-align: right; font-family: var(--font-mono); word-break: break-all; }

.dd-map-wrap {
  background: #060B18;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 320px;
  margin-bottom: 1rem;
}
.dd-map-bar {
  padding: 0.625rem 1rem;
  background: rgba(6,11,24,0.96);
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-2);
  display: flex; align-items: center; gap: 0.5rem;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom: 1px solid var(--border);
}
.dd-map-bar i { color: var(--brand); }
#dd-map { flex: 1; }

.dd-io-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1px;
  background: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}
.io-cell {
  background: var(--surface);
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: background 0.1s;
}
.io-cell:hover { background: var(--surface-3); }
.io-name { font-size: 0.6rem; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
.io-val { font-family: var(--font-mono); font-size: 0.88rem; font-weight: 600; color: var(--text-1); }

/* ═══════════════════════════════════════════
   TRIPS PAGE
   ═══════════════════════════════════════════ */
.trip-row-actions { display: flex; gap: 4px; }

/* Devices table */
.devices-table { min-width: unset !important; }

@media (max-width: 768px) {
  .devices-table,
  .devices-table tbody { display: block; width: 100%; }
  .devices-table thead { display: none; }
  .devices-table tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "device  actions"
      "gps     status";
    padding: 0.875rem 1rem;
    gap: 0.375rem 0.75rem;
    align-items: start;
    border-bottom: 1px solid var(--border);
  }
  .devices-table td { padding: 0; }
  .devices-table .td-device  { grid-area: device; }
  .devices-table .td-status  { grid-area: status; justify-self: end; align-self: end; }
  .devices-table .td-gps     { grid-area: gps; }
  .devices-table .td-actions { grid-area: actions; }
}

/* Trips table cells */
.trips-table { min-width: unset !important; }
.trip-dates {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.78rem; color: var(--text-2); margin-bottom: 0.25rem;
  font-family: var(--font-mono);
}
.trip-arrow { color: var(--text-3); font-size: 0.7rem; }
.trip-date-val { white-space: nowrap; }
.trip-stats {
  display: flex; gap: 0.75rem;
  font-size: 0.7rem; color: var(--text-3);
}
.trip-stats i { font-size: 0.65rem; margin-right: 2px; }

/* Mobile: card layout */
@media (max-width: 768px) {
  .trips-table,
  .trips-table tbody { display: block; width: 100%; }
  .trips-table thead { display: none; }
  .trips-table tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "device  actions"
      "meta    status";
    padding: 0.875rem 1rem;
    gap: 0.375rem 0.75rem;
    align-items: start;
  }
  .trips-table td { padding: 0; }
  .trips-table .td-device  { grid-area: device; }
  .trips-table .td-meta    { grid-area: meta; }
  .trips-table .td-status  { grid-area: status; justify-self: end; align-self: end; }
  .trips-table .td-actions { grid-area: actions; }

  .trip-dates {
    flex-direction: column;
    gap: 0.15rem;
    align-items: flex-start;
  }
  .trip-arrow { transform: rotate(90deg); font-size: 0.6rem; margin-left: 2px; }
  .trip-date-val { font-size: 0.73rem; }
}

.trip-status-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 20px;
  font-size: 0.67rem; font-weight: 700;
  border: 1px solid transparent;
}
.trip-status-badge.completed { background: rgba(16,185,129,0.1); color: var(--green); border-color: rgba(16,185,129,0.2); }
.trip-status-badge.progress  { background: rgba(59,130,246,0.1); color: var(--brand); border-color: rgba(59,130,246,0.2); }

/* ═══════════════════════════════════════════
   TRIP MAP PAGE
   ═══════════════════════════════════════════ */
.trip-map-page { display: flex; flex-direction: column; height: 100%; overflow: hidden; padding: 1rem 1.5rem; gap: 0.75rem; }
.trip-map-header { display: flex; align-items: center; gap: 1rem; flex-shrink: 0; }

.tm-badges { display: flex; flex-wrap: wrap; gap: 0.375rem; flex-shrink: 0; }
.tm-trip-badge {
  display: inline-flex; align-items: center; gap: 0.375rem;
  padding: 0.28rem 0.75rem;
  border-radius: 20px;
  font-size: 0.7rem; font-weight: 600;
}
.tm-color-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

.tm-layout {
  display: grid;
  grid-template-columns: 1fr;
  flex: 1;
  min-height: 0;
  gap: 1rem;
}
.tm-layout.tm-has-legend { grid-template-columns: 1fr 280px; }

.tm-map-wrap {
  background: #060B18;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
  min-height: 0;
}
.tm-map-loading {
  position: absolute; inset: 0; background: #060B18; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.75rem; color: var(--text-3); font-size: 0.875rem;
}
#tm-map { height: 100%; }

.tm-legend-card { display: flex; flex-direction: column; overflow: hidden; border-radius: var(--radius); }
.tm-legend-body { flex: 1; overflow-y: auto; padding: 0.75rem; }
.tm-legend-item {
  display: flex; align-items: center; gap: 0.625rem;
  padding: 0.625rem; border-radius: var(--radius-sm);
  margin-bottom: 4px; cursor: pointer;
  border: 1px solid transparent; transition: all 0.12s;
}
.tm-legend-item:hover { background: var(--surface-3); border-color: var(--border); }
.tm-legend-dot { width: 12px; height: 4px; border-radius: 2px; flex-shrink: 0; }
.tm-legend-name { font-size: 0.78rem; font-weight: 600; color: var(--text-1); }
.tm-legend-time { font-size: 0.68rem; color: var(--text-3); }
.tm-legend-dist { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-2); margin-left: auto; }

/* ═══════════════════════════════════════════
   ANALYTICS PAGE
   ═══════════════════════════════════════════ */
.an-filter-bar {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: flex-end;
  gap: 0.625rem;
  margin-bottom: 1rem;
}
@media (max-width: 480px) {
  .an-filter-bar {
    grid-template-columns: 1fr 1fr;
  }
  .an-filter-bar .btn-primary {
    grid-column: 1 / -1;
  }
}
.an-filter-group { display: flex; flex-direction: column; gap: 0.25rem; }
.an-label { font-size: 0.6rem; color: var(--text-3); font-weight: 700; text-transform: uppercase; letter-spacing: 0.09em; }
.nd-date-input {
  padding: 0.38rem 0.625rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem; color: var(--text-1);
  font-family: var(--font-mono);
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
  color-scheme: dark;
}
.nd-date-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-glow); }

.an-kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 1rem; margin-bottom: 1rem; }

.an-tabs {
  display: flex; gap: 2px; margin-bottom: -1px; position: relative; z-index: 1;
  overflow-x: auto; flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.an-tabs::-webkit-scrollbar { display: none; }
.an-tab {
  display: inline-flex; align-items: center;
  padding: 0.5rem 0.875rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  color: var(--text-3); font-size: 0.75rem; font-weight: 600;
  cursor: pointer; font-family: var(--font-body); transition: all 0.12s;
  letter-spacing: 0.01em;
  white-space: nowrap; flex-shrink: 0;
}
.an-tab:hover { background: var(--surface-3); color: var(--text-2); }
.an-tab.active { background: var(--surface); color: var(--brand); border-bottom-color: var(--surface); z-index: 2; position: relative; }

.an-tab-card { border-radius: 0 var(--radius) var(--radius) var(--radius); }

.rank-gold   { background: rgba(251,191,36,0.15); color: #FCD34D; border: 1px solid rgba(251,191,36,0.25); padding: 2px 8px; border-radius: 20px; font-size: .68rem; font-weight: 700; }
.rank-silver { background: rgba(148,163,184,0.1); color: var(--text-2); border: 1px solid var(--border); padding: 2px 8px; border-radius: 20px; font-size: .68rem; font-weight: 700; }
.rank-bronze { background: rgba(251,146,60,0.12); color: #FB923C; border: 1px solid rgba(251,146,60,0.2); padding: 2px 8px; border-radius: 20px; font-size: .68rem; font-weight: 700; }

/* Score bar */
.score-bar-wrap { display: flex; align-items: center; gap: 0.5rem; }
.score-bar-bg { flex: 1; height: 5px; background: rgba(255,255,255,0.06); border-radius: 3px; overflow: hidden; }
.score-bar-fill { height: 100%; border-radius: 3px; }

/* ═══════════════════════════════════════════
   SPINNER / LOADING
   ═══════════════════════════════════════════ */
.spinner {
  width: 24px; height: 24px;
  border: 2px solid rgba(59,130,246,0.15);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-lg { width: 40px; height: 40px; border-width: 3px; }

.loading-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 3rem; gap: 1rem; color: var(--text-3); font-size: 0.845rem;
}

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 3rem; gap: 0.75rem; color: var(--text-3);
}
.empty-state i { font-size: 2rem; opacity: 0.2; }
.empty-state p { font-size: 0.845rem; }

/* ═══════════════════════════════════════════
   MOBILE
   ═══════════════════════════════════════════ */
.mobile-topbar {
  display: none;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: center;
  padding: 0 1rem;
  gap: 0.75rem;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.mobile-brand-logo {
  height: 48px;
  width: auto;
  object-fit: contain;
}

.bottom-nav {
  display: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.375rem 0 env(safe-area-inset-bottom, 0.375rem);
  flex-shrink: 0;
}
.bottom-nav-inner { display: flex; }
.bn-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 0.375rem 0.25rem;
  border: none; background: none; cursor: pointer;
  color: var(--text-3); font-size: 0.6rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  font-family: var(--font-body); transition: color 0.15s;
}
.bn-item i { font-size: 1.2rem; }
.bn-item.active { color: var(--brand); }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 90;
  backdrop-filter: blur(2px);
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .mobile-topbar { display: flex; }
  .bottom-nav { display: block; }
  .topbar { display: none; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .an-kpi-grid { grid-template-columns: 1fr 1fr; }
  .dd-cards-row { grid-template-columns: 1fr; }
  .panel { display: none; }
  .tm-layout.tm-has-legend { grid-template-columns: 1fr; }

  .content-scroll { padding: 1rem; }
  .kpi-card { padding: 1rem; }
  .kc-val { font-size: 1.6rem; }
  .kc-icon { display: none; }
  .kc-lbl { font-size: 0.68rem; }
  .page-h1 { font-size: 1.25rem; }
}

/* ═══════════════════════════════════════════
   LEAFLET OVERRIDES
   ═══════════════════════════════════════════ */
.leaflet-container { font-family: var(--font-body); }
.leaflet-control-attribution { display: none; }
.leaflet-control-zoom a {
  background: rgba(6,11,24,0.88) !important;
  color: rgba(255,255,255,0.7) !important;
  border-color: rgba(255,255,255,0.1) !important;
  backdrop-filter: blur(8px);
}
.leaflet-control-zoom a:hover {
  background: rgba(59,130,246,0.6) !important;
  color: white !important;
}
.leaflet-popup-content-wrapper {
  background: rgba(13,26,46,0.95) !important;
  color: var(--text-1) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-md) !important;
}
.leaflet-popup-tip { background: rgba(13,26,46,0.95) !important; }
.leaflet-tooltip {
  background: rgba(6,11,24,0.92) !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
  color: var(--text-1) !important;
  border-radius: var(--radius-xs) !important;
  font-family: var(--font-body) !important;
  font-size: 0.78rem !important;
  box-shadow: var(--shadow-sm) !important;
  padding: 4px 10px !important;
  backdrop-filter: blur(8px);
}

/* Marker animation */
@keyframes vping {
  0% { transform: scale(1); opacity: 0.65; }
  100% { transform: scale(3.2); opacity: 0; }
}
