:root {
  --color-road: #E24B4A;
  --color-pavement: #D85A30;
  --color-traffic: #378ADD;
  --color-pedestrian: #7F77DD;
  --color-green: #639922;
  --color-furniture: #1D9E75;
  --color-recreation: #D9A62E;
  --color-waste: #BA7517;
  --color-water: #2AA9C7;
  --color-noise: #888780;
  --bg: #0f1012;
  --panel: #1a1b1e;
  --text: #f0f0ee;
  --text-dim: #9a9a95;
}

@media (prefers-color-scheme: light) {
  :root { --bg: #f5f5f3; --panel: #ffffff; --text: #16171a; --text-dim: #55565c; }
}
:root[data-theme="dark"] { --bg: #0f1012; --panel: #1a1b1e; --text: #f0f0ee; --text-dim: #9a9a95; }
:root[data-theme="light"] { --bg: #f5f5f3; --panel: #ffffff; --text: #16171a; --text-dim: #55565c; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }

#app { display: grid; grid-template-columns: 340px 1fr; height: 100vh; height: 100dvh; }
#sidebar { overflow-y: auto; background: var(--panel); border-right: 1px solid rgba(128,128,128,.2); padding: 16px; -webkit-overflow-scrolling: touch; }
#map { height: 100vh; height: 100dvh; }

.sidebar-back, .btn-back {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; color: var(--text-dim); font-size: .82rem;
  cursor: pointer; padding: 6px 0; margin-bottom: 12px;
}
.sidebar-back svg { width: 14px; height: 14px; }

.mobile-only { display: none; }
.sheet-handle { display: none; }

/* ---- Mobile layout: map fills the screen, sidebar becomes a bottom sheet ---- */
@media (max-width: 800px) {
  #app { display: block; height: 100vh; height: 100dvh; }
  #map { height: 100vh; height: 100dvh; width: 100%; }

  #sidebar {
    position: fixed; left: 0; right: 0; bottom: 0;
    height: 78vh; height: 78dvh;
    border-radius: 18px 18px 0 0;
    border-right: none;
    border-top: 1px solid rgba(128,128,128,.2);
    box-shadow: 0 -8px 24px rgba(0,0,0,.35);
    transform: translateY(calc(100% - 64px));
    transition: transform .28s ease;
    z-index: 500;
    padding-top: 10px;
  }
  #sidebar.open { transform: translateY(0); }

  .sheet-handle {
    display: block; width: 100%; text-align: center; cursor: pointer;
    padding: 6px 0 14px; margin: 0 0 6px; border: none; background: none;
  }
  .sheet-handle .bar { display: inline-block; width: 40px; height: 4px; border-radius: 999px; background: rgba(128,128,128,.5); }
  .sheet-handle .label { display: block; font-size: .78rem; color: var(--text-dim); margin-top: 6px; }

  .mobile-only { display: block; }

  input, select { min-height: 40px; }
  .view-toggle button, .category-checks label { min-height: 38px; }
}

.view-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.view-toggle button { flex: 1; padding: 8px; border-radius: 8px; border: 1px solid rgba(128,128,128,.3); background: transparent; color: var(--text); cursor: pointer; }
.view-toggle button.active { background: var(--color-traffic); color: #fff; border-color: var(--color-traffic); }

.filter-group { margin-bottom: 14px; }
.filter-group label { display: block; font-size: .8rem; color: var(--text-dim); margin-bottom: 4px; }
.filter-group select, .filter-group input:not([type=checkbox]):not([type=range]) { width: 100%; padding: 8px; border-radius: 6px; border: 1px solid rgba(128,128,128,.3); background: transparent; color: var(--text); }
.filter-group input[type=date] { color-scheme: dark; }
:root[data-theme="light"] .filter-group input[type=date] { color-scheme: light; }

.category-checks { display: flex; flex-direction: column; gap: 2px; }
.category-checks label {
  display: flex; align-items: center; gap: 8px; font-size: .85rem;
  padding: 4px 2px; border-radius: 8px; cursor: pointer;
}
.category-checks label:active { background: rgba(128,128,128,.12); }
.category-checks input[type=checkbox] { width: 17px; height: 17px; flex-shrink: 0; margin: 0; accent-color: var(--color-traffic); }
.category-checks .cat-icon {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.category-checks .cat-icon svg { width: 12px; height: 12px; }
.category-checks .cat-label { flex: 1; }

.panel-card { background: var(--panel); border: 1px solid rgba(128,128,128,.2); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.muni-stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.muni-stat { background: rgba(128,128,128,.1); border-radius: 10px; padding: 8px; text-align: center; }
.muni-stat b { display: block; font-size: 1.3rem; }
.muni-stat span { font-size: .7rem; color: var(--text-dim); }

.muni-category-bars { margin-top: 8px; }
.muni-bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: .78rem; }
.muni-bar-label { width: 84px; flex-shrink: 0; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.muni-bar-track { flex: 1; height: 8px; border-radius: 999px; background: rgba(128,128,128,.15); overflow: hidden; }
.muni-bar-fill { display: block; height: 100%; border-radius: 999px; }
.muni-bar-count { width: 22px; text-align: right; font-weight: 700; }

.marker-badge { background: #fff; color: #111; border-radius: 999px; font-size: 10px; font-weight: 700; padding: 1px 5px; border: 1px solid #333; }

.severity-pulse {
  animation: cp-pulse 1.4s infinite;
}
@keyframes cp-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,255,255,.6); }
  70% { box-shadow: 0 0 0 10px rgba(255,255,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}

.issue-pulse {
  animation: cp-issue-pulse 1.6s infinite;
}
@keyframes cp-issue-pulse {
  0% { box-shadow: 0 0 0 0 rgba(226,75,74,.7); }
  70% { box-shadow: 0 0 0 14px rgba(226,75,74,0); }
  100% { box-shadow: 0 0 0 0 rgba(226,75,74,0); }
}

.history-entry { border-left: 2px solid rgba(128,128,128,.3); padding-left: 10px; margin-bottom: 12px; }
.history-entry.worsened { border-left-color: var(--color-road); }
.history-entry.improved { border-left-color: var(--color-green); }

.rank-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.rank-Observer { background: #666; color: #fff; }
.rank-Scout { background: #378ADD; color: #fff; }
.rank-Analyst { background: #639922; color: #fff; }
.rank-Researcher { background: #BA7517; color: #fff; }
.rank-Expert { background: #E24B4A; color: #fff; }

.notify-banner { background: #4a1f1f; color: #ffb3b3; padding: 8px 10px; border-radius: 8px; font-size: .85rem; margin-bottom: 10px; }

/* Leaflet control tweaks for touch */
.leaflet-touch .leaflet-bar a { width: 36px; height: 36px; line-height: 36px; }
