
:root {
    color-scheme: dark;
    --bg: #0b1120;
    --surface: #151f32;
    --surface-alt: #1c2940;
    --border: #293750;
    --text: #e5edf8;
    --muted: #91a2ba;
    --accent: #38bdf8;
    --green: #34d399;
    --orange: #fbbf24;
    --red: #fb7185;
}

* {
    box-sizing: border-box;
}

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

button,
select {
    font: inherit;
}

.container {
    width: min(1440px, calc(100% - 40px));
    margin: 0 auto;
}

.topbar {
    border-bottom: 1px solid var(--border);
    background: #101a2b;
}

.topbar-content {
    min-height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 13px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: #123a55;
    color: var(--accent);
    font-size: 23px;
}

.brand h1 {
    margin: 0;
    font-size: 1.25rem;
    letter-spacing: .2px;
}

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

.connection {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--muted);
    font-size: .85rem;
}

.connection-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 12px #34d39988;
}

.connection.error .connection-dot {
    background: var(--red);
    box-shadow: none;
}

main {
    padding: 32px 0 48px;
}

.page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 28px;
}

.page-heading h2 {
    margin: 0;
    font-size: 1.55rem;
}

.page-heading p {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: .9rem;
}

.sensor-control {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sensor-control label {
    color: var(--muted);
    font-size: .85rem;
}

.sensor-control select {
    min-width: 150px;
    padding: 10px 34px 10px 12px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
    cursor: pointer;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.metric-card {
    position: relative;
    overflow: hidden;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.metric-card::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--accent);
}

.metric-card.humidity::after {
    background: #a78bfa;
}

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

.metric-value {
    margin-top: 15px;
    font-size: clamp(2.2rem, 5vw, 3.2rem);
    font-weight: 650;
    letter-spacing: -1.5px;
}

.metric-value small {
    margin-left: 5px;
    color: var(--muted);
    font-size: 1.2rem;
    font-weight: 400;
}

.metric-description {
    margin-top: 12px;
    color: var(--muted);
    font-size: .82rem;
}

.panel {
    margin-bottom: 24px;
    padding: 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.panel-heading h3 {
    margin: 0;
    font-size: 1rem;
}

.panel-heading span {
    color: var(--muted);
    font-size: .8rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
}

.info-item label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: .8rem;
}

.info-item strong {
    font-size: .95rem;
    font-weight: 550;
    overflow-wrap: anywhere;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    white-space: nowrap;
}

th {
    padding: 12px 14px;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 550;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 14px;
    font-size: .86rem;
    border-bottom: 1px solid #29375088;
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover {
    background: var(--surface-alt);
}

.empty-state {
    padding: 30px;
    color: var(--muted);
    text-align: center;
}

.footer {
    padding: 18px 0;
    color: var(--muted);
    border-top: 1px solid var(--border);
    font-size: .78rem;
    text-align: center;
}

@media (max-width: 700px) {
    .container {
        width: min(100% - 28px, 1440px);
    }

    .topbar-content {
        min-height: 68px;
    }

    main {
        padding-top: 24px;
    }

    .page-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .sensor-control {
        width: 100%;
        justify-content: space-between;
    }

    .sensor-control select {
        flex: 1;
        max-width: 220px;
    }

    .metrics {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .metric-card {
        padding: 20px;
    }

    .info-grid {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    .panel {
        padding: 17px;
    }

    .connection {
        font-size: .75rem;
    }
}

/* =========================================
   HISTORIAL AMBIENTAL
========================================= */

.history-panel {
    margin-top: 24px;
}

.history-description {
    display: block;
    margin-top: 5px;
    color: #94a3b8;
    font-size: 0.85rem;
}

.period-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.period-control label {
    color: #94a3b8;
    font-size: 0.85rem;
}

.period-control select {
    background: #1e293b;
    color: #e2e8f0;
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 8px 12px;
}

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

.chart-card {
    min-width: 0;
    padding: 18px;
    background: #111c2e;
    border: 1px solid #263449;
    border-radius: 10px;
}

.chart-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.chart-heading h4 {
    margin: 0;
    font-size: 1rem;
    color: #e2e8f0;
}

.chart-heading span {
    color: #94a3b8;
    font-size: 0.85rem;
}

.chart-container {
    width: 100%;
    min-height: 260px;
    position: relative;
}

.chart-container svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.chart-loading {
    color: #94a3b8;
    text-align: center;
    padding: 80px 10px;
    font-size: 0.9rem;
}

.history-footer {
    margin-top: 16px;
    color: #94a3b8;
    font-size: 0.8rem;
}

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

    .panel-heading {
        flex-wrap: wrap;
        gap: 12px;
    }

    .period-control {
        width: 100%;
        justify-content: space-between;
    }
}
