/* =========================================================================================
   Temperaturüberwachung – Gestaltung
   Instrumentencharakter: kühle Nebelgrau-Flächen, Petrol als Leitfarbe, das Farbband der
   Thermometerskala als einziges buntes Element. Schrift: Barlow (lokal eingebunden).
   ========================================================================================= */

@font-face { font-family: "Barlow"; font-style: normal; font-weight: 400; font-display: swap;
    src: url("../fonts/barlow-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-style: normal; font-weight: 500; font-display: swap;
    src: url("../fonts/barlow-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-style: normal; font-weight: 600; font-display: swap;
    src: url("../fonts/barlow-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-style: normal; font-weight: 500; font-display: swap;
    src: url("../fonts/barlow-semi-condensed-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-style: normal; font-weight: 600; font-display: swap;
    src: url("../fonts/barlow-semi-condensed-latin-600-normal.woff2") format("woff2"); }

:root {
    --bg: #E8EDEF;
    --surface: #FFFFFF;
    --surface-2: #F3F6F7;
    --ink: #132A33;
    --ink-soft: #3C525B;
    --muted: #64777F;
    --line: #CDD8DC;
    --accent: #0D6B7A;
    --accent-strong: #09525E;
    --accent-ink: #FFFFFF;
    --ok: #1E8A5A;
    --warn: #B4521A;
    --danger: #B42318;
    --focus: #1F8FA1;

    --font-body: "Barlow", "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-display: "Barlow Semi Condensed", "Barlow", "Segoe UI", system-ui, sans-serif;

    --radius-s: 4px;
    --radius-m: 10px;

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0E1B21;
        --surface: #15252C;
        --surface-2: #1A2D35;
        --ink: #E2EBEE;
        --ink-soft: #B9C8CD;
        --muted: #8DA1A9;
        --line: #29404A;
        --accent: #5BB8C6;
        --accent-strong: #84CCD7;
        --accent-ink: #06222A;
        --ok: #4CC38A;
        --warn: #E8955A;
        --danger: #F07A6E;
        --focus: #7FD0DC;
        color-scheme: dark;
    }
}

/* ---- Grundlagen -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.5;
    font-variant-numeric: tabular-nums;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }

p { margin: 0; }

a { color: var(--accent); }

code {
    font-size: 0.9em;
    padding: 0.05em 0.3em;
    border-radius: var(--radius-s);
    background: var(--surface-2);
}

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.muted { color: var(--muted); }

/* ---- Rahmen ------------------------------------------------------------------------------ */

.shell { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 2rem;
    padding: 0 1.5rem;
    min-height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--ink);
    text-decoration: none;
}

.brand-mark { flex: none; color: var(--ink); }

.brand-name {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.25rem;
    letter-spacing: 0.005em;
}

.mainnav { display: flex; gap: 0.25rem; align-self: stretch; }

.mainnav a {
    display: inline-flex;
    align-items: center;
    padding: 0 0.9rem;
    color: var(--ink-soft);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
}

.mainnav a:hover { color: var(--ink); }

.mainnav a.active {
    color: var(--ink);
    border-bottom-color: var(--accent);
}

.topbar-end { display: flex; align-items: center; gap: 1.25rem; }

.broker {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--ink-soft);
}

.broker-dot {
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    background: var(--muted);
}

.broker-connected .broker-dot { background: var(--ok); }
.broker-disconnected .broker-dot { background: var(--danger); }
.broker-disconnected .broker-text { color: var(--danger); }

.logout { margin: 0; }

.content {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    padding: 2.25rem 1.5rem 4rem;
}

.page-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 2rem;
    margin-bottom: 1.5rem;
}

/* ---- Schaltflächen und Felder ------------------------------------------------------------ */

.btn-primary,
.btn-quiet {
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-s);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.5rem;
}

.btn-primary {
    padding: 0.5rem 1.1rem;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: var(--accent-ink);
}

.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }

.btn-quiet {
    padding: 0.35rem 0.8rem;
    min-height: 2.1rem;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink-soft);
}

.btn-quiet:hover { color: var(--ink); border-color: var(--muted); }

.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 0.35rem; }

.field > label,
.field-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ink-soft);
}

.field input,
.field select {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    padding: 0.45rem 0.65rem;
    min-height: 2.5rem;
}

.field input:hover,
.field select:hover { border-color: var(--muted); }

.field input.invalid { border-color: var(--danger); }

.validation-message { color: var(--danger); font-size: 0.875rem; }

.form-error {
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 8%, transparent);
    border-left: 3px solid var(--danger);
    padding: 0.6rem 0.8rem;
    border-radius: 0 var(--radius-s) var(--radius-s) 0;
}

.check { display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

/* ---- Leerzustand ------------------------------------------------------------------------- */

.empty {
    max-width: 38rem;
    padding: 2rem;
    background: var(--surface);
    border: 1px dashed var(--line);
    border-radius: var(--radius-m);
    display: grid;
    gap: 0.75rem;
}

.empty h2 { font-size: 1.25rem; }

/* ---- Dashboard: Sensoren ----------------------------------------------------------------- */

.sensors { display: grid; gap: 1.5rem; }

.sensor {
    display: grid;
    grid-template-columns: minmax(0, 1.75fr) minmax(15rem, 1fr);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    overflow: hidden;
}

.sensor-main { padding: 1.75rem 2rem 1.5rem; min-width: 0; }

.sensor-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.75rem;
}

.sensor-head h2 { font-size: 1.25rem; font-weight: 600; }

.sensor-id { font-size: 0.8125rem; color: var(--muted); }

.readout {
    display: flex;
    align-items: flex-start;
    margin: 0.75rem 0 1.25rem;
    font-family: var(--font-display);
    font-weight: 600;
    line-height: 0.9;
    letter-spacing: -0.02em;
}

.readout-value { font-size: clamp(4.5rem, 11vw, 7.5rem); }

.readout-unit {
    font-size: clamp(1.75rem, 3.6vw, 2.5rem);
    font-weight: 500;
    color: var(--ink-soft);
    margin: 0.35em 0 0 0.15em;
    letter-spacing: 0;
}

.sensor.is-stale .readout { color: var(--muted); }

.stale-note {
    color: var(--warn);
    font-size: 0.9375rem;
    max-width: 34rem;
    margin: -0.5rem 0 1.25rem;
}

.tscale { display: block; width: 100%; height: auto; max-width: 640px; overflow: visible; }

.tscale-range { fill: var(--accent); fill-opacity: 0.16; stroke: var(--accent); stroke-opacity: 0.45; stroke-width: 1; }

.tscale-tick { stroke: var(--muted); stroke-width: 1; }
.tscale-tick.major { stroke: var(--ink-soft); stroke-width: 1.5; }

.tscale-label { fill: var(--muted); font-family: var(--font-body); font-size: 12px; }

.tscale-marker line { stroke: var(--ink); stroke-width: 2; }
.tscale-marker path { fill: var(--ink); }
.tscale-marker { transition: transform 600ms cubic-bezier(0.2, 0.7, 0.2, 1); }

.scale-legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.4rem;
    font-size: 0.875rem;
    color: var(--muted);
}

.legend-swatch {
    width: 1.1rem;
    height: 0.75rem;
    border-radius: 2px;
    background: color-mix(in srgb, var(--accent) 16%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}

.sensor-facts {
    margin: 0;
    padding: 1.25rem 1.5rem;
    background: var(--surface-2);
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
}

.sensor-facts > div { padding: 0.8rem 0; border-bottom: 1px solid var(--line); }
.sensor-facts > div:last-child { border-bottom: 0; }

.sensor-facts dt { font-size: 0.8125rem; color: var(--muted); }

.sensor-facts dd {
    margin: 0.1rem 0 0;
    font-size: 1.0625rem;
    font-weight: 500;
}

.dd-sub { display: block; font-size: 0.875rem; font-weight: 400; color: var(--muted); }
.dd-warn { color: var(--warn); }

/* ---- Verlauf ----------------------------------------------------------------------------- */

.history-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1.25rem 2rem;
    margin-bottom: 1.5rem;
}

.history-controls .form-error { flex-basis: 100%; }

.segmented {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    background: var(--surface);
    overflow: hidden;
}

.segmented button {
    font: inherit;
    font-weight: 500;
    color: var(--ink-soft);
    background: transparent;
    border: 0;
    border-right: 1px solid var(--line);
    padding: 0 0.95rem;
    min-height: 2.5rem;
    cursor: pointer;
}

.segmented button:last-child { border-right: 0; }
.segmented button:hover { color: var(--ink); background: var(--surface-2); }

.segmented button[aria-pressed="true"] {
    background: var(--accent);
    color: var(--accent-ink);
}

.range-fields { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; }

.chart-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    padding: 1.5rem 1.5rem 1.25rem;
}

.chart-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.25rem 1rem; margin-bottom: 1rem; }
.chart-head h2 { font-size: 1.25rem; font-weight: 600; }
.chart-head p { font-size: 0.9375rem; }

.chart-wrap { position: relative; height: clamp(280px, 52vh, 480px); }
.chart-wrap.is-empty canvas { visibility: hidden; }

.chart-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    text-align: center;
    padding: 1rem;
}

.chart-panel[aria-busy="true"] .chart-wrap { opacity: 0.55; }

.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 1.25rem 0 0;
    border-top: 1px solid var(--line);
}

.stats > div { padding: 1rem 1rem 0 0; }
.stats > div + div { padding-left: 1rem; border-left: 1px solid var(--line); }

.stats dt { font-size: 0.8125rem; color: var(--muted); }

.stats dd {
    margin: 0.15rem 0 0;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.75rem;
    line-height: 1.1;
}

.stats dd.stat-sub {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 0.875rem;
    color: var(--muted);
}

.chart-note { margin-top: 1rem; font-size: 0.875rem; color: var(--muted); max-width: 46rem; }

/* ---- Anmeldung --------------------------------------------------------------------------- */

.auth-page {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.auth-card {
    width: min(100%, 25rem);
    background: var(--surface);
    border: 1px solid var(--line);
    border-top: 4px solid var(--accent);
    border-radius: var(--radius-m);
    padding: 2rem;
    display: grid;
    gap: 1.25rem;
}

.brand-auth { margin-bottom: 0.25rem; }

.auth-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.5625rem;
}

.auth-form { display: grid; gap: 1rem; }

/* ---- Fehleranzeige und Wiederverbindung -------------------------------------------------- */

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1000;
    padding: 0.75rem 3rem 0.75rem 1.5rem;
    background: var(--warn);
    color: #FFFFFF;
}

#blazor-error-ui a { color: inherit; font-weight: 600; }

#blazor-error-ui .dismiss {
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
    font: inherit;
    color: inherit;
    background: transparent;
    border: 0;
    cursor: pointer;
}

.components-reconnect-first-attempt-visible,
.components-reconnect-repeated-attempt-visible,
.components-reconnect-failed-visible,
.components-pause-visible,
.components-resume-failed-visible,
.components-rejoining-animation {
    display: none;
}

#components-reconnect-modal.components-reconnect-show .components-reconnect-first-attempt-visible,
#components-reconnect-modal.components-reconnect-show .components-rejoining-animation,
#components-reconnect-modal.components-reconnect-paused .components-pause-visible,
#components-reconnect-modal.components-reconnect-resume-failed .components-resume-failed-visible,
#components-reconnect-modal.components-reconnect-retrying,
#components-reconnect-modal.components-reconnect-retrying .components-reconnect-repeated-attempt-visible,
#components-reconnect-modal.components-reconnect-retrying .components-rejoining-animation,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-failed .components-reconnect-failed-visible {
    display: block;
}

#components-reconnect-modal {
    width: min(90vw, 22rem);
    margin: 20vh auto;
    padding: 2rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    background: var(--surface);
    color: var(--ink);
}

#components-reconnect-modal::backdrop { background: rgb(14 27 33 / 0.45); }

.components-reconnect-container { display: flex; flex-direction: column; align-items: center; gap: 1rem; text-align: center; }

#components-reconnect-modal button {
    font: inherit;
    font-weight: 500;
    border: 0;
    border-radius: var(--radius-s);
    padding: 0.45rem 1.2rem;
    background: var(--accent);
    color: var(--accent-ink);
    cursor: pointer;
}

.components-rejoining-animation { position: relative; width: 56px; height: 56px; }

.components-rejoining-animation div {
    position: absolute;
    border: 3px solid var(--accent);
    border-radius: 50%;
    animation: reconnect-ring 1.5s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}

.components-rejoining-animation div:nth-child(2) { animation-delay: -0.5s; }

@keyframes reconnect-ring {
    0% { inset: 28px; opacity: 1; }
    100% { inset: 0; opacity: 0; }
}

/* ---- Kleine Bildschirme ------------------------------------------------------------------ */

@media (max-width: 760px) {
    .topbar {
        grid-template-columns: 1fr auto;
        gap: 0 1rem;
        padding: 0.5rem 1rem 0;
    }

    .mainnav { grid-column: 1 / -1; grid-row: 2; min-height: 2.75rem; }
    .mainnav a { padding: 0 0.75rem 0 0; margin-right: 0.75rem; }
    .broker-text { display: none; }

    .content { padding: 1.5rem 1rem 3rem; }
    .page-title { font-size: 1.5625rem; }

    .sensor { grid-template-columns: 1fr; }
    .sensor-main { padding: 1.25rem 1.25rem 1rem; }
    .sensor-facts { border-left: 0; border-top: 1px solid var(--line); padding: 0.5rem 1.25rem; }

    .stats { grid-template-columns: 1fr; }
    .stats > div + div { padding-left: 0; border-left: 0; border-top: 1px solid var(--line); }
    .stats > div { padding-bottom: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
    .tscale-marker { transition: none; }
    .components-rejoining-animation div { animation: none; }
}
