* {
    box-sizing: border-box;
}

body {
    margin: 0;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: url('../img/dia.jpg') no-repeat center center fixed;
    background-size: cover;
    color: #fff;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.map-header {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "actions title filters";
    align-items: center;
    gap: 12px;
    padding-top: 8px;
    padding-bottom: 6px;
}

.header-actions {
    grid-area: actions;
}

.station-filters {
    grid-area: filters;
}

.header-actions,
.station-filters {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
}

.titulo {
    grid-area: title;
    margin: 0;
    color: #0c09ad;
    font-size: 38px;
    font-family: 'Angsana New', 'Segoe UI', sans-serif;
    font-weight: bold;
    text-align: center;
    line-height: 1.05;
    text-shadow: 1px 1px 3px rgb(0, 254, 241), -1px -1px 5px rgb(126, 253, 246);
}

@media (max-width: 1366px) {
    .map-header {
        gap: 8px;
        padding-top: 6px;
        padding-bottom: 5px;
    }

    .titulo {
        font-size: 32px;
    }

    .toggle-button {
        min-width: 42px;
        height: 42px;
        padding: 3px 7px;
    }

    .toggle-button img {
        width: 30px;
        height: 30px;
    }

    .filter-btn {
        font-size: 0.76rem;
        padding: 4px 8px !important;
    }

    .main-row {
        min-height: calc(100vh - 142px);
    }

    .menu-side {
        height: calc(100vh - 142px);
        max-height: calc(100vh - 142px);
    }

    #map {
        height: calc(100vh - 142px);
    }

    .menu-side.show {
        width: 172px;
    }

    #deptList {
        min-width: 166px;
        padding: 4px 5px 8px 8px;
    }

    #deptList .list-group-item {
        width: 154px;
        font-size: 0.78rem;
        padding: 4px 6px;
        margin-bottom: 4px;
    }
}

.toggle-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 46px;
    height: 46px;
    padding: 4px 8px;
    background-color: #333333;
    color: #ffffff;
    border: 2px solid #17d1d1;
    border-radius: 25px;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.2s, transform 0.2s;
}

.toggle-button:hover {
    background-color: #17d1d1;
    transform: scale(1.06);
}

.toggle-button img {
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.filter-btn {
    border-radius: 20px !important;
    padding: 5px 10px !important;
    font-size: 0.82rem;
    font-weight: 600;
    background: rgba(51, 51, 51, 0.88);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
    transition: all 0.2s;
}

.filter-btn.active {
    background: #17d1d1 !important;
    border-color: #17d1d1 !important;
    color: #061b1b !important;
    box-shadow: 0 0 12px rgba(23, 209, 209, 0.45);
}

.main-row {
    flex: 1 1 auto;
    min-height: 0;
    padding-right: 12px;
}

.menu-side {
    width: 0;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    transition: width 0.25s ease;
}

.menu-side.show {
    width: 192px;
}

#deptList {
    min-width: 184px;
    height: 100%;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 12px 8px 12px;
}

#deptList::-webkit-scrollbar,
.station-filters::-webkit-scrollbar {
    width: 7px;
    height: 6px;
}

#deptList::-webkit-scrollbar-thumb,
.station-filters::-webkit-scrollbar-thumb {
    background: rgba(23, 209, 209, 0.75);
    border-radius: 8px;
}

#deptList::-webkit-scrollbar-track,
.station-filters::-webkit-scrollbar-track {
    background: rgba(51, 51, 51, 0.45);
    border-radius: 8px;
}

#deptList .list-group-item {
    width: calc(100% - 2px);
    margin: 0 0 5px;
    padding: 5px 8px;
    line-height: 1.15;
    background-color: #333333;
    color: #ffffff;
    border: 2px solid #17d1d1;
    border-radius: 25px !important;
    text-align: center;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.2s;
}

#deptList .list-group-item:hover,
#deptList .list-group-item.active {
    background-color: #17d1d1;
    color: #061b1b;
    transform: scale(1.04);
}

.map-col {
    padding: 0 0 0 8px;
    position: relative;
    min-height: 0;
}

#map {
    width: 100%;
    height: 100%;
    min-height: 240px;
    color: #ffffff;
    border: 4px solid #17d1d1;
    border-radius: 15px;
    z-index: 1;
    overflow: hidden;
    box-shadow: 0 4px 22px rgba(0, 0, 0, 0.34);
}

.sicon-wrap {
    background: none !important;
    border: none !important;
}

.sicon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.65);
    transition: transform 0.2s;
}

.sicon:hover {
    transform: scale(1.18);
}

.s-meteo {
    background: linear-gradient(135deg, #f39c12, #e74c3c);
}

.s-pluvial {
    background: linear-gradient(135deg, #3498db, #2980b9);
}

.s-fluvial {
    background: linear-gradient(135deg, #00b894, #00cec9);
}

.s-nodata {
    background: linear-gradient(135deg, #636e72, #b2bec3);
    border-color: #dfe6e9;
    opacity: 0.85;
}

.info-bar {
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 12px 0;
    padding: 8px 12px;
    line-height: 18px;
    background-color: #333333;
    color: #ffffff;
    border: 2px solid #17d1d1;
    border-radius: 15px;
    font-size: 0.88rem;
}

.info-label {
    color: #17d1d1;
    font-weight: 700;
}

.info-value {
    color: #ffffff;
    font-weight: 600;
}

.source-note {
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin: 4px 12px 0;
    color: #ffffff;
    font-size: 10px;
}

.popup-station {
    font-family: 'Segoe UI', sans-serif;
    font-size: 0.85rem;
    line-height: 1.8;
    min-width: 190px;
}

.popup-title {
    color: #0c0a3b;
    font-size: 1rem;
    display: block;
    margin-bottom: 4px;
}

.popup-station i {
    width: 18px;
    text-align: center;
}

.leaflet-popup-content-wrapper {
    background: rgba(255, 255, 255, 0.88);
    color: #333333;
    border: 2px solid #17d1d1;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.leaflet-popup-content {
    margin: 12px 16px;
}

.leaflet-container {
    background: #1a1a3e;
}

.logo-container {
    width: 250px;
    opacity: 0.82;
    background-color: rgba(255, 255, 255, 0.3);
    padding: 5px;
    border-radius: 15px;
}

.logo-container img {
    width: 100%;
    display: block;
}

.logo-container-bottom {
    width: 190px;
    opacity: 0.72;
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    padding: 5px;
}

.logo-container-bottom img {
    width: 100%;
    display: block;
}

@media (max-width: 992px) {
    .map-header {
        grid-template-columns: auto minmax(0, 1fr);
        grid-template-areas:
            "title title"
            "actions filters";
        justify-items: stretch;
        gap: 5px 7px;
    }

    .header-actions {
        justify-content: center;
    }

    .station-filters {
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: thin;
        padding-bottom: 2px;
    }

    .titulo {
        font-size: 28px;
    }

    .main-row {
        min-height: calc(100vh - 184px);
    }

    #map {
        height: calc(100vh - 184px);
    }

    .menu-side {
        position: absolute;
        z-index: 1000;
        height: calc(100vh - 184px);
        max-height: calc(100vh - 184px);
        left: -178px;
        background: rgba(0, 0, 0, 0.34);
        transition: left 0.25s ease, width 0.25s ease;
    }

    .menu-side.show {
        left: 0;
        width: 172px;
    }

    #deptList {
        min-width: 166px;
        max-height: 100%;
        overflow-y: auto;
        padding: 4px 11px 14px 8px;
    }

    #deptList .list-group-item {
        width: calc(100% - 2px);
        font-size: 0.78rem;
        padding: 4px 6px;
    }
}

@media (max-width: 768px) {
    .map-header {
        gap: 6px;
        padding-left: 6px !important;
        padding-right: 6px !important;
    }

    .titulo {
        font-size: 21px;
        white-space: normal;
    }

    .station-filters {
        width: auto;
    }

    .filter-btn {
        flex: 0 0 auto;
        font-size: 0.72rem;
        padding: 4px 8px !important;
    }

    .main-row {
        min-height: calc(100vh - 180px);
        padding-right: 6px;
    }

    .menu-side {
        height: calc(100vh - 180px);
        max-height: calc(100vh - 180px);
        left: -168px;
    }

    .menu-side.show {
        left: 0;
        width: 164px;
    }

    #deptList {
        min-width: 158px;
        padding: 4px 11px 12px 7px;
    }

    #deptList .list-group-item {
        width: calc(100% - 2px);
        font-size: 0.74rem;
        padding: 4px 6px;
    }

    .map-col {
        padding-left: 6px;
    }

    #map {
        height: calc(100vh - 180px);
        border-radius: 10px;
    }

    .info-bar {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
        margin: 6px 8px 0;
        font-size: 0.72rem;
        line-height: 16px;
    }

    .source-note {
        flex-direction: column;
        gap: 2px;
        margin: 4px 8px 0;
        font-size: 8px;
    }

    .logo-container {
        width: 112px;
    }

    .logo-container-bottom {
        width: 130px;
    }
}

@media (max-width: 420px) {
    .titulo {
        font-size: 18px;
    }

    .toggle-button {
        min-width: 38px;
        height: 38px;
        padding: 3px 6px;
    }

    .toggle-button img {
        width: 27px;
        height: 27px;
    }

    .filter-btn {
        font-size: 0.66rem;
        padding: 3px 7px !important;
    }

    .main-row {
        min-height: calc(100vh - 174px);
    }

    .menu-side {
        height: calc(100vh - 174px);
        max-height: calc(100vh - 174px);
    }

    #map {
        height: calc(100vh - 174px);
    }
}

/* Overrides finales: el mapa ocupa el espacio disponible y el footer siempre queda visible. */
.main-row {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

.menu-side,
.menu-side.show {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

#deptList {
    height: 100%;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
}

#map {
    height: 100%;
}

@media (max-width: 992px) {
    .main-row {
        min-height: 0;
    }

    .menu-side,
    .menu-side.show {
        top: 0;
        bottom: 0;
        height: auto;
        max-height: none;
        overflow: hidden;
    }

    #deptList {
        height: 100%;
        max-height: 100%;
        overflow-y: auto;
        overflow-x: hidden;
    }

    #map {
        height: 100%;
        min-height: 240px;
    }
}

@media (max-width: 768px) {
    #map {
        min-height: 220px;
    }

    .info-bar {
        gap: 4px;
        padding: 6px 8px;
    }

    .source-note {
        line-height: 1.15;
    }
}

@media (min-width: 1800px) {
    .map-header {
        padding-top: 12px;
        padding-bottom: 10px;
        gap: 18px;
    }

    .titulo {
        font-size: clamp(42px, 2.1vw, 64px);
    }

    .toggle-button {
        min-width: 54px;
        height: 54px;
    }

    .toggle-button img {
        width: 40px;
        height: 40px;
    }

    .filter-btn {
        font-size: clamp(0.9rem, 0.52vw, 1.15rem);
        padding: 7px 14px !important;
    }

    .menu-side.show {
        width: 220px;
    }

    #deptList {
        min-width: 212px;
    }

    #deptList .list-group-item {
        font-size: clamp(0.95rem, 0.5vw, 1.15rem);
        padding: 7px 10px;
    }

    .info-bar {
        font-size: clamp(0.95rem, 0.48vw, 1.12rem);
        padding: 10px 16px;
    }

    .source-note {
        font-size: clamp(11px, 0.42vw, 14px);
    }
}
