/* ============================================================
   PREMIUM ANALYTICS THEME � Glassmorphism + Gradient Edition
   All original IDs and API bindings remain intact.
   ============================================================ */

/* ---------- Premium Color Tokens ---------- */
:root {
  --accent-2: #60a5fa;
  --accent-3: #a78bfa;
  --gold: #fbbf24;
  --rose: #fb7185;
  --shadow: 0 22px 70px rgba(0, 0, 0, .45);
  --glass-edge: rgba(255, 255, 255, .08);
  --glass-bg: rgba(255, 255, 255, .04);
  --glass-bg-strong: rgba(255, 255, 255, .08);
  --gradient-accent: linear-gradient(135deg, #5eead4, #60a5fa);
  --gradient-warm: linear-gradient(135deg, #fbbf24, #fb7185);
  --gradient-cold: linear-gradient(135deg, #60a5fa, #a78bfa);
  --kpi-glow: 0 0 30px rgba(94, 234, 212, .08);
}

/* ---------- Premium Body Background ---------- */
body {
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(94, 234, 212, .10), transparent 60%),
    radial-gradient(ellipse 60% 40% at 90% 5%, rgba(96, 165, 250, .09), transparent 55%),
    radial-gradient(ellipse 50% 30% at 50% 100%, rgba(167, 139, 250, .06), transparent 50%),
    linear-gradient(165deg, #050b18, #080d1a 40%, #0a1428 70%, #060c1a);
}

/* ========================
   SIDEBAR � Glass Premium
   ======================== */
.side {
  position: fixed;
  inset: 0 auto 0 0;
  width: 240px;
  background: rgba(5, 9, 20, .72);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border-right: 1px solid var(--glass-edge);
  z-index: 100;
  padding: 12px 14px;
}
.side-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px 0;
  padding: 0 4px;
}
.side h2 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -.03em;
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0;
  position: relative;
}
.side h2::after {
  content: '?';
  -webkit-text-fill-color: initial;
  color: var(--accent);
  font-size: 8px;
  margin-left: 4px;
  animation: liveDot 2s infinite;
  display: inline-block;
}
@keyframes liveDot {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}
.side a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  text-decoration: none;
  padding: 11px 14px;
  border-radius: 10px;
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 500;
  transition: all .25s cubic-bezier(.4, 0, .2, 1);
  position: relative;
}
/* Sidebar nav icons � use CSS masks so color follows --muted/text */
.side a::before {
  content: '';
  display: inline-flex;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  background-color: var(--muted);
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  transition: background-color .25s;
}
.side a:hover::before {
  background-color: var(--text);
}
.side a.active::before {
  background-color: var(--accent);
}
/* Dashboard � grid icon */
.side a[href="/"]::before {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Crect x='3' y='3' width='7' height='7'/%3E%3Crect x='14' y='3' width='7' height='7'/%3E%3Crect x='3' y='14' width='7' height='7'/%3E%3Crect x='14' y='14' width='7' height='7'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Crect x='3' y='3' width='7' height='7'/%3E%3Crect x='14' y='3' width='7' height='7'/%3E%3Crect x='3' y='14' width='7' height='7'/%3E%3Crect x='14' y='14' width='7' height='7'/%3E%3C/svg%3E");
}
/* Reports � bar chart icon */
.side a[href="/reports"]::before {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cline x1='18' y1='20' x2='18' y2='10'/%3E%3Cline x1='12' y1='20' x2='12' y2='4'/%3E%3Cline x1='6' y1='20' x2='6' y2='14'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cline x1='18' y1='20' x2='18' y2='10'/%3E%3Cline x1='12' y1='20' x2='12' y2='4'/%3E%3Cline x1='6' y1='20' x2='6' y2='14'/%3E%3C/svg%3E");
}
/* Setup � gear icon */
.side a[href="/setup"]::before {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z'/%3E%3C/svg%3E");
}
/* Logout � exit door icon */
.side a[href="/logout"]::before {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4'/%3E%3Cpolyline points='16 17 21 12 16 7'/%3E%3Cline x1='21' y1='12' x2='9' y2='12'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4'/%3E%3Cpolyline points='16 17 21 12 16 7'/%3E%3Cline x1='21' y1='12' x2='9' y2='12'/%3E%3C/svg%3E");
}

/* Gradient hover overlay on ::after (since ::before is used for icons) */
.side a::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: var(--gradient-accent);
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
  z-index: -1;
}
.side a:hover::after,
.side a.active::after {
  opacity: .12;
}
.side a:hover {
  color: var(--text);
  transform: translateX(4px);
}
.side a.active {
  color: var(--accent);
  font-weight: 600;
  background: rgba(94, 234, 212, .07);
  border: 1px solid rgba(94, 234, 212, .15);
}
.side a span {
  position: relative;
  z-index: 1;
}
.side-toggle {
  display: flex;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--glass-edge);
  color: var(--muted);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  align-items: center;
  justify-content: center;
  padding: 0;
  min-height: 0;
  transition: all .2s;
}
.side-toggle:hover {
  background: rgba(255, 255, 255, .1);
  color: var(--text);
}

/* Desktop collapsed sidebar */
@media (min-width: 901px) {
  .side.collapsed {
    width: 56px;
    padding: 12px 10px;
  }
  .side.collapsed .side-header h2,
  .side.collapsed .nav-label {
    display: none;
  }
  .side.collapsed .side-header {
    margin-bottom: 8px;
    padding: 0;
    justify-content: center;
  }
  .side.collapsed a {
    justify-content: center;
    padding: 12px 0;
    margin-bottom: 2px;
    gap: 0;
  }
  .side.collapsed a::after {
    display: none;
  }
  .side.collapsed ~ .shell {
    margin-left: 56px;
  }
}

/* Sidebar backdrop overlay */
.side-backdrop {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(6px);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
.side-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* ========================
   SHELL / LAYOUT
   ======================== */
.shell { 
  margin-left: 240px; 
  padding: 14px; 
  position: relative;
  z-index: 1;
}

/* ========================
   TOP HEADER
   ======================== */
.top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}
.top h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.2;
}
.top p {
  color: var(--muted);
  margin: 2px 0 0;
  font-size: 13px;
}
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}
select option { 
  color: #eef2ff; 
  background: #0f172a; 
}

/* ========================
   KPI CARDS � Premium Glass
   ======================== */
.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 10px;
  margin: 0 0 12px;
}
.kpis article {
  position: relative;
  padding: 16px 16px 14px;
  background: var(--glass-bg);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--glass-edge);
  border-radius: 14px;
  box-shadow: var(--shadow), var(--kpi-glow);
  overflow: hidden;
  transition: transform .3s cubic-bezier(.4, 0, .2, 1), box-shadow .3s;
}
.kpis article:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow), 0 0 40px rgba(94, 234, 212, .12);
}
/* KPI gradient accent bar */
.kpis article::after {
  content: '';
  position: absolute;
  inset: auto 0 0;
  height: 3px;
  background: var(--gradient-accent);
  opacity: .7;
}
/* KPI shimmer overlay */
.kpis article::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, .03) 50%, transparent 60%);
  pointer-events: none;
}
.kpis article:nth-child(2)::after { background: var(--gradient-cold); }
.kpis article:nth-child(3)::after { background: var(--gradient-warm); }
.kpis article:nth-child(4)::after { background: linear-gradient(135deg, #fb7185, #f97316); }
.kpis article:nth-child(5)::after { background: linear-gradient(135deg, #34d399, #5eead4); }
.kpis span {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 4px;
}
.kpis strong {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.1;
  display: block;
}
.kpis small {
  display: block;
  color: var(--accent);
  font-size: 11px;
  margin-top: 3px;
  opacity: .8;
  font-weight: 500;
}

/* ========================
   PANELS � Glass Cards
   ======================== */
.panel {
  padding: 16px;
  min-height: 260px;
  background: var(--glass-bg);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--glass-edge);
  border-radius: 14px;
  box-shadow: var(--shadow);
  transition: transform .3s cubic-bezier(.4, 0, .2, 1), box-shadow .3s;
  position: relative;
  overflow: hidden;
}
.panel:hover {
  box-shadow: var(--shadow), 0 0 30px rgba(94, 234, 212, .06);
}
.panel h2 {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -.01em;
  margin: 0 0 10px;
  color: var(--text);
}
.panel canvas { 
  width: 100% !important; 
  height: 240px !important; 
  max-width: 100% !important;
}
.report-grid .panel { min-height: 410px; }
.report-grid .panel canvas { height: 255px !important; }

/* ========================
   CARD RESIZE & LOCK
   ======================== */
.panel.card-resizable {
  overflow: visible;
  min-width: 200px;
  min-height: 150px;
  transition: none;
  display: flex;
  flex-direction: column;
  position: relative;
}
/* Make map, canvas, and list containers grow/shrink with the panel */
.panel.card-resizable .map,
.panel.card-resizable canvas,
.panel.card-resizable .list,
.panel.card-resizable .funnel,
.panel.card-resizable .detail-box,
.panel.card-resizable .table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  height: auto !important;
  max-height: none !important;
}
.panel.card-resizable .map { min-height: 120px; }
.panel.card-resizable canvas { min-height: 80px; }

/* -------- 8 Resize Handles (4 corners + 4 edges) -------- */
.panel.card-resizable .resize-handle {
  position: absolute;
  z-index: 10;
  background: transparent;
  opacity: 0;
  transition: opacity .15s;
}
.panel.card-resizable:hover .resize-handle { opacity: 1; }

/* Corner handles — 12×12 squares */
.panel.card-resizable .resize-handle.nw {
  top: -5px; left: -5px; width: 14px; height: 14px;
  cursor: nwse-resize;
}
.panel.card-resizable .resize-handle.ne {
  top: -5px; right: -5px; width: 14px; height: 14px;
  cursor: nesw-resize;
}
.panel.card-resizable .resize-handle.sw {
  bottom: -5px; left: -5px; width: 14px; height: 14px;
  cursor: nesw-resize;
}
.panel.card-resizable .resize-handle.se {
  bottom: -5px; right: -5px; width: 14px; height: 14px;
  cursor: nwse-resize;
}

/* Edge handles — 8px wide/tall bars */
.panel.card-resizable .resize-handle.n {
  top: -4px; left: 14px; right: 14px; height: 8px;
  cursor: n-resize;
}
.panel.card-resizable .resize-handle.s {
  bottom: -4px; left: 14px; right: 14px; height: 8px;
  cursor: s-resize;
}
.panel.card-resizable .resize-handle.e {
  right: -4px; top: 14px; bottom: 14px; width: 8px;
  cursor: e-resize;
}
.panel.card-resizable .resize-handle.w {
  left: -4px; top: 14px; bottom: 14px; width: 8px;
  cursor: w-resize;
}

/* Bottom-right decorative grip (visual only) */
.panel.card-resizable .resize-grip {
  position: absolute;
  right: 3px; bottom: 3px;
  width: 14px; height: 14px;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
  background: linear-gradient(135deg, transparent 35%, var(--accent, #5eead4) 35%, var(--accent, #5eead4) 50%, transparent 50%, transparent 60%, var(--accent, #5eead4) 60%, var(--accent, #5eead4) 75%, transparent 75%);
  border-radius: 0 0 14px 0;
}
.panel.card-resizable:hover .resize-grip { opacity: .5; }

/* Auto-reflow: unlocked panels in a grid section wrap naturally */
.grid.card-reflow {
  display: flex;
  flex-wrap: wrap;
  gap: var(--grid-gap, 12px);
}
.grid.card-reflow > .panel {
  flex: 1 1 280px;
  min-width: 200px;
  max-width: 100%;
}
.grid.card-reflow > .panel.card-resizable {
  flex: 0 0 auto;
  width: var(--panel-w, auto);
}
.panel .card-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 5;
  opacity: 0;
  transition: opacity .2s;
  background: linear-gradient(135deg, transparent 40%, var(--accent, #5eead4) 40%, var(--accent, #5eead4) 55%, transparent 55%, transparent 65%, var(--accent, #5eead4) 65%, var(--accent, #5eead4) 80%, transparent 80%);
  border-radius: 0 0 14px 0;
}
.panel.card-resizable:hover .card-resize-handle { opacity: .6; }
.panel.card-resizable .card-resize-handle:hover { opacity: 1; }

/* Lock/Unlock button */
.card-lock-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  background: none;
  cursor: pointer;
  opacity: .35;
  transition: opacity .2s, color .2s;
  padding: 0;
  margin-left: auto;
  color: var(--text-muted, #667);
  flex-shrink: 0;
}
.card-lock-btn:hover { opacity: 1; }
.card-lock-btn.locked { opacity: .6; color: var(--accent, #5eead4); }
.card-lock-btn svg { width: 16px; height: 16px; fill: currentColor; }

/* ========================
   MAP � Glass Container
   ======================== */
.map {
  height: 320px;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

/* Map auto-focus toggle checkbox */
.map-autofocus-label {
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 8px;
  vertical-align: middle;
  color: var(--text-muted, #8899bb);
  user-select: none;
}
.map-autofocus-label input[type="checkbox"] {
  accent-color: var(--accent, #5eead4);
  width: 13px;
  height: 13px;
  cursor: pointer;
}
  z-index: 1;
  border: 1px solid var(--glass-edge);
}
.map .leaflet-container {
  height: 100%;
  width: 100%;
  border-radius: 12px;
  background: #0b1730;
}

/* ========================
   MAP MARKERS
   ======================== */
.map-marker {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid rgba(255, 255, 255, .7);
  box-shadow: 0 0 16px var(--accent), 0 0 40px rgba(94, 234, 212, .25);
}
.map-marker.pulse {
  animation: markerPulse 2s infinite;
}
.map-marker.has-count {
  width: 32px; height: 32px;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 0 0 3px rgba(94, 234, 212, .5), 0 0 30px var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.marker-count {
  color: #031018;
  font-weight: 800;
  font-size: 13px;
  line-height: 1;
  text-align: center;
  font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
}
@keyframes markerPulse {
  0%   { box-shadow: 0 0 0 0 rgba(94, 234, 212, .6); }
  50%  { box-shadow: 0 0 0 12px rgba(94, 234, 212, 0); }
  100% { box-shadow: 0 0 0 0 rgba(94, 234, 212, 0); }
}

/* Leaflet Controls � Dark Theme */
.leaflet-control-zoom a {
  background: rgba(10, 20, 40, .85) !important;
  color: #9aa6c2 !important;
  border-color: rgba(255, 255, 255, .12) !important;
}
.leaflet-control-zoom a:hover {
  color: #edf2ff !important;
  background: rgba(20, 35, 60, .95) !important;
}
.leaflet-popup-content-wrapper {
  background: rgba(10, 20, 40, .92) !important;
  color: #edf2ff !important;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 10px !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .5) !important;
  backdrop-filter: blur(12px);
}
.leaflet-popup-tip {
  background: rgba(10, 20, 40, .92) !important;
  border: 1px solid rgba(255, 255, 255, .12);
}
.leaflet-popup-content {
  margin: 10px 14px !important;
  font-size: 13px;
  line-height: 1.5;
}
.leaflet-popup-content strong { color: var(--accent); }

/* ========================
   GRID LAYOUTS
   ======================== */
.grid {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}
.grid.two   { grid-template-columns: 1.2fr .8fr; }
.grid.three { grid-template-columns: repeat(3, 1fr); }
.grid.one   { grid-template-columns: 1fr; }

/* ========================
   LISTS / ROWS
   ======================== */
.list {
  display: grid;
  gap: 6px;
  max-height: 310px;
  overflow-y: auto;
}
/* Custom scrollbar for list containers */
.list::-webkit-scrollbar {
  width: 4px;
}
.list::-webkit-scrollbar-track {
  background: transparent;
}
.list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .1);
  border-radius: 4px;
}
.list::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, .18);
}

/* Active Session List */
.session-list {
  display: grid;
  gap: 6px;
}
.session-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--glass-edge);
  border-radius: 10px;
  background: rgba(255, 255, 255, .03);
  transition: background .2s;
}
.session-row:hover {
  background: rgba(255, 255, 255, .06);
}
.session-icon {
  font-size: 24px;
  flex-shrink: 0;
  width: 36px;
  text-align: center;
}
.session-info {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}
.session-info strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.session-meta {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-meta code {
  font-size: 10px;
  padding: 0 4px;
}
.session-status {
  color: var(--accent);
  font-size: 10px;
  animation: markerPulse 2s infinite;
  flex-shrink: 0;
}
.session-self {
  border-color: rgba(94, 234, 212, .25);
  background: rgba(94, 234, 212, .05);
}
.session-kill {
  background: transparent;
  border: 1px solid var(--rose);
  color: var(--rose);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  min-height: 0;
  flex-shrink: 0;
  transition: all .2s;
}
.session-kill:hover {
  background: var(--rose);
  color: #fff;
}
.session-kill:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* ========================
   AD FUNNEL VISUALIZATION
   ======================== */
.funnel {
  padding: 4px 0;
}
.funnel-bars {
  display: grid;
  gap: 8px;
}
.funnel-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.funnel-label {
  width: 80px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
  text-align: right;
}
.funnel-track {
  flex: 1;
  height: 22px;
  background: rgba(255, 255, 255, .05);
  border-radius: 6px;
  overflow: hidden;
}
.funnel-bar {
  height: 100%;
  border-radius: 6px;
  transition: width .6s cubic-bezier(.16, 1, .3, 1);
  min-width: 4px;
}
.funnel-value {
  width: 60px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-align: right;
  flex-shrink: 0;
}
.funnel-metrics {
  display: flex;
  gap: 12px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--glass-edge);
}
.funnel-metric {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .04);
}
.funnel-metric .fm-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 4px;
}
.funnel-metric strong {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
}
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--glass-edge);
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  box-shadow: none;
  text-align: left;
  min-height: 0;
  font-size: 13px;
  cursor: default;
  transition: all .2s;
}
.row:hover {
  background: rgba(255, 255, 255, .04);
  transform: none;
  box-shadow: none;
}
.row i {
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
  box-shadow: 0 0 10px var(--accent);
}
.row.clickable { cursor: pointer; }
.row.clickable:hover span { color: var(--accent); }

/* ========================
   CHART TOGGLE BUTTONS
   ======================== */
.chart-toggle {
  display: inline-flex;
  gap: 3px;
  margin-left: auto;
  vertical-align: middle;
}
.toggle-btn {
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--glass-edge);
  color: var(--muted);
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all .2s;
  line-height: 1;
}
.toggle-btn:hover {
  background: rgba(255, 255, 255, .1);
  color: var(--text);
}
.toggle-btn.active {
  background: var(--accent);
  color: #031018;
  border-color: var(--accent);
  font-weight: 700;
  box-shadow: 0 0 12px rgba(94, 234, 212, .3);
}

/* ========================
   FORMS & INPUTS
   ======================== */
input, select, button, .button {
  border: 1px solid var(--glass-edge);
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  text-decoration: none;
  min-height: 42px;
  font-size: 13px;
  font-family: inherit;
  transition: all .2s cubic-bezier(.4, 0, .2, 1);
  outline: none;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(94, 234, 212, .12);
}
button, .button {
  cursor: pointer;
  background: var(--gradient-accent);
  border: 0;
  color: #031018;
  font-weight: 700;
  font-size: 13px;
}
button:hover, .button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(94, 234, 212, .2);
}

/* Danger / hot buttons */
.btn-delete-game {
  background: transparent;
  border: 1px solid var(--rose);
  color: var(--rose);
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  transition: all .2s;
  line-height: 1;
  min-height: 0;
}
.btn-delete-game:hover {
  background: var(--rose);
  color: #1d0a01;
  transform: none;
  box-shadow: none;
}

/* ========================
   MISC ELEMENTS
   ======================== */
code {
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, .06);
  font-size: 12px;
  color: var(--accent);
  white-space: pre-wrap;
  word-break: break-word;
}
.danger-zone {
  border-color: rgba(251, 113, 133, .25) !important;
}
.danger-zone button {
  background: linear-gradient(135deg, #fb7185, #f97316);
  color: #1d0a01;
}

/* ========================
   DELETE TABLE CHECKBOXES
   ======================== */
.table-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  padding: 12px;
  border-radius: 10px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.06);
}
.table-checkboxes .checkbox-all {
  width: 100%;
  margin-bottom: 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.table-checkboxes .checkbox-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.06);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.table-checkboxes .checkbox-item:hover {
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.12);
}
.table-checkboxes .checkbox-item code {
  background: none;
  padding: 0;
  font-size: 12px;
  color: var(--text-muted);
}
.table-checkboxes input[type="checkbox"] {
  accent-color: var(--accent, #5eead4);
  cursor: pointer;
}

/* ========================
   AUTH / LOGIN / INSTALL
   ======================== */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: min(480px, 92vw);
  padding: 36px;
  border: 1px solid var(--glass-edge);
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.page-install .auth-card {
  width: min(580px, 94vw);
}
.auth-card h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -.03em;
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.auth-card p {
  color: var(--muted);
  margin: 6px 0 20px;
  font-size: 14px;
}

/* ========================
   FORM GRID
   ======================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-grid label input,
.form-grid label select {
  width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  overflow: hidden;
}
.form-grid button {
  grid-column: 1 / -1;
  margin-top: 4px;
}
/* Remember me checkbox */
.remember-label {
  grid-column: 1 / -1;
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  cursor: pointer;
  margin-top: -4px;
}
.remember-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.inline-form {
  display: flex;
  gap: 10px;
}
.inline-form input { flex: 1; }

/* ========================
   TABLES
   ======================== */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
td, th {
  border-bottom: 1px solid var(--glass-edge);
  padding: 12px;
  text-align: left;
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ========================
   ALERTS
   ======================== */
.error {
  padding: 12px 16px;
  background: rgba(251, 113, 133, .12);
  border: 1px solid rgba(251, 113, 133, .3);
  border-radius: 10px;
  margin: 12px 0;
  font-size: 13px;
  color: var(--rose);
}
.ok {
  padding: 12px 16px;
  background: rgba(34, 197, 94, .12);
  border: 1px solid rgba(34, 197, 94, .25);
  border-radius: 10px;
  margin: 12px 0;
  font-size: 13px;
  color: #34d399;
}

/* ========================
   MODAL OVERLAY
   ======================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .65);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  animation: fadeIn .2s forwards;
}
@keyframes fadeIn { to { opacity: 1; } }
.modal-card {
  background: var(--bg);
  border: 1px solid var(--glass-edge);
  border-radius: 16px;
  width: min(520px, 92vw);
  padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .5);
  animation: slideUp .25s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--glass-edge);
}
.modal-header h2 { margin: 0; font-size: 18px; color: var(--rose); }
.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all .2s;
}
.modal-close:hover { color: var(--text); background: rgba(255,255,255,.06); }
.modal-body { padding: 18px 24px; }
.modal-body p { margin: 6px 0; font-size: 14px; }
.modal-body input { width: 100%; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--glass-edge);
}
.modal-cancel {
  background: transparent;
  border: 1px solid var(--glass-edge);
  color: var(--muted);
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all .2s;
}
.modal-cancel:hover { color: var(--text); border-color: var(--text); }
.modal-delete {
  background: var(--rose);
  border: none;
  color: #fff;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all .2s;
}
.modal-delete:hover:not(:disabled) { filter: brightness(1.15); }
.modal-delete:disabled { opacity: .35; cursor: not-allowed; }

/* ========================
   DRAG & DROP
   ======================== */
.shell .grid.draggable-area { min-height: 0; }
.shell .grid .panel[draggable="true"] {
  cursor: grab;
  transition: transform .2s, box-shadow .2s, opacity .2s;
  touch-action: none;
}
.shell .grid .panel[draggable="true"]:active { cursor: grabbing; }
.shell .grid .panel.dragging { opacity: .45; transform: scale(.97); z-index: 10; }
.shell .grid .panel.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), var(--shadow);
}
.shell .grid .panel .drag-hint {
  position: absolute;
  top: 8px;
  right: 8px;
  opacity: 0;
  transition: opacity .3s;
  color: var(--muted);
  font-size: 11px;
  pointer-events: none;
}
.shell .grid .panel[draggable="true"]:hover .drag-hint { opacity: 1; }
.shell .grid.drag-reorder-active .panel { position: relative; }
.shell .grid .panel.drop-before::before {
  content: '';
  position: absolute;
  left: -9px; top: 10%;
  height: 80%; width: 3px;
  background: var(--accent);
  border-radius: 2px;
}
.shell .grid .panel.drop-after::after {
  content: '';
  position: absolute;
  right: -9px; top: 10%;
  height: 80%; width: 3px;
  background: var(--accent);
  border-radius: 2px;
}

/* ========================
   DETAIL BOX / PILLS
   ======================== */
.detail-box section { margin: 14px 0; }
.detail-box h3 { margin: 12px 0 8px; font-size: 14px; color: var(--accent); }
.pill-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.pill {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--glass-edge);
  border-radius: 8px;
  background: rgba(255, 255, 255, .04);
  font-size: 13px;
}
.table-scroll {
  overflow: auto;
  max-height: 440px;
  border: 1px solid var(--glass-edge);
  border-radius: 10px;
}
.loading {
  color: var(--muted);
  padding: 18px;
  font-size: 14px;
}
.theme-toggle {
  display: inline-flex;
  align-items: center;
  min-width: 52px;
  justify-content: center;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--glass-edge);
 
}

/* Dark Theme */
.theme-toggle {
    color: #ffffff;
}

/* Light Theme */
body.light .theme-toggle {
    color: #031018;
}
.theme-toggle svg {
  width: 20px; height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.custom-date { display: none; }
.custom-date.show { display: inline-block; }

/* Mobile sidebar toggle � hidden on desktop, shown on mobile */
.mobile-toggle {
  display: none;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--glass-edge);
  color: var(--muted);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 20px;
  align-items: center;
  justify-content: center;
  padding: 0;
  min-height: 0;
  flex-shrink: 0;
  transition: all .2s;
}
.mobile-toggle:hover {
  background: rgba(255, 255, 255, .1);
  color: var(--text);
}

/* ========================
   RESPONSIVE
   ======================== */
@media (max-width: 1100px) {
  .grid.three, .grid.two, .kpis { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .mobile-toggle {
    display: flex;
  }
  .side-toggle {
    display: none;
  }
  .side {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 250px;
    transform: translateX(-100%);
    transition: transform .3s cubic-bezier(.16, 1, .3, 1);
    z-index: 100;
  }
  .side.open {
    transform: translateX(0);
  }
  .shell {
    margin: 0;
  }
  .kpis, .grid.two, .grid.three, .form-grid {
    grid-template-columns: 1fr;
  }
  .top {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* ========================
   LIGHT THEME OVERRIDES
   ======================== */
body.light {
  --glass-bg: rgba(255, 255, 255, .65);
  --glass-bg-strong: rgba(255, 255, 255, .82);
  --glass-edge: rgba(12, 20, 38, .08);
  --shadow: 0 18px 45px rgba(20, 28, 45, .08);
  --kpi-glow: 0 0 30px rgba(94, 234, 212, .06);
}
body.light {
  background:
    radial-gradient(ellipse 70% 40% at 10% -5%, rgba(94, 234, 212, .07), transparent 60%),
    radial-gradient(ellipse 50% 30% at 90% 5%, rgba(96, 165, 250, .06), transparent 55%),
    linear-gradient(165deg, #f0f4f8, #f5f7fb 50%, #eef2f6) !important;
}
body.light .side {
  background: rgba(255, 255, 255, .72);
  backdrop-filter: blur(24px) saturate(1.4);
}
body.light input, body.light select {
  background: rgba(255, 255, 255, .7);
  color: #111827;
}
body.light select option { color: #111827; background: #fff; }
body.light .toggle-btn {
  background: rgba(0, 0, 0, .05);
  border-color: rgba(0, 0, 0, .09);
}
body.light .toggle-btn:hover {
  background: rgba(0, 0, 0, .08);
}
body.light .toggle-btn.active {
  background: var(--accent);
  color: #031018;
  border-color: var(--accent);
}
body.light .leaflet-container { background: #d4e3f0 !important; }
body.light .leaflet-control-zoom a {
  background: rgba(255, 255, 255, .9) !important;
  color: #667085 !important;
  border-color: rgba(0, 0, 0, .1) !important;
}
body.light .leaflet-popup-content-wrapper {
  background: rgba(255, 255, 255, .95) !important;
  color: #111827 !important;
  border-color: rgba(0, 0, 0, .1);
}
body.light .leaflet-popup-tip {
  background: rgba(255, 255, 255, .95) !important;
  border-color: rgba(0, 0, 0, .1);
}
body.light .kpis article::before {
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, .5) 50%, transparent 60%);
}
body.light .btn-delete-game:hover {
  color: #1d0a01;
}
body.light .theme-toggle {
  background: rgba(0, 0, 0, .04);
  border: 1px solid rgba(0, 0, 0, .09);
}
body.light .side-backdrop {
  background: rgba(0, 0, 0, .35);
}

/* ========================
   ENTRANCE ANIMATIONS
   ======================== */
@keyframes panelFadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.kpis article {
  animation: panelFadeIn .5s cubic-bezier(.16, 1, .3, 1) both;
}
.kpis article:nth-child(1) { animation-delay: 0s; }
.kpis article:nth-child(2) { animation-delay: .05s; }
.kpis article:nth-child(3) { animation-delay: .1s; }
.kpis article:nth-child(4) { animation-delay: .15s; }
.kpis article:nth-child(5) { animation-delay: .2s; }
.grid .panel {
  animation: panelFadeIn .5s cubic-bezier(.16, 1, .3, 1) both;
}
.grid:nth-child(1) .panel { animation-delay: .1s; }
.grid:nth-child(1) .panel:last-child { animation-delay: .15s; }
.grid:nth-child(2) .panel { animation-delay: .2s; }
.grid:nth-child(2) .panel:last-child { animation-delay: .25s; }
.grid:nth-child(3) .panel { animation-delay: .3s; }
.grid:nth-child(3) .panel:last-child { animation-delay: .35s; }
.grid:nth-child(4) .panel { animation-delay: .4s; }
.grid:nth-child(4) .panel:last-child { animation-delay: .45s; }
.grid:nth-child(5) .panel { animation-delay: .5s; }
.grid:nth-child(5) .panel:last-child { animation-delay: .55s; }

/* Smooth KPI value transitions */
.kpis strong {
  transition: all .4s cubic-bezier(.16, 1, .3, 1);
}

/* Sidebar nav link icons � handled above in sidebar section */

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  html, body {
    background: var(--bg) !important;
    color: var(--text) !important;
  }
  .side, .modal-overlay, .drag-hint, .no-print { display: none !important; }
  .shell { margin: 0 !important; padding: 16px !important; max-width: 100% !important; }
  .panel, .kpis article {
    background: rgba(255,255,255,.08) !important;
    border-color: var(--glass-edge) !important;
    box-shadow: none !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .panel h2, .panel span, .panel strong, .panel code, .row, .muted { color: var(--text) !important; }
  .panel .row i { background: var(--accent) !important; box-shadow: 0 0 6px var(--accent) !important; }
  input, select, button, .button {
    background: rgba(255,255,255,.06) !important;
    border-color: var(--glass-edge) !important;
    color: var(--text) !important;
    box-shadow: none !important;
  }
  .grid { display: grid !important; gap: 12px !important; margin-bottom: 12px !important; break-inside: avoid; }
  .grid.two { grid-template-columns: 1fr 1fr !important; }
  .grid.three { grid-template-columns: 1fr 1fr 1fr !important; }
  .grid.one { grid-template-columns: 1fr !important; }
  .kpis { grid-template-columns: repeat(4, 1fr) !important; margin: 12px 0 !important; }
  .top { margin-bottom: 12px !important; }
  canvas { max-width: 100% !important; max-height: 280px !important; }
  body.light { background: #f5f7fb !important; color: #111827 !important; }
  body.light .panel { background: rgba(255,255,255,.94) !important; }
  .map { background: var(--bg) !important; height: 300px !important; }
  .map .leaflet-container { background: var(--bg) !important; }
}
