/* NovoCon Ventilübersicht – 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;
}
