:root {
    --bg: #f5f7f2;
    --surface: #ffffff;
    --surface-soft: #eef4f7;
    --text: #172022;
    --muted: #607076;
    --line: #d6e0df;
    --accent: #0f8a8a;
    --accent-dark: #096567;
    --warm: #e36f3d;
    --ok: #1f9d63;
    --warn: #b26a00;
    --shadow: 0 18px 44px rgba(25, 40, 44, .12);
    --blue-soft: #c4d5e5;
    --orange: #df4f24;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

a {
    color: inherit;
}

.site-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 18px clamp(18px, 4vw, 48px);
    background: rgba(255, 255, 255, .92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 500;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), #67a64d);
    font-weight: 800;
}

.brand-title {
    margin: 0;
    font-size: clamp(1.1rem, 2vw, 1.45rem);
    line-height: 1.1;
}

.brand-subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: .92rem;
}

.nav-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--accent-dark);
    background: #fff;
    font-size: .92rem;
    white-space: nowrap;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 9px 12px;
    border-radius: 8px;
    color: #fff;
    background: var(--accent);
    font-size: .92rem;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.nav-link:hover {
    background: var(--accent-dark);
}

.layout {
    display: grid;
    grid-template-columns: minmax(280px, 330px) minmax(540px, 1fr) minmax(260px, 310px);
    gap: 18px;
    padding: 18px;
    min-height: 0;
}

.panel {
    padding: clamp(16px, 2vw, 24px);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    overflow: auto;
}

.panel h2 {
    margin: 0 0 10px;
    font-size: clamp(1.65rem, 3vw, 2.5rem);
    line-height: 1;
}

.panel-intro {
    margin: 0 0 24px;
    color: var(--muted);
    line-height: 1.5;
}

.history-form {
    margin: 0 0 18px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f9fbfb;
}

.history-form label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.history-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    gap: 8px;
    align-items: center;
}

.history-controls input,
.history-controls select,
.history-controls button,
.reset-link {
    min-height: 40px;
    border-radius: 8px;
    font: inherit;
}

.history-controls input,
.history-controls select {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--line);
    padding: 8px 10px;
    color: var(--text);
    background: #fff;
}

.history-controls select {
    min-width: 104px;
}

.history-controls button {
    border: 0;
    padding: 0 14px;
    color: #fff;
    background: var(--accent);
    font-weight: 800;
    cursor: pointer;
}

.reset-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    padding: 0 12px;
    color: var(--accent-dark);
    text-decoration: none;
    background: #fff;
    font-weight: 800;
}

.station-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.station-card + .station-card {
    margin-top: 14px;
}

.station-head {
    padding: 18px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    background: var(--surface-soft);
}

.station-name {
    margin: 0;
    font-size: 1.08rem;
}

.station-meta {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: .9rem;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 9px;
    border-radius: 999px;
    background: #fff;
    color: var(--accent-dark);
    border: 1px solid var(--line);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}

.status::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ok);
}

.status[data-status="error"]::before,
.status[data-status="offline"]::before {
    background: var(--warm);
}

.status[data-status="nodata"]::before {
    background: var(--warn);
}

.status[data-status="archive"]::before {
    background: var(--muted);
}

.readings {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
    background: var(--line);
}

.reading {
    padding: 14px;
    background: #fff;
    min-width: 0;
}

.reading-label {
    display: block;
    color: var(--muted);
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.reading-value {
    display: block;
    margin-top: 6px;
    font-size: 1.22rem;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.station-foot {
    padding: 14px 18px;
    color: var(--muted);
    font-size: .9rem;
    background: #fff;
}

.charts-panel {
    min-width: 0;
    overflow: auto;
}

.section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin: 0 0 14px;
}

.section-head h2 {
    margin: 0;
    font-size: clamp(1.45rem, 2.5vw, 2rem);
    line-height: 1;
}

.section-head p {
    margin: 5px 0 0;
    color: var(--muted);
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.chart-card {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 10px 26px rgba(25, 40, 44, .10);
    padding: 14px;
}

.chart-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    min-height: 58px;
}

.weather-icon {
    width: 50px;
    height: 50px;
    display: grid;
    place-items: center;
    color: #233043;
    flex: 0 0 auto;
}

.weather-icon svg {
    width: 46px;
    height: 46px;
}

.chart-reading {
    text-align: right;
    min-width: 0;
}

.chart-reading h3 {
    margin: 0 0 6px;
    font-size: 1rem;
    color: #11183a;
}

.chart-reading strong {
    display: block;
    font-size: 1.05rem;
    color: #11183a;
    overflow-wrap: anywhere;
}

.chart-box {
    position: relative;
    height: clamp(190px, 24vh, 270px);
    min-height: 190px;
    margin-top: 10px;
}

.chart-box canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.extremes {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.extreme {
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3px 8px;
    font-weight: 800;
    font-size: .92rem;
}

.extreme.high {
    color: #fff;
    background: var(--orange);
}

.extreme.low {
    color: #0e2d4b;
    background: var(--blue-soft);
}

.chart-card-temperature .weather-icon {
    color: #297ee8;
}

.chart-card-pressure .weather-icon {
    color: #36405e;
}

.chart-card-humidity .weather-icon {
    color: #157d91;
}

.chart-card-rain .weather-icon {
    color: #172033;
}

.map-wrap {
    align-self: start;
    height: min(520px, calc(100vh - 116px));
    min-height: 340px;
    position: relative;
    display: grid;
    grid-template-rows: auto 1fr;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}

#map {
    width: 100%;
    height: 100%;
    min-height: 0;
    background: #dbe9e8;
}

.map-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
}

.map-title span {
    color: var(--muted);
    font-size: .9rem;
}

.gm-style .map-popup {
    color: var(--text);
}

.leaflet-popup-content-wrapper {
    border-radius: 8px;
}

.map-popup {
    min-width: 230px;
}

.map-popup h3 {
    margin: 0 0 8px;
    font-size: 1rem;
}

.map-popup dl {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 14px;
    margin: 0;
}

.map-popup dt {
    color: var(--muted);
}

.map-popup dd {
    margin: 0;
    font-weight: 700;
}

.marker-pin {
    width: 32px;
    height: 32px;
    border-radius: 8px 8px 8px 0;
    transform: rotate(-45deg);
    background: var(--accent);
    border: 3px solid #fff;
    box-shadow: 0 8px 18px rgba(0, 0, 0, .25);
}

.marker-pin span {
    position: absolute;
    inset: 5px;
    display: grid;
    place-items: center;
    transform: rotate(45deg);
    color: #fff;
    font-size: 14px;
    font-weight: 900;
}

.leaflet-div-icon {
    background: transparent;
    border: 0;
}

@media (max-width: 1220px) {
    .layout {
        grid-template-columns: minmax(300px, 360px) 1fr;
    }

    .map-wrap {
        grid-column: 1 / -1;
        height: 380px;
    }
}

@media (max-width: 920px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .panel {
        max-height: none;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .map-wrap,
    #map {
        min-height: 360px;
    }
}

@media (max-width: 620px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .nav-pill {
        width: 100%;
        justify-content: center;
    }

    .readings {
        grid-template-columns: 1fr;
    }

    .history-controls {
        grid-template-columns: 1fr;
    }

    .layout {
        padding: 12px;
    }

    .chart-box {
        height: 230px;
    }
}
