/* x-EM OPTES dashboard — neutral theme (light + dark) */
:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #1d4ed8;
    --primary-hover: #1e40af;
    --primary-soft: #dbeafe;
    --accent: #0ea5e9;
    --ok: #15803d;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --error: #b91c1c;
    --chart-grid: rgba(15, 23, 42, .07);
    --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 8px rgba(15, 23, 42, .04);
    --radius: 10px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1120;
        --surface: #111827;
        --surface-2: #0f172a;
        --border: #1f2937;
        --text: #e5e7eb;
        --text-muted: #94a3b8;
        --primary: #3b82f6;
        --primary-hover: #60a5fa;
        --primary-soft: #1e3a8a;
        --warn-soft: #422006;
        --warn: #fbbf24;
        --ok: #4ade80;
        --error: #f87171;
        --chart-grid: rgba(226, 232, 240, .08);
        --shadow: none;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    color: var(--text);
    background: var(--bg);
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--text-muted); font-weight: 400; }
.nowrap { white-space: nowrap; }
kbd { font: 11px ui-monospace, monospace; border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; background: var(--surface-2); }

/* ---------------------------------------------------------------- top bar */
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 24px; min-width: 0; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
    padding: 6px 12px; border-radius: 7px; white-space: nowrap;
    font-weight: 600; font-size: 14px; text-decoration: none; color: var(--text-muted);
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--primary); background: var(--primary-soft); }
.tab:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
    display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff;
}
.brand-name { font-size: 16px; letter-spacing: .01em; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-end { display: flex; align-items: center; gap: 16px; }
.help-link {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 7px;
    font-weight: 600; font-size: 13px; text-decoration: none; color: var(--text-muted);
}
.help-link:hover { color: var(--text); background: var(--surface-2); }
.help-link.active { color: var(--primary); background: var(--primary-soft); }
.help-link:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.tz-note { color: var(--text-muted); font-size: 12px; }
.badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; }
.badge-warn { background: var(--warn-soft); color: var(--warn); }

/* ---------------------------------------------------------------- layout */
main { padding: 16px 20px 32px; }
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.content { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) 370px; gap: 16px; align-items: start; }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 16px;
    min-width: 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.actions { display: flex; gap: 6px; }

/* ---------------------------------------------------------------- filters */
.filters { position: sticky; top: 70px; }
.field { margin-bottom: 14px; }
.field > label:not(.check) { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .04em; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
select, input[type=datetime-local], input[type=search] {
    width: 100%; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: 7px;
    padding: 7px 9px;
}
select:focus, input:focus, .ms-btn:focus-visible, .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
/* Technical grid code shown small beside the readable name (selectors, titles). */
.grid-code {
    font: 400 11px ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--text-muted);
    letter-spacing: 0; text-transform: none; white-space: nowrap; vertical-align: middle;
}
.range { display: grid; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.chip {
    font: inherit; font-size: 12px; padding: 3px 9px; border-radius: 999px; cursor: pointer;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.toggles { display: grid; gap: 6px; }
.check { display: flex; gap: 7px; align-items: center; font-size: 13px; cursor: pointer; }
.status { font-size: 12px; margin-top: 10px; min-height: 18px; color: var(--text-muted); }
.status-ok { color: var(--ok); }
.status-warn { color: var(--warn); }
.status-error { color: var(--error); }

/* ---------------------------------------------------------------- buttons */
.btn {
    font: inherit; font-weight: 600; font-size: 13px;
    padding: 7px 12px; border-radius: 7px; cursor: pointer;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    text-decoration: none; display: inline-block;
}
.btn:hover { border-color: var(--primary); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.link-btn { font: inherit; font-size: 12px; background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0; }

/* ---------------------------------------------------------------- multiselect */
.ms { position: relative; }
.ms-btn {
    width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 6px;
    font: inherit; color: var(--text); text-align: left; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px;
}
.ms-btn.ms-empty .ms-text { color: var(--text-muted); }
.ms-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-caret { flex: none; color: var(--text-muted); }
.ms-pop {
    position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; width: max(100%, 260px);
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .15); padding: 8px;
}
.ms-search { margin-bottom: 6px; }
.ms-list { max-height: 260px; overflow: auto; border-top: 1px solid var(--border); padding-top: 4px; }
.ms-item { display: flex; align-items: center; gap: 7px; padding: 4px 4px; border-radius: 5px; cursor: pointer; }
.ms-item:hover { background: var(--surface-2); }
.ms-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-sub { margin-left: auto; font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.ms-all { font-weight: 600; }
.ms-none { padding: 8px; color: var(--text-muted); }
.ms-foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }
.ms-count { font-size: 12px; color: var(--text-muted); }
.ms-foot-btns { display: flex; gap: 6px; }

/* ---------------------------------------------------------------- KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.kpi-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 24px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------------------------------------------------------------- chart */
.chart-wrap { position: relative; height: 440px; }
.empty {
    position: absolute; inset: 0; display: grid; place-items: center;
    color: var(--text-muted); background: var(--surface); text-align: center; padding: 20px;
}
.empty[hidden] { display: none; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 10px; max-height: 96px; overflow: auto; }
.legend-item {
    display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 12px; color: var(--text);
    background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 2px 6px; cursor: pointer;
}
.legend-item:hover { border-color: var(--border); background: var(--surface-2); }
.legend-item.off { opacity: .4; text-decoration: line-through; }
.tip { cursor: help; text-decoration: underline dotted var(--text-muted); text-underline-offset: 3px; }   /* has a title tooltip */
.legend-swatch { width: 18px; height: 0; border-top: 2.5px solid; flex: none; }
.legend-tools { display: flex; gap: 10px; margin-top: 4px; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow: auto; max-height: 460px; }
.table-wrap .tbl thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.tbl td { white-space: nowrap; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.tbl th { font-size: 12px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.tbl .num { text-align: right; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl-compact th, .tbl-compact td { padding: 4px 6px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: 0; }

.kv { width: 100%; border-collapse: collapse; margin-top: 8px; }
.kv th, .kv td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.kv th { width: 42%; font-weight: 500; color: var(--text-muted); }
.kv td { word-break: break-word; }

.minis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mini { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.mini-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.mini-value { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.unit { font-size: 12px; font-weight: 400; color: var(--text-muted); }
details { margin-top: 12px; }
summary { cursor: pointer; color: var(--primary); font-size: 13px; }

.error-page { max-width: 560px; margin: 60px auto; text-align: center; }

/* ---------------------------------------------------------------- forecast tab */
/* One colour per source, the same in every chart and card of the tab. */
:root {
    --src-enhanced: #1d4ed8;
    --src-meteo1: #ea580c;
    --src-meteo2: #7c3aed;
    --src-base: #475569;
}
@media (prefers-color-scheme: dark) {
    :root {
        --src-enhanced: #3b82f6;
        --src-meteo1: #ea580c;
        --src-meteo2: #8b5cf6;
        --src-base: #94a3b8;
    }
}
.src-enhanced { --c: var(--src-enhanced); }
.src-meteo1 { --c: var(--src-meteo1); }
.src-meteo2 { --c: var(--src-meteo2); }
.src-base { --c: var(--src-base); }

.ctx-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 28px; }
.ctx-label { display: block; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 3px; }
.ctx-value { font-size: 15px; font-weight: 600; padding: 5px 0; }
.ctx-value select { width: auto; min-width: 180px; font-weight: 600; }
.ctx-bar input[type=date] {
    font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px; width: auto;
}

.src-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.src-card {
    background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--c);
    border-radius: var(--radius); padding: 10px 14px;
}
.src-card-hero { background: color-mix(in srgb, var(--c) 10%, var(--surface)); border-color: var(--c); }
.src-name { font-weight: 600; }
.src-name .dot { background: var(--c); }
.src-value { margin-top: 2px; font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.src-value .unit { font-size: 15px; }
.src-cap { font-size: 14px; font-weight: 600; color: var(--text); }

.scatter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.scatter-cell { min-width: 0; }
.scatter-cell .src-name { margin-bottom: 6px; }

.src-cards + .status:empty { display: none; }
.norm-note { margin: 10px 0 0; }
.norm-note strong { color: var(--text); font-weight: 600; }
.chart-wrap.chart-short { height: 340px; }
.dot.sq { border-radius: 2px; }
.ts-chips { display: flex; gap: 6px; }
.chip[aria-pressed="true"] { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1200px) {
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .layout { grid-template-columns: 1fr; }
    .filters { position: static; }
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tz-note { display: none; }
    .topbar { padding: 10px 12px; }
    .topbar-left { gap: 10px; }
    .brand-name { white-space: nowrap; }
    .tab { padding: 6px 8px; }
    .src-cards { grid-template-columns: 1fr; }
    .src-value { font-size: 26px; }
    .scatter-grid { grid-template-columns: 1fr; }
    main { padding: 12px 16px 24px; }
    .chart-wrap { height: 340px; }
}

/* ---------------------------------------------------------------- Help page (glossary generated from descriptions.json) */
.content.help { display: grid; grid-template-columns: 240px minmax(0, 860px); gap: 16px; align-items: start; }
.help-toc { position: sticky; top: 72px; grid-row: span 3; }
.help-toc ul { list-style: none; margin: 8px 0 0; padding: 0; }
.help-toc ul ul { margin: 4px 0 0 12px; }
.help-toc li { margin: 4px 0; }
.help-toc a { color: var(--text-muted); text-decoration: none; font-size: 14px; }
.help-toc a:hover { color: var(--primary); }
.help-body h2 { margin-bottom: 10px; }
.help-body, .help-steps { line-height: 1.55; }
.help-steps { margin: 0; padding-left: 22px; }
.help-steps li { margin: 6px 0; }
.help-chapter { font-size: 15px; margin-top: 22px; color: var(--text); text-transform: none; letter-spacing: 0; }
.help-body h4 { font-size: 13px; margin: 16px 0 6px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; scroll-margin-top: 72px; }
.help-body section, .help-body[id] { scroll-margin-top: 72px; }
.glossary { margin: 0; display: grid; grid-template-columns: minmax(200px, 280px) 1fr; border-top: 1px solid var(--border); }
.glossary dt, .glossary dd { margin: 0; padding: 8px 0; border-bottom: 1px solid var(--border); }
.glossary dt { font-weight: 600; padding-right: 16px; }
.glossary dt .grid-code { margin-left: 4px; }
.glossary-unit { color: var(--text-muted); font-weight: 400; font-size: 12px; white-space: nowrap; }
