/* ═══════════════════════════════════════════════════════════
   AGORAH — Layout principal
   ═══════════════════════════════════════════════════════════ */

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

body {
  font-family: var(--font-ui);
  overflow: hidden;
  background: var(--gray-100);
  color: var(--gray-800);
}

/* ── MAP ──────────────────────────────────────────────────── */
#map {
  position: fixed;
  inset: 0;
  z-index: 1;
}

/* ── HEADER ───────────────────────────────────────────────── */
#header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--agorah-teal-dark);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  box-shadow: var(--shadow-md);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header-brand .logo-mark {
  width: 30px; height: 30px;
  background: var(--agorah-teal-mid);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 13px;
  color: white;
  letter-spacing: -0.5px;
}

.header-brand .brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.header-brand .brand-name {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 13px;
  color: white;
  letter-spacing: 0.5px;
}

.header-brand .brand-sub {
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  font-weight: 400;
  letter-spacing: 0.2px;
}

.header-divider {
  width: 1px;
  height: 28px;
  background: rgba(255,255,255,0.12);
  margin: 0 16px;
  flex-shrink: 0;
}

.header-kpis {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}

.header-kpi {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
  transition: background var(--dur-fast) var(--ease);
}

.header-kpi:hover {
  background: rgba(255,255,255,0.10);
}

.header-kpi .kpi-icon {
  font-size: 13px;
  line-height: 1;
}

.header-kpi .kpi-body {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.header-kpi .kpi-val {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: white;
}

.header-kpi .kpi-lbl {
  font-size: 9px;
  color: rgba(255,255,255,0.45);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.kpi-dot.green   { background: var(--fluide-color); box-shadow: 0 0 6px var(--fluide-color); }
.kpi-dot.amber   { background: var(--dense-color);  box-shadow: 0 0 6px var(--dense-color); }
.kpi-dot.red     { background: var(--congestion-color); box-shadow: 0 0 6px var(--congestion-color); }
.kpi-dot.yellow  { background: var(--carjaune-color); box-shadow: 0 0 6px var(--carjaune-color); }
.kpi-dot.pulse   { animation: pulse-dot 2s infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.7); }
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.btn-refresh {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  color: white;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
  font-family: var(--font-ui);
}

.btn-refresh:hover { background: rgba(255,255,255,0.14); }

.btn-refresh svg { flex-shrink: 0; }

.refresh-timer {
  font-family: var(--font-mono);
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  min-width: 32px;
}

/* ── LEFT PANEL ───────────────────────────────────────────── */
#panel-left {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  left: 12px;
  width: var(--panel-w);
  max-height: calc(100vh - var(--header-h) - 24px);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.panel-title {
  font-family: var(--font-head);
  font-size: 11px;
  font-weight: 700;
  color: var(--agorah-teal);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.panel-scroll {
  overflow-y: auto;
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-scroll::-webkit-scrollbar { width: 3px; }
.panel-scroll::-webkit-scrollbar-track { background: transparent; }
.panel-scroll::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }

/* ── LEGEND ───────────────────────────────────────────────── */
#legend {
  position: fixed;
  bottom: 28px;
  right: 52px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 50;
  padding: 10px 14px;
}

.legend-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--gray-500);
  margin-bottom: 8px;
}

.legend-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--gray-700);
}

.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-range {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--gray-400);
  margin-left: auto;
}

/* ── SIDEBAR ──────────────────────────────────────────────── */
#sidebar {
  position: fixed;
  top: var(--header-h);
  right: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--header-h));
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-left: var(--glass-border);
  box-shadow: var(--shadow-xl);
  z-index: 60;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease);
  overflow: hidden;
}

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

/* ── LOADING OVERLAY ──────────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--agorah-teal-dark);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: opacity var(--dur-slow) var(--ease);
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-logo {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 28px;
  color: white;
  letter-spacing: 2px;
}

.loading-sub {
  font-size: 12px;
  color: rgba(255,255,255,0.45);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.loading-bar-wrap {
  width: 200px;
  height: 3px;
  background: rgba(255,255,255,0.12);
  border-radius: 2px;
  overflow: hidden;
}

.loading-bar {
  height: 100%;
  width: 0;
  background: var(--agorah-teal-mid);
  border-radius: 2px;
  animation: loadbar 1.8s var(--ease) forwards;
}

@keyframes loadbar {
  0%   { width: 0; }
  60%  { width: 75%; }
  100% { width: 100%; }
}

/* ── TOAST CONTAINER ──────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

/* ── LEAFLET OVERRIDES ────────────────────────────────────── */
.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow-md) !important;
}

.leaflet-control-zoom a {
  background: var(--glass-bg) !important;
  backdrop-filter: var(--glass-blur);
  color: var(--agorah-teal) !important;
  border: 1px solid var(--gray-200) !important;
  font-weight: 700;
  transition: background var(--dur-fast) var(--ease);
}

.leaflet-control-zoom a:hover {
  background: var(--agorah-teal-pale) !important;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-lg) !important;
  border: var(--glass-border) !important;
  background: var(--glass-bg) !important;
  backdrop-filter: var(--glass-blur);
}

.leaflet-popup-tip { background: var(--glass-bg) !important; }

/* ── RESPONSIVE ───────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --panel-w: calc(100vw - 24px);
    --sidebar-w: 100vw;
  }

  #panel-left {
    display: none;
  }

  #sidebar {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    top: auto;
    bottom: 0;
    height: 70vh;
    width: 100vw;
    transform: translateY(100%);
    border-left: none;
    border-top: var(--glass-border);
  }

  #sidebar.open { transform: translateY(0); }
}
