:root {
    --bg: #e9efec;
    --surface: #ffffff;
    --surface-soft: #f6f8f7;
    --ink: #132023;
    --muted: #6c7a7d;
    --border: #d3ddda;

    --header-dark: #0f1817;
    --header-mid: #123d2d;
    --header-green: #006f3d;
    --evo-green: #00b55a;

    --series-110: #17728c;
    --series-35: #00a878;
    --series-45: #89999d;

    --danger: #c54138;
    --warning: #cc9017;

    --radius: 11px;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
}

body {
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: "Segoe UI", Arial, Helvetica, sans-serif;
    font-size: 13px;
}

.dashboard {
    width: 100%;
    height: 100vh;
    padding: 10px 15px 8px;
    display: grid;
    grid-template-rows: 94px 54px 74px minmax(0, 1fr) 48px;
    gap: 9px;
}

/* =========================================================
   CABECERA TIPO INDEX
   ========================================================= */

.hero {
    position: relative;
    min-width: 0;
    overflow: hidden;
    display: grid;
    grid-template-columns: 200px minmax(340px, 1fr) minmax(620px, 1.35fr);
    align-items: center;
    gap: 18px;
    padding: 11px 18px;
    border-radius: 20px;
    color: #fff;
    background:
        linear-gradient(102deg,
            var(--header-dark) 0%,
            #10231f 37%,
            var(--header-mid) 70%,
            var(--header-green) 100%);
    box-shadow: 0 9px 24px rgba(30, 55, 47, .12);
}

.hero::before,
.hero::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}

.hero::before {
    width: 270px;
    height: 270px;
    right: 70px;
    top: -170px;
    background: rgba(255, 255, 255, .035);
}

.hero::after {
    width: 180px;
    height: 180px;
    right: 230px;
    bottom: -130px;
    background: rgba(255, 255, 255, .025);
}

.logo-box {
    position: relative;
    z-index: 2;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 15px;
    border-radius: 15px;
    background: #fff;
}

.logo-box img {
    display: block;
    width: auto;
    max-width: 100%;
    height: 48px;
    object-fit: contain;
}

.hero-copy {
    position: relative;
    z-index: 2;
    min-width: 0;
}

.hero-eyebrow {
    margin: 0 0 4px;
    color: #60f3ab;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .17em;
}

.hero-title {
    margin: 0;
    font-size: clamp(23px, 2vw, 29px);
    line-height: 1.02;
    font-weight: 800;
    letter-spacing: -.02em;
}

.hero-subtitle {
    margin: 6px 0 0;
    color: #dce9e4;
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hero-stats {
    position: relative;
    z-index: 2;
    min-width: 0;
    display: grid;
    grid-template-columns: 1.55fr .63fr .88fr;
    gap: 9px;
}

.hero-stat {
    min-width: 0;
    height: 56px;
    padding: 9px 12px;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 12px;
    background: rgba(255,255,255,.075);
}

.hero-stat-label {
    display: block;
    margin-bottom: 5px;
    color: #a8c9bb;
    font-size: 8px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.hero-stat-value {
    display: block;
    color: #fff;
    font-size: 11px;
    font-weight: 750;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hero-stat-value.green {
    color: #5ff0aa;
}

/* =========================================================
   CONTROLES LINEALES
   ========================================================= */

.controls {
    min-width: 0;
    display: grid;
    grid-template-columns:
        135px 175px 175px minmax(360px, 1fr) 160px 225px 100px;
    align-items: stretch;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.control {
    min-width: 0;
    padding: 7px 11px 5px;
    border-right: 1px solid var(--border);
}

.control:last-child {
    border-right: 0;
}

.control-label {
    display: block;
    margin-bottom: 2px;
    color: #7c898b;
    font-size: 8px;
    line-height: 1;
    font-weight: 800;
    letter-spacing: .07em;
    text-transform: uppercase;
}

select,
input[type="datetime-local"] {
    width: 100%;
    height: 29px;
    padding: 0;
    border: 0;
    border-bottom: 1px solid #c5cfcc;
    border-radius: 0;
    outline: none;
    background: transparent;
    color: var(--ink);
    font: inherit;
}

.meters {
    display: flex;
    align-items: center;
    gap: 17px;
    height: 29px;
    white-space: nowrap;
}

.meter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #526164;
    font-size: 11px;
    cursor: pointer;
}

.meter input {
    accent-color: var(--evo-green);
}

/* Serie secundaria OMIE. Se diferencia por color y patrón visual. */
.secondary-control {
    min-width: 0;
}

.secondary-series {
    height: 29px;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.omie-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #6a7476;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: color .15s ease, opacity .15s ease;
}

.omie-toggle input {
    accent-color: var(--danger);
}

.omie-toggle input:checked + span {
    color: var(--danger);
}

.omie-toggle.is-disabled {
    opacity: .48;
    cursor: not-allowed;
}

.omie-state {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #9a5d57;
    font-size: 8px;
    font-weight: 650;
}

.fixed-date {
    height: 29px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #c5cfcc;
    color: var(--ink);
    font-size: 11px;
    white-space: nowrap;
}

.reload {
    width: 100%;
    height: 100%;
    border: 0;
    background: #182221;
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    cursor: pointer;
}

.reload:hover {
    background: #263331;
}

.dashboard-link-wrap {
    padding: 0 !important;
    display: flex;
    align-items: stretch;
}

.dashboard-link {
    width: 100%;
    height: 100%;
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;

    border: 2px solid #08703c;
    background: #111718;
    color: #ffffff;

    text-decoration: none;
    font-size: 15px;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;

    transition:
        background .15s ease,
        border-color .15s ease,
        transform .15s ease;
}

.dashboard-link:hover {
    background: #0a3e28;
    border-color: #00b050;
}

.dashboard-link:focus-visible {
    outline: 3px solid rgba(0,176,80,.25);
    outline-offset: -3px;
}

/* =========================================================
   KPIS COMPACTOS
   ========================================================= */

.kpis {
    min-width: 0;
    display: grid;
    /* Tres medidores con exactamente el mismo ancho y TOTAL algo mayor. */
    grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.12fr);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.kpi {
    position: relative;
    min-width: 0;
    padding: 10px 15px 8px 17px;
    border-right: 1px solid var(--border);

    /* Centrado horizontal y vertical de todo el contenido del BOX. */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.kpi:last-child {
    border-right: 0;
}

.kpi::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
}

.k110::before { background: var(--series-110); }
.k35::before  { background: var(--series-35); }
.k45::before  { background: var(--series-45); }
.ktotal::before { background: #1b2927; }

/* El total se distingue sin romper la estética general del dashboard. */
.ktotal {
    background: #eef2f1;
}

.kpi-label {
    width: 100%;
    color: #59676a;
    font-size: 10px;
    font-weight: 650;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kpi-main {
    margin-top: 5px;
    display: flex;
    align-items: baseline;
    justify-content: center;
    width: 100%;
    gap: 4px;
}

.kpi-value {
    font-size: 20px;
    line-height: 1;
    font-weight: 700;
    letter-spacing: -.02em;
}

.kpi-unit {
    color: #859194;
    font-size: 9px;
}

.kpi-sub {
    width: 100%;
    margin-top: 4px;
    color: #879396;
    font-size: 8px;
    text-align: center;
}

/* =========================================================
   GRÁFICA FLEXIBLE: OCUPA EL RESTO DEL VIEWPORT
   ========================================================= */

.chart-panel {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.chart-head {
    flex: 0 0 43px;
    min-height: 43px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding: 7px 13px;
    background: #f7f9f8;
    border-bottom: 1px solid var(--border);
}

.chart-head h2 {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
}

.chart-hint {
    margin-top: 2px;
    color: #8a9698;
    font-size: 8px;
}

.range-info {
    color: #647174;
    font-size: 9px;
    white-space: nowrap;
}

.chart-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 6px 10px 4px;
}

.canvas-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.empty {
    display: none;
    height: 100%;
    align-items: center;
    justify-content: center;
    color: #7e8b8d;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 1450px) {
    .controls {
        grid-template-columns:
            110px 140px 140px minmax(390px, 1fr) 125px 195px 86px;
    }

    .meters {
        gap: 10px;
    }

    .meter {
        font-size: 10px;
    }
}

@media (max-width: 1180px) {
    .hero {
        grid-template-columns: 160px minmax(260px, 1fr) minmax(490px, 1.45fr);
    }

    .hero-stats {
        grid-template-columns: 1.35fr .7fr .9fr;
    }

    .controls {
        grid-template-columns:
            100px 125px 125px minmax(360px, 1fr) 115px 180px 80px;
    }

    .meters {
        gap: 9px;
    }
}

@media (max-width: 920px), (max-height: 650px) {
    body {
        overflow: auto;
    }

    .dashboard {
        height: auto;
        min-height: 100vh;
        grid-template-rows: auto auto auto 450px auto;
    }

    .hero {
        grid-template-columns: 150px 1fr;
    }

    .hero-stats {
        grid-column: 1 / -1;
    }

    .controls {
        grid-template-columns: repeat(2, 1fr);
    }

    .control {
        border-bottom: 1px solid var(--border);
    }

    .control:nth-child(2n) {
        border-right: 0;
    }

    .control:nth-child(4) {
        grid-column: 1 / -1;
    }

    .control:nth-child(5) {
        grid-column: 1 / -1;
    }

    .control:nth-child(6),
    .control:nth-child(7) {
        padding: 0;
    }

    .dashboard-link,
    .reload {
        min-height: 38px;
    }
}

@media (max-width: 650px) {
    .dashboard {
        padding: 6px;
        gap: 6px;
    }

    .hero {
        display: block;
        border-radius: 14px;
    }

    .logo-box {
        width: 160px;
        margin-bottom: 10px;
    }

    .hero-stats {
        margin-top: 10px;
        grid-template-columns: 1fr;
    }

    .kpis {
        grid-template-columns: 1fr 1fr;
    }

    .kpi:nth-child(2) {
        border-right: 0;
    }

    .kpi:nth-child(-n+2) {
        border-bottom: 1px solid var(--border);
    }
}
