/* Störungs- & Pikett-Analyse Wärmeverbünde — Oberfläche */

:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #dde3e9;
  --border-strong: #c4ced8;
  --text: #16202a;
  --text-muted: #62717f;
  --text-faint: #8b98a5;
  --accent: #0f6a54;
  --accent-soft: #e4f1ec;
  --accent-2: #1f6feb;
  --input-bg: #eef5fb;
  --input-border: #b9d3ea;
  --warn: #b4590c;
  --warn-soft: #fdf1e2;
  --danger: #b3261e;
  --danger-soft: #fbeceb;
  --ok: #1a7a4c;
  --ok-soft: #e7f5ee;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 4px 14px rgba(16, 32, 48, .05);
  --radius: 8px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12171c;
    --surface: #1a2129;
    --surface-2: #1f272f;
    --border: #2c363f;
    --border-strong: #3d4a55;
    --text: #e6ecf1;
    --text-muted: #9aa8b5;
    --text-faint: #75838f;
    --accent: #4ec4a1;
    --accent-soft: #17332b;
    --accent-2: #6aa9f5;
    --input-bg: #16242f;
    --input-border: #2f4a5e;
    --warn: #e8a35c;
    --warn-soft: #33261a;
    --danger: #f08b83;
    --danger-soft: #351f1e;
    --ok: #5ec78e;
    --ok-soft: #16301f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12171c;
  --surface: #1a2129;
  --surface-2: #1f272f;
  --border: #2c363f;
  --border-strong: #3d4a55;
  --text: #e6ecf1;
  --text-muted: #9aa8b5;
  --text-faint: #75838f;
  --accent: #4ec4a1;
  --accent-soft: #17332b;
  --accent-2: #6aa9f5;
  --input-bg: #16242f;
  --input-border: #2f4a5e;
  --warn: #e8a35c;
  --warn-soft: #33261a;
  --danger: #f08b83;
  --danger-soft: #351f1e;
  --ok: #5ec78e;
  --ok-soft: #16301f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.25; }
a { color: var(--accent-2); }

/* ---------- Kopf ---------- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

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

.brand { display: flex; align-items: center; gap: 11px; margin-right: auto; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 7px; flex: none;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 17px;
}
.brand h1 { font-size: 15px; letter-spacing: -.1px; }
.brand p { margin: 1px 0 0; font-size: 12px; color: var(--text-muted); }

.topbar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.tabs {
  width: 100%;
  display: flex; gap: 2px; overflow-x: auto;
  margin-top: 8px;
}
.tab {
  appearance: none; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 14px; color: var(--text-muted);
  padding: 9px 14px 10px; border-bottom: 2px solid transparent;
  white-space: nowrap; border-radius: 6px 6px 0 0;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab .lock { font-size: 11px; opacity: .75; }

/* ---------- Layout ---------- */

main { max-width: 1500px; margin: 0 auto; padding: 22px 20px 72px; }
.view[hidden] { display: none; }
.view > * + * { margin-top: 20px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 14px; letter-spacing: .01em; }
.card-head .spacer { margin-left: auto; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }

.grid-2 { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.grid-3 { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

/* ---------- Kennzahlen ---------- */

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.kpi-value { font-size: 25px; font-weight: 650; letter-spacing: -.5px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.kpi.is-ok .kpi-value { color: var(--ok); }
.kpi.is-warn .kpi-value { color: var(--warn); }

/* ---------- Tabellen ---------- */

.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 8px 11px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--text-muted);
  font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap; border-bottom: 1px solid var(--border-strong);
}
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 600; background: var(--surface-2); border-top: 1px solid var(--border-strong); }
.t-compact th, .t-compact td { padding: 6px 10px; }
.nowrap { white-space: nowrap; }
.muted { color: var(--text-muted); }
.empty { padding: 28px 16px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* Anteil-Balken in Tabellen */
.mini { display: block; height: 4px; border-radius: 2px; background: var(--accent); min-width: 1px; }
.mini-wrap { background: var(--border); border-radius: 2px; width: 90px; }

/* ---------- Badges ---------- */

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---------- Formulare & Buttons ---------- */

label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }

input, select, textarea {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--input-bg); border: 1px solid var(--input-border);
  border-radius: 6px; padding: 7px 9px; width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
textarea { resize: vertical; min-height: 66px; }
input[type="search"] { background: var(--surface-2); border-color: var(--border); }

.btn {
  appearance: none; cursor: pointer; font: inherit; font-size: 13.5px; font-weight: 500;
  padding: 7px 13px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: none; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.field-row { display: grid; gap: 13px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.field-row.wide { grid-template-columns: 1fr; }
.form-grid > * + * { margin-top: 13px; }
.hint { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

.filterbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filterbar select, .filterbar input { width: auto; min-width: 130px; }
.filterbar input[type="search"] { min-width: 210px; }

/* ---------- Diagramme ---------- */

/* Das Koordinatensystem wird zur Behälterbreite passend berechnet (charts.js),
   darum bleibt die Höhe konstant und die Schrift in normaler Grösse. */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: .25; }
.chart .axis { stroke: var(--border-strong); stroke-width: .35; }
.chart .bar { fill: var(--accent); }
.chart .line { fill: none; stroke: var(--accent); stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); }
.chart .cat { fill: var(--text-muted); }
.chart .tick { fill: var(--text-faint); }
.chart .val { fill: var(--text-muted); font-weight: 600; }

/* Waagrechte Balken als HTML — Beschriftung ungekürzt und in Lesegrösse. */
.hbars { display: flex; flex-direction: column; gap: 7px; }
.hbar {
  display: grid; align-items: center; gap: 12px;
  grid-template-columns: minmax(110px, 210px) 1fr 3.2em;
  font-size: 13.5px;
}
.hbar-name { text-align: right; color: var(--text); overflow-wrap: anywhere; line-height: 1.3; }
.hbar-track {
  position: relative; height: 20px; border-radius: 4px;
  background: var(--border);
}
.hbar-fill {
  position: absolute; inset: 0 auto 0 0; height: 100%;
  border-radius: 4px; background: var(--accent); min-width: 0;
}
.hbar-wert { font-variant-numeric: tabular-nums; color: var(--text-muted); font-weight: 600; }

@media (max-width: 560px) {
  .hbar {
    grid-template-columns: 1fr 3.2em;
    grid-template-areas: "name name" "track wert";
    gap: 3px 10px;
  }
  .hbar-name { grid-area: name; text-align: left; font-size: 12.5px; }
  .hbar-track { grid-area: track; height: 16px; }
  .hbar-wert { grid-area: wert; }
}

/* ---------- Dialog ---------- */

dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 0;
  background: var(--surface); color: var(--text);
  width: min(880px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  box-shadow: 0 12px 48px rgba(0, 0, 0, .28);
}
dialog::backdrop { background: rgba(8, 14, 20, .5); }
.dlg-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); border-radius: 12px 12px 0 0;
}
.dlg-head h2 { font-size: 15px; margin-right: auto; }
.dlg-body { padding: 18px; overflow-y: auto; max-height: calc(100vh - 190px); }
.dlg-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 13px 18px; border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 12px 12px;
}

/* ---------- Anleitung ---------- */

.prose { max-width: 78ch; }
.prose h3 { font-size: 14px; margin: 22px 0 6px; }
.prose h3:first-child { margin-top: 0; }
.prose p { margin: 0 0 10px; color: var(--text-muted); }
.prose ol, .prose ul { margin: 0 0 10px; padding-left: 20px; color: var(--text-muted); }
.prose li { margin-bottom: 5px; }
.prose strong { color: var(--text); font-weight: 600; }

.note {
  border-left: 3px solid var(--warn); background: var(--warn-soft);
  padding: 11px 14px; border-radius: 0 6px 6px 0; font-size: 13.5px;
}
.note.info { border-left-color: var(--accent); background: var(--accent-soft); }
.note strong { display: block; margin-bottom: 2px; }

/* ---------- Stammdaten-Listen ---------- */

.listcol { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.listcol h3 { font-size: 12.5px; padding: 9px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.listcol ul { list-style: none; margin: 0; padding: 0; }
.listcol li {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px 5px 12px; border-bottom: 1px solid var(--border); font-size: 13.5px;
}
.listcol li:last-of-type { border-bottom: 0; }
.listcol li .btn { margin-left: auto; }
.listcol form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); background: var(--surface-2); }
.listcol form input { font-size: 13px; padding: 5px 8px; }

/* ---------- Toast ---------- */

#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(14px);
  background: var(--text); color: var(--bg);
  padding: 9px 17px; border-radius: 20px; font-size: 13.5px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 90;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Druck ---------- */

@media print {
  .topbar, .no-print, .btn { display: none !important; }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
  .card { break-inside: avoid; box-shadow: none; }
  .view[hidden] { display: none !important; }
}

/* ---------- Anmeldeseite ---------- */

body.anmeldeseite { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.anmeldung { width: min(420px, 100%); }
.anmeldung .brand h1 { font-size: 16px; }
.anmeldung .card-body { padding: 20px; }
.anmelde-fuss { text-align: center; font-size: 12px; margin: 18px 0 0; }

.fehlermeldung {
  background: var(--danger-soft); color: var(--danger);
  border-radius: 6px; padding: 9px 12px; font-size: 13.5px;
}

/* ---------- Benutzermenü ---------- */

.benutzer-menu { position: relative; }
.avatar {
  display: inline-grid; place-items: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; margin-right: 2px;
}
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
  min-width: 210px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 28px rgba(0, 0, 0, .18);
}
.menu-kopf {
  padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 5px; font-size: 13.5px;
}
.menu-eintrag {
  display: block; width: 100%; text-align: left;
  appearance: none; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 13.5px; color: var(--text);
  padding: 7px 10px; border-radius: 6px;
}
.menu-eintrag:hover { background: var(--surface-2); }

.verbindung {
  font-size: 12.5px; font-weight: 600; color: var(--danger);
  background: var(--danger-soft); padding: 3px 9px; border-radius: 20px;
}

.mono { font-family: var(--mono); font-size: 12.5px; }

#toast.fehler { background: var(--danger); color: #fff; }

.listcol-hinweis {
  margin: 0; padding: 8px 12px; font-size: 12px; color: var(--text-faint);
  background: var(--surface-2); border-top: 1px solid var(--border);
}
