html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
}

#app {
    height: 100%;
}

.layout {
    display: grid;
    grid-template-columns: 2fr 1fr; /* 8 i 4 columnes equivalents */
    height: 100%;
}

#map-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
}

#cy {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    pointer-events: auto;
}

#cy-leaflet {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
}

#sidebar {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 1rem;
    overflow-y: auto;
    height: 100%;
}

.align-right {
    text-align: right;
    padding: 1em;
}

#sidebar {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    padding: 1em;
    box-sizing: border-box;
}

.sidebar-footer {
    margin-top: 0;
}

.sidebar-footer .footer-item {
    display: flex;
    align-items: center;
    gap: 0.5em;
    margin-bottom: 0.5em;
}

.footer-item {
    display: flex;
    align-items: center;
    gap: 0.5em;
    margin-bottom: 0.5em;
}

.icon-pan,
.icon-select {
    width: 20px;
    height: 20px;
    display: inline-block;
    margin-right: 0.5em;
    flex-shrink: 0;
}

.icon-pan {
    background-size: 16px 16px;
    background-position: 50% 50%;
    background-repeat: no-repeat;
    background-image: url('data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20448%20512%22%3E%3Cpath%20fill%3D%22currentColor%22%20d%3D%22M372.57%20112.641v-10.825c0-43.612-40.52-76.691-83.039-65.546-25.629-49.5-94.09-47.45-117.982.747C130.269%2026.456%2089.144%2057.945%2089.144%20102v126.13c-19.953-7.427-43.308-5.068-62.083%208.871-29.355%2021.796-35.794%2063.333-14.55%2093.153L132.48%20498.569a32%2032%200%200%200%2026.062%2013.432h222.897c14.904%200%2027.835-10.289%2031.182-24.813l30.184-130.958A203.637%20203.637%200%200%200%20448%20310.564V179c0-40.62-35.523-71.992-75.43-66.359zm27.427%20197.922c0%2011.731-1.334%2023.469-3.965%2034.886L368.707%20464h-201.92L51.591%20302.303c-14.439-20.27%2015.023-42.776%2029.394-22.605l27.128%2038.079c8.995%2012.626%2029.031%206.287%2029.031-9.283V102c0-25.645%2036.571-24.81%2036.571.691V256c0%208.837%207.163%2016%2016%2016h6.856c8.837%200%2016-7.163%2016-16V67c0-25.663%2036.571-24.81%2036.571.691V256c0%208.837%207.163%2016%2016%2016h6.856c8.837%200%2016-7.163%2016-16V101.125c0-25.672%2036.57-24.81%2036.57.691V256c0%208.837%207.163%2016%2016%2016h6.857c8.837%200%2016-7.163%2016-16v-76.309c0-26.242%2036.57-25.64%2036.57-.691v131.563z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E');
}

.icon-select {
    background-size: 16px 16px;
    background-position: 55% 50%;
    background-repeat: no-repeat;
    background-image: url('data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20320%20512%22%3E%3Cpath%20fill%3D%22currentColor%22%20d%3D%22M302.189%20329.126H196.105l55.831%20135.993c3.889%209.428-.555%2019.999-9.444%2023.999l-49.165%2021.427c-9.165%204-19.443-.571-23.332-9.714l-53.053-129.136-86.664%2089.138C18.729%20472.71%200%20463.554%200%20447.977V18.299C0%201.899%2019.921-6.096%2030.277%205.443l284.412%20292.542c11.472%2011.179%203.007%2031.141-12.5%2031.141z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E');
}

#map-wrapper #cy {
    z-index: 1;
    pointer-events: none;
}

#map-wrapper #cy-leaflet {
    z-index: 2;
}

.leaflet-tooltip.cytt {
     padding: 6px 8px;
     background: #fff;
     border: 1px solid #d1d5db;
     border-radius: 6px;
     box-shadow: 0 4px 12px rgba(0,0,0,.08);
     font: 12px/1.3 system-ui, sans-serif;
     z-index: 999;
}

.leaflet-tooltip.cytt strong {
    font-weight: 600;
}

.cy-leaflet-toggle {
    display:  none !important;
}

/* estil compacte */
/* contenidor compacte enganxat a baix (ja ho tens) */
.res-mini{ margin-top:auto; margin-bottom:8px; }

.res-stack{            /* disposició en dues files */
    display: grid;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid #e7eaf0;
    border-radius: 10px;
    background: #fff;
    font-size: 12px; line-height: 1.2;
}

/* línia superior: volum en una línia */
.res-top{
    display: grid;
    grid-template-columns: 14px auto auto 1fr; /* icona, label, valor, barra */
    align-items: center;
    gap: 6px 8px;
}
.res-top .ico{ width:14px; height:14px; color:#0d6efd; }
.res-top .lab{ color:#6b7280; }
.res-top .val{ font-weight:600; color:#0f172a;}

/* barra de capacitat mini */
.cap{ width:100%; height:6px; background:#eef2f7; border:1px solid #e7eaf0;
    border-radius:999px; overflow:hidden; }
.cap-fill{ height:100%; background:linear-gradient(90deg,#60a5fa,#0ea5e9); }

/* línia inferior: dues píndoles costat a costat */
.res-bottom{
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.res-item{
    display:flex; align-items:center; gap:6px;
    padding:6px 8px; border-radius:999px; background:#f8fafc;
}
.res-item .ico{ width:14px; height:14px; color:#0d6efd; }
.res-item .ico.in{ color:#16a34a; }
.res-item .ico.out{ color:#dc2626; }
.res-item .lab{ color:#6b7280; }
.res-item .val{ font-weight:600; color:#0f172a;}

/* responsiu: si l’ample és molt estret, que caiguin en dues línies */
@media (max-width: 380px){
    .res-top{ grid-template-columns: 14px auto 1fr; }
    .res-top .val{ justify-self:end; }
    .res-bottom{ grid-template-columns: 1fr; }
}

.month-select {
    display:flex; gap:.5rem; align-items:center;
}
button, .month-select select {
    padding:.25rem .5rem;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: .25rem;
    cursor: pointer;
}

button:hover {
    background: #d1d5db;
}

/* --------LOADER ---------------------------------------- */

.loading-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(2px);
}

.loading-box {
    text-align: center;
    font-family: sans-serif;
    color: #333;
}

.spinner {
    border: 5px solid #f3f3f3;
    border-top: 5px solid #0077cc;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.res-header-text h4 {
    margin: 0;
    font-size: 0.95rem;
}

.res-header-text .lab {
    font-size: 0.8rem;
    opacity: 0.8;
}

.res-table-wrapper {
    margin-top: 0.5rem;
}

.res-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.res-table th,
.res-table td {
    padding: 4px 6px;
    text-align: left;
}

.res-table thead tr {
    border-bottom: 1px solid rgba(0,0,0,0.08);
}

.res-table tbody tr:nth-child(odd) {
    background: rgba(0,0,0,0.02);
}

.res-input {
    width: 100%;
    box-sizing: border-box;
}

.res-actions {
    margin-top: 0.6rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.res-actions button {
    padding: 4px 10px;
    border-radius: .25rem;
    border: 1px solid #d1d5db;
    cursor: pointer;
}

.res-error {
    color: red;
    margin: 0;
    font-size: 0.8rem;
}

.res-table td.val {
    text-align: right;
}

.res-table th.val {
    text-align: right;
}

/* Alinea els inputs numèrics a la dreta */
.res-table input[type="number"] {
    text-align: right;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1200;
}

.modal-dialog {
    background: #fff;
    border-radius: 12px;
    min-width: 320px;
    max-width: 640px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 30px rgba(0,0,0,0.25);
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0,0,0,0.08);
}

.modal-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    border: none;
    background: transparent;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.modal-body {
    padding: 12px 16px;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 16px 12px;
    border-top: 1px solid rgba(0,0,0,0.08);
}

.btn-primary,
.btn-secondary {
    padding: 6px 12px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-primary {
    background: #0074D9;
    color: #fff;
}

.btn-secondary {
    background: #eee;
    color: #333;
}

.scenario-block {
    border-radius: 10px;
    border: 1px solid #e7eaf0;
    background: #f9fafb;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.85rem;
}

.scenario-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.scenario-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 500;
    color: #0f172a;
}

.scenario-toggle input[type="checkbox"] {
    margin: 0;
    width: 14px;
    height: 14px;
    accent-color: #0074D9; /* navegadors moderns */
}

.scenario-title {
    font-size: 0.9rem;
}

.scenario-chip {
    margin-left: auto;
    padding: 2px 8px;
    border-radius: 999px;
    background: #e0f2fe;
    color: #0369a1;
    font-size: 0.75rem;
    font-weight: 600;
}

.scenario-desc {
    margin: 0;
    color: #6b7280;
    font-size: 0.8rem;
}

.scenario-slider {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.scenario-slider input[type="range"] {
    width: 100%;
}

.scenario-values {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: #374151;
}

.scenario-value-new {
    font-weight: 600;
}

.scenario-value-delta {
    opacity: 0.8;
}

.map-title {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 999px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
    font-size: 0.85rem;
    color: #111827;
    z-index: 10; /* per sobre del mapa i del cy */
    pointer-events: none; /* no bloqueja el zoom ni els clics al mapa */
}

.map-title strong {
    font-weight: 600;
}

.map-legend {
    position: absolute;
    left: 10px;
    bottom: 10px;
    z-index: 10;
    font-size: 0.8rem;
    color: #111827;
    pointer-events: none; /* no bloqueja el mapa */
}

.map-legend .legend-block {
    background: rgba(255, 255, 255, 0.96);
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 6px 18px rgba(0,0,0,0.12);
    padding: 6px 6px 6px 8px;   /* compacte, poca dreta */
    margin-top: 6px;
    min-width: auto;
    width: auto;
    pointer-events: auto;
}

.legend-title {
    font-weight: 600;
    font-size: 0.8rem;
    margin-bottom: 4px;
}

/* ---------- LLEGENDES PER A UN SOL MES (línies/punts blau/vermell) ---------- */

.legend-symbol {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.legend-label {
    font-size: 0.78rem;
    color: #374151;
}

.legend-line {
    width: 22px;
    height: 0;
    border-top-width: 2px;
    border-top-style: solid;
    border-radius: 999px;
}

.legend-line.red {
    border-top-color: #dc2626; /* vermell */
}

.legend-line.blue {
    border-top-color: #2563eb; /* blau */
}

.legend-point {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    border: 2px solid transparent;
}

.legend-point.blue {
    background: #2563eb;
}

.legend-point.red {
    background: #dc2626;
}

/* Escala bàsica (per a llegenda mensual, si la fas servir) */
.legend-scale {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 0.7rem;
    color: #4b5563;
    padding: 2px 0;
}

/* Una mica de responsive per pantalles estretes */
@media (max-width: 800px) {
    .map-legend {
        right: 6px;
        bottom: 6px;
    }

    .map-legend .legend-block {
        min-width: 170px;
    }
}

/* ---------- LLEGENDES ANUALS (12 línies + 12 punts) ---------- */

.legend-category {
    margin-top: 4px;
}

.legend-subtitle {
    font-size: 0.75rem;
    color: #4b5563;
    margin-bottom: 2px;
}

/* Filera: columna de símbols + números al costat */
.legend-block-annual .legend-multi-row {
    display: flex;
    align-items: stretch;
    gap: 4px;
}

/* Columna de 12 símbols (de 0 a baix a 12 a dalt) */
.legend-block-annual .legend-multi-column {
    display: flex;
    flex-direction: column-reverse; /* primer color a baix, últim a dalt */
    gap: 1px;
}

/* Línies petites (cabal ambiental) */
.legend-tiny-line {
    width: 22px;
    height: 0;
    border-top-width: 3px;
    border-top-style: solid;
    border-radius: 999px;
}

/* Punts petits (demanda) */
.legend-tiny-point {
    width: 7px;
    height: 7px;
    border-radius: 999px;
}

/* Escala dins del bloc anual: enganxada a la columna de símbols */
.legend-block-annual .legend-scale {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    margin-left: 4px;
    font-size: 0.7rem;
    color: #4b5563;
    padding: 0;
    line-height: 1;
}

/* Distribució en dues columnes per a la llegenda anual */
.legend-annual-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 14px;
    margin-top: 6px;
}

/* Ajustos per mantenir-la compacta */
.legend-category {
    margin-top: 0;
}

.legend-subtitle {
    margin-bottom: 2px;
}

/* Columna de símbols + escala */
.legend-block-annual .legend-multi-row {
    display: flex;
    align-items: stretch;
    gap: 4px;
}

.legend-block-annual {
    padding-right: 4px !important; /* o 0 si vols encara més compacte */
    min-width: auto !important;
}

/* Columna vertical de 12 símbols */
.legend-block-annual .legend-multi-column {
    display: flex;
    flex-direction: column-reverse;
    justify-content: space-between; /* distribueix els 12 símbols uniformement */
    height: 120px; /* <-- alçada comuna (pots ajustar-ho) */
}

/* Sobreescribim perquè els gap no desalineïn */
.legend-block-annual .legend-multi-column > * {
    margin: 0;
}

/* ---------- LLEGENDES ANUALS (12 línies + 12 punts) ---------- */

.legend-category {
    margin-top: 2px;
}

.legend-subtitle {
    font-size: 0.75rem;
    color: #4b5563;
    margin-bottom: 2px;
    padding-right: 0.3rem;
}

/* llegenda anual en 2 columnes, però ajustada al contingut */
.legend-annual-grid {
    display: flex;
    gap: 12px;              /* separació entre les dues columnes */
    margin-top: 4px;
}

.legend-block-annual {
    padding-right: 4px;
}

/* Columna símbols + números */
.legend-block-annual .legend-multi-row {
    display: flex;
    align-items: stretch;
    gap: 4px;
}

/* Columna vertical de 12 símbols, tots amb la mateixa alçada total */
.legend-block-annual .legend-multi-column {
    display: flex;
    flex-direction: column-reverse;
    justify-content: space-between;
    height: 120px;          /* mateixa alçada per línies i punts */
}

/* Línies petites (cabal ambiental) */
.legend-tiny-line {
    width: 22px;
    height: 0;
    border-top-width: 3px;
    border-top-style: solid;
    border-radius: 999px;
}

/* Punts petits (demanda) */
.legend-tiny-point {
    width: 7px;
    height: 7px;
    border-radius: 999px;
}

/* Escala enganxada al costat dels símbols */
.legend-block-annual .legend-scale {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    margin-left: 2px;
    font-size: 0.7rem;
    color: #4b5563;
    line-height: 1;
    padding: 0;
}

