/* ===== Base ===== */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
  color: #2a2a2a;
}

/* Propaga la tipografia als controls i popups de Leaflet */
.leaflet-container {
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
}

/* ===== Layout: mapa a tota pantalla + barra lateral flotant ===== */
:root { --sidebar-w: 420px; }

#app {
  position: relative;
  height: 100%;
  overflow: hidden;
}

/* El mapa ocupa tot el fons; la barra hi flota a sobre */
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#sidebar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  /* Fons translúcid amb desenfocament del mapa al darrere (vidre esmerilat) */
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 2px 0 14px rgba(0, 0, 0, 0.18);
  overflow-y: auto;
  z-index: 1200;
  transition: transform 0.25s ease;
}
#app.collapsed #sidebar { transform: translateX(-100%); }

.sidebar-scroll { padding: 18px 18px 24px; }

/* Els controls de baix a l'esquerra (nord + escala) s'aparten de la barra */
.leaflet-bottom.leaflet-left {
  left: var(--sidebar-w);
  transition: left 0.25s ease;
}
#app.collapsed .leaflet-bottom.leaflet-left { left: 0; }

/* ----- Botó de col·lapsar ----- */
#sidebar-toggle {
  position: absolute;
  top: 14px;
  left: calc(var(--sidebar-w) + 14px);
  width: 26px;
  height: 40px;
  border: none;
  border-radius: 0 6px 6px 0;
  background: #9C3D1A;
  color: #fff;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  z-index: 1300;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.25);
  transition: left 0.25s ease;
}
#app.collapsed #sidebar-toggle { left: 0; }
#sidebar-toggle:hover { background: #B5451F; }

/* ----- Marca / capçalera del panell ----- */
.brand h1 {
  margin: 0;
  font-family: "Poppins", "Inter", sans-serif;
  font-size: 1.12rem;
  font-weight: 600;
  line-height: 1.25;
  color: #9C3D1A;
}
.brand-acr { color: #C9662F; }
.brand-sub {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: #666;
}

.intro {
  margin: 14px 0 4px;
  font-size: 0.8rem;
  line-height: 1.45;
  color: #555;
}

/* ----- Panells ----- */
.panel {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #eaeaea;
}
.panel-title {
  margin: 0 0 9px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: #9C3D1A;
}

/* Subapartat dins d'un panell (p. ex. "Temperatura") */
.subpanel {
  margin: 4px 0 4px 6px;
  padding-left: 10px;
  border-left: 2px solid #E3D3C8;
}
.subpanel-title {
  margin: 4px 0 3px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: #C9662F;
}

/* ----- Grups temàtics del control de capes (marc: exposició / vulnerabilitat / resposta) ----- */
.layer-group { margin: 11px 0; }
.layer-group-title {
  margin: 0 0 4px;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: #C9662F;
}
.group-cap {
  display: block;
  margin: 0 0 3px;
  font-size: 0.74rem;
  color: #777;
}

/* ----- Files de control (radios / checkboxes) ----- */
.ctrl-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 0.82rem;
  color: #333;
  cursor: pointer;
}
.ctrl-row input { accent-color: #9C3D1A; cursor: pointer; }

/* ----- Anàlisi combinada: síntesi derivada (vulnerabilitat × resposta) -----
   No és una pota del risc, sinó el que surt de combinar-ne dues; té secció pròpia
   després de les tres, dins una targeta que la distingeix de les capes. */
.analysis-block {
  margin: 14px 0 10px;
  padding: 9px 11px;
  background: #FBF5F0;
  border: 1px solid #E9D9CD;
  border-radius: 6px;
}
.analysis-nota { margin: 4px 0 0; }

/* Interruptor de la síntesi: el checkbox es dibuixa com a toggle (és un mode, no
   una capa), per distingir-lo dels interruptors de capa. */
.analysis-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 30px;
  height: 17px;
  border-radius: 999px;
  background: #cfc4bb;
  transition: background 0.15s;
  flex: 0 0 auto;
}
.analysis-row input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.analysis-row input[type="checkbox"]:checked { background: #9C3D1A; }
.analysis-row input[type="checkbox"]:checked::after { transform: translateX(13px); }

/* Capa de vulnerabilitat "presa" per la síntesi: atenuada i amb nota */
.ctrl-row.locked { opacity: 0.5; }
.lock-note {
  margin: 0 0 4px 24px;
  font-size: 0.66rem;
  font-style: italic;
  color: #9C3D1A;
}

/* Popup en mode bivariant: la matriu 3×3 amb la cel·la de la zona ressaltada */
.popup-biv-matrix { margin: 8px 0 2px; }
.biv-cell-on {
  z-index: 2;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #1a1a1a;
}
.popup-biv-rows { margin-top: 8px; }
.popup-biv-rows .comp-head { padding: 3px 0; }
.popup-biv-prio {
  margin: 8px 0 2px;
  padding: 6px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #7a1f1f;
  background: rgba(200, 90, 90, 0.14);
  border-radius: 4px;
}

/* ----- Capa de context (límits municipals), deliberadament secundària ----- */
.ctrl-context {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #eee;
  font-size: 0.75rem;
  color: #888;
}
.ctrl-context input { accent-color: #b9a99d; }

.range-full { width: 100%; cursor: pointer; accent-color: #9C3D1A; }

/* Nota de cobertura sota una capa (p. ex. abast dels refugis) */
.capa-nota {
  margin: 1px 0 5px 24px;
  font-size: 0.68rem;
  font-style: italic;
  line-height: 1.35;
  color: #999;
}

/* ----- Selector de municipi i botó ----- */
.select-full {
  width: 100%;
  padding: 7px 9px;
  font-size: 0.82rem;
  font-family: inherit;
  color: #333;
  background: #fff;
  border: 1px solid #E3D3C8;
  border-radius: 5px;
  cursor: pointer;
}
.select-full:focus {
  outline: none;
  border-color: #9C3D1A;
}

.btn-reset {
  width: 100%;
  margin-top: 8px;
  padding: 7px 9px;
  font-size: 0.78rem;
  font-family: inherit;
  color: #9C3D1A;
  background: #FBEEE7;
  border: 1px solid #E3D3C8;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-reset:hover { background: #F3DDD0; }

/* ----- Font de les dades ----- */
.font-dades {
  margin: 20px 0 0;
  padding-top: 14px;
  border-top: 1px solid #eaeaea;
  font-size: 0.68rem;
  font-style: italic;
  color: #888;
  line-height: 1.4;
}
.font-dades a {
  color: #9C3D1A;
  text-decoration: underline;
}
.font-dades a:hover { color: #B5451F; }

/* Barra de gradient contínua VERTICAL (mateixos colors que el mapa) */
.legend-vert {
  display: flex;
  gap: 7px;
  margin-top: 4px;
}

.legend-ramp-v {
  width: 14px;
  height: 104px;
  border-radius: 3px;
  /* de baix (0, blau) a dalt (100, vermell) */
  background: linear-gradient(to top,
    #2b83ba 0%,
    #abdda4 25%,
    #ffffbf 50%,
    #fdae61 75%,
    #d7191c 100%);
}

.legend-ramp-v-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 104px;
  font-size: 0.66rem;
  color: #555;
}
.legend-ramp-v-labels b { color: #333; }

/* ===== Targeta flotant de llegenda + transparència (dins el mapa) ===== */
.map-legend {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 11px 13px;
  border-radius: 8px;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.25);
  font-size: 0.8rem;
  color: #333;
  max-width: 240px;
}
.map-legend-title {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.2;
  color: #9C3D1A;
}
.map-legend-opacitat {
  margin-top: 11px;
  padding-top: 9px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}
.map-legend-opacitat label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.72rem;
  color: #555;
}
.map-legend-opacitat input[type="range"] {
  width: 100%;
  cursor: pointer;
  accent-color: #9C3D1A;
}

/* ----- Llegenda de temperatura (capa ràster IDE AMB) ----- */
.map-legend-temp {
  margin-top: 11px;
  padding-top: 9px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}
/* Degradat groc (fresc) → vermell (calor), calcat de la simbologia del servei */
.legend-ramp-temp {
  background: linear-gradient(to top,
    #F5F400 0%,
    #F5BA00 25%,
    #F57C00 50%,
    #F53F00 75%,
    #F50100 100%);
}
/* Rampa contínua de l'increment projectat (lila clar → violeta fosc) */
.legend-ramp-incr {
  background: linear-gradient(to top,
    #f2e6f7 0%,
    #d0a9e0 25%,
    #a860c9 50%,
    #7d2fae 75%,
    #4a0d78 100%);
}

/* ----- Llegenda del mode bivariant (matriu 3×3) ----- */
.biv-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
.biv-axis-y {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 0.6rem;
  color: #555;
  white-space: nowrap;
}
.biv-grid {
  display: grid;
  grid-template-columns: repeat(3, 22px);
  grid-template-rows: repeat(3, 22px);
  gap: 2px;
}
.biv-grid i {
  display: block;
  position: relative;
  width: 22px;
  height: 22px;
  border-radius: 2px;
}
.biv-axis-x {
  font-size: 0.6rem;
  color: #555;
  margin-top: 4px;
  padding-left: 22px;
}

/* Llegenda de classes discretes (no s'usa ara; es conserva per si de cas) */
.legend-classes {
  margin-top: 4px;
}
.legend-classe {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.74rem;
  color: #444;
  line-height: 1.5;
}
.legend-classe-box {
  display: inline-block;
  width: 15px;
  height: 15px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  flex: none;
}
.legend-nota {
  margin-top: 6px;
  font-size: 0.66rem;
  font-style: italic;
  color: #999;
  line-height: 1.35;
}

/* Petits distintius de degradat a les etiquetes de les capes de dades */
.swatch-temp,
.swatch-ivac,
.swatch-incr {
  display: inline-block;
  width: 22px;
  height: 9px;
  margin-right: 6px;
  border-radius: 2px;
  vertical-align: middle;
  border: 1px solid rgba(0, 0, 0, 0.2);
}
.swatch-temp {
  background: linear-gradient(to right, #F5F400, #F57C00, #F50100);
}
.swatch-incr {
  background: linear-gradient(to right, #f2e6f7, #a860c9, #4a0d78);
}
/* Rampa Spectral de l'IVAC (0 blau → 100 vermell) */
.swatch-ivac {
  background: linear-gradient(to right,
    #2b83ba, #abdda4, #ffffbf, #fdae61, #d7191c);
}

/* Pastilles de to dels mapes base: mateix llenguatge visual que les icones de
   capa, i alhora una mini-previsualització del to de cada fons. */
.bm-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  border-radius: 3px;
  vertical-align: middle;
  border: 1px solid rgba(0, 0, 0, 0.2);
}
.bm-positron { background: #f4f1ec; }
.bm-dataviz  { background: linear-gradient(135deg, #dce7ec, #cfe0d3); }
.bm-dark     { background: #1b1f27; }
.bm-esri     { background: linear-gradient(135deg, #4f6d3f, #8a7b4f); }

/* ===== Símbol del nord ===== */
.nord-control {
  background: rgba(255, 255, 255, 0.9);
  padding: 4px 6px 2px;
  border-radius: 6px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
  line-height: 0;
}

/* ===== Popup ===== */
.popup-ivac { font-size: 0.85rem; min-width: 250px; }
.popup-ivac > b {
  display: block;
  color: #9C3D1A;
  font-size: 1rem;
  line-height: 1.2;
}

.popup-overline {
  display: block;
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: #C9662F;
}

.popup-ref {
  display: block;
  margin-top: 1px;
  font-size: 0.68rem;
  color: #999;
}

.popup-ivac-total {
  margin: 6px 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e0e0e0;
}

.popup-ivac-titol {
  display: block;
  margin: 4px 0 2px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #888;
}

/* --- Files de components amb barra de gradient --- */
.comp-row {
  margin: 7px 0;
  cursor: help;
}
.comp-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 0.76rem;
}
.comp-name { flex: 1; color: #444; }
.comp-val {
  font-weight: 600;
  color: #333;
  white-space: nowrap;
}
.comp-val-total { color: #9C3D1A; font-size: 0.9rem; }

/* Barra de gradient Spectral continu i suau (blau → vermell) */
.comp-bar {
  position: relative;
  height: 9px;
  margin-top: 3px;
  border-radius: 4px;
  background: linear-gradient(to right,
    #2b83ba 0%,
    #abdda4 25%,
    #ffffbf 50%,
    #fdae61 75%,
    #d7191c 100%);
}
.comp-bar-marker {
  position: absolute;
  top: -2px;
  width: 2px;
  height: 13px;
  background: #1a1a1a;
  border-radius: 1px;
  transform: translateX(-1px);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85);
}

.comp-num {
  display: inline-block;
  width: 15px;
  height: 15px;
  line-height: 15px;
  margin-right: 3px;
  text-align: center;
  border-radius: 50%;
  background: #9C3D1A;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
}

.popup-ivac-nota {
  display: block;
  margin-top: 5px;
  font-size: 0.66rem;
  color: #999;
  font-style: italic;
}

.popup-ivac-footnote {
  margin: 8px 0 0;
  padding-top: 7px;
  border-top: 1px solid #e0e0e0;
  font-size: 0.68rem;
  line-height: 1.35;
  color: #666;
}

/* ===== Refugis climàtics ===== */
/* Punt de color a l'etiqueta de la capa (mini-llegenda) */
.dot-refugi {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 50%;
  background: #4f46e5;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
  vertical-align: middle;
}

/* Clústers en to índic (fora de la rampa Spectral de l'IVAC) i deliberadament
   DISCRETS: halo tènue i disc interior més petit, perquè la resposta pública no
   eclipsi la coropleta de vulnerabilitat, que és la lectura principal. */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large { background-color: rgba(79, 70, 229, 0.14); }
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background-color: rgba(79, 70, 229, 0.72);
  width: 26px;
  height: 26px;
  margin-left: 7px;
  margin-top: 7px;
  border-radius: 13px;
}
.marker-cluster div {
  color: #fff;
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
  font-weight: 500;
  font-size: 0.72rem;
}
.marker-cluster span { line-height: 26px; }

/* Popup del refugi — mateixa paleta terracota que la interfície i el popup IVAC */
.popup-refugi { font-size: 0.85rem; min-width: 210px; }
.popup-refugi > b {
  display: block;
  color: #9C3D1A;
  font-size: 1rem;
  line-height: 1.2;
  margin-top: 1px;
}
.popup-refugi .popup-overline { color: #C9662F; }
.ref-adr {
  display: block;
  margin-top: 3px;
  font-size: 0.8rem;
  color: #444;
}
.ref-zona {
  display: block;
  margin-top: 1px;
  font-size: 0.72rem;
  color: #999;
}
.ref-tip {
  display: inline-block;
  margin-top: 5px;
  padding: 1px 8px;
  font-size: 0.66rem;
  font-weight: 500;
  color: #9C3D1A;
  background: #FBEEE7;
  border-radius: 10px;
}
.ref-font {
  display: block;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid #eee;
  font-size: 0.62rem;
  color: #aaa;
}
.ref-block {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e0e0e0;
}
.ref-label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #888;
}

/* Horari estructurat: període (temporada) + llista dia → hores amb pics */
.ref-periode {
  margin-top: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #9C3D1A;
}
.ref-periode:first-of-type { margin-top: 0; }
.ref-hores {
  list-style: none;
  margin: 3px 0 0;
  padding: 0;
}
.ref-hores li {
  position: relative;
  padding-left: 12px;
  margin: 5px 0;
}
.ref-hores li::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 6px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #C9662F;
}
.ref-dia {
  display: block;
  font-size: 0.76rem;
  font-weight: 500;
  color: #333;
  line-height: 1.3;
}
.ref-hora {
  display: block;
  font-size: 0.73rem;
  color: #777;
  line-height: 1.3;
}
.ref-link {
  display: inline-block;
  margin-right: 10px;
  font-size: 0.76rem;
  color: #9C3D1A;
  font-weight: 500;
  text-decoration: none;
}
.ref-link:hover { text-decoration: underline; }

/* ===== Responsivitat mòbil ===== */
@media (max-width: 768px) {
  /* La barra no tapa tota la pantalla i arrenca plegada (via JS) */
  :root { --sidebar-w: min(420px, 86vw); }

  #sidebar { background: rgba(255, 255, 255, 0.92); }

  /* Targeta de llegenda més compacta */
  .map-legend {
    max-width: 190px;
    padding: 9px 11px;
    font-size: 0.73rem;
  }
  .map-legend-title { font-size: 0.72rem; }
  .legend-ramp-v,
  .legend-ramp-v-labels { height: 86px; }

  .brand h1 { font-size: 1rem; }
}
