:root {
  --bg: #f4f6fa;
  --flaeche: #ffffff;
  --rand: #dde3ee;
  --text: #172033;
  --leise: #6b7689;
  --akzent: #1f3864;
  --akzent-hell: #eaf0fb;
  --gruen: #157347;
  --rot: #b42318;
  --gelb: #b25e09;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* Muss vor den display-Regeln stehen: sonst überschreibt z.B. .dialog{display:flex}
   das hidden-Attribut und das Detailfenster liegt dauerhaft über der Seite. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Kopf */
.kopf {
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px; height: 56px;
  background: var(--akzent); color: #fff;
  position: sticky; top: 0; z-index: 20;
}
.marke { font-weight: 700; font-size: 16px; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.punkt { width: 9px; height: 9px; border-radius: 50%; background: #6ee7a8; box-shadow: 0 0 0 3px rgba(110,231,168,.25); }
.reiter { display: flex; gap: 4px; }
.reiter-btn {
  background: transparent; border: 0; color: #c3cee4; padding: 8px 14px;
  border-radius: 7px; cursor: pointer; font-size: 14px; font-family: inherit;
}
.reiter-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.reiter-btn.aktiv { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.kopf-rechts { margin-left: auto; }
.stand { font-size: 12px; color: #b7c4de; }

main { padding: 20px; max-width: 1680px; margin: 0 auto; }

/* Kennzahlen */
.kacheln { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kachel { background: var(--flaeche); border: 1px solid var(--rand); border-radius: var(--radius); padding: 14px 16px; }
.kachel .wert { font-size: 22px; font-weight: 700; letter-spacing: -.4px; }
.kachel .titel { font-size: 12px; color: var(--leise); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }

/* Filter */
.filterleiste { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.filterleiste input, .filterleiste select {
  font: inherit; padding: 7px 10px; border: 1px solid var(--rand);
  border-radius: 8px; background: var(--flaeche); color: var(--text); min-width: 120px;
}
.filterleiste input[type=search] { min-width: 250px; flex: 1 1 250px; }
.filterleiste input:focus, .filterleiste select:focus { outline: 2px solid var(--akzent); outline-offset: -1px; }
.knopf, .knopf-leise {
  font: inherit; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--rand); background: var(--flaeche); color: var(--text); text-decoration: none;
}
.knopf { background: var(--akzent); border-color: var(--akzent); color: #fff; }
.knopf:hover { filter: brightness(1.15); }
.knopf-leise:hover { background: var(--akzent-hell); }
.knopf-leise:disabled { opacity: .45; cursor: default; }

/* Tabelle */
/* Eigener Scroll-Container: nur so klebt der Tabellenkopf zuverlässig oben.
   Bei sticky gegen den Viewport rutscht er sonst über die erste Zeile, sobald
   die Tabelle weiter oben auf der Seite beginnt. */
.tabellen-huelle {
  background: var(--flaeche); border: 1px solid var(--rand);
  border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 230px);
}
.tabelle { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabelle th {
  text-align: left; padding: 10px 12px; background: #f7f9fd; color: var(--leise);
  font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--rand); white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.tabelle th[data-sort] { cursor: pointer; user-select: none; }
.tabelle th[data-sort]:hover { color: var(--akzent); }
.tabelle th.num, .tabelle td.num { text-align: right; white-space: nowrap; }
.tabelle td { padding: 9px 12px; border-bottom: 1px solid #eef1f7; vertical-align: middle; }
.tabelle tbody tr:hover { background: #f8faff; }
.tabelle tbody tr:last-child td { border-bottom: 0; }
.fz-name { font-weight: 600; }
.fz-zusatz { color: var(--leise); font-size: 12px; }
.leer { padding: 40px; text-align: center; color: var(--leise); }

/* Marker */
.pille { display: inline-block; padding: 1px 7px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pille.eigen { background: #e6f4ea; color: var(--gruen); }
.pille.fremd { background: #eef1f7; color: var(--leise); }
.runter { color: var(--gruen); font-weight: 600; }
.rauf { color: var(--rot); font-weight: 600; }
.lang { color: var(--gelb); font-weight: 600; }

.blaettern { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 14px; color: var(--leise); }

/* Karten */
.karten { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.karte { background: var(--flaeche); border: 1px solid var(--rand); border-radius: var(--radius); padding: 16px; }
.karte h3 { margin: 0 0 4px; font-size: 15px; }
.karte .zeile { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; border-bottom: 1px solid #f2f5fa; }
.karte .zeile:last-child { border-bottom: 0; }
.karte .zeile span:last-child { font-weight: 600; }
.abschnitt { font-size: 15px; margin: 24px 0 10px; }

/* Dialog */
.dialog { position: fixed; inset: 0; background: rgba(15,22,38,.55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.dialog-box { background: var(--flaeche); border-radius: 14px; max-width: 860px; width: 100%; max-height: 88vh; overflow-y: auto; padding: 24px; position: relative; }
.dialog-zu { position: absolute; top: 12px; right: 14px; border: 0; background: transparent; font-size: 26px; line-height: 1; cursor: pointer; color: var(--leise); }
.dialog-zu:hover { color: var(--text); }
.dialog h2 { margin: 0 0 2px; font-size: 19px; }
.dialog .unter { color: var(--leise); margin-bottom: 16px; }
.dm-raster { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 16px 0; }
.dm-feld { background: #f7f9fd; border-radius: 8px; padding: 9px 12px; }
.dm-feld .k { font-size: 11px; color: var(--leise); text-transform: uppercase; letter-spacing: .4px; }
.dm-feld .v { font-weight: 600; margin-top: 1px; }
.verlauf { width: 100%; height: 190px; }
.hist-tab { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.hist-tab td, .hist-tab th { padding: 5px 8px; border-bottom: 1px solid #eef1f7; text-align: left; }
.hist-tab th { color: var(--leise); font-weight: 600; font-size: 11px; text-transform: uppercase; }
.hist-tab td.num, .hist-tab th.num { text-align: right; }

@media (max-width: 720px) {
  .kopf { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 10px; }
  .tabellen-huelle { max-height: none; }
  main { padding: 12px; }
}

/* ---------- Anmeldung ---------- */
.anmeldung { display: flex; align-items: center; justify-content: center; min-height: 78vh; }
.anmelde-box { background: var(--flaeche); border: 1px solid var(--rand); border-radius: 14px;
  padding: 32px; width: 100%; max-width: 380px; }
.marke.gross { color: var(--akzent); font-size: 20px; margin-bottom: 4px; }
.anmelde-box .unter { color: var(--leise); margin: 0 0 20px; }
.anmelde-box label, .formular label, .karte label { display: block; margin-bottom: 12px;
  font-size: 12px; color: var(--leise); font-weight: 600; }
.anmelde-box input, .formular input, .formular select, .karte input, .karte select {
  display: block; width: 100%; margin-top: 4px; font: 14px/1.4 inherit; font-weight: 400;
  color: var(--text); padding: 9px 11px; border: 1px solid var(--rand); border-radius: 8px;
  background: #fff; }
.anmelde-box input:focus, .formular input:focus, .formular select:focus {
  outline: 2px solid var(--akzent); outline-offset: -1px; }
.knopf.breit { width: 100%; margin-top: 6px; }
.schmal { max-width: 460px; margin: 0 auto; }
.schmal h1 { font-size: 20px; }

/* ---------- Hinweise ---------- */
.hinweis { background: var(--akzent-hell); border: 1px solid #cfdcf3; color: var(--akzent);
  padding: 11px 14px; border-radius: 9px; margin-bottom: 16px; font-size: 13px; }
.hinweis.warnung { background: #fdecea; border-color: #f5c6c2; color: var(--rot); }
.hinweis.gut { background: #e6f4ea; border-color: #b7e0c4; color: var(--gruen); }
.hinweis code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; }

/* ---------- Unterreiter ---------- */
.unterreiter { display: flex; gap: 4px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.unterreiter-btn { background: transparent; border: 1px solid transparent; color: var(--leise);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font: inherit; text-decoration: none; }
.unterreiter-btn:hover { background: var(--flaeche); color: var(--text); }
.unterreiter-btn.aktiv { background: var(--flaeche); border-color: var(--rand);
  color: var(--akzent); font-weight: 600; }
.unterreiter .kopf-rechts { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.unterreiter .stand { color: var(--leise); }

h1 { font-size: 21px; margin: 0 0 16px; }

/* ---------- Formulare in Tabellen ---------- */
.formular .feldreihe { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.formular .haken { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 4px 0 14px; }
.formular .haken input { width: auto; margin: 0; }
.reihe { display: inline-flex; gap: 5px; align-items: center; margin: 0 4px 4px 0; }
.reihe select, .reihe input { margin-top: 0; padding: 5px 8px; font-size: 13px; }
.reihe input.klein { width: 150px; }
.aktionen { white-space: normal; min-width: 300px; }
.knopf-leise.gefahr { color: var(--rot); border-color: #f0c8c4; }
.knopf-leise.gefahr:hover { background: #fdecea; }
.pille.warn { background: #fdf1e3; color: var(--gelb); }
.schluessel { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.schluessel code { background: #fff; border: 1px solid var(--rand); padding: 8px 11px;
  border-radius: 7px; font-size: 13px; word-break: break-all; flex: 1 1 320px; }

/* ---------- Preiskorridor ---------- */
.korridor { width: 100%; height: 96px; margin: 4px 0 8px; }
.korridor-kopf { display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.einordnung { font-weight: 700; font-size: 15px; }
h3.abschnitt { font-size: 15px; margin: 26px 0 6px; padding-top: 18px;
  border-top: 1px solid var(--rand); }

/* ---------- Einrichtungsassistent ---------- */

body.einrichtung { background: var(--bg); padding: 0; }
.ein-huelle { max-width: 660px; margin: 0 auto; padding: 40px 20px 60px; }
.ein-kopf {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 17px; color: var(--akzent); margin-bottom: 22px;
}

.ein-schritte { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 18px; }
.ein-schritte li {
  flex: 1; display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--leise); padding: 8px 10px;
  background: var(--flaeche); border: 1px solid var(--rand); border-radius: 8px;
}
.ein-schritte li span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 19px; height: 19px; border-radius: 50%; flex: none;
  background: var(--rand); color: var(--leise); font-size: 11px; font-weight: 700;
}
.ein-schritte li.jetzt { border-color: var(--akzent); color: var(--akzent); font-weight: 600; }
.ein-schritte li.jetzt span { background: var(--akzent); color: #fff; }
.ein-schritte li.erledigt span { background: var(--gruen); color: #fff; }
.ein-schritte li.erledigt { color: var(--gruen); }

.ein-karte {
  background: var(--flaeche); border: 1px solid var(--rand);
  border-radius: var(--radius); padding: 28px;
}
.ein-karte h1 { margin: 0 0 12px; font-size: 21px; color: var(--akzent); }
.ein-karte h2 { margin: 22px 0 10px; font-size: 15px; }
.ein-karte p { margin: 0 0 12px; }
.ein-karte code {
  background: #f2f5fa; border: 1px solid var(--rand); border-radius: 4px;
  padding: 1px 5px; font-size: 12.5px; font-family: ui-monospace, Menlo, Consolas, monospace;
}
.ein-pfad { text-align: center; margin: 16px 0; }
.ein-pfad code { font-size: 14px; padding: 8px 14px; display: inline-block; }
.ein-klein { font-size: 12px; color: var(--leise); }

.pruefliste { list-style: none; padding: 0; margin: 14px 0; }
.pruefliste li {
  display: flex; gap: 9px; align-items: baseline;
  padding: 5px 0; border-bottom: 1px solid #f2f5fa; font-size: 13px;
}
.pruefliste li:last-child { border-bottom: 0; }
.pruefliste li b { font-weight: 700; width: 14px; flex: none; text-align: center; }
.pruefliste li.ok b { color: var(--gruen); }
.pruefliste li.warnung b { color: var(--gelb); }
.pruefliste li.fehler b { color: var(--rot); }
.pruefliste li.fehler { color: var(--rot); font-weight: 600; }

.ein-form { display: flex; flex-direction: column; gap: 5px; margin-top: 16px; }
.ein-form label { font-size: 12px; color: var(--leise); font-weight: 600; margin-top: 8px; }
.ein-form input {
  font: inherit; padding: 9px 11px; border: 1px solid var(--rand);
  border-radius: 8px; background: var(--flaeche); color: var(--text);
}
.ein-form input:focus { outline: 2px solid var(--akzent); outline-offset: -1px; }
.ein-form .ein-token {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 17px; letter-spacing: 2px; text-align: center; text-transform: uppercase;
}
.ein-form button { margin-top: 16px; align-self: flex-start; }

.ein-todo { list-style: none; padding: 0; margin: 0; }
.ein-todo li {
  padding: 9px 0 9px 26px; border-bottom: 1px solid #f2f5fa;
  font-size: 13.5px; position: relative;
}
.ein-todo li:last-child { border-bottom: 0; }
.ein-todo li::before { position: absolute; left: 2px; font-weight: 700; }
.ein-todo li.offen::before { content: '□'; color: var(--leise); }
.ein-todo li.erledigt::before { content: '✓'; color: var(--gruen); }

.ein-fuss { text-align: center; font-size: 12px; color: var(--leise); margin-top: 18px; }
