:root {
  color-scheme: dark;
  --plane:      #07080a;
  --surface:    rgba(22,24,28,0.82);
  --surface-2:  rgba(255,255,255,0.055);
  --surface-3:  rgba(255,255,255,0.10);
  --ink:        #f2f3f5;
  --ink-2:      #a8adb8;
  --ink-3:      #6b7080;
  --line:       rgba(255,255,255,0.07);
  --line-2:     rgba(255,255,255,0.13);
  --accent:     #4d93ea;
  --accent-dim: rgba(77,147,234,0.16);
  --danger:     #e06a6a;
  --shadow:     0 16px 48px -12px rgba(0,0,0,0.75), 0 2px 8px rgba(0,0,0,0.4);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--plane); color: var(--ink);
  font: 400 13px/1.5 var(--font);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
::selection { background: rgba(77,147,234,0.32); }

/* ══════════ Toolbar ══════════ */
#topbar {
  position: absolute; inset: 0 0 auto 0; height: 52px; z-index: 30;
  display: flex; align-items: center; gap: 2px; padding: 0 10px 0 16px;
  background: linear-gradient(180deg, rgba(11,12,15,0.94) 0%, rgba(11,12,15,0.72) 100%);
  backdrop-filter: blur(20px) saturate(140%);
  border-bottom: 1px solid var(--line);
}
#brand, .brand {
  display: flex; align-items: center; gap: 9px; margin-right: 14px;
  font-size: 13px; font-weight: 600; letter-spacing: -0.005em;
  color: var(--ink); white-space: nowrap; user-select: none;
}
#brand .mark, .brand .mark {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 3px rgba(77,147,234,0.16), 0 0 14px 2px rgba(77,147,234,0.6);
}
.divider { width: 1px; height: 18px; background: var(--line); margin: 0 9px; flex: none; }
.grow { flex: 1 1 auto; }

/* Knöpfe: rahmenlos, Gewicht kommt über Fläche und Ink */
.tb {
  display: inline-flex; align-items: center; gap: 6px;
  font: 500 12.5px/1 var(--font); color: var(--ink-2);
  background: transparent; border: 0; border-radius: 8px;
  padding: 8px 11px; cursor: pointer; white-space: nowrap;
  transition: background .13s ease, color .13s ease, opacity .13s;
}
.tb:hover { background: var(--surface-2); color: var(--ink); }
.tb:active { background: var(--surface-3); }
.tb.solid {
  background: rgba(255,255,255,0.09); color: var(--ink); font-weight: 560;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
}
.tb.solid:hover { background: rgba(255,255,255,0.14); }
.tb.on {
  background: var(--accent-dim); color: #9cc4f6;
  box-shadow: inset 0 0 0 1px rgba(77,147,234,0.38);
}
.tb[disabled] { opacity: .3; pointer-events: none; }
.tb .ic { width: 15px; height: 15px; flex: none; opacity: .9; }
.tb.icon-only { padding: 8px; }

kbd {
  font: 500 10px/1 var(--font); color: var(--ink-3);
  background: rgba(255,255,255,0.06); border-radius: 4px;
  padding: 3px 5px; margin-left: 2px;
}

/* ══════════ Suche ══════════ */
.search-wrap { position: relative; display: flex; align-items: center; }
.search-wrap .ic {
  position: absolute; left: 10px; width: 14px; height: 14px;
  color: var(--ink-3); pointer-events: none;
}
#search {
  font: 400 12.5px var(--font); color: var(--ink);
  width: 200px; padding: 8px 10px 8px 30px;
  background: rgba(255,255,255,0.055); border: 1px solid transparent;
  border-radius: 8px; transition: background .13s, border-color .13s, width .18s;
}
#search::placeholder { color: var(--ink-3); }
#search:focus {
  outline: none; width: 240px;
  background: rgba(255,255,255,0.08); border-color: rgba(77,147,234,0.45);
}

/* ══════════ Canvas ══════════ */
#stage { position: absolute; inset: 52px 0 0 0; }
canvas { display: block; width: 100%; height: 100%; }

/* ══════════ Panels ══════════ */
.panel {
  background: var(--surface);
  backdrop-filter: blur(24px) saturate(150%);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: var(--shadow);
}
.panel-title {
  font: 600 10px/1 var(--font); text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--ink-3);
}

/* Legende */
#legend {
  position: absolute; left: 16px; bottom: 16px; z-index: 20;
  padding: 12px 10px 8px; min-width: 190px; user-select: none;
}
#legend .panel-title { padding: 0 8px 9px; }
.lg-row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: 7px; cursor: pointer;
  color: var(--ink-2); font-size: 12.5px;
  transition: background .12s, opacity .12s;
}
.lg-row:hover { background: var(--surface-2); color: var(--ink); }
.lg-row.off { opacity: .32; }
.lg-row .glyph { width: 13px; height: 13px; flex: none; }
.lg-row .n {
  margin-left: auto; color: var(--ink-3); font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

/* Inspector */
#inspector {
  position: absolute; top: 64px; right: 16px; bottom: 16px; width: 316px; z-index: 25;
  display: none; flex-direction: column; overflow: hidden;
}
#inspector.open { display: flex; }
.insp-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 13px; border-bottom: 1px solid var(--line);
}
.insp-head .glyph { width: 13px; height: 13px; flex: none; }
.insp-body {
  padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.14) transparent;
}
.insp-foot {
  margin-top: auto; padding: 12px 14px; border-top: 1px solid var(--line);
  display: flex; gap: 8px;
}
.insp-foot .tb {
  flex: 1; justify-content: center;
  background: rgba(255,255,255,0.055);
}
.insp-foot .tb:hover { background: var(--surface-3); }
.insp-foot .tb.del:hover { background: rgba(224,106,106,0.16); color: #f0a0a0; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font: 500 11px/1 var(--font); color: var(--ink-3); letter-spacing: .01em; }
input[type=text], input[type=number], textarea, select {
  font: 400 13px var(--font); color: var(--ink); width: 100%;
  background: rgba(255,255,255,0.045);
  border: 1px solid transparent; border-radius: 8px; padding: 9px 10px;
  transition: background .13s, border-color .13s, box-shadow .13s;
}
input:hover, textarea:hover, select:hover { background: rgba(255,255,255,0.07); }
input:focus, textarea:focus, select:focus {
  outline: none; background: rgba(255,255,255,0.08);
  border-color: rgba(77,147,234,0.55);
  box-shadow: 0 0 0 3px rgba(77,147,234,0.12);
}
textarea { resize: vertical; min-height: 66px; line-height: 1.5; }
select {
  appearance: none; cursor: pointer; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7080' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
/* Die Liste rendert der Browser selbst und nimmt sonst Weiß als Hintergrund */
select option { background: #1a1c21; color: var(--ink); }

.pair { color: var(--ink-2); font-size: 13px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.pair .arrow { color: var(--ink-3); }

.conn { display: flex; flex-direction: column; gap: 3px; }
.conn-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: 7px; font-size: 12.5px; color: var(--ink-2);
  transition: background .12s;
}
.conn-item:hover { background: var(--surface-2); }
.conn-item .glyph { width: 10px; height: 10px; flex: none; }
.conn-item .nm {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: pointer; flex: 1;
}
.conn-item .nm:hover { color: var(--ink); }
.conn-item .lb { color: var(--ink-3); font-size: 11px; }
.conn-item .x {
  opacity: 0; cursor: pointer; color: var(--ink-3); flex: none;
  width: 18px; height: 18px; display: grid; place-items: center; border-radius: 5px;
  transition: opacity .12s, background .12s, color .12s;
}
.conn-item:hover .x { opacity: 1; }
.conn-item .x:hover { background: rgba(224,106,106,0.18); color: #f0a0a0; }
.empty { color: var(--ink-3); font-size: 12.5px; padding: 3px 8px; }

/* ══════════ Hint / Toast / Tooltip ══════════ */
#hint {
  position: absolute; left: 50%; transform: translateX(-50%); top: 68px; z-index: 28;
  display: none; align-items: center; gap: 9px; pointer-events: none;
  padding: 9px 16px; border-radius: 999px;
  background: rgba(18,32,52,0.88); backdrop-filter: blur(16px);
  box-shadow: inset 0 0 0 1px rgba(77,147,234,0.35), 0 8px 28px rgba(0,0,0,0.5);
  color: #9cc4f6; font-size: 12.5px; font-weight: 500;
}
#hint.show { display: flex; animation: drop .22s cubic-bezier(.2,.9,.3,1.2); }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -8px); } }
#hint .pip {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 10px var(--accent); animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .35; } }

#toast {
  position: absolute; left: 50%; bottom: 22px; z-index: 55;
  transform: translate(-50%, 10px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 999px;
  background: rgba(24,26,31,0.94); backdrop-filter: blur(16px);
  box-shadow: inset 0 0 0 1px var(--line-2), 0 10px 32px rgba(0,0,0,0.55);
  color: var(--ink); font-size: 12.5px; font-weight: 500;
  transition: opacity .2s ease, transform .2s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#tooltip {
  position: absolute; z-index: 26; pointer-events: none; display: none;
  padding: 11px 13px; max-width: 262px; border-radius: 11px;
  background: rgba(20,22,26,0.96); backdrop-filter: blur(20px);
  box-shadow: inset 0 0 0 1px var(--line-2), 0 14px 40px rgba(0,0,0,0.6);
}
#tooltip .tt-top { display: flex; align-items: center; gap: 8px; }
#tooltip .glyph { width: 10px; height: 10px; flex: none; }
#tooltip .tt-name { font-weight: 600; font-size: 13px; color: var(--ink); }
#tooltip .tt-meta { color: var(--ink-3); font-size: 11.5px; margin-top: 5px; }
#tooltip .tt-note {
  color: var(--ink-2); font-size: 12.5px; margin-top: 8px;
  padding-top: 8px; border-top: 1px solid var(--line);
}

/* ══════════ Typ-Picker ══════════ */
/* Erscheint dort, wo der Zug endet — der neue Knoten entsteht unter dem
   Zeiger, nicht in der Bildmitte. */
#picker {
  position: absolute; z-index: 30; display: none;
  padding: 6px; min-width: 198px;
}
#picker.show { display: block; animation: pop .14s cubic-bezier(.2,.9,.3,1.15); }
@keyframes pop { from { opacity: 0; transform: scale(.95) translateY(-5px); } }
#picker .panel-title { padding: 6px 8px 8px; }
.pk-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 8px; border: 0; border-radius: 7px; cursor: pointer;
  background: transparent; color: var(--ink-2);
  font: 500 12.5px var(--font); text-align: left;
  transition: background .1s, color .1s;
}
.pk-row.cur, .pk-row:hover { background: var(--surface-3); color: var(--ink); outline: none; }
.pk-row .glyph { width: 12px; height: 12px; flex: none; }
.pk-row .kbd {
  margin-left: auto; color: var(--ink-3); font-size: 10.5px;
  padding: 1px 5px; border-radius: 4px; background: rgba(255,255,255,0.06);
  font-variant-numeric: tabular-nums;
}

/* ══════════ Inline-Umbenennen ══════════ */
#rename {
  position: absolute; z-index: 29; display: none;
  transform: translateX(-50%);
  width: 176px; padding: 5px 9px; text-align: center;
  font: 600 12.5px var(--font); color: #fff;
  background: rgba(16,18,22,0.94); backdrop-filter: blur(14px);
  border: 1px solid rgba(77,147,234,0.6); border-radius: 7px;
  box-shadow: 0 0 0 3px rgba(77,147,234,0.13), 0 10px 26px rgba(0,0,0,0.55);
}
#rename.show { display: block; }

/* ══════════ Status ══════════ */
#status {
  position: absolute; right: 16px; bottom: 16px; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 13px; border-radius: 9px;
  background: rgba(22,24,28,0.74); backdrop-filter: blur(20px);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink-3); font-size: 11.5px; font-variant-numeric: tabular-nums;
  transition: right .18s ease;
}
#status b { color: var(--ink-2); font-weight: 600; }
#status .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--ink-3); opacity: .5; }
body.insp-open #status { right: 348px; }

/* ══════════ Server-Modus ══════════ */
/* Ohne Server (Datei geöffnet) bleibt alles wie gehabt; die Teile für
   Speichern auf dem Server erscheinen nur, wenn einer antwortet. */
body:not(.server) .srv-only { display: none !important; }

#sync, #planSync {
  display: inline-flex; align-items: center; gap: 7px; margin-right: 6px;
  font-size: 11.5px; color: var(--ink-3); white-space: nowrap; user-select: none;
}
#sync .pip, #planSync .pip { width: 6px; height: 6px; border-radius: 50%; background: #199e70; flex: none; }
#sync.dirty .pip, #sync.saving .pip, #planSync.dirty .pip, #planSync.saving .pip { background: #d9a526; }
#sync.saving .pip, #planSync.saving .pip { animation: pulse 1s ease-in-out infinite; }
#sync.error .pip, #sync.conflict .pip, #planSync.error .pip, #planSync.conflict .pip { background: #e06a6a; }
#sync.error, #sync.conflict, #planSync.error, #planSync.conflict { color: #f0a0a0; }

#me {
  display: inline-flex; align-items: center; gap: 8px; margin-left: 6px;
  font-size: 12px; color: var(--ink-2); white-space: nowrap;
}
#me .avatar {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-dim); color: #9cc4f6; font: 600 10.5px/1 var(--font);
}

/* Vollbild-Schicht für Anmelden / Laden / Fehler */
#gate {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: center; justify-content: center;
  background: rgba(10,11,13,0.82); backdrop-filter: blur(10px);
}
#gate.show { display: flex; }
#gate .box {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  padding: 28px 32px; min-width: 300px; max-width: 420px; text-align: center;
}
#gate .msg { color: var(--ink-2); font-size: 13px; line-height: 1.5; }

/* Lageplan: draw.io als Vollbild über der Karte. Dialoge (50) und
   Meldungen (55) liegen darüber, die Anmeldeschicht (60) sowieso. */
#planBack {
  position: fixed; inset: 0; z-index: 45; display: none; flex-direction: column;
  background: var(--plane);
}
#planBack.show { display: flex; }
#planBack .plan-head {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  border-bottom: 1px solid var(--line); background: rgba(20,22,26,0.96);
}
#planBack .grow { flex: 1; }
#planFrame { flex: 1; position: relative; }
#planFrame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #1e1e1e; }
.plan-meta { color: var(--ink-3); font-size: 12px; line-height: 1.45; }
.plan-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.plan-btns .tb { padding: 6px 10px; font-size: 12px; }
.plan-btns .tb.solid { background: var(--accent-dim); color: #9cc4f6; }

/* Dialoge: Konflikt, Verlauf */
#modalBack {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: center; justify-content: center; background: rgba(0,0,0,0.45);
}
#modalBack.show { display: flex; }
#modal {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 120px);
  display: flex; flex-direction: column; overflow: hidden;
}
#modal .m-head {
  display: flex; align-items: center; padding: 14px 16px 13px;
  border-bottom: 1px solid var(--line);
}
#modal .m-body {
  padding: 16px; overflow-y: auto; color: var(--ink-2); font-size: 13px; line-height: 1.55;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.14) transparent;
}
#modal .m-foot {
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
  padding: 12px 16px; border-top: 1px solid var(--line);
}
#modal .m-foot .tb { background: rgba(255,255,255,0.055); }
#modal .m-foot .tb:hover { background: var(--surface-3); }
#modal .m-foot .tb.solid { background: var(--accent-dim); color: #9cc4f6; }
.hist-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 8px; border-radius: 7px; transition: background .12s;
}
.hist-row:hover { background: var(--surface-2); }
.hist-row .when { color: var(--ink); font-variant-numeric: tabular-nums; }
.hist-row .who { color: var(--ink-3); font-size: 12px; }
.hist-row .tb { margin-left: auto; padding: 6px 9px; font-size: 12px; }
.hist-row.cur .tb { visibility: hidden; }

/* ══════════ Legende: Abschnitte ══════════ */
#legend { max-height: calc(100vh - 220px); overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.14) transparent; }
#legend .lg-sec { padding: 12px 8px 7px; }
#legend .lg-sec:first-child { padding-top: 0; }
.lg-row .eye {
  width: 18px; height: 18px; display: grid; place-items: center; border-radius: 5px;
  color: var(--ink-3); opacity: 0; flex: none; transition: opacity .12s, background .12s;
}
.lg-row:hover .eye, .lg-row.off .eye { opacity: 1; }
.lg-row .eye:hover { background: var(--surface-3); color: var(--ink); }
.lg-row .n + .eye { margin-left: 2px; }
.lg-line { width: 18px; height: 8px; flex: none; }
.lg-hint { color: var(--ink-3); font-size: 11.5px; padding: 2px 8px 6px; line-height: 1.45; }

/* ══════════ Suchergebnisse ══════════ */
#results {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 35;
  width: 300px; padding: 6px; display: none;
}
#results.show { display: block; animation: pop .12s cubic-bezier(.2,.9,.3,1.15); }
.rs-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 7px;
  color: var(--ink-2); font-size: 12.5px; cursor: pointer;
}
.rs-row.cur, .rs-row:hover { background: var(--surface-3); color: var(--ink); }
.rs-row .glyph { width: 11px; height: 11px; flex: none; }
.rs-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rs-row .sub { color: var(--ink-3); font-size: 11px; white-space: nowrap; }
.rs-empty { color: var(--ink-3); font-size: 12px; padding: 6px 8px; }

/* ══════════ Minimap ══════════ */
#minimap {
  position: absolute; right: 16px; bottom: 58px; z-index: 20;
  width: 196px; height: 128px; padding: 0; overflow: hidden; cursor: crosshair;
  border-radius: 11px; transition: right .18s ease;
}
#minimap.off { display: none; }
#minimap canvas { width: 196px; height: 128px; }
body.insp-open #minimap { right: 348px; }

/* ══════════ Inspector-Zusätze ══════════ */
.tb.wide { width: 100%; justify-content: center; background: rgba(255,255,255,0.055); }
.tb.wide:hover { background: var(--surface-3); }
.swatches { display: flex; gap: 8px; }
.swatch {
  width: 22px; height: 22px; border-radius: 50%; cursor: pointer; border: 0; padding: 0;
  transition: transform .12s, box-shadow .12s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.on { box-shadow: 0 0 0 2px var(--plane), 0 0 0 3.5px #fff; }
.members { display: flex; flex-direction: column; gap: 3px; max-height: 240px; overflow-y: auto; }

/* ══════════ Tastenkürzel ══════════ */
.keys { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; align-items: center; }
.keys kbd { font-size: 11px; padding: 3px 6px; margin: 0 2px 0 0; color: var(--ink-2); white-space: nowrap; }
.keys .sec { grid-column: 1 / -1; margin-top: 8px; font: 600 10px/1 var(--font); text-transform: uppercase; letter-spacing: .09em; color: var(--ink-3); }
.keys .sec:first-child { margin-top: 0; }
