:root {
  --blau: #1f497d;          /* Kopf / Primär (aus der Excel-Vorlage) */
  --blau-hell: #2f6bb3;
  --gelb: #fff3b0;          /* Ort/Raum */
  --gelb-rand: #e6c700;
  --stark: #ffc000;         /* Starkstrom */
  --bus: #00b0f0;           /* Bus/Steuerung */
  --netz: #f2dcdb;          /* Netzwerk */
  --grau: #f4f5f7;
  --rand: #d7dbe0;
  --text: #1c2430;
  --gefahr: #c0392b;
  --schatten: 0 1px 3px rgba(0,0,0,.08);
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: #eef1f5;
  line-height: 1.4;
}

/* ---------- Kopf ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--blau); color: #fff;
  box-shadow: var(--schatten);
}
.top .marke { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.top nav { display: flex; gap: 8px; align-items: center; }

main { max-width: 1080px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.5rem; margin: .2em 0; }
h2 { font-size: 1.15rem; }
.unterzeile { color: #5b6572; margin-bottom: 12px; }
.hinweis, .leer, .leer-klein { color: #6a7280; }
.hinweis { font-size: .9rem; }
small { color: #6a7280; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border: 1px solid var(--rand); border-radius: 8px;
  background: #fff; color: var(--text); font: inherit; font-size: .9rem;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--grau); }
.btn-primär { background: var(--blau); color: #fff; border-color: var(--blau); }
.btn-primär:hover { background: var(--blau-hell); }
.btn-gefahr { color: var(--gefahr); border-color: #e2b6b0; background: #fff; }
.btn-gefahr:hover { background: #fdecea; }
.btn-mini { padding: 3px 8px; font-size: .8rem; }
.top .btn { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.3); }
.top .btn-primär { background: #fff; color: var(--blau); border-color: #fff; }

/* ---------- Formulare ---------- */
.stack { display: flex; flex-direction: column; gap: 10px; }
.reihe { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.feld-reihe { display: flex; gap: 12px; align-items: flex-end; flex-wrap: nowrap; }
.feld-reihe.wrap { flex-wrap: wrap; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: #45505f; font-weight: 600; }
input, select, textarea {
  padding: 8px 10px; border: 1px solid var(--rand); border-radius: 8px;
  font: inherit; background: #fff; color: var(--text); min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blau-hell); border-color: var(--blau-hell); }
.w-flex { flex: 1 1 220px; }
.w-nr { width: 90px; flex: 0 0 auto; }
.w-kat { width: 220px; }
.w-farbe { width: 130px; }

.panel {
  background: #fff; border: 1px solid var(--rand); border-radius: var(--radius);
  padding: 16px; margin: 18px 0; box-shadow: var(--schatten);
}

/* ---------- Login / Einrichten ---------- */
.login-wrap { display: flex; justify-content: center; padding-top: 6vh; }
.login-box { width: 100%; max-width: 380px; }
.login-box h1 { color: var(--blau); margin-top: 0; }
.passwort-menü { margin-top: 18px; display: inline-block; }
.passwort-menü .menü-inhalt { min-width: 260px; }

/* ---------- Flash ---------- */
.flashes { margin-bottom: 12px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 10px 12px; border-radius: 8px; border: 1px solid; }
.flash-ok { background: #eaf7ee; border-color: #b7e0c4; }
.flash-warn { background: #fff6e5; border-color: #f0d38a; }

/* ---------- Baustellen-Karten ---------- */
.karten { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 14px 0; }
.karte {
  display: block; background: #fff; border: 1px solid var(--rand); border-left: 5px solid var(--blau);
  border-radius: var(--radius); padding: 14px; text-decoration: none; color: var(--text); box-shadow: var(--schatten);
}
.karte:hover { border-left-color: var(--stark); }
.karte-titel { font-weight: 700; font-size: 1.05rem; }
.karte-sub { color: #5b6572; font-size: .9rem; }
.karte-notiz { color: #8a929c; font-size: .85rem; margin-top: 4px; }

/* ---------- Etage / Raum ---------- */
.kopf-zeile { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.etage {
  background: #fff; border: 1px solid var(--rand); border-radius: var(--radius);
  padding: 14px; margin: 16px 0; box-shadow: var(--schatten);
}
.etage-kopf { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  border-bottom: 2px solid var(--blau); padding-bottom: 6px; margin-bottom: 10px; }
.etage-kopf h2 { margin: 0; color: var(--blau); }
.kuerzel-tag {
  display: inline-block; margin-left: 6px; padding: 1px 9px; border-radius: 999px;
  background: var(--blau); color: #fff; font-size: .8rem; font-weight: 700; vertical-align: middle;
}
.werkzeuge { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.werkzeuge form { display: inline-flex; gap: 4px; }

.raum { border: 1px solid var(--rand); border-radius: 8px; margin: 10px 0; overflow: hidden; }
.raum-kopf {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--gelb); border-left: 6px solid var(--gelb-rand); padding: 6px 10px;
}
.raum-name { font-weight: 700; }
.raum-neu { margin-top: 10px; }
.leer-klein { padding: 8px 10px; font-size: .9rem; }

/* ---------- Kabel-Tabelle ---------- */
.tabelle-wrap { overflow-x: auto; }
.kabel-tabelle { width: 100%; border-collapse: collapse; font-size: .9rem; }
.kabel-tabelle th, .kabel-tabelle td {
  border: 1px solid var(--rand); padding: 5px 8px; text-align: left; vertical-align: middle;
}
.kabel-tabelle thead th { background: #eceff3; font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; color: #5b6572; }
.zelle-nr { font-weight: 700; background: #f7f8fa; text-align: center; width: 60px; }
.zelle-kabel a { color: var(--text); font-weight: 600; text-decoration: none; }
.zelle-kabel a:hover { color: var(--blau); text-decoration: underline; }
.zelle-typ { white-space: nowrap; color: #45505f; }
.zelle-farbe { font-weight: 600; }
.zelle-aktionen { width: 1%; white-space: nowrap; }
.mini-notiz { font-size: .78rem; color: #8a929c; font-style: italic; }
.leer-ader { color: #a0a7b0; font-size: .85rem; }

/* Kategorie-Farbstreifen wie in der Excel-Vorlage */
.kat-stark    .zelle-farbe { border-left: 4px solid var(--stark); }
.kat-bus      .zelle-farbe { border-left: 4px solid var(--bus); }
.kat-stark    .zelle-kabel { box-shadow: inset 4px 0 0 var(--stark); }
.kat-bus      .zelle-kabel { box-shadow: inset 4px 0 0 var(--bus); }
.kat-netzwerk .zelle-kabel { box-shadow: inset 4px 0 0 #d9a7a3; }
.zelle-netz { background: var(--netz); font-style: italic; }

.liste td { vertical-align: top; }

/* ---------- Kabel-Formular ---------- */
.kabel-form { max-width: 760px; }
.adern-kopf { display: flex; justify-content: space-between; align-items: center; margin: 6px 0; }
.adern-tabelle { width: 100%; border-collapse: collapse; }
.adern-tabelle th { text-align: left; font-size: .8rem; color: #5b6572; padding: 4px 6px; }
.adern-tabelle td { padding: 3px 6px; }
.adern-tabelle input { width: 100%; }
.hidden { display: none !important; }

/* Automatisch vergebene Kabelnummer – nicht editierbar */
.nr-fest {
  background: var(--grau); color: var(--blau); font-weight: 700; text-align: center;
  cursor: not-allowed;
}

/* ---------- Menü (Details) ---------- */
.menü { position: relative; }
.menü > summary { list-style: none; }
.menü > summary::-webkit-details-marker { display: none; }
.menü-inhalt {
  position: absolute; right: 0; z-index: 10; margin-top: 6px; min-width: 240px;
  background: #fff; border: 1px solid var(--rand); border-radius: 10px; padding: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.15); display: flex; flex-direction: column; gap: 10px;
}
.menü-inhalt .reihe input { flex: 1; }

/* ---------- Ein-/Ausklappen (Etage / Raum / Kabel) ---------- */
.klapp-btn {
  border: none; background: transparent; cursor: pointer; color: inherit;
  font-size: .85rem; padding: 0 4px 0 0; line-height: 1;
}
.kabel-toggle {
  border: none; background: transparent; cursor: pointer; color: var(--blau);
  font-size: .8rem; margin-right: 3px; padding: 0;
}
.etage.zu .etage-body,
.raum.zu .raum-body { display: none; }
.etage.zu .etage-kopf { border-bottom-color: transparent; margin-bottom: 0; }
.kabel-block:not(.zu) .ader-summary { display: none; }
.kabel-block.zu .ader-erste,
.kabel-block.zu tr.ader-detail { display: none; }
.ader-summary { color: #6a7280; font-style: italic; }

/* Werkzeuge des Kabels immer in EINER Reihe (Stift neben Pfeilen und Löschen). */
.zelle-aktionen .werkzeuge { flex-wrap: nowrap; }
/* Zugeklappt: kompakte Einzeiler – nur der Stift bleibt sichtbar. */
.kabel-block.zu .nur-offen { display: none; }
.kabel-block.zu > tr > td { padding-top: 3px; padding-bottom: 3px; }

/* ---------- Aktion/Belegung direkt in der Tabelle bearbeiten ---------- */
.feld-bearbeitbar { position: relative; cursor: pointer; padding-right: 20px !important; }
.feld-bearbeitbar:hover { background: #fffbe6; box-shadow: inset 0 0 0 1px var(--gelb-rand); }
.feld-bearbeitbar:hover::after {
  content: "✎"; position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  font-size: .8rem; color: #8a929c; pointer-events: none;
}
.feld-bearbeitbar input.feld-eingabe { width: 100%; padding: 2px 6px; font-size: .9rem; }
.feld-bearbeitbar:has(input)::after { content: none; }
.feld-bearbeitbar.gespeichert { background: #eaf7ee; transition: background .4s; }

/* ---------- Kabelkatalog ---------- */
.ader-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ader-chip {
  display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: .82rem;
  background: var(--grau); border: 1px solid var(--rand); border-left: 3px solid var(--rand);
}
.ader-chip.kat-stark { border-left-color: var(--stark); }
.ader-chip.kat-bus { border-left-color: var(--bus); }
.ader-chip.kat-netzwerk { border-left-color: #d9a7a3; }
.w-typ { width: 200px; }

/* ---------- Sicherungs-Hierarchie ---------- */
.sich-baum { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.sich-zeile {
  margin-left: calc(var(--tiefe, 0) * 26px);
  background: #fff; border: 1px solid var(--rand); border-radius: 8px;
  border-left: 4px solid var(--blau); box-shadow: var(--schatten);
}
.sich-haupt { display: flex; align-items: center; gap: 8px; padding: 8px 10px; flex-wrap: wrap; }
.sich-zeile.versteckt { display: none; }
.klapp-platz { display: inline-block; width: 1.1em; }
.sich-name { font-weight: 700; font-size: 1rem; }
.sich-art { font-size: .8rem; color: #5b6572; }
.art-fi, .art-fils { color: var(--bus); font-weight: 700; }
.art-sls { color: var(--gefahr); font-weight: 700; }
.sich-chip {
  font-size: .78rem; font-weight: 700; padding: 1px 8px; border-radius: 999px;
  background: var(--gelb); border: 1px solid var(--gelb-rand);
}
.sich-notiz { font-size: .85rem; color: #8a929c; font-style: italic; }
.sich-werkzeuge { margin-left: auto; }
.sich-edit-inhalt {
  display: none; border-top: 1px solid var(--rand); padding: 10px;
  background: var(--grau); border-radius: 0 0 8px 8px;
}
.sich-zeile.offen .sich-edit-inhalt { display: block; }

@media (max-width: 640px) {
  .feld-reihe { flex-wrap: wrap; }
  .w-kat { width: 100%; }
  .kopf-zeile { flex-direction: column; }
  .menü-inhalt { right: auto; left: 0; }
  .sich-zeile { margin-left: calc(var(--tiefe, 0) * 14px); }
}
