/* Logische Schaltungen und Aussagenlogik: Schaltbild-Editor, Szenen, Tabellen, Terme, KV-Diagramme, Kreuzungen. */

.schaltbild { display: flex; flex-direction: column; gap: .5rem; margin: .6rem 0; }
.schaltbild[hidden] { display: none; }   /* verdeckte Schaltung (Tresor): sonst ueberstimmt display: flex das hidden */
/* Oben: Auswahl (links) + allgemeine Knoepfe (rechts); darunter Bauteil-Leiste links neben der Flaeche */
.sb-werkzeug { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center; justify-content: space-between;
  padding: .35rem .5rem; background: #f1f5f9; border: 1px solid #cbd5e1; border-radius: 8px; min-height: 48px; }
.sb-auswahl, .sb-allgemein, .sb-anzahl { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.sb-allgemein { margin-left: auto; }
.sb-auswahl-titel { font-weight: 600; font-size: .95rem; color: #0f172a; }
.sb-auswahl-titel.leer { font-weight: 400; color: #64748b; font-style: italic; }
.sb-anzahl button { min-width: 40px; }
.sb-anzahl span { font-size: .9rem; }
.sb-rumpf { display: flex; gap: .5rem; align-items: flex-start; min-width: 0; }
.sb-rumpf > .sb-flaeche { flex: 1 1 auto; min-width: 0; }
.sb-palette { flex: 0 0 auto; width: 8.6rem; display: flex; flex-direction: column; gap: .5rem; padding: .4rem;
  background: #f8fafc; border: 1px solid #cbd5e1; border-radius: 8px; max-height: 34rem; overflow-y: auto; }
.sb-gruppe-titel { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #475569;
  margin: 0 0 .2rem .1rem; }
.sb-gruppe-knoepfe { display: flex; flex-direction: column; gap: .25rem; }
.sb-bauteil-knopf { display: flex; align-items: center; gap: .3rem; min-height: 40px; width: 100%; text-align: left;
  justify-content: flex-start; padding-left: .35rem; padding-right: .35rem; overflow: hidden; }
.sb-bauteil-knopf span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Schmale Bildschirme: Leiste ueber der Flaeche, Gruppen nebeneinander */
@media (max-width: 640px) {
  .sb-rumpf { flex-direction: column; align-items: stretch; }
  .sb-palette { width: auto; max-height: none; flex-direction: row; flex-wrap: wrap; }
  .sb-gruppe-knoepfe { flex-direction: row; flex-wrap: wrap; }
  .sb-bauteil-knopf { width: auto; }
}
.sb-icon { display: inline-block; min-width: 1.4em; text-align: center; font-weight: 600; }
.sb-flaeche { overflow: auto; max-width: 100%; border: 1px solid #cbd5e1; border-radius: 8px;
  background: #fbfdff; background-image: radial-gradient(#dbe4ee 1px, transparent 1px); background-size: 10px 10px;
  -webkit-overflow-scrolling: touch; }
.schaltbild.nur-ansehen .sb-flaeche { background: #fff; background-image: none; }
.sb-svg { display: block; user-select: none; -webkit-user-select: none; font-family: inherit; }
.sb-svg:focus { outline: 2px solid #00b0df; outline-offset: -2px; }
.sb-name-feld { font-size: 16px; width: 6em; padding: .2rem .4rem; }
.sb-name-label { display: inline-flex; gap: .3rem; align-items: center; font-size: .9rem; }
.sb-hinweis { min-height: 1.3em; margin: 0; font-size: .9rem; color: #475569; }
.sb-tabelle table { width: auto; }
.sb-tab td, .sb-tab th { text-align: center; min-width: 2.2em; }
.sb-tab .sb-aus { background: #eff8fc; font-weight: 600; }

/* Zeichnung */
.sb-draht { fill: none; stroke: #1f2937; stroke-width: 2; stroke-linejoin: round; }
.sb-treffer { fill: none; stroke: transparent; stroke-width: 12; }
.sb-leitung.an .sb-draht { stroke: #dc2626; stroke-width: 3; }
.sb-leitung.gewaehlt .sb-draht { stroke: #0284c7; stroke-dasharray: 6 3; }
.sb-punkt { fill: #1f2937; }
.sb-linie { stroke: #1f2937; stroke-width: 2; fill: none; }
.sb-koerper, .sb-koerper path, .sb-koerper rect { fill: #fff; stroke: #1f2937; stroke-width: 2; }
.sb-koerper.an { fill: #fde68a; }
.sb-lampe .sb-koerper.an { fill: #fde047; }
.sb-schein { fill: rgba(253, 224, 71, .45); stroke: none; }
.sb-symbol { font-size: 14px; fill: #1f2937; pointer-events: none; }
.sb-wert { font-size: 15px; font-weight: 700; fill: #1f2937; pointer-events: none; }
.sb-name { font-size: 15px; fill: #0f172a; font-weight: 600; pointer-events: none; }
.sb-modul { font-size: 12px; font-weight: 700; fill: #1f2937; pointer-events: none; }
.sb-pin-name { font-size: 10px; fill: #475569; pointer-events: none; }
.sb-griff { fill: transparent; cursor: grab; }
.sb-bauteil { touch-action: none; }
.sb-bauteil.fest .sb-griff { cursor: default; }
.sb-schalter .sb-griff, .sb-taster .sb-griff { cursor: pointer; }
.sb-bauteil.gewaehlt .sb-koerper, .sb-bauteil.gewaehlt .sb-koerper path { stroke: #0284c7; stroke-width: 3; }
.sb-pin { cursor: crosshair; touch-action: none; }
.sb-pin-treffer { fill: transparent; }
.sb-pin-punkt { pointer-events: none; fill: #fff; stroke: #64748b; stroke-width: 1.5; }
.sb-pin-aus .sb-pin-punkt { fill: #e2e8f0; }
.sb-pin.belegt .sb-pin-punkt { fill: #1f2937; stroke: #1f2937; r: 2.5; }
.sb-pin.offen .sb-pin-punkt { fill: #0284c7; stroke: #0284c7; r: 6; }
.sb-pin:hover .sb-pin-punkt { stroke: #0284c7; }

/* Statische Abbildungen (schaltung_svg.py) */
.schaltung-abbildung { overflow-x: auto; max-width: 100%; margin: .6rem 0; }
.schaltung-abbildung svg { max-width: none; }

/* Szenen (Kettensaege, Ampel, Tresor, ...): Bedienelemente antippbar, Ausgaenge mit Klasse .an */
.logik-szene { display: flex; justify-content: center; margin: .4rem 0; }
.logik-szene svg { max-width: 100%; height: auto; }
.logik-szene [data-eingang] { cursor: pointer; }
.logik-szene [data-eingang]:focus { outline: 2px solid #00b0df; }
.logik-szene .knopf-kappe { transition: transform .1s; }
.logik-szene [data-eingang].an .knopf-kappe { fill: #16a34a; }
.logik-szene [data-eingang].an .hebel-arm { transform: rotate(60deg); }
.logik-szene .hebel-arm { transform-box: fill-box; transform-origin: 50% 100%; transition: transform .15s; }
.logik-szene [data-ausgang] .licht { fill: #475569; transition: fill .15s; }
.logik-szene [data-ausgang].an .licht { fill: var(--licht, #facc15); }
.logik-szene [data-ausgang].an .glanz { opacity: 1; }
.logik-szene .glanz { opacity: 0; transition: opacity .15s; }
.logik-szene .nur-an { opacity: 0; transition: opacity .2s; }
.logik-szene [data-ausgang].an .nur-an, .logik-szene [data-ausgang].an.nur-an { opacity: 1; }
.logik-szene [data-ausgang].an .nur-aus { opacity: 0; }
@keyframes logik-drehen { to { transform: rotate(360deg); } }
.logik-szene [data-ausgang].an .dreht { animation: logik-drehen .35s linear infinite; transform-box: fill-box; transform-origin: center; }
.logik-szene .szene-text { font-size: 13px; fill: #334155; }

/* Belegungstabellen zum Ausfuellen */
.lg-tabelle { overflow-x: auto; max-width: 100%; }
.lg-tabelle table { width: auto; border-collapse: collapse; }
.lg-tabelle th, .lg-tabelle td { text-align: center; padding: .2rem .5rem; min-width: 2.4em; }
.lg-tabelle .lg-trenn { border-left: 3px double #94a3b8; }
.lg-zelle { min-width: 2.6em; min-height: 36px; font-size: 16px; font-weight: 700; border: 1px solid #94a3b8;
  border-radius: 6px; background: #fff; cursor: pointer; }
.lg-zelle:empty::after, .lg-zelle[data-wert=""]::after { content: '·'; color: #94a3b8; }
.lg-zelle.falsch { border-color: #dc2626; background: #fef2f2; }

/* Term-Eingabe */
.lg-term-zeile { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.lg-term-feld { font-size: 18px; padding: .35rem .5rem; min-width: 14em; flex: 1 1 14em; font-family: inherit; }
.lg-tasten { display: flex; flex-wrap: wrap; gap: .3rem; margin: .35rem 0; }
.lg-tasten button { min-width: 44px; min-height: 40px; font-size: 18px; }
.lg-term-stand { font-size: .95rem; color: #334155; min-height: 1.3em; }
.lg-term-stand.fehler { color: #b91c1c; }

/* Termbaum */
.lg-baum svg { max-width: 100%; height: auto; }
.lg-baum-bau { overflow-x: auto; }
.lg-baum-knoten { cursor: pointer; }
.lg-baum-knoten circle { fill: #fff; stroke: #1f2937; stroke-width: 2; }
.lg-baum-knoten.leer circle { stroke-dasharray: 4 3; stroke: #64748b; }
.lg-baum-knoten.gewaehlt circle { stroke: #0284c7; stroke-width: 3; fill: #e0f2fe; }
.lg-baum-knoten text { font-size: 16px; text-anchor: middle; pointer-events: none; }

/* KV-Diagramm */
.lg-kv { overflow-x: auto; }
.lg-kv table { border-collapse: collapse; width: auto; margin: .4rem 0; }
.lg-kv th { font-weight: 600; font-size: .9rem; padding: .2rem .4rem; color: #334155; }
.lg-kv td { padding: 0; }
.lg-kv-zelle { width: 52px; height: 48px; font-size: 18px; font-weight: 700; border: 1px solid #64748b; background: #fff;
  position: relative; cursor: pointer; }
.lg-kv-zelle.markiert { background: #bae6fd; }
.lg-kv-zelle .lg-kv-bloecke { position: absolute; inset: 2px; display: flex; flex-wrap: wrap; gap: 2px; align-items: flex-end;
  pointer-events: none; }
.lg-kv-zelle .lg-kv-block { width: 8px; height: 8px; border-radius: 50%; }
.lg-kv-liste { display: flex; flex-direction: column; gap: .3rem; }
.lg-kv-eintrag { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.lg-kv-farbe { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }

/* Kreuzung (Ampelsteuerung) */
.lg-kreuzung { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-start; }
.lg-kreuzung-bild { flex: 0 1 380px; max-width: 100%; }
.lg-kreuzung-bild svg { width: 100%; height: auto; }
.lg-kreuzung-rest { flex: 1 1 260px; min-width: 0; }
.lg-ampel { cursor: pointer; }
.lg-ampel .rot { fill: #ef4444; }
.lg-ampel .gruen { fill: #374151; }
.lg-ampel.an .rot { fill: #374151; }
.lg-ampel.an .gruen { fill: #22c55e; }
.lg-spur { fill: none; stroke-width: 6; stroke-linecap: round; opacity: .35; }
.lg-spur.an { opacity: 1; }
.lg-spur.konflikt { stroke: #dc2626 !important; opacity: 1; stroke-dasharray: 10 6; }
.lg-status { font-weight: 700; padding: .25rem .6rem; border-radius: 999px; display: inline-block; }
.lg-status.unsicher { background: #fee2e2; color: #991b1b; }
.lg-status.sicher { background: #fef9c3; color: #854d0e; }
.lg-status.optimal { background: #dcfce7; color: #166534; }

/* Spielwiese: Speichern/Laden, eigene Module */
.lg-spielwiese { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .6rem; }
.lg-sw-knoepfe { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.lg-sw-name { font-size: 16px; padding: .3rem .5rem; min-width: 10em; }
.lg-sw-listen { display: flex; flex-wrap: wrap; gap: 1rem 2rem; }
.lg-sw-liste { min-width: 240px; }
.lg-sw-liste h4 { margin: .2rem 0; }
.sb-modul-knopf { border-style: dashed; }

/* Szenen mit Teilen, die vom Eingang abhaengen (Relais): Strom rot, Kontakt auf/zu */
.logik-szene [data-zeigt-eingang].an .nur-an, .logik-szene [data-eingang].an .nur-an { opacity: 1; }
.logik-szene [data-zeigt-eingang].an .nur-aus, .logik-szene [data-eingang].an .nur-aus { opacity: 0; }
.logik-szene .strom { transition: stroke .15s; }
.logik-szene [data-zeigt-eingang].an .strom, .logik-szene [data-ausgang].an .strom { stroke: #dc2626; }

/* Abbildungen nebeneinander, bei wenig Platz untereinander (Termbaum + Schaltung) */
.lg-nebeneinander { display: flex; flex-wrap: wrap; gap: .5rem 2rem; align-items: flex-end; }
.lg-nebeneinander > figure { flex: 0 1 auto; max-width: 100%; margin: .4rem 0; }
.lg-nebeneinander svg { max-width: 100%; height: auto; }
