:root {
  --bg: #f4f5f7;
  --flaeche: #ffffff;
  --rand: #d6d9de;
  --rand-stark: #b3b8c0;
  --text: #1f2328;
  --leise: #6b727c;
  --primaer: #2f6fb5;
  --primaer-text: #ffffff;
  --gefahr: #c0392b;
  --warn-bg: #fdf3e3;
  --warn-rand: #e0b054;
  --fehler-bg: #fdecea;
  --fehler-rand: #d9534f;
  --sp-input: #4c8c4c;
  --sp-mischer-a: #3e6fa8;
  --sp-mischer-b: #6a4ca8;
  --sp-output: #c07a2e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1d21;
    --flaeche: #24272c;
    --rand: #3a3f46;
    --rand-stark: #50565e;
    --text: #e6e8ea;
    --leise: #9aa1aa;
    --primaer: #4b8fd6;
    --warn-bg: #3a2f1c;
    --warn-rand: #8a6b2a;
    --fehler-bg: #3a2320;
    --fehler-rand: #a4453f;
  }
}

* { box-sizing: border-box; }

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

/* ---------- Kopf ---------- */
.kopf {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 20px;
  background: var(--flaeche);
  border-bottom: 1px solid var(--rand);
  position: sticky;
  top: 0;
  z-index: 5;
}
.kopf h1 { font-size: 17px; margin: 0; font-weight: 600; }

.tabs { display: flex; gap: 4px; }
.tabs button {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 14px;
  color: var(--leise);
  cursor: pointer;
  font: inherit;
}
.tabs button.aktiv {
  background: var(--bg);
  border-color: var(--rand);
  color: var(--text);
  font-weight: 600;
}

main { padding: 16px 20px 60px; }

/* ---------- Leiste ---------- */
.leiste {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.luecke { flex: 1; }
.wachsend { flex: 0 1 260px; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--flaeche);
  border: 1px solid var(--rand-stark);
  border-radius: 6px;
  padding: 6px 8px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primaer);
  outline-offset: -1px;
}
textarea { width: 100%; resize: vertical; }

button {
  font: inherit;
  background: var(--flaeche);
  color: var(--text);
  border: 1px solid var(--rand-stark);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--primaer); }
button.primaer { background: var(--primaer); color: var(--primaer-text); border-color: var(--primaer); }
button.gefahr { color: var(--gefahr); border-color: var(--gefahr); }
button.klein { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }

.schalter { display: flex; }
.schalter button { border-radius: 0; margin-left: -1px; }
.schalter button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.schalter button:last-child { border-radius: 0 6px 6px 0; }
.schalter button.aktiv { background: var(--primaer); color: var(--primaer-text); border-color: var(--primaer); }

.kasten { display: flex; align-items: center; gap: 6px; color: var(--leise); }
.leise { color: var(--leise); font-weight: 400; }

.status { color: var(--leise); font-size: 13px; min-height: 20px; margin-bottom: 6px; }

.hinweise {
  background: var(--warn-bg);
  border: 1px solid var(--warn-rand);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 12px;
}
.hinweise ul { margin: 4px 0 0; padding-left: 20px; }

.fehler {
  background: var(--fehler-bg);
  border: 1px solid var(--fehler-rand);
  border-radius: 6px;
  padding: 8px 12px;
  margin-top: 10px;
}
.fehler ul { margin: 0; padding-left: 20px; }

/* ---------- Spalten ---------- */
.spalten {
  display: grid;
  grid-template-columns: repeat(4, minmax(240px, 1fr));
  gap: 12px;
  align-items: start;
}
@media (max-width: 1100px) {
  .spalten { grid-template-columns: repeat(2, minmax(240px, 1fr)); }
}

.spalte {
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-top: 3px solid var(--rand-stark);
  border-radius: 8px;
  padding: 10px;
  min-height: 140px;
}
.spalte[data-id="input"]     { border-top-color: var(--sp-input); }
.spalte[data-id="mischer-a"] { border-top-color: var(--sp-mischer-a); }
.spalte[data-id="mischer-b"] { border-top-color: var(--sp-mischer-b); }
.spalte[data-id="output"]    { border-top-color: var(--sp-output); }

.spalte-titel {
  width: 100%;
  border: 1px solid transparent;
  background: none;
  font-weight: 600;
  padding: 4px 6px;
  margin-bottom: 8px;
}
.spalte-titel:hover { border-color: var(--rand); }

.karte {
  border: 1px solid var(--rand);
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 8px;
  background: var(--bg);
  position: relative;
}
.karte.fehlt { border-color: var(--fehler-rand); background: var(--fehler-bg); }
.karte .bezeichnung { width: 100%; font-weight: 600; margin-bottom: 4px; padding-right: 24px; }
.karte .typ { color: var(--leise); font-size: 12px; }
.karte .ports { font-size: 12px; margin: 6px 0; }
.karte .speisung { width: 100%; font-size: 12px; }
.karte .entfernen {
  position: absolute;
  top: 6px; right: 6px;
  border: none; background: none;
  color: var(--leise);
  padding: 2px 6px;
  line-height: 1;
}
.karte .entfernen:hover { color: var(--gefahr); }

.spalte-leer { color: var(--leise); font-size: 13px; text-align: center; padding: 12px 0; }

/* ---------- Verkabeln ---------- */
.hilfe {
  background: var(--flaeche);
  border: 1px dashed var(--primaer);
  border-radius: 6px;
  padding: 6px 12px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--leise);
}
#armiert-info { color: var(--primaer); font-weight: 600; margin-left: 8px; }

.ports-liste { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; }

.port {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--rand);
  border-left: 4px solid var(--f, #999);
  border-radius: 4px;
  background: var(--flaeche);
}
.port:hover { border-color: var(--primaer); border-left-color: var(--f, #999); }
.port .richtung {
  font-size: 10px;
  font-weight: 700;
  color: var(--leise);
  min-width: 26px;
}
.port .bezeichner { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.port .belegt { color: var(--primaer); font-size: 11px; }
.port.armiert {
  border-color: var(--primaer);
  box-shadow: inset 0 0 0 1px var(--primaer);
  font-weight: 600;
}

.abschnitt { font-size: 15px; margin: 24px 0 8px; }
.bilanz { color: var(--leise); font-size: 13px; margin-bottom: 8px; }
.bilanz .schlecht { color: var(--gefahr); font-weight: 600; }
.bilanz .mittel { color: #b8860b; font-weight: 600; }

.kabel-liste { display: flex; flex-direction: column; gap: 4px; }
.kabel-zeile {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}
.kabel-zeile.fehler { border-color: var(--fehler-rand); background: var(--fehler-bg); }
.kabel-zeile.warnung { border-color: var(--warn-rand); background: var(--warn-bg); }
.kabel-zeile .strang { flex: 1; min-width: 0; }
.kabel-zeile .signal {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,.25);
}
.kabel-zeile .befund { font-size: 12px; color: var(--leise); display: block; }
.kabel-zeile .weg { border: none; background: none; color: var(--leise); padding: 2px 6px; }
.kabel-zeile .weg:hover { color: var(--gefahr); }

/* ---------- Listen ---------- */
.liste { display: flex; flex-direction: column; gap: 6px; }

.zeile {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
}
.zeile:hover { border-color: var(--primaer); }
.zeile.inaktiv { opacity: .55; }
.zeile .haupt { flex: 1; min-width: 0; }
.zeile .name { font-weight: 600; }
.zeile .unter { color: var(--leise); font-size: 12px; }
.zeile .marke {
  font-size: 11px;
  border: 1px solid var(--rand-stark);
  border-radius: 10px;
  padding: 1px 8px;
  color: var(--leise);
  white-space: nowrap;
}

/* ---------- Dialoge ---------- */
dialog {
  border: 1px solid var(--rand-stark);
  border-radius: 10px;
  background: var(--flaeche);
  color: var(--text);
  padding: 0;
  width: min(980px, 94vw);
  max-height: 90vh;
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
#dlg-auswahl { width: min(620px, 94vw); display: flex; flex-direction: column; }
#dlg-auswahl[open] { display: flex; }

.dlg-kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rand);
}
.schliessen { border: none; background: none; color: var(--leise); font-size: 16px; padding: 2px 8px; }
.dlg-koerper { padding: 16px; overflow: auto; max-height: calc(90vh - 130px); }
.dlg-liste { padding: 0 16px 16px; overflow: auto; max-height: 52vh; }
.dlg-fuss {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--rand);
}

.neu-zeile {
  margin: 12px 16px 8px;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  border-style: dashed;
  border-color: var(--primaer);
  color: var(--primaer);
  background: none;
}
.such-feld { margin: 0 16px 12px; }

.raster { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.raster.zwei { grid-template-columns: 1fr 1fr; }
.raster label, .dlg-koerper > label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--leise); }
.raster label input, .dlg-koerper > label textarea { color: var(--text); }

fieldset {
  border: 1px solid var(--rand);
  border-radius: 6px;
  padding: 8px 12px 12px;
  margin: 0 0 12px;
}
legend { font-size: 13px; color: var(--leise); padding: 0 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.chips label { display: flex; align-items: center; gap: 5px; font-size: 13px; }

/* ---------- Porttabelle ---------- */
#port-tabelle { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
#port-tabelle th {
  text-align: left;
  font-size: 12px;
  color: var(--leise);
  font-weight: 600;
  padding: 0 4px 4px;
}
#port-tabelle th.schmal { width: 78px; }
#port-tabelle td { padding: 2px; }
#port-tabelle input, #port-tabelle select { width: 100%; padding: 4px 6px; font-size: 13px; }
#port-tabelle .weg { border: none; background: none; color: var(--leise); padding: 2px 6px; }
#port-tabelle .weg:hover { color: var(--gefahr); }
.port-farbe {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: -1px;
  border: 1px solid rgba(0,0,0,.25);
}
