/* =============================================================================
   VIDEOTRON — Full-screen AQMS display
   Supports: body[data-view="ispu"|"table"|"overview"]
   Supports: body[data-theme="light"|"dark"]
   ============================================================================= */

/* ── Design tokens ──────────────────────────────────────────────────────────── */
:root {
    --vt-bg:           #0f172a;
    --vt-surface:      #1e293b;
    --vt-surface-2:    #273549;
    --vt-border:       #334155;
    --vt-text:         #f1f5f9;
    --vt-text-muted:   #94a3b8;
    --vt-accent:       #38bdf8;

    --vt-good:         #22c55e;
    --vt-medium:       #84cc16;
    --vt-bad:          #facc15;
    --vt-very-bad:     #ef4444;
    --vt-hazard:       #1e293b;

    --vt-ticker-bg:    #0f172a;
    --vt-ticker-text:  #f8fafc;

    --vt-header-h:     5rem;
    --vt-ticker-h:     2.8rem;
    --vt-footer-h:     2.4rem;
    --vt-scale-w:      5.5rem;
}

[data-theme="light"] {
    --vt-bg:           #f0f4f8;
    --vt-surface:      #ffffff;
    --vt-surface-2:    #e8eef4;
    --vt-border:       #cbd5e1;
    --vt-text:         #0f172a;
    --vt-text-muted:   #64748b;
    --vt-ticker-bg:    #1e293b;
    --vt-ticker-text:  #f8fafc;
}

/* ── Base ───────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    background: var(--vt-bg);
    color: var(--vt-text);
    font-family: Arial, sans-serif;
    font-size: clamp(12px, 1.2vw, 16px);
}

.vt-body {
    width: 100vw; height: 100vh;
    display: flex; align-items: stretch;
}

/* ── Board ──────────────────────────────────────────────────────────────────── */
.vt-board {
    width: 100%; height: 100%;
    display: grid;
    gap: 0;
}

/* Grid templates per view */
[data-view="ispu"]     .vt-board { grid-template-rows: var(--vt-header-h) 1fr var(--vt-ticker-h) var(--vt-footer-h); }
[data-view="table"]    .vt-board { grid-template-rows: var(--vt-header-h) 1fr var(--vt-ticker-h) var(--vt-footer-h); }
[data-view="overview"] .vt-board { grid-template-rows: var(--vt-header-h) 1fr var(--vt-ticker-h) var(--vt-footer-h); }

/* ── Theme toggle ───────────────────────────────────────────────────────────── */
.vt-theme-toggle {
    position: fixed; top: 0.5rem; right: 0.7rem; z-index: 100;
    padding: 0.2rem 0.5rem;
    background: var(--vt-surface-2);
    border: 1px solid var(--vt-border);
    color: var(--vt-text-muted);
    font-size: 0.65rem; font-family: Arial, sans-serif;
    letter-spacing: 0.08em;
    border-radius: 4px; cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
}
.vt-theme-toggle:hover { opacity: 1; }

/* ── Error banner ───────────────────────────────────────────────────────────── */
.vt-error-banner {
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    padding: 0.5rem 1rem;
    background: #7f1d1d;
    color: #fecaca;
    font-size: 0.8rem; font-weight: 700;
    display: flex; align-items: center; gap: 0.5rem;
    justify-content: center;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.vt-board-header {
    background: var(--vt-surface);
    border-bottom: 2px solid var(--vt-accent);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.vt-header-left {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.vt-title {
    font-size: clamp(0.9rem, 1.6vw, 1.4rem);
    font-weight: 800;
    letter-spacing: 0.08em;
    color: var(--vt-text);
    line-height: 1.1;
}

.vt-subtitle {
    font-size: clamp(0.65rem, 1vw, 0.85rem);
    color: var(--vt-text-muted);
    letter-spacing: 0.06em;
}

.vt-header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.15rem;
    flex-shrink: 0;
}

.vt-hdr-time {
    font-size: clamp(1.2rem, 2.2vw, 2rem);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--vt-accent);
    letter-spacing: 0.05em;
    line-height: 1;
}

.vt-hdr-date {
    font-size: clamp(0.6rem, 0.9vw, 0.75rem);
    color: var(--vt-text-muted);
    letter-spacing: 0.06em;
}

/* ── Status badge ───────────────────────────────────────────────────────────── */
.vt-status-badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 100px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.status-loading     { background: #334155; color: #94a3b8; }
.status-online      { background: #14532d; color: #86efac; }
.status-offline     { background: #450a0a; color: #fca5a5; }
.status-maintenance { background: #1e3a5f; color: #93c5fd; }
.status-terlambat   { background: #431407; color: #fdba74; }

/* ── Main board (ISPU view) ─────────────────────────────────────────────────── */
.vt-main-board {
    display: flex;
    overflow: hidden;
    height: 100%;
}

/* ── Category scale sidebar ─────────────────────────────────────────────────── */
.vt-category-scale {
    width: var(--vt-scale-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.vt-scale-band {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: 0.25rem 0.3rem 0;
    overflow: hidden;
    border-left: 3px solid transparent;
}

/* Proportional heights: 4:2:2:1:1 = 200:100:100:50:50 ISPU units */
.vt-scale-band.vt-band-hazard   { flex: 4; background: #450a0a; border-color: #ef4444; }
.vt-scale-band.vt-band-very-bad { flex: 2; background: #7f1d1d; border-color: #f87171; }
.vt-scale-band.vt-band-bad      { flex: 2; background: #713f12; border-color: #facc15; }
.vt-scale-band.vt-band-medium   { flex: 1; background: #1e3a5f; border-color: #38bdf8; }
.vt-scale-band.vt-band-good     { flex: 1; background: #14532d; border-color: #22c55e; }

.vt-scale-num {
    display: block;
    font-size: clamp(0.55rem, 0.85vw, 0.72rem);
    font-weight: 700;
    color: rgba(255,255,255,0.85);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.vt-scale-num--bot {
    margin-top: auto;
    padding-bottom: 0.2rem;
}

.vt-scale-lbl {
    display: block;
    font-size: clamp(0.5rem, 0.7vw, 0.62rem);
    font-weight: 600;
    color: rgba(255,255,255,0.75);
    letter-spacing: 0.03em;
    line-height: 1.15;
    margin-top: 0.15rem;
    word-break: keep-all;
    overflow: hidden;
}

[data-theme="light"] .vt-scale-band.vt-band-hazard   { background: #fecaca; border-color: #ef4444; }
[data-theme="light"] .vt-scale-band.vt-band-very-bad { background: #fed7aa; border-color: #f97316; }
[data-theme="light"] .vt-scale-band.vt-band-bad      { background: #fef08a; border-color: #ca8a04; }
[data-theme="light"] .vt-scale-band.vt-band-medium   { background: #bae6fd; border-color: #0284c7; }
[data-theme="light"] .vt-scale-band.vt-band-good     { background: #bbf7d0; border-color: #16a34a; }
[data-theme="light"] .vt-scale-num  { color: rgba(0,0,0,0.7); }
[data-theme="light"] .vt-scale-lbl  { color: rgba(0,0,0,0.6); }

/* ── Bars panel ─────────────────────────────────────────────────────────────── */
.vt-bars-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 0.5rem;
}

.vt-param-labels {
    display: grid;
    gap: 0.3rem;
    padding: 0.4rem 0 0.2rem;
    flex-shrink: 0;
}

.vt-param-labels span {
    text-align: center;
    font-size: clamp(0.65rem, 1vw, 0.85rem);
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--vt-text-muted);
}

.vt-bars-grid {
    flex: 1;
    display: grid;
    gap: 0.4rem;
    overflow: hidden;
    padding-bottom: 0.3rem;
}

.vt-pollutant {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    overflow: hidden;
}

.vt-bar-shell {
    flex: 1;
    width: 100%;
    min-height: 0;
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    background: var(--vt-surface-2);
}

.vt-bar-segments {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    pointer-events: none;
}

.vt-bar-segments .seg { opacity: 0.07; }
.seg-hazard   { background: #ef4444; flex: 4; }
.seg-very-bad { background: #f97316; flex: 2; }
.seg-bad      { background: #facc15; flex: 2; }
.seg-medium   { background: #38bdf8; flex: 1; }
.seg-good     { background: #22c55e; flex: 1; }

.vt-bar-fill {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 3px;
    background: #22c55e;
    border-radius: 4px 4px 0 0;
    transition: height 0.8s ease, background 0.5s ease, box-shadow 0.5s ease;
}

.vt-param-reading {
    display: flex;
    align-items: baseline;
    gap: 0.2rem;
    flex-shrink: 0;
}

.vt-param-val {
    font-size: clamp(0.75rem, 1.3vw, 1.1rem);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--vt-text);
}

.vt-param-unit {
    font-size: clamp(0.55rem, 0.7vw, 0.65rem);
    color: var(--vt-text-muted);
}

.vt-ispu-reading {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.vt-ispu-reading strong {
    font-size: clamp(0.8rem, 1.4vw, 1.2rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--vt-text);
}

.vt-ispu-cat {
    font-size: clamp(0.5rem, 0.7vw, 0.6rem);
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--vt-text-muted);
}

/* ── Running ticker ─────────────────────────────────────────────────────────── */
.vt-bottom-led {
    background: var(--vt-ticker-bg);
    border-top: 1px solid var(--vt-border);
    overflow: hidden;
    position: relative;
    height: var(--vt-ticker-h);
    display: flex;
    align-items: center;
}

.vt-ticker-track {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.vt-ticker-inner {
    position: absolute;
    top: 50%; transform: translateY(-50%);
    white-space: nowrap;
    font-size: clamp(0.75rem, 1.1vw, 0.95rem);
    font-weight: 700;
    font-family: Arial, sans-serif;
    color: var(--vt-ticker-text);
    letter-spacing: 0.06em;
}

/* ── Footer ─────────────────────────────────────────────────────────────────── */
.vt-footer {
    background: var(--vt-surface);
    border-top: 1px solid var(--vt-border);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-size: clamp(0.6rem, 0.85vw, 0.72rem);
    color: var(--vt-text-muted);
    letter-spacing: 0.05em;
}

.vt-footer strong {
    color: var(--vt-text);
    font-weight: 700;
}

/* ── Table view ─────────────────────────────────────────────────────────────── */
.vt-table-section {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0.6rem 1rem;
}

.vt-param-table {
    width: 100%;
    height: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.vt-param-table thead {
    position: sticky; top: 0;
    background: var(--vt-surface);
    z-index: 1;
}

.vt-param-table th {
    padding: 0.5rem 0.6rem;
    font-size: clamp(0.65rem, 0.95vw, 0.8rem);
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--vt-text-muted);
    border-bottom: 2px solid var(--vt-accent);
    text-align: left;
}

.vt-th-no    { width: 4rem; text-align: center; }
.vt-th-val   { width: 8rem; text-align: right; }
.vt-th-unit  { width: 6rem; }

.vt-param-table tbody tr {
    border-bottom: 1px solid var(--vt-border);
}

.vt-tbl-row--ispu { border-left: 3px solid var(--vt-accent); }

.vt-param-table td {
    padding: 0.6rem 0.6rem;
    font-size: clamp(0.75rem, 1.2vw, 1rem);
    vertical-align: middle;
}

.vt-td-no {
    text-align: center;
    font-size: clamp(0.65rem, 0.9vw, 0.78rem);
    color: var(--vt-text-muted);
}

.vt-td-param {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.vt-td-code {
    font-weight: 800;
    font-size: clamp(0.75rem, 1.1vw, 0.95rem);
    letter-spacing: 0.05em;
    color: var(--vt-text);
}

.vt-td-name {
    font-size: clamp(0.55rem, 0.8vw, 0.7rem);
    color: var(--vt-text-muted);
}

.vt-td-val {
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-size: clamp(0.9rem, 1.4vw, 1.15rem);
    color: var(--vt-text);
}

.vt-td-unit {
    font-size: clamp(0.65rem, 0.85vw, 0.72rem);
    color: var(--vt-text-muted);
}

/* ── Overview view ──────────────────────────────────────────────────────────── */
.vt-overview-grid {
    display: grid;
    grid-template-columns: 1.1fr 1fr 1fr;
    gap: 0;
    overflow: hidden;
    height: 100%;
}

.vt-ov-left,
.vt-ov-center,
.vt-ov-right {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--vt-border);
    padding: 0.5rem;
    gap: 0.4rem;
}

.vt-ov-right { border-right: none; }

.vt-ov-panel-title {
    font-size: clamp(0.6rem, 0.9vw, 0.75rem);
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--vt-accent);
    border-bottom: 1px solid var(--vt-border);
    padding-bottom: 0.3rem;
    flex-shrink: 0;
}

.vt-ov-left .vt-main-board {
    flex: 1;
    min-height: 0;
}

/* Center panel */
.vt-ov-center {
    align-items: center;
    justify-content: center;
}

.vt-ov-circle-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    flex-shrink: 0;
}

.vt-ov-ispu-circle {
    width: clamp(100px, 14vw, 160px);
    height: clamp(100px, 14vw, 160px);
    border-radius: 50%;
    background: #22c55e;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 30px rgba(34,197,94,0.4);
    transition: background 0.6s ease, box-shadow 0.6s ease;
}

.vt-ov-circle-label {
    font-size: clamp(0.55rem, 0.8vw, 0.7rem);
    font-weight: 700;
    letter-spacing: 0.12em;
    color: rgba(255,255,255,0.8);
    line-height: 1;
}

.vt-ov-circle-val {
    font-size: clamp(2rem, 4vw, 3.5rem);
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    color: #fff;
    line-height: 1;
}

.vt-ov-ispu-cat {
    font-size: clamp(0.9rem, 1.5vw, 1.2rem);
    font-weight: 800;
    letter-spacing: 0.1em;
    color: var(--vt-text);
    text-align: center;
}

.vt-ov-info-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex: 1;
    justify-content: center;
}

.vt-ov-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    background: var(--vt-surface);
    border-radius: 4px;
    border: 1px solid var(--vt-border);
}

.vt-ov-info-lbl {
    font-size: clamp(0.55rem, 0.75vw, 0.65rem);
    color: var(--vt-text-muted);
    letter-spacing: 0.06em;
    font-weight: 600;
}

.vt-ov-info-val {
    font-size: clamp(0.7rem, 1vw, 0.85rem);
    font-weight: 700;
    color: var(--vt-text);
    text-align: right;
}

/* Right panel — meteo */
.vt-ov-meteo-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    overflow-y: auto;
}

.vt-ov-meteo-row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 0.1rem 0.4rem;
    background: var(--vt-surface);
    border: 1px solid var(--vt-border);
    border-radius: 4px;
    padding: 0.35rem 0.5rem;
    flex-shrink: 0;
}

.vt-ov-meteo-info {
    grid-column: 1; grid-row: 1;
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
}

.vt-ov-meteo-code {
    font-weight: 800;
    font-size: clamp(0.7rem, 1vw, 0.85rem);
    color: var(--vt-text);
    letter-spacing: 0.04em;
}

.vt-ov-meteo-name {
    font-size: clamp(0.5rem, 0.7vw, 0.6rem);
    color: var(--vt-text-muted);
}

.vt-ov-meteo-val-wrap {
    grid-column: 2; grid-row: 1;
    display: flex;
    align-items: baseline;
    gap: 0.2rem;
    justify-content: flex-end;
}

.vt-ov-meteo-val {
    font-size: clamp(0.85rem, 1.3vw, 1.1rem);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--vt-text);
}

.vt-ov-meteo-unit {
    font-size: clamp(0.5rem, 0.65vw, 0.6rem);
    color: var(--vt-text-muted);
}

.vt-ov-sparkline-wrap {
    grid-column: 1 / -1; grid-row: 2;
    height: clamp(20px, 2.5vh, 32px);
}

.vt-ov-sparkline {
    width: 100%;
    height: 100%;
    display: block;
}

.vt-ov-meteo-empty {
    font-size: 0.75rem;
    color: var(--vt-text-muted);
    text-align: center;
    padding: 1rem;
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    :root { --vt-scale-w: 3.8rem; }
    .vt-scale-lbl { display: none; }
    .vt-overview-grid { grid-template-columns: 1fr 1fr; }
    .vt-ov-right {
        grid-column: 1 / -1;
        border-right: none;
        border-top: 1px solid var(--vt-border);
    }
}
