/* ────────────────────────────────────────
   Fleet Tracker — Dashboard Styles
   ──────────────────────────────────────── */

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

:root {
  --bg:           #0f1117;
  --surface:      #1a1d27;
  --surface-2:    #222538;
  --border:       #2a2d3a;
  --border-2:     #343749;
  --accent:       #3b82f6;
  --accent-hover: #2563eb;
  --green:        #22c55e;
  --amber:        #f59e0b;
  --red:          #ef4444;
  --text:         #e2e8f0;
  --text-muted:   #94a3b8;
  --text-dim:     #64748b;

  --topnav-h:     52px;
  --sidebar-w:    280px;
  --panel-w:      340px;
  --radius:       8px;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; }

/* ── Top Nav ── */
.topnav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--topnav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 1rem; gap: 1rem;
}
.topnav-left  { display: flex; align-items: center; gap: 0.75rem; flex: 1; }
.topnav-center { display: flex; align-items: center; gap: 0.5rem; }
.topnav-right  { display: flex; align-items: center; gap: 0.4rem; flex: 1; justify-content: flex-end; }

.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1rem; }
.brand-icon { color: var(--accent); font-size: 1.1rem; }

.sidebar-toggle, .nav-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 1rem;
  padding: 0.4rem 0.6rem; border-radius: var(--radius);
  display: flex; align-items: center; gap: 0.4rem;
  transition: background 0.15s, color 0.15s;
}
.sidebar-toggle:hover, .nav-btn:hover { background: var(--surface-2); color: var(--text); }

.alert-btn { position: relative; }
.badge {
  position: absolute; top: 2px; right: 2px;
  background: var(--red); color: #fff;
  font-size: 0.65rem; font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 999px; padding: 0 3px;
  display: flex; align-items: center; justify-content: center;
}

/* connection status */
.connection-status { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text-muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); transition: background 0.3s; }
.status-dot.connected { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.disconnected { background: var(--red); }

/* User dropdown */
.user-menu { position: relative; }
.dropdown {
  display: none; position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface-2); border: 1px solid var(--border-2);
  border-radius: var(--radius); min-width: 200px;
  padding: 0.4rem 0; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 2000;
}
.dropdown.open { display: block; }
.dropdown-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 1rem; color: var(--text-muted);
  font-size: 0.875rem; cursor: pointer;
  background: none; border: none; width: 100%; text-align: left;
  text-decoration: none; transition: background 0.1s, color 0.1s;
}
.dropdown-item:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.dropdown-sep { border: none; border-top: 1px solid var(--border); margin: 0.4rem 0; }

/* ── Layout ── */
.layout {
  position: fixed;
  top: var(--topnav-h); left: 0; right: 0; bottom: 0;
  display: flex; overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width 0.25s ease, opacity 0.25s ease;
  flex-shrink: 0;
}
.sidebar.collapsed { width: 0; opacity: 0; pointer-events: none; }

.sidebar-search {
  padding: 0.75rem; position: relative;
  border-bottom: 1px solid var(--border);
}
.sidebar-search i {
  position: absolute; left: 1.3rem; top: 50%; transform: translateY(-50%);
  color: var(--text-dim); font-size: 0.85rem;
}
.sidebar-search input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 0.875rem; padding: 0.45rem 0.7rem 0.45rem 2rem;
  outline: none; transition: border-color 0.15s;
}
.sidebar-search input:focus { border-color: var(--accent); }

.sidebar-section { overflow: hidden; display: flex; flex-direction: column; }
.sidebar-section:last-child { flex: 1; overflow: hidden; }

.section-header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.6rem 1rem;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.section-header i { font-size: 0.8rem; }
.count-badge {
  margin-left: auto; background: var(--surface-2);
  border-radius: 999px; font-size: 0.7rem; padding: 1px 7px;
  color: var(--text-dim);
}

.entity-list {
  list-style: none; overflow-y: auto; flex: 1;
}
.entity-item {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.65rem 1rem; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  transition: background 0.1s;
}
.entity-item:hover { background: var(--surface-2); }
.entity-item.active { background: rgba(59,130,246,0.1); border-left: 2px solid var(--accent); }

.entity-status {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-dim); flex-shrink: 0;
}
.entity-status.moving  { background: var(--green); box-shadow: 0 0 5px var(--green); }
.entity-status.parked  { background: var(--amber); }
.entity-status.offline { background: var(--text-dim); }

.entity-info { flex: 1; min-width: 0; }
.entity-name { font-size: 0.875rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entity-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 1px; }

.entity-speed {
  font-size: 0.75rem; color: var(--text-muted); text-align: right; flex-shrink: 0;
}
.list-placeholder { padding: 1rem; color: var(--text-dim); font-size: 0.85rem; text-align: center; list-style: none; }

/* ── Map ── */
.map-container {
  flex: 1; position: relative; overflow: hidden;
}
#map { width: 100%; height: 100%; background: #1a1d27; }

/* Leaflet overrides */
.leaflet-bar a { background-color: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-bar a:hover { background-color: var(--surface-2) !important; }
.leaflet-control-attribution { background: rgba(15,17,23,0.7) !important; color: var(--text-dim) !important; }
.leaflet-popup-content-wrapper { background: var(--surface) !important; color: var(--text) !important; border: 1px solid var(--border) !important; border-radius: var(--radius) !important; box-shadow: 0 4px 20px rgba(0,0,0,0.5) !important; }
.leaflet-popup-tip { background: var(--surface) !important; }
.leaflet-popup-close-button { color: var(--text-muted) !important; }

/* ── Detail Panel ── */
.detail-panel {
  width: var(--panel-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width 0.25s ease, opacity 0.25s ease;
  flex-shrink: 0;
}
.detail-panel.hidden { width: 0; opacity: 0; pointer-events: none; }

.panel-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 0.75rem;
  flex-shrink: 0;
}
.panel-title-row { display: flex; align-items: center; gap: 0.75rem; flex: 1; min-width: 0; }
.panel-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--surface-2); display: flex;
  align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
}
.panel-header h2 { font-size: 1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-subtitle { font-size: 0.75rem; color: var(--text-muted); }
.panel-close { background: none; border: none; color: var(--text-dim); cursor: pointer; padding: 0.3rem; font-size: 1rem; border-radius: 6px; }
.panel-close:hover { color: var(--text); background: var(--surface-2); }

.panel-tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.tab-btn {
  flex: 1; background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 0.8rem; font-weight: 500;
  padding: 0.65rem; border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { flex: 1; overflow-y: auto; padding: 1rem; }
.tab-content.hidden { display: none; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-bottom: 1rem; }
.stat-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.7rem;
}
.stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.3rem; }
.stat-value { font-size: 1.1rem; font-weight: 600; }
.stat-value.green { color: var(--green); }
.stat-value.amber { color: var(--amber); }
.stat-value.red   { color: var(--red); }

.section-label { font-size: 0.7rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; margin-top: 1rem; }

.diag-item { display: flex; align-items: center; justify-content: space-between; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.diag-label { font-size: 0.8rem; color: var(--text-muted); }
.diag-value { font-size: 0.85rem; font-weight: 500; }

/* Trip list */
.trip-list { list-style: none; }
.trip-item {
  padding: 0.75rem 0; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.1s; border-radius: 6px;
}
.trip-item:hover { background: var(--surface-2); padding-left: 0.5rem; }
.trip-date { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.trip-stats { display: flex; gap: 1rem; }
.trip-stat { display: flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; color: var(--text-muted); }
.trip-stat i { font-size: 0.7rem; color: var(--text-dim); }
.trip-stat strong { color: var(--text); }

.load-more {
  width: 100%; margin-top: 0.75rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-muted);
  cursor: pointer; font-size: 0.85rem; padding: 0.6rem;
  transition: background 0.15s, color 0.15s;
}
.load-more:hover { background: var(--border); color: var(--text); }

/* ── Alert list (panel) ── */
.alert-list { list-style: none; }
.alert-item {
  display: flex; gap: 0.75rem; align-items: flex-start;
  padding: 0.7rem 0; border-bottom: 1px solid var(--border);
}
.alert-dot {
  width: 8px; height: 8px; border-radius: 50%; margin-top: 4px; flex-shrink: 0;
}
.alert-dot.info     { background: var(--accent); }
.alert-dot.warning  { background: var(--amber); }
.alert-dot.critical { background: var(--red); }
.alert-msg { font-size: 0.825rem; line-height: 1.4; }
.alert-time { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* ── Playback Bar ── */
.playback-bar {
  position: absolute; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  display: flex; align-items: center; gap: 1rem;
  min-width: 560px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  z-index: 800;
}
.playback-bar.hidden { display: none; }
.playback-info { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.playback-info i { color: var(--accent); }
.playback-info span { font-size: 0.875rem; font-weight: 600; }
.playback-meta { color: var(--text-muted) !important; font-weight: 400 !important; font-size: 0.78rem !important; }
.playback-controls { display: flex; gap: 0.4rem; flex-shrink: 0; }
.pb-btn {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-muted);
  cursor: pointer; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; transition: background 0.15s, color 0.15s;
}
.pb-btn:hover { background: var(--border-2); color: var(--text); }
.pb-btn.pb-play { background: var(--accent); color: #fff; border-color: var(--accent); }
.pb-btn.pb-play:hover { background: var(--accent-hover); }
.playback-scrubber { flex: 1; display: flex; align-items: center; gap: 0.6rem; }
.playback-scrubber input[type=range] { flex: 1; accent-color: var(--accent); cursor: pointer; }
.scrubber-time { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.pb-close {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 1rem; padding: 0.25rem; flex-shrink: 0;
}
.pb-close:hover { color: var(--text); }

/* ── Alert Drawer ── */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 1100;
}
.drawer-backdrop.hidden { display: none; }
.alert-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 420px; background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 1200;
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.25s ease;
}
.alert-drawer.open { transform: translateX(0); }
.alert-drawer.hidden { display: none; }
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-header h2 { font-size: 1rem; display: flex; align-items: center; gap: 0.5rem; }
.drawer-actions { display: flex; align-items: center; gap: 0.5rem; }
.text-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-muted); cursor: pointer; font-size: 0.8rem; padding: 0.35rem 0.75rem;
  transition: background 0.15s, color 0.15s;
}
.text-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 1rem; padding: 0.3rem;
  border-radius: var(--radius); transition: background 0.1s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.full-alert-list { list-style: none; overflow-y: auto; flex: 1; padding: 0.5rem 1.25rem; }
.full-alert-item {
  display: flex; gap: 0.75rem; align-items: flex-start;
  padding: 0.85rem 0; border-bottom: 1px solid var(--border);
}
.full-alert-item.acknowledged .alert-msg { opacity: 0.5; }
.alert-ack-btn {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-dim); cursor: pointer; font-size: 0.7rem; padding: 2px 8px;
  transition: background 0.1s;
}
.alert-ack-btn:hover { background: var(--surface-2); color: var(--text); }

/* ── Toast Notifications ── */
.toast-container {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  z-index: 3000; display: flex; flex-direction: column; gap: 0.5rem;
  pointer-events: none;
}
.toast {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.75rem 1rem;
  display: flex; align-items: center; gap: 0.6rem;
  font-size: 0.875rem; box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  min-width: 280px; max-width: 420px;
  animation: toastIn 0.25s ease;
  pointer-events: auto;
}
.toast.warning { border-left: 3px solid var(--amber); }
.toast.critical { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }
.toast.success { border-left: 3px solid var(--green); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Geofence mode indicator ── */
.nav-btn.geofence-active { background: rgba(59,130,246,0.2); color: var(--accent); }

/* ── Utility ── */
.hidden { display: none !important; }
