/* OST61 (NovoCon-Ventile, Temperaturen) – hand-written, no frameworks. */

:root {
    color-scheme: light dark;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #f7f9fb;
    --text: #18222d;
    --muted: #5e6a78;
    --border: #dce2e9;
    --accent: #1d5fc4;
    --accent-text: #ffffff;
    --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);

    --ok: #18794e;
    --ok-bg: #e3f4ea;
    --warn: #8f6200;
    --warn-bg: #fff3d1;
    --alarm: #c4271d;
    --alarm-bg: #fde9e7;
    --offline: #6b7480;
    --offline-bg: #eceff2;

    --radius: 10px;
    --topbar-h: 0px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1318;
        --surface: #161c23;
        --surface-2: #1c232b;
        --text: #e5ebf1;
        --muted: #8e9aa8;
        --border: #2a333e;
        --accent: #5c9cf6;
        --accent-text: #0b1220;
        --shadow: none;

        --ok: #4cc283;
        --ok-bg: rgb(76 194 131 / 14%);
        --warn: #e0b13a;
        --warn-bg: rgb(224 177 58 / 15%);
        --alarm: #ff6b5f;
        --alarm-bg: rgb(255 107 95 / 15%);
        --offline: #8b949e;
        --offline-bg: rgb(139 148 158 / 15%);
    }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font: 15px/1.45 var(--font);
    background: var(--bg);
    color: var(--text);
}

a { color: var(--accent); }
h1, h2 { margin: 0; line-height: 1.25; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Status colours: every element with data-status gets --st / --st-bg ------------------- */

[data-status="ok"] { --st: var(--ok); --st-bg: var(--ok-bg); }
[data-status="warnung"] { --st: var(--warn); --st-bg: var(--warn-bg); }
[data-status="alarm"] { --st: var(--alarm); --st-bg: var(--alarm-bg); }
[data-status="offline"], [data-status="wartet"] { --st: var(--offline); --st-bg: var(--offline-bg); }

.dot {
    display: inline-block; flex: none;
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--st, var(--offline));
}

.badge {
    display: inline-block; flex: none;
    padding: 3px 10px; border-radius: 999px;
    font-size: 12.5px; font-weight: 650; white-space: nowrap;
    color: var(--st); background: var(--st-bg);
}
.badge-lg { font-size: 14px; padding: 5px 14px; }

/* ---- Buttons and inputs ------------------------------------------------------------------ */

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; padding: 0 18px;
    border: 1px solid transparent; border-radius: 8px;
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-quiet { background: transparent; color: var(--text); border-color: var(--border); }
.btn-quiet:hover { background: var(--surface-2); }

input[type="text"], input[type="password"], input[type="search"] {
    width: 100%; min-height: 44px; padding: 0 12px;
    font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }

/* ---- Top bar ----------------------------------------------------------------------------- */

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

.topbar-inner {
    max-width: 1680px; margin: 0 auto; padding: 10px 16px;
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
}

.brand {
    display: inline-flex; align-items: center; gap: 10px; min-height: 44px;
    color: var(--text); text-decoration: none; font-weight: 700; font-size: 17px;
}
.brand-sub { font-weight: 500; color: var(--muted); }
.brand-mark { width: 28px; height: 28px; padding: 4px; border-radius: 8px; background: var(--accent); color: var(--accent-text); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }

.chip {
    display: inline-flex; align-items: baseline; gap: 6px;
    padding: 5px 12px; border-radius: 999px;
    background: var(--surface-2); border: 1px solid var(--border);
    font-size: 13px; white-space: nowrap;
}
.chip b { font-variant-numeric: tabular-nums; }
.chip-label { color: var(--muted); }
.chip[data-tone="alarm"][data-active="true"] { background: var(--alarm-bg); border-color: transparent; color: var(--alarm); }
.chip[data-tone="alarm"][data-active="true"] .chip-label { color: inherit; }
.chip[data-tone="offline"][data-active="true"] { background: var(--offline-bg); border-color: transparent; }

.logout { margin: 0 0 0 auto; }
.chips + .logout { margin-left: 0; }

.banner {
    position: sticky; top: 0; z-index: 10;
    padding: 10px 16px; text-align: center; font-weight: 600;
    background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid var(--border);
}

/* ---- Page and toolbar -------------------------------------------------------------------- */

.page { max-width: 1680px; margin: 0 auto; padding: 16px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px 12px; margin-bottom: 14px; }

.search { position: relative; flex: 1 1 260px; max-width: 460px; }
.search svg { position: absolute; left: 12px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 38px; }

.segmented {
    display: inline-flex; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.segmented button {
    min-height: 44px; padding: 0 14px;
    font: inherit; font-weight: 550; color: var(--text);
    background: transparent; border: 0; border-left: 1px solid var(--border); cursor: pointer;
}
.segmented button:first-child { border-left: 0; }
.segmented button:hover { background: var(--surface-2); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

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

/* ---- Desktop table ----------------------------------------------------------------------- */

.valves {
    width: 100%; border-collapse: separate; border-spacing: 0;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); font-size: 14px;
}
.valves thead th {
    position: sticky; top: 0; z-index: 2;
    padding: 10px 10px; text-align: left; white-space: nowrap;
    font-size: 12.5px; font-weight: 650; color: var(--muted);
    background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.valves thead th:first-child { border-top-left-radius: var(--radius); }
.valves thead th:last-child { border-top-right-radius: var(--radius); }
.valves td { padding: 9px 10px; border-top: 1px solid var(--border); vertical-align: top; }
.valves .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.valves .group-row th {
    padding: 16px 10px 6px; text-align: left;
    font-size: 13px; font-weight: 650; color: var(--muted);
    background: var(--bg); border-top: 1px solid var(--border);
}
.valves tbody:first-of-type .group-row th { border-top: 0; }
.valves tr.valve { cursor: pointer; }
.valves tr.valve:hover td { background: var(--surface-2); }
.valves td.name a { color: var(--text); font-weight: 600; text-decoration: none; }
.valves td.name a:hover { text-decoration: underline; }
.valves tr[data-status="offline"] td,
.valves tr[data-status="offline"] td.name a,
.valves tr[data-status="wartet"] td,
.valves tr[data-status="wartet"] td.name a { color: var(--offline); }

.status-cell { min-width: 160px; }
.status-cell .dot { margin-right: 6px; vertical-align: 1px; }
.valves tr[data-status="alarm"] .status-cell,
.valves tr[data-status="warnung"] .status-cell { color: var(--st); font-weight: 600; }
.seen { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; }

/* ---- Mobile cards ------------------------------------------------------------------------ */

.cards { display: none; }

.card {
    display: block; padding: 12px 14px; min-height: 44px;
    color: var(--text); text-decoration: none;
    background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--st);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.card:active { background: var(--surface-2); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-title { min-width: 0; }
.card-title strong { display: block; font-size: 16px; overflow-wrap: anywhere; }
.card-sub { display: block; color: var(--muted); font-size: 13px; }
.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 12px; margin: 12px 0 0; }
.card-grid dt { color: var(--muted); font-size: 12px; }
.card-grid dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.card-note { margin: 10px 0 0; font-size: 13.5px; font-weight: 600; color: var(--st); }
.card-note.seen { margin-top: 2px; font-weight: 400; }
.card[data-status="offline"] .card-grid dd,
.card[data-status="wartet"] .card-grid dd,
.card[data-status="offline"] .card-title strong { color: var(--offline); }

@media (max-width: 899.98px) {
    .table-wrap { display: none; }
    .cards { display: grid; gap: 10px; }
    .chips { order: 3; width: 100%; margin-left: 0; }
    .logout, .chips + .logout { margin-left: auto; }
    .search { max-width: none; flex-basis: 100%; }
    .segmented { width: 100%; }
    .segmented button { flex: 1 1 auto; }
}

@media (max-width: 479.98px) {
    .brand-sub { display: none; }
    .chips { gap: 6px; }
    .chip { padding: 4px 10px; }
}

@media (max-width: 1399.98px) {
    .valves .col-gw { display: none; }
}

@media (min-width: 900px) and (max-width: 1199.98px) {
    .page { padding: 12px; }
    .valves { font-size: 13px; }
    .valves thead th, .valves td { padding-left: 6px; padding-right: 6px; }
    .valves thead th { font-size: 12px; }
    .status-cell { min-width: 120px; }
}

/* ---- Detail page ------------------------------------------------------------------------- */

.back {
    display: inline-flex; align-items: center; gap: 4px; min-height: 44px; margin: -6px 0 6px;
    font-weight: 600; text-decoration: none;
}
.back svg { width: 18px; height: 18px; }

.detail-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 10px 16px; margin-bottom: 14px; }
.detail-head h1 { font-size: 24px; overflow-wrap: anywhere; }
.detail-sub { margin: 4px 0 0; color: var(--muted); }

.status-box {
    margin-bottom: 16px; padding: 12px 16px;
    background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--st);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.status-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin: 0; font-weight: 600; }
.status-line .seen { display: inline; }
.alarm-list { margin: 8px 0 0; padding-left: 20px; }
.alarm-list:empty { display: none; }
.alarm-list li[data-schwere="alarm"] { color: var(--alarm); }
.alarm-list li[data-schwere="warnung"] { color: var(--warn); }

.groups { column-width: 360px; column-gap: 14px; }
.group {
    break-inside: avoid; margin: 0 0 14px; padding: 12px 16px 6px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.group h2 { font-size: 13px; font-weight: 700; letter-spacing: .02em; color: var(--accent); margin-bottom: 4px; }
.group dl { margin: 0; }
.group .row { display: flex; justify-content: space-between; gap: 16px; padding: 7px 0; border-top: 1px solid var(--border); }
.group .row:first-child { border-top: 0; }
.group dt { color: var(--muted); min-width: 0; }
.group dd { flex: 0 0 auto; max-width: 62%; margin: 0; text-align: right; font-weight: 550; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.detail[data-status="offline"] .group dd { color: var(--offline); }

.footnote { color: var(--muted); font-size: 13px; text-align: center; margin: 8px 0 16px; }

/* ---- Login ------------------------------------------------------------------------------- */

.login-page .login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }

.login-card {
    width: 100%; max-width: 400px; padding: 28px 24px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.login-head { text-align: center; margin-bottom: 20px; }
.login-head .brand-mark { width: 44px; height: 44px; padding: 8px; border-radius: 12px; }
.login-head h1 { font-size: 21px; margin-top: 12px; }
.login-head p { margin: 6px 0 0; color: var(--muted); }
.login-form { display: grid; gap: 6px; }
.login-form label { font-weight: 600; font-size: 14px; margin-top: 8px; }
.login-form .btn { margin-top: 16px; width: 100%; }
.login-card > .btn { width: 100%; }

.alert {
    margin-bottom: 8px; padding: 10px 12px; border-radius: 8px;
    background: var(--alarm-bg); color: var(--alarm); font-weight: 600;
}

/* ---- Navigation -------------------------------------------------------------------------- */

.nav { display: flex; gap: 4px; }
.nav a {
    display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 8px;
    color: var(--muted); text-decoration: none; font-weight: 600;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--accent); }

/* ---- Temperatures ------------------------------------------------------------------------ */

:root {
    --chart-grid: #e6eaef;
    --chart-axis: #c5cdd6;
    --chart-ctx: #cdd4dc;
    --chart-avg: #d4622a;
}
@media (prefers-color-scheme: dark) {
    :root {
        --chart-grid: #232b34;
        --chart-axis: #34404c;
        --chart-ctx: #3b4652;
        --chart-avg: #ec8550;
    }
}

.temp { display: grid; gap: 16px; max-width: 1400px; }
.t-head h1 { font-size: 24px; }
.t-sub { margin: 4px 0 0; color: var(--muted); }
.t-alert { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-weight: 600; }

.t-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.t-kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; min-width: 0; }
.t-kpi-label { color: var(--muted); font-size: 13px; }
.t-kpi-value { font-size: 26px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.t-kpi-note { color: var(--muted); font-size: 12.5px; min-height: 18px; overflow-wrap: anywhere; }

.t-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.t-panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 8px 16px; margin-bottom: 12px; }
.t-panel-head h2 { font-size: 17px; }
.t-hint { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.t-hint.is-warn { color: var(--warn); font-weight: 600; }
.t-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.t-pick { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.t-pick select {
    min-height: 44px; max-width: 180px; padding: 0 10px; border-radius: 8px;
    font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
}
.t-empty { color: var(--muted); text-align: center; padding: 48px 16px; margin: 0; }

.t-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.key { display: inline-block; width: 16px; border-top: 2px solid; border-radius: 1px; vertical-align: middle; margin-right: 6px; }
.k-sel { border-color: var(--accent); }
.k-avg { border-color: var(--chart-avg); }
.k-hov { border-color: var(--text); }
.k-ctx { border-color: var(--chart-ctx); }
.k-none { border-color: transparent; }

/* The global svg rule (icons) sets stroke and fill; the charts set their own. */
.t-chart { position: relative; touch-action: pan-y; }
.t-chart svg, .t-spark svg { display: block; fill: none; stroke: none; }
.temp svg text { font: 12px var(--font); fill: var(--muted); stroke: none; }
.temp .gridline { stroke: var(--chart-grid); stroke-width: 1; }
.temp .base { stroke: var(--chart-axis); stroke-width: 1; }
.temp .ylab { text-anchor: end; dominant-baseline: middle; font-variant-numeric: tabular-nums; }
.temp .xlab { text-anchor: middle; }
.temp .ctx path, .temp path.ctxl { fill: none; stroke: var(--chart-ctx); stroke-width: 1.25; stroke-linejoin: round; stroke-linecap: round; }
.temp path.avg, .temp path.sel, .temp path.hov { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.temp path.avg { stroke: var(--chart-avg); stroke-width: 2; }
.temp path.sel { stroke: var(--accent); stroke-width: 2; }
.temp path.hov { stroke: var(--text); stroke-width: 1.5; }
.temp .pt { stroke: var(--surface); stroke-width: 2; }
.temp .pt.sel { fill: var(--accent); }
.temp .pt.avg { fill: var(--chart-avg); }
.temp .pt.hov { fill: var(--text); }
.temp .cross { stroke: var(--muted); stroke-width: 1; }
.temp .endlab { fill: var(--text); font-weight: 600; dominant-baseline: middle; }
.temp .endlab .v { fill: var(--muted); font-weight: 400; }
.temp .hit { cursor: crosshair; outline: none; }

.t-tip {
    position: absolute; z-index: 2; display: none; pointer-events: none;
    min-width: 190px; padding: 8px 10px; font-size: 13px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 4px 16px rgb(0 0 0 / 14%);
}
.t-tip-time { color: var(--muted); margin-bottom: 4px; }
.t-tip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.t-tip-row b { font-variant-numeric: tabular-nums; min-width: 62px; }
.t-tip-row span { color: var(--muted); }
.t-tip-sep { border-top: 1px solid var(--border); margin: 6px 0; }

.t-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.t-tile {
    display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 10px 12px 8px;
    font: inherit; color: var(--text); text-align: left; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--st, var(--border)); border-radius: var(--radius);
}
.t-tile:hover { background: var(--surface-2); }
.t-tile.is-sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.t-tile-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; min-height: 22px; }
.t-tile-name { color: var(--muted); font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-tile .badge { font-size: 11.5px; padding: 1px 8px; }
.t-tile-value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.t-tile-note { color: var(--muted); font-size: 12px; min-height: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-tile[data-status="offline"] .t-tile-value, .t-tile[data-status="wartet"] .t-tile-value { color: var(--offline); }
.t-tile[data-status="warnung"] .t-tile-note { color: var(--warn); }
.t-tile.is-hist .t-tile-value { color: var(--accent); }
.t-spark { display: block; height: 44px; margin-top: 4px; }

.t-table-wrap { overflow-x: auto; }
.t-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
.t-table th, .t-table td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.t-table .l { text-align: left; }
.t-table th button { font: inherit; font-weight: 650; color: var(--muted); background: none; border: 0; padding: 4px 0; cursor: pointer; }
.t-table th[aria-sort] button { color: var(--text); }
.t-table th[aria-sort] button::after { content: " \2193"; }
.t-table th[aria-sort="ascending"] button::after { content: " \2191"; }
.t-table tbody tr { cursor: pointer; }
.t-table tbody tr:hover { background: var(--surface-2); }
.t-table tbody tr.is-sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); font-weight: 650; }
.t-table td.st { color: var(--st); }
.t-table tr[data-status="ok"] td.st { color: var(--muted); }

@media (max-width: 899.98px) {
    .t-controls, .t-controls .segmented { width: 100%; }
    .t-pick { width: 100%; }
    .t-pick select { flex: 1; max-width: none; }
}

@media (max-width: 479.98px) {
    .t-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .t-tile { padding: 8px 10px 6px; }
    .t-tile-value { font-size: 19px; }
    .t-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .t-kpi-value { font-size: 21px; }
    .t-panel { padding: 12px; }
    .nav a { padding: 0 8px; }
}
