/* ================================================================
   1FLEET — Dark Operations Console Theme
   Signature choice: amber accent + monospace telemetry readouts
   + sharp-edged cards with left accent borders (no SaaS radius)
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600;700&display=swap');

/* ── Tokens ─────────────────────────────────────────────────── */
:root {
  --bg:          #080D1A;
  --bg-card:     #0E1420;
  --bg-raised:   #141B28;
  --bg-hover:    #1A2236;
  --border:      #1E2D42;
  --border-dim:  #142030;

  --accent:      #F59E0B;
  --accent-dim:  #92600A;
  --accent-glow: rgba(245,158,11,0.15);

  --idle:        #10B981;
  --idle-dim:    rgba(16,185,129,0.2);
  --inuse:       #EF4444;
  --inuse-dim:   rgba(239,68,68,0.2);

  --text:        #E2E8F0;
  --text-sub:    #7C8FA8;
  --text-dim:    #3D5068;

  --mono:        'JetBrains Mono', monospace;
  --sans:        'Inter', sans-serif;

  --sidebar-w:   220px;

  /* ── z-index scale ──────────────────────────────────────────────
     Single source of truth for stacking. Leaflet's own ceiling is its
     control container at z-index 1000; EVERY overlay layer below is set
     ABOVE 1000 so it wins even if the map's stacking context is ever
     broken by a plugin. The map wrapper is also isolated (see
     .leaflet-container) as a second line of defence.
       base content … < map < dropdown < modal < toast              */
  --z-map:       1;     /* Leaflet map (internals contained below this) */
  --z-dropdown:  1100;  /* profile menu / popovers   (> Leaflet's 1000) */
  --z-modal:     1200;  /* modal overlays + backdrops                   */
  --z-toast:     1300;  /* toasts + exclusion banner — always on top    */
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

input, button, select { font-family: inherit; }

.hidden { display: none !important; }
.w-full { width: 100%; }

/* ── Layout ─────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-brand {
  padding: 18px 16px 15px;
  border-bottom: 1px solid var(--border);
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 9px;
}
.sidebar-logo {
  height: 38px;
  width: auto;
  flex-shrink: 0;
}
.brand-wordmark {
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #ffffff;
  line-height: 1;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--text-sub);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover {
  color: var(--text);
  background: var(--bg-hover);
  text-decoration: none;
}
.nav-item.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-left-color: var(--accent);
}

.sidebar-bottom {
  padding: 12px;
  border-top: 1px solid var(--border);
}

/* Dataset selector in sidebar */
.dataset-selector {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  padding: 10px 12px;
  cursor: pointer;
}
.ds-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); margin-bottom: 3px; }
.ds-value { font-size: 12px; color: var(--text); font-weight: 600; margin-bottom: 6px; overflow: hidden; }
.ds-value .ds-name { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ds-value .ds-meta { display: block; font-size: 10px; color: var(--text-dim); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.ds-change-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.15s;
}
.ds-change-btn:hover { background: var(--accent-glow); }

/* ── Main wrap ──────────────────────────────────────────────── */
.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Top bar ────────────────────────────────────────────────── */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.page-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.geofence-warning {
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-glow);
  border: 1px solid var(--accent-dim);
  padding: 4px 10px;
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

/* ── Profile menu ───────────────────────────────────────────── */
.profile-menu { position: relative; }

.profile-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid var(--border);
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  transition: background 0.15s;
}
.profile-btn:hover { background: var(--bg-raised); }

.avatar {
  width: 28px; height: 28px;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; font-family: var(--mono);
  border-radius: 50%;
}

.chevron { width: 14px; height: 14px; color: var(--text-sub); }

.profile-dropdown {
  position: absolute;
  right: 0; top: calc(100% + 4px);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  min-width: 220px;
  z-index: var(--z-dropdown, 1100);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

/* Contain Leaflet's high internal z-indexes (panes/controls up to ~1000)
   in their own stacking context so they can never paint over overlays.
   Applies to both map pages — createMap() adds .leaflet-container. */
.leaflet-container {
  isolation: isolate;
  z-index: var(--z-map, 1);
}

.profile-info { padding: 12px 16px; }
.profile-info-name { font-weight: 600; font-size: 14px; }
.profile-info-email { color: var(--text-sub); font-size: 12px; margin-top: 2px; }
.profile-info-role { margin-top: 6px; display: inline-block; }

.dropdown-divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

.dropdown-item {
  display: block; width: 100%;
  background: none; border: none;
  padding: 9px 16px;
  text-align: left;
  color: var(--text-sub);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.dropdown-item:hover { background: var(--bg-hover); color: var(--text); }
.dropdown-item.text-danger:hover { color: var(--inuse); }

/* ── Page content ───────────────────────────────────────────── */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Footer ─────────────────────────────────────────────────── */
.app-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}
.footer-inner {
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.footer-brand { font-weight: 700; font-size: 12px; color: var(--text-sub); }
.footer-sep { color: var(--text-dim); font-size: 12px; }
.footer-ia-logo { height: 20px; width: auto; opacity: 0.8; }
.footer-pps-logo { height: 20px; width: auto; opacity: 0.8; }
.footer-link { font-size: 12px; color: var(--text-sub); }
.footer-link:hover { color: var(--accent); }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 20px 24px;
}

.card-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 12px;
  font-weight: 600;
}

.card-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

/* ── KPI / Telemetry readouts ───────────────────────────────── */
.kpi-block { display: flex; flex-direction: column; gap: 4px; }
.kpi-label { font-size: 11px; color: var(--text-sub); text-transform: uppercase; letter-spacing: 0.08em; }
.kpi-value {
  font-family: var(--mono);
  font-size: 36px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.kpi-value.accent { color: var(--accent); }
.kpi-value.idle-color { color: var(--idle); }
.kpi-value.inuse-color { color: var(--inuse); }
.kpi-sub { font-size: 12px; color: var(--text-sub); }

/* ── Utilisation bar ────────────────────────────────────────── */
.util-bar-wrap { height: 8px; background: var(--idle-dim); border: 1px solid var(--border); margin: 8px 0; }
.util-bar { height: 100%; background: var(--inuse); transition: width 0.4s; }

/* ── Tables ─────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 8px 12px;
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-dim);
  color: var(--text-sub);
  vertical-align: middle;
}
/* Sortable column headers */
.data-table th[data-col]:hover {
  color: var(--text);
  background: rgba(255,255,255,0.03);
}
.data-table th[data-col] .sort-arrow {
  display: inline-block;
  width: 14px;
  font-size: 10px;
  color: var(--accent);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); color: var(--text); }
.data-table td.mono { font-family: var(--mono); color: var(--text); }
.data-table td.bold { font-weight: 600; color: var(--text); }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border: 1px solid;
}
.badge-admin { color: var(--accent); border-color: var(--accent-dim); background: var(--accent-glow); }
.badge-user { color: var(--text-sub); border-color: var(--border); }
.badge-idle { color: var(--idle); border-color: rgba(16,185,129,0.4); background: var(--idle-dim); }
.badge-inuse { color: var(--inuse); border-color: rgba(239,68,68,0.4); background: var(--inuse-dim); }
.badge-ready { color: var(--idle); border-color: rgba(16,185,129,0.4); }
.badge-processing { color: var(--accent); border-color: var(--accent-dim); }
.badge-error { color: var(--inuse); border-color: rgba(239,68,68,0.4); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  border: none; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 9px 18px;
  transition: opacity 0.15s, background 0.15s;
  text-decoration: none;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #000; }
.btn-primary:hover:not(:disabled) { background: #D97706; }
.btn-ghost { background: transparent; color: var(--text-sub); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: var(--inuse); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #DC2626; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ── Form fields ────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--text-sub); font-weight: 500; }
.field input, .field select {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field select option { background: var(--bg-raised); }

/* ── Login screen ───────────────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
.login-wrap { width: 100%; max-width: 420px; padding: 24px; }
.login-card { background: var(--bg-card); border: 1px solid var(--border); border-left: 3px solid var(--accent); padding: 36px; }
.login-brand { text-align: center; margin-bottom: 28px; }
.login-logo { height: 48px; width: auto; }
.login-title { font-size: 20px; font-weight: 700; margin-bottom: 24px; color: var(--text); }
.login-error { color: var(--inuse); font-size: 13px; background: var(--inuse-dim); border: 1px solid rgba(239,68,68,0.3); padding: 8px 12px; margin-bottom: 14px; }
.login-footer { display: flex; align-items: center; gap: 8px; margin-top: 28px; border-top: 1px solid var(--border); padding-top: 20px; color: var(--text-sub); font-size: 12px; }
.login-ia-logo { height: 18px; width: auto; opacity: 0.7; }

/* ── Modals ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: var(--z-modal, 1200);
  padding: 24px;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  width: 100%; max-width: 680px;
  max-height: 80vh;
  display: flex; flex-direction: column;
}
.modal-sm { max-width: 420px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-sub); font-size: 18px; cursor: pointer; padding: 4px 8px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 16px; }

/* ── Upload zone ────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--accent); background: var(--accent-glow); }
.upload-icon { font-size: 32px; color: var(--accent); margin-bottom: 8px; }
.upload-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.upload-link { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* Progress bar */
.progress-label { font-size: 13px; color: var(--text-sub); margin-bottom: 8px; }
.progress-bar-wrap { background: var(--bg-raised); border: 1px solid var(--border); height: 6px; }
.progress-bar { height: 100%; background: var(--accent); width: 0%; transition: width 0.3s; }

/* Duplicate warning */
.dup-warning { border: 1px solid var(--accent-dim); background: var(--accent-glow); padding: 16px; }
.dup-title { font-weight: 600; color: var(--accent); margin-bottom: 8px; }
.dup-details { font-size: 13px; color: var(--text-sub); margin-bottom: 12px; }
.dup-actions { display: flex; gap: 8px; }

/* Dataset list */
.ds-list-header { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.ds-list { display: flex; flex-direction: column; gap: 2px; max-height: 280px; overflow-y: auto; }
.ds-empty { color: var(--text-dim); font-size: 13px; padding: 12px 0; text-align: center; }
.ds-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s;
}
.ds-item:hover { background: var(--bg-hover); }
.ds-item.selected { border-color: var(--accent); background: var(--accent-glow); }
.ds-item-info { min-width: 0; }
.ds-item-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ds-item-meta { font-size: 11px; color: var(--text-sub); margin-top: 2px; }
.ds-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Loading / spinner ──────────────────────────────────────── */
.loading-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 60px; color: var(--text-sub); }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Charts ─────────────────────────────────────────────────── */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { max-height: 260px; }

/* ── Section row helpers ────────────────────────────────────── */
.row { display: flex; gap: 16px; }
.row > .card { flex: 1; min-width: 0; }
.col-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.col-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }

/* ── Bucket selector ────────────────────────────────────────── */
.bucket-selector {
  display: flex; gap: 2px; border: 1px solid var(--border); width: fit-content;
}
.bucket-btn {
  background: none; border: none; padding: 5px 14px;
  color: var(--text-sub); font-size: 12px; cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.bucket-btn.active { background: var(--accent); color: #000; font-weight: 700; }
.bucket-btn:hover:not(.active) { background: var(--bg-hover); color: var(--text); }

/* ── Map (Area Management) ──────────────────────────────────── */
#leaflet-map { width: 100%; height: 100%; min-height: 480px; }
.map-wrap { flex: 1; border: 1px solid var(--border); overflow: hidden; min-height: 480px; }
.areas-layout { display: flex; gap: 16px; height: calc(100vh - 200px); min-height: 500px; }
.areas-sidebar { width: 280px; flex-shrink: 0; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.area-item { background: var(--bg-card); border: 1px solid var(--border); padding: 10px 14px; }
.area-item-name { font-weight: 600; font-size: 13px; }
.area-item-actions { display: flex; gap: 6px; margin-top: 8px; }

/* Leaflet dark overrides */
.leaflet-container { background: #0A1020; }
.leaflet-control-zoom a { background: var(--bg-raised) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-control-zoom a:hover { background: var(--bg-hover) !important; }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Responsive (basic) ─────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 60px; }
  .nav-item span { display: none; }
  .sidebar-brand { padding: 12px 10px; }
  .sidebar-logo { height: 28px; }
  .brand-wordmark { font-size: 15px; }
  .ds-label, .ds-value, .ds-change-btn { display: none; }
  .col-3 { grid-template-columns: repeat(2, 1fr); }
}

/* ── Misc ───────────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-mono { font-family: var(--mono); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-dim); }
.empty-state h3 { font-size: 16px; color: var(--text-sub); margin-bottom: 8px; }
.empty-state p { font-size: 13px; margin-bottom: 16px; }

.pct-bar-row { display: flex; align-items: center; gap: 10px; }
.pct-bar-track { flex: 1; height: 6px; background: var(--bg-raised); border: 1px solid var(--border); }
.pct-bar-fill { height: 100%; transition: width 0.4s; }
.pct-label { font-family: var(--mono); font-size: 12px; color: var(--text-sub); min-width: 40px; text-align: right; }
