@import url('base.css');

html, body {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
}

/* ========================================
   Mapa i controls de Leaflet
   ======================================== */

#map {
  position: absolute;
  top: 60px;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  background: var(--surface-3);
  font-family: var(--font-sans);
}

.leaflet-container a {
  color: var(--primary);
}

.leaflet-top.leaflet-left,
.leaflet-top.leaflet-right {
  padding-top: 4px;
}

.leaflet-bar,
.leaflet-touch .leaflet-bar {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-lg) !important;
  overflow: hidden;
  background: var(--surface);
}

.leaflet-bar a,
.leaflet-touch .leaflet-bar a {
  width: 38px;
  height: 38px;
  line-height: 38px;
  background-color: var(--surface);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  transition: background-color 0.15s, color 0.15s;
}

.leaflet-bar a:hover,
.leaflet-touch .leaflet-bar a:hover {
  background-color: var(--surface-3);
  color: var(--primary);
}

.leaflet-bar a:first-child {
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
}

.leaflet-bar a:last-child {
  border-bottom: none;
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
  font-weight: 500 !important;
}

/* Icona de pantalla completa amb Font Awesome (visible en tots dos temes) */
.leaflet-control-zoom-fullscreen,
.leaflet-touch .leaflet-control-zoom-fullscreen {
  background-image: none !important;
}

.leaflet-control-zoom-fullscreen::before {
  content: '\f065';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  font-size: 0.9rem;
}

.leaflet-fullscreen-on .leaflet-control-zoom-fullscreen::before {
  content: '\f066';
}

.leaflet-control-layers {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-lg) !important;
  background: var(--surface) !important;
  color: var(--text);
}

.leaflet-control-layers-toggle {
  width: 42px !important;
  height: 42px !important;
  background-size: 22px 22px;
}

html.dark .leaflet-control-layers-toggle {
  filter: invert(0.9) hue-rotate(180deg);
}

.leaflet-control-layers-expanded {
  padding: 0.75rem 1rem 0.75rem 0.85rem;
  font-size: var(--text-sm);
}

.leaflet-control-layers-list label {
  color: var(--text);
  padding: 0.15rem 0;
}

.leaflet-control-layers-separator {
  border-top-color: var(--border) !important;
}

.leaflet-control-layers input {
  accent-color: var(--primary);
}

.leaflet-control-attribution {
  background: var(--surface-glass) !important;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--text-muted);
  border-top-left-radius: var(--radius-sm);
  font-size: 0.68rem;
}

.leaflet-control-attribution a {
  color: var(--primary) !important;
}

.leaflet-control-scale-line {
  background: var(--surface-glass);
  border-color: var(--text-muted);
  color: var(--text);
  font-size: 0.68rem;
}

/* Tooltips */
.leaflet-tooltip {
  background: var(--brand-ink);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0.45rem 0.7rem;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  line-height: 1.4;
}

.leaflet-tooltip strong {
  font-size: var(--text-sm);
}

.leaflet-tooltip-top::before {
  border-top-color: var(--brand-ink);
}

.tooltip-level {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  opacity: 0.9;
}

.tooltip-level .status-dot {
  width: 7px;
  height: 7px;
}

/* Botons de control propis */
.leaflet-control-locate,
.leaflet-control-rotate-btn {
  text-align: center;
  font-size: 0.95rem !important;
}

.leaflet-control-locate.active {
  background: var(--primary) !important;
  color: #fff !important;
}

/* ========================================
   Filtre per població
   ======================================== */

.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 40px;
  padding: 0 0.95rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: background-color 0.15s, border-color 0.15s;
}

.filter-toggle i {
  color: var(--primary);
}

.filter-toggle:hover,
.filter-toggle[aria-expanded="true"] {
  border-color: var(--primary);
  background: var(--primary-light);
}

.filter-toggle__badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.filter-toggle__badge[hidden] {
  display: none;
}

#filtroPoblacion {
  position: absolute;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  width: 300px;
  max-height: min(440px, calc(100% - 140px));
  padding: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  font-size: var(--text-sm);
  animation: dropdown-in 0.2s var(--ease-out);
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

.filtro-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.65rem;
}

.filtro-header__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-base);
  color: var(--text-strong);
}

.filtro-header__title i {
  color: var(--primary);
  font-size: 0.9rem;
}

#filtroPoblacion .close-filtres {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.95rem;
}

#filtroPoblacion .close-filtres:hover {
  background: var(--surface-3);
  color: var(--text-strong);
}

.filtro-search {
  position: relative;
  margin-bottom: 0.5rem;
}

.filtro-search i {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  font-size: 0.8rem;
  pointer-events: none;
}

#buscadorPoblacio {
  width: 100%;
  padding: 0.55rem 0.75rem 0.55rem 2.1rem;
  font-family: inherit;
  font-size: var(--text-sm);
  color: var(--text-strong);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

#buscadorPoblacio:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

#filtroLista {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  max-height: none !important;
  margin: 0 -0.35rem 0.6rem;
  padding: 0 0.35rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.pob-entry {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: background-color 0.12s;
}

.pob-entry:hover {
  background: var(--surface-3);
}

.pob-entry[data-selected="true"] {
  background: var(--primary-light);
}

.pob-entry .checkbox {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.15s, border-color 0.15s;
}

.pob-entry[data-selected="true"] .checkbox {
  background: var(--primary);
  border-color: var(--primary);
}

.pob-entry[data-selected="true"] .checkbox::after {
  content: '\f00c';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  font-size: 10px;
  color: #fff;
}

.pob-entry .label {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  color: var(--text);
}

.pob-entry .label span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pob-entry[data-selected="true"] .label {
  color: var(--primary-dark);
  font-weight: 600;
}

.pob-entry .count {
  flex-shrink: 0;
  min-width: 26px;
  padding: 0.05rem 0.4rem;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-align: center;
}

#resetFiltres {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  width: 100%;
  padding: 0.55rem;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error-bg);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s;
}

#resetFiltres:hover {
  background: var(--error-bg);
}

html.dark #resetFiltres {
  color: var(--error-text);
}

/* ========================================
   Llegenda amb recompte
   ======================================== */

.map-legend {
  position: absolute;
  bottom: 1.75rem;
  left: 1rem;
  z-index: 999;
  width: 230px;
  padding: 0.9rem 1rem;
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
}

.map-legend__toggle {
  display: none;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: none;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  width: 100%;
}

.map-legend__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding-bottom: 0.6rem;
  margin-bottom: 0.55rem;
  border-bottom: 1px solid var(--border);
}

.map-legend__title {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.map-legend__total {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.2rem 0;
  color: var(--text);
}

.legend-item small {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.legend-count {
  margin-left: auto;
  font-weight: 700;
  font-size: var(--text-xs);
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}

.legend-item--fire {
  margin-top: 0.35rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
}

.legend-dot,
.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--level-color, var(--level-off));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--level-color, var(--level-off)) 22%, transparent);
}

.legend-dot--good { --level-color: var(--level-good); }
.legend-dot--mid { --level-color: var(--level-mid); }
.legend-dot--low { --level-color: var(--level-low); }
.legend-dot--off { --level-color: var(--level-off); }

.legend-dot--fire {
  width: 18px;
  height: 18px;
  margin: 0 -4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--fire-gradient);
  box-shadow: none;
  color: #fff;
  font-size: 0.55rem;
}

/* ========================================
   Marcadors de bassa i clústers
   ======================================== */

.balsa-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.balsa-icon__drop {
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 3px 8px rgba(15, 42, 58, 0.35);
  border: 2px solid #fff;
  transition: transform 0.2s var(--ease-out);
}

.balsa-icon__drop i {
  transform: rotate(45deg);
}

.leaflet-marker-icon:hover .balsa-icon__drop {
  transform: rotate(-45deg) scale(1.15);
}

.balsa-icon__fire {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--fire-gradient);
  color: #fff;
  border: 1.5px solid #fff;
  animation: fire-pulse 1.6s infinite;
}

@keyframes fire-pulse {
  0% { box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.7); }
  70% { box-shadow: 0 0 0 7px rgba(249, 115, 22, 0); }
  100% { box-shadow: 0 0 0 0 rgba(249, 115, 22, 0); }
}

.leaflet-marker-icon.balsa-icon-wrapper,
.leaflet-marker-icon.marker-cluster-custom {
  background: transparent;
  border: none;
}

.cluster-bubble {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: #fff;
  border: 2px solid #fff;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.8rem;
  box-shadow: 0 0 0 5px rgba(33, 161, 192, 0.28), 0 4px 12px rgba(15, 42, 58, 0.35);
  transition: transform 0.2s var(--ease-out);
}

.cluster-bubble--md {
  font-size: 0.85rem;
  box-shadow: 0 0 0 6px rgba(33, 161, 192, 0.3), 0 4px 12px rgba(15, 42, 58, 0.35);
}

.cluster-bubble--lg {
  font-size: 0.95rem;
  background: linear-gradient(135deg, #127A99 0%, #17526F 100%);
  box-shadow: 0 0 0 8px rgba(18, 122, 153, 0.25), 0 6px 16px rgba(15, 42, 58, 0.4);
}

.cluster-bubble--fire {
  background: var(--fire-gradient);
  box-shadow: 0 0 0 6px rgba(249, 115, 22, 0.3), 0 4px 12px rgba(15, 42, 58, 0.35);
}

.marker-cluster-custom:hover .cluster-bubble {
  transform: scale(1.08);
}

/* ========================================
   Popup de bassa
   ======================================== */

.leaflet-popup-content-wrapper {
  padding: 0;
  overflow: hidden;
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xl);
}

.leaflet-popup-content {
  margin: 0;
  width: 280px !important;
  font-family: var(--font-sans);
  line-height: 1.4;
}

.leaflet-popup-tip {
  background: var(--surface);
  box-shadow: none;
}

.leaflet-container a.leaflet-popup-close-button {
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font: 400 18px/27px var(--font-sans);
  text-align: center;
  transition: background-color 0.15s;
}

.leaflet-container a.leaflet-popup-close-button:hover {
  background: rgba(255, 255, 255, 0.32);
  color: #fff;
}

.balsa-popup__header {
  position: relative;
  padding: 1rem 2.75rem 1rem 1.1rem;
  background: var(--brand-gradient);
  color: #fff;
  overflow: hidden;
}

/* Ones decoratives */
.balsa-popup__header::after {
  content: '';
  position: absolute;
  right: -30px;
  bottom: -40px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 18px solid rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.balsa-popup--fire .balsa-popup__header {
  background: var(--fire-gradient);
}

.balsa-popup__eyebrow {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.85;
}

.balsa-popup__title {
  margin: 0.2rem 0 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
}

.balsa-popup__header .badge {
  margin-top: 0.55rem;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  box-shadow: none;
}

.balsa-popup__body {
  padding: 1rem 1.1rem 1.1rem;
}

.balsa-popup__level {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.level-ring {
  --size: 66px;
  position: relative;
  width: var(--size);
  height: var(--size);
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--level-color) calc(var(--pct) * 1%), var(--surface-3) 0);
}

.level-ring::before {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--surface);
}

.level-ring span {
  position: relative;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}

.level-ring small {
  font-size: 0.65em;
  font-weight: 700;
  color: var(--text-muted);
}

.balsa-popup__level-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.balsa-popup__label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.balsa-popup__status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-strong);
}

.balsa-popup__lectura {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.balsa-popup__lectura--antiga {
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius);
  background: var(--warning-bg);
  color: var(--warning-text);
  font-weight: 600;
}

.balsa-popup__incendi {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.9rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.balsa-popup__incendi i {
  color: var(--fire);
  margin-right: 0.3rem;
}

.balsa-popup__actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.9rem;
}

.balsa-popup__actions .btn {
  flex: 1;
  font-size: var(--text-sm);
  padding: 0.55rem 0.5rem;
}

.leaflet-container .balsa-popup__actions a.btn {
  color: var(--primary);
}

/* ========================================
   Brúixola
   ======================================== */

.compass-control {
  width: 44px;
  height: 44px;
  background: var(--surface);
  border-radius: 50%;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.compass-needle {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 15px solid var(--error);
  position: absolute;
  top: 5px;
  transform-origin: 50% 17px;
  transition: transform 0.2s ease;
}

.compass-label {
  position: absolute;
  bottom: 3px;
  font-size: 9px;
  font-weight: 800;
  color: var(--text-muted);
}

/* ========================================
   Filtres ràpids
   ======================================== */

.quick-filters {
  position: absolute;
  bottom: 1.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 998;
  display: flex;
  gap: 0.25rem;
  padding: 0.35rem;
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 2rem);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.quick-filter {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 0 1.05rem;
  min-height: 42px;
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.2s, color 0.2s, box-shadow 0.2s;
}

.quick-filter i {
  font-size: 0.85rem;
  color: var(--primary);
}

.quick-filter--fire i {
  color: var(--fire);
}

.quick-filter:hover {
  background: var(--surface-3);
}

.quick-filter[aria-pressed="true"] {
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: 0 4px 12px -4px rgba(18, 122, 153, 0.7);
}

.quick-filter--fire[aria-pressed="true"] {
  background: var(--fire-gradient);
  box-shadow: 0 4px 12px -4px rgba(239, 68, 68, 0.7);
}

.quick-filter[aria-pressed="true"] i {
  color: #fff;
}

.quick-filter[aria-pressed="true"] .qf-dot {
  box-shadow: 0 0 0 2px #fff;
}

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

.qf-dot--mid {
  background: linear-gradient(90deg, var(--level-mid) 50%, var(--level-good) 50%);
}

.qf-dot--good {
  background: var(--level-good);
}

/* Desplegable de filtres per a mòbil */
.mobile-filter-wrapper {
  display: none;
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
}

.mobile-filter-toggle {
  display: none;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  color: var(--text-strong);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  padding: 0 1.15rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  min-height: 48px;
}

.mobile-filter-toggle i {
  color: var(--primary);
}

.mobile-filter-menu {
  display: none;
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.4rem;
  box-shadow: var(--shadow-xl);
  min-width: 190px;
  z-index: 1000;
}

.mobile-filter-menu.open {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  animation: dropdown-in 0.18s var(--ease-out);
}

.mobile-filter-item {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border: none;
  background: transparent;
  text-align: left;
  min-height: 44px;
  padding: 0 0.85rem;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}

.mobile-filter-item i {
  width: 16px;
  color: var(--primary);
  text-align: center;
}

.mobile-filter-item .qf-dot {
  margin: 0 3.5px;
}

.mobile-filter-item[aria-pressed="true"] {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 700;
}

/* ========================================
   Botó d'emergència i ruta
   ======================================== */

.emergency-fab {
  position: fixed;
  bottom: 1.75rem;
  right: 1.25rem;
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  height: 56px;
  padding: 0 1.35rem 0 1.1rem;
  border-radius: var(--radius-full);
  background: var(--fire-gradient);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 24px -6px rgba(239, 68, 68, 0.6), var(--shadow-lg);
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s var(--ease-out), box-shadow 0.2s;
}

.emergency-fab i {
  font-size: 1.3rem;
}

.emergency-fab::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.55);
  animation: fab-pulse 2.4s infinite;
  pointer-events: none;
}

@keyframes fab-pulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  70% { box-shadow: 0 0 0 14px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.emergency-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px -6px rgba(239, 68, 68, 0.7), var(--shadow-lg);
}

.emergency-fab:active {
  transform: scale(0.97);
}

.stop-route-btn {
  position: fixed;
  top: calc(60px + 1rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  background: var(--brand-ink);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow-xl);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 0.7rem 1.25rem 0.7rem 1rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  white-space: nowrap;
  animation: dropdown-in 0.25s var(--ease-out);
}

.stop-route-btn::before {
  content: '';
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22C55E;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  animation: route-live 1.6s infinite;
}

@keyframes route-live {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
  70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.stop-route-btn__action {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0.25rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  background: rgba(239, 68, 68, 0.9);
  font-size: var(--text-xs);
  font-weight: 700;
}

.stop-route-btn:hover .stop-route-btn__action {
  background: #DC2626;
}

/* Botó de capes en mòbil */
.mobile-layers-btn {
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  z-index: 999;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
}

/* Al mapa els avisos van a dalt per no tapar el botó d'emergència */
.toast-container {
  top: calc(60px + 4.5rem);
  bottom: auto;
}

/* ========================================
   Panel lateral "Basses més properes"
   ======================================== */

.side-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 20, 28, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 1001;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.side-panel-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 88vw;
  background: var(--surface-2);
  z-index: 1002;
  box-shadow: var(--shadow-xl);
  transform: translateX(100%);
  transition: transform 0.35s var(--ease-out);
  display: flex;
  flex-direction: column;
}

.side-panel.open {
  transform: translateX(0);
}

.side-panel__header {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.25rem 1.35rem;
  background: var(--fire-gradient);
  color: #fff;
  overflow: hidden;
}

.side-panel__header::after {
  content: '';
  position: absolute;
  right: -40px;
  top: -50px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 22px solid rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.side-panel__title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.side-panel__subtitle {
  margin: 0.25rem 0 0;
  font-size: var(--text-sm);
  opacity: 0.9;
}

.side-panel__close {
  position: relative;
  z-index: 1;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s;
}

.side-panel__close:hover {
  background: rgba(255, 255, 255, 0.32);
}

.side-panel__content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.side-panel__item {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--level-color, var(--level-off));
  border-radius: var(--radius-lg);
  padding: 0.9rem 1rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, transform 0.2s var(--ease-out);
}

.side-panel__item:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.side-panel__rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin: -1px 0.55rem 0 0;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.side-panel__row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.side-panel__name {
  display: flex;
  align-items: flex-start;
  min-width: 0;
  font-weight: 700;
  font-size: var(--text-sm);
  line-height: 1.35;
  color: var(--text-strong);
}

.side-panel__name .badge {
  margin-left: 0.2rem;
  vertical-align: 1px;
}

.side-panel__dist {
  flex-shrink: 0;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: var(--text-xs);
  font-weight: 700;
  white-space: nowrap;
}

.side-panel__meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin: 0 0 0.6rem calc(22px + 0.55rem);
}

.side-panel__meta--antiga {
  color: var(--warning-text);
  font-weight: 600;
}

.side-panel__meta .status-dot {
  width: 7px;
  height: 7px;
}

.side-panel__item .progress-bar {
  margin-bottom: 0.75rem;
}

.side-panel__actions {
  display: flex;
  gap: 0.5rem;
}

.side-panel__actions .btn {
  flex: 1;
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 768px) {
  .emergency-fab__label {
    display: none;
  }
  .emergency-fab {
    width: 60px;
    height: 60px;
    padding: 0;
    justify-content: center;
  }
}

@media (max-width: 600px) {
  .leaflet-control-zoom {
    display: none !important;
  }

  #filtroPoblacion {
    width: calc(100vw - 2rem);
    left: 1rem !important;
    right: 1rem;
    max-height: 60vh;
    padding: 1rem;
  }

  /* Amagar filtres horitzontals i mostrar botó compacte */
  .quick-filters {
    display: none;
  }
  .mobile-filter-wrapper {
    display: flex;
  }
  .mobile-filter-toggle {
    display: flex;
  }

  .map-legend {
    position: fixed;
    bottom: 3.25rem;
    left: 1rem;
    width: auto;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none;
    box-shadow: none;
    padding: 0;
    z-index: 999;
  }
  .map-legend__toggle {
    display: flex;
    width: 48px;
    height: 48px;
    align-items: center;
    justify-content: center;
    background: var(--surface-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--primary);
    font-size: 1.1rem;
    box-shadow: var(--shadow-lg);
    padding: 0;
  }
  .map-legend__toggle .legend-toggle-text {
    display: none;
  }
  /* Només es pot plegar en mòbil, on hi ha el botó per tornar-la a obrir */
  .map-legend.collapsed .map-legend__body {
    display: none;
  }
  .map-legend__body {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 0;
    width: 230px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0.9rem 1rem;
    box-shadow: var(--shadow-xl);
  }

  .emergency-fab {
    bottom: 3.25rem;
    right: 1rem;
  }

  .mobile-layers-btn {
    bottom: 3.25rem;
    left: 1rem;
  }

  .mobile-filter-wrapper {
    bottom: 3.25rem;
  }

  .compass-control {
    width: 40px;
    height: 40px;
  }
  .compass-needle {
    border-left-width: 4px;
    border-right-width: 4px;
    border-bottom-width: 13px;
    top: 4px;
    transform-origin: 50% 15px;
  }

  .leaflet-popup-content {
    width: calc(100vw - 3rem) !important;
    min-width: 260px;
    max-width: 320px;
  }
  .balsa-popup__actions .btn {
    padding: 0.7rem 0.5rem;
  }

  .stop-route-btn {
    top: auto;
    bottom: 7.5rem;
    font-size: var(--text-base);
    padding: 0.85rem 1.5rem 0.85rem 1.2rem;
  }

  .side-panel {
    width: 100vw;
    max-width: 100vw;
  }
  .side-panel__name {
    font-size: var(--text-base);
  }
  .side-panel__actions .btn {
    padding: 0.65rem 0.75rem;
    font-size: var(--text-sm);
  }
}

@media (max-width: 480px) {
  #map {
    top: 56px;
  }
}
