/* ═══════════════════════════════════════════════════════════
   Hamburg-Mitte Wahl-Radar – style.css
   Mobile-first · Bottom Sheet · Drill-Down
   ═══════════════════════════════════════════════════════════ */

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

:root {
  --bg:         #1a1a2e;
  --surface:    #16213e;
  --surface-2:  #0f3460;
  --accent:     #4ade80;
  --accent-dim: #22c55e;
  --text:       #e2e8f0;
  --text-muted: #94a3b8;
  --border:     rgba(255,255,255,0.08);
  --shadow:     0 8px 32px rgba(0,0,0,0.45);
  --radius:     12px;
  --font:       'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --safe-b:     env(safe-area-inset-bottom, 0px);
}

html, body {
  font-family: var(--font);
  color: var(--text);
  overflow: hidden;
  height: 100%;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ── Map (always fullscreen) ─────────────────────────────── */
#map { position: absolute; inset: 0; z-index: 1; }
.leaflet-container { background: #0d1117; }
.leaflet-control-attribution { font-size: 9px !important; opacity: 0.4; }

/* ══════════════════════════════════════════════════════════
   BACK BUTTON (Drill-Down)
   ══════════════════════════════════════════════════════════ */
.btn-back {
  position: absolute;
  z-index: 1100;
  top: 16px;
  left: 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px 10px 12px;
  background: var(--accent);
  color: #0a0a0a;
  border: none;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(74,222,128,0.35);
  transition: transform 0.15s, opacity 0.25s;
}
.btn-back:hover { transform: scale(1.03); }
.btn-back:active { transform: scale(0.97); }
.btn-back.hidden { display: none; }

/* ══════════════════════════════════════════════════════════
   SIDEBAR / BOTTOM-SHEET  (mobile-first = bottom sheet)
   ══════════════════════════════════════════════════════════ */
#sidebar {
  position: absolute;
  z-index: 1200;
  /* mobile: bottom sheet */
  left: 0; right: 0; bottom: 0;
  max-height: 80vh;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.5);
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32,0.72,0,1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
#sidebar.open { transform: translateY(0); }

.sidebar-inner {
  flex: 1;
  overflow-y: auto;
  padding: 4px 20px 20px;
  -webkit-overflow-scrolling: touch;
}

/* Sheet handle (mobile) */
.sheet-handle {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
  cursor: grab;
  flex-shrink: 0;
}
.sheet-handle span {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,0.2);
}

/* Sheet close button (mobile) */
.sheet-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  z-index: 2;
  line-height: 1;
  padding: 4px 8px;
}

/* Placeholder */
#sidebar-placeholder {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  color: var(--text-muted);
  gap: 12px;
  padding: 32px 0;
}
.placeholder-icon { font-size: 40px; opacity: 0.4; }
#sidebar-placeholder p { font-size: 14px; line-height: 1.5; max-width: 260px; }

#sidebar-content { display: flex; flex-direction: column; gap: 20px; }
#sidebar-content.hidden { display: none; }

/* ══════════════════════════════════════════════════════════
   CONTROLS  (mobile-first = fullscreen modal, hidden)
   ══════════════════════════════════════════════════════════ */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 1300;
  background: rgba(0,0,0,0.6);
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}
.scrim.visible { opacity: 1; pointer-events: auto; }
.scrim.hidden { display: none; }

.controls {
  position: fixed;
  z-index: 1400;
  inset: 0;
  background: var(--surface);
  padding: 20px;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32,0.72,0,1);
}
.controls.open { transform: translateY(0); }

.controls-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.controls-title {
  font-size: 16px !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  color: var(--text) !important;
  margin: 0 !important;
}
.controls-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 28px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.controls h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
}
.controls h3:not(:first-child) { margin-top: 18px; }

.controls select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  appearance: auto;
}

.slider-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.slider-label span {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.slider-label input[type=range] {
  width: 100%;
  margin-top: 6px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* FAB (mobile only) */
.fab {
  position: absolute;
  z-index: 1100;
  bottom: 90px;
  right: 16px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.92); }

/* Legend */
#legend {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
#legend h4 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
}
.legend-bar {
  height: 12px;
  border-radius: 3px;
  margin-bottom: 4px;
}
.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ══════════════════════════════════════════════════════════
   BRIEFING COMPONENTS (shared mobile + desktop)
   ══════════════════════════════════════════════════════════ */

/* Header */
#briefing-header { padding-bottom: 16px; border-bottom: 1px solid var(--border); }
#briefing-header h2 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
#briefing-header .sub { font-size: 12px; color: var(--text-muted); font-weight: 400; }

/* Sections */
section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent);
  margin-bottom: 10px;
  font-weight: 600;
}

/* Bar chart */
.bar-row { display: flex; align-items: center; margin-bottom: 6px; font-size: 13px; }
.bar-label { width: 90px; flex-shrink: 0; font-weight: 500; text-align: right; padding-right: 10px; }
.bar-track { flex: 1; height: 20px; background: rgba(255,255,255,0.06); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.4s ease; min-width: 2px; }
.bar-value { width: 52px; flex-shrink: 0; text-align: right; font-size: 12px; font-weight: 600; padding-left: 8px; font-variant-numeric: tabular-nums; }

/* Candidates */
.candidate { display: flex; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.candidate:last-child { border-bottom: none; }
.candidate .rank { width: 24px; font-weight: 700; color: var(--accent); flex-shrink: 0; }
.candidate .name { flex: 1; font-weight: 500; }
.candidate .votes { font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 12px; margin-left: 8px; white-space: nowrap; }

/* Demografie grid */
.demo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.demo-card { background: rgba(255,255,255,0.04); padding: 12px; border-radius: 8px; text-align: center; }
.demo-card .value { font-size: 22px; font-weight: 700; line-height: 1; }
.demo-card .label { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* Strategy */
.strategy-box {
  background: rgba(74,222,128,0.08);
  border-left: 3px solid var(--accent);
  padding: 14px 16px;
  border-radius: 0 8px 8px 0;
  font-size: 13px;
  line-height: 1.6;
}

/* Action bar */
.action-bar { padding-top: 16px; border-top: 1px solid var(--border); }
#btn-pdf {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #0a0a0a;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
#btn-pdf:hover { background: var(--accent-dim); }
#btn-pdf:active { transform: scale(0.98); }

/* Stadtteil summary card (shown when clicking stadtteil in macro view) */
.stadtteil-summary { margin-bottom: 4px; }
.stadtteil-summary .stat-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.stadtteil-summary .stat-row:last-child { border-bottom: none; }
.stadtteil-summary .stat-label { color: var(--text-muted); }
.stadtteil-summary .stat-value { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Stadtteil drill-down prompt */
.drill-prompt {
  margin-top: 12px;
  padding: 12px;
  background: rgba(74,222,128,0.1);
  border-radius: 8px;
  text-align: center;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.2s;
}
.drill-prompt:hover { background: rgba(74,222,128,0.18); }

/* ══════════════════════════════════════════════════════════
   DESKTOP  (>= 768px)
   ══════════════════════════════════════════════════════════ */
@media (min-width: 768px) {

  /* Sidebar → floating left panel */
  #sidebar {
    top: 16px;
    left: 16px;
    bottom: 16px;
    right: auto;
    width: 400px;
    max-height: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transform: none;
    border: 1px solid var(--border);
  }
  #sidebar.open { transform: none; }
  .sidebar-inner { padding: 24px; }

  /* Hide mobile-only elements */
  .sheet-handle { display: none; }
  .sheet-close { display: none; }
  .fab { display: none; }

  /* Controls → floating top-right panel */
  .controls {
    position: absolute;
    top: 16px;
    right: 16px;
    left: auto;
    bottom: auto;
    width: 260px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: none;
    overflow-y: visible;
  }
  .controls.open { transform: none; }
  .controls-header { display: none; }
  .scrim { display: none !important; }

  /* Back button nudge for sidebar */
  .btn-back { left: 430px; }
}

/* ══════════════════════════════════════════════════════════
   SCROLLBAR
   ══════════════════════════════════════════════════════════ */
.sidebar-inner::-webkit-scrollbar { width: 6px; }
.sidebar-inner::-webkit-scrollbar-track { background: transparent; }
.sidebar-inner::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }

/* ══════════════════════════════════════════════════════════
   PDF EXPORT OVERRIDES
   ══════════════════════════════════════════════════════════ */
.pdf-mode {
  background: #ffffff !important;
  color: #1a1a1a !important;
  padding: 24px !important;
  width: 520px !important;
}
.pdf-mode h2 { color: #111 !important; }
.pdf-mode .sub { color: #666 !important; }
.pdf-mode section h3 { color: #16a34a !important; }
.pdf-mode .bar-track { background: #e5e7eb !important; }
.pdf-mode .bar-value { color: #333 !important; }
.pdf-mode .candidate .votes { color: #666 !important; }
.pdf-mode .demo-card { background: #f3f4f6 !important; }
.pdf-mode .demo-card .label { color: #666 !important; }
.pdf-mode .demo-card .value { color: #111 !important; }
.pdf-mode .strategy-box { background: rgba(22,163,74,0.08) !important; color: #1a1a1a !important; }
.pdf-mode .action-bar { display: none !important; }

/* Leaflet stadtteil label tooltip */
.stadtteil-label {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.7), 0 0 2px rgba(0,0,0,0.5);
  text-align: center;
  white-space: nowrap;
}
.stadtteil-label::before { display: none; }
