:root {
    --background: #f4f7f9;
    --surface: #ffffff;
    --text: #17212b;
    --muted: #6b7785;
    --border: #dfe5ea;
    --primary: #176b87;
    --shadow: 0 4px 18px rgba(0, 0, 0, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family:
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background: var(--background);
    color: var(--text);
}

.main-header {
    background: #102a3a;
    color: white;
    padding: 24px max(24px, calc((100% - 1400px) / 2));
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.main-header h1 {
    margin: 0;
    font-size: 2rem;
}

.main-header p {
    margin: 5px 0 0;
    opacity: 0.8;
}

.status-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 7px;
}

.system-status {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 600;
    white-space: nowrap;
    font-size: 0.88rem;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #a0a7ad;
}

.system-status.online .status-dot {
    background: #36d37e;
}

.system-status.warning .status-dot {
    background: #f0ad3d;
}

.system-status.offline .status-dot {
    background: #e25555;
}

main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 28px 24px 48px;
}

.summary {
    margin-bottom: 20px;
}

.summary-info {
    display: flex;
    flex-wrap: wrap;
    gap: 14px 40px;
    background: var(--surface);
    padding: 18px 22px;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.summary-info div {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.label {
    color: var(--muted);
    font-size: 0.85rem;
}

.sensor-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}

.sensor-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sensor-card span {
    color: var(--muted);
    font-size: 0.9rem;
}

.sensor-card strong {
    font-size: 1.85rem;
    line-height: 1;
}

.sensor-card small {
    color: var(--muted);
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: hidden;
}

.panel-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.panel-header h2 {
    margin: 0;
    font-size: 1.15rem;
}

.panel-header p {
    color: var(--muted);
    margin: 4px 0 0;
    font-size: 0.9rem;
}

.panel-header label {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
}

select {
    padding: 8px 10px;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: white;
}

#map {
    height: 520px;
    width: 100%;
}

.map-legend {
    padding: 14px 20px 4px;
}

.legend-title {
    font-size: 0.84rem;
    color: var(--muted);
    margin-bottom: 8px;
}

.legend-scale {
    display: grid;
    grid-template-columns: auto minmax(180px, 400px) auto;
    align-items: center;
    gap: 10px;
    max-width: 520px;
    font-size: 0.8rem;
}

.legend-gradient {
    height: 10px;
    border-radius: 20px;
    background:
        linear-gradient(
            90deg,
            #2c7bb6 0%,
            #abd9e9 25%,
            #ffffbf 50%,
            #fdae61 75%,
            #d7191c 100%
        );
}

.legend-labels {
    max-width: 520px;
    padding: 3px 32px 0;
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 0.7rem;
}

.map-note {
    margin: 0;
    padding: 8px 20px 14px;
    color: var(--muted);
    font-size: 0.8rem;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

th,
td {
    padding: 11px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    background: #f8fafb;
    color: #41505c;
    font-weight: 650;
}

tbody tr:hover {
    background: #f7fafc;
}

.error-message {
    padding: 14px 18px;
    margin-bottom: 20px;
    border-radius: 10px;
    border: 1px solid #efb7b7;
    background: #fff0f0;
    color: #8e2525;
}

footer {
    text-align: center;
    color: var(--muted);
    padding: 20px;
    font-size: 0.85rem;
}

@media (max-width: 1050px) {
    .sensor-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 700px) {
    .main-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .sensor-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .panel-header {
        align-items: flex-start;
        flex-direction: column;
    }

    #map {
        height: 420px;
    }
}

@media (max-width: 430px) {
    main {
        padding-left: 12px;
        padding-right: 12px;
    }

    .sensor-grid {
        grid-template-columns: 1fr 1fr;
        gap: 9px;
    }

    .sensor-card {
        padding: 14px;
    }

    .sensor-card strong {
        font-size: 1.5rem;
    }
}

.map-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
}

@media (max-width: 700px) {
    .map-controls {
        width: 100%;
        align-items: flex-start;
        flex-direction: column;
    }
}

.period-selector {
    margin-left: auto;
}

.period-selector select {
    margin-top: 2px;
    min-width: 155px;
}

@media (max-width: 700px) {
    .period-selector {
        margin-left: 0;
    }
}

.custom-period-controls {
    margin-top: 10px;
    padding: 12px;
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    background: #f8fafb;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.custom-period-controls[hidden] {
    display: none;
}

.custom-period-controls label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: var(--muted);
    font-size: 0.8rem;
}

.custom-period-controls input {
    padding: 8px 9px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: white;
    color: var(--text);
    font: inherit;
}

.custom-period-controls button {
    padding: 9px 15px;
    border: 0;
    border-radius: 7px;
    background: var(--primary);
    color: white;
    font-weight: 600;
    cursor: pointer;
}

.custom-period-controls button:hover {
    filter: brightness(0.94);
}

@media (max-width: 700px) {
    .custom-period-controls {
        align-items: stretch;
        flex-direction: column;
    }
}

.header-brand {
    min-width: 250px;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.main-nav a {
    color: rgba(255, 255, 255, 0.78);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
    padding: 8px 12px;
    border-radius: 7px;
    transition: background 0.2s ease, color 0.2s ease;
}

.main-nav a:hover,
.main-nav a.active {
    color: white;
    background: rgba(255, 255, 255, 0.10);
}

@media (max-width: 700px) {
    .main-nav {
        width: 100%;
    }
}

/* ===== LOGO PRINCIPAL AIR QUALITY ===== */

.header-brand {
    display: flex;
    align-items: center;
    min-width: 0;
}

.brand-logo-link {
    display: inline-flex;
    align-items: center;
    line-height: 0;
    text-decoration: none;
}

.header-logo {
    display: block;
    width: auto;
    height: 52px;
    max-width: 280px;
    object-fit: contain;
}

@media (max-width: 700px) {
    .header-logo {
        height: 42px;
        max-width: 220px;
    }
}

/* ===== IDENTIDAD DE CABECERA AIR QUALITY ===== */

.brand-wordmark {
    position: relative;

    display: inline-flex;
    flex-direction: column;
    justify-content: center;

    min-height: 42px;
    padding-left: 15px;

    color: inherit;
    line-height: 1;
    text-decoration: none;
}

.brand-wordmark::before {
    content: "";

    position: absolute;
    left: 0;
    top: 3px;
    bottom: 3px;

    width: 4px;

    border-radius: 999px;

    background:
        linear-gradient(
            180deg,
            #18b7e8 0%,
            #17a8c9 45%,
            #38b54a 100%
        );
}

.brand-name {
    display: block;

    font-size: 1.34rem;
    font-weight: 800;
    letter-spacing: -0.035em;
}

.brand-air {
    color: #ffffff;
}

.brand-quality {
    color: #4bc2a2;
}

.brand-subtitle {
    display: block;

    margin-top: 5px;

    color: #adc0c9;

    font-size: 0.66rem;
    font-weight: 500;
    letter-spacing: 0.025em;
}

.header-brand {
    display: flex;
    align-items: center;
}


@media (max-width: 700px) {
    .brand-wordmark {
        min-height: 36px;
        padding-left: 12px;
    }

    .brand-name {
        font-size: 1.12rem;
    }

    .brand-subtitle {
        font-size: 0.58rem;
    }
}


/* ===== AIR QUALITY HEADER LOGO ===== */

.brand-logo-link {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    text-decoration: none;
}

.brand-logo-image {
    display: block;

    width: 194px;
    max-height: 48px;

    height: auto;

    object-fit: contain;
}

.header-brand {
    display: flex;
    align-items: center;
}

@media (max-width: 700px) {

    .brand-logo-image {
        width: 170px;
        max-height: 42px;
    }
}
