* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f7f8fa; --panel: #ffffff; --line: #e3e6ea; --text: #1d2530; --muted: #68727f;
  --accent: #2563eb;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column; overflow: hidden;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
h1 { font-size: 17px; font-weight: 700; }
h1 span { font-weight: 400; color: var(--muted); }
.stats { font-size: 12px; color: var(--muted); margin-top: 2px; }
.viewtoggle button {
  padding: 7px 18px; border: 1px solid var(--line); background: var(--panel);
  cursor: pointer; font-size: 14px;
}
.viewtoggle button:first-child { border-radius: 8px 0 0 8px; }
.viewtoggle button:last-child { border-radius: 0 8px 8px 0; margin-left: -1px; }
.viewtoggle button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.toolbar .lbl { color: var(--muted); margin-right: 4px; }
.filtergroup { display: flex; align-items: center; gap: 4px; }
.filtergroup button {
  min-width: 26px; padding: 4px 8px; border: 1px solid var(--line); background: #fff;
  border-radius: 6px; cursor: pointer; font-size: 13px;
}
.filtergroup button.active { outline: 2px solid var(--accent); outline-offset: -2px; font-weight: 600; }
.filtergroup button.bereich-chip.active { color: #fff; }
select, input[type="search"] {
  padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px;
  background: #fff;
}
.search-wrap { position: relative; }
#search { width: 300px; }
.search-results {
  position: absolute; top: 32px; left: 0; width: 460px; max-height: 340px; overflow: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; z-index: 40;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.search-results div { padding: 7px 10px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f1f3f5; }
.search-results div:hover { background: #eef4ff; }
.search-results .sr-meta { color: var(--muted); font-size: 11px; }
#edge-toggles label { display: flex; align-items: center; gap: 4px; color: var(--muted); cursor: pointer; }
button.ghost { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; }

main { flex: 1; display: flex; min-height: 0; position: relative; }
.view { flex: 1; min-width: 0; position: relative; overflow: hidden; }
#canvas { width: 100%; height: 100%; display: block; cursor: grab; }
#canvas.dragging { cursor: grabbing; }

.tooltip {
  position: absolute; pointer-events: none; background: rgba(29,37,48,.94); color: #fff;
  padding: 6px 10px; border-radius: 6px; font-size: 12.5px; max-width: 340px; z-index: 30;
  line-height: 1.35;
}
.tooltip .tt-meta { color: #aebbcc; font-size: 11px; }

.legend {
  position: absolute; left: 12px; bottom: 34px; background: rgba(255,255,255,.94);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 12px;
  display: flex; flex-direction: column; gap: 3px;
}
.legend .item { display: flex; align-items: center; gap: 6px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 50%; }
.legend .edge-sample { width: 22px; height: 0; border-top: 2px solid #98a2b0; }
.legend .edge-sample.dashed { border-top-style: dashed; border-top-color: #7c5cd6; }
.legend .edge-sample.dotted { border-top-style: dotted; border-top-color: #b3bcc7; }
.hint {
  position: absolute; left: 12px; bottom: 8px; font-size: 11.5px; color: var(--muted);
}

/* ── Detailpanel ── */
.panel {
  width: 400px; flex: none; background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; overscroll-behavior: contain; padding: 16px 18px 40px;
  position: relative; z-index: 10; /* über dem Canvas, empfängt eigene Maus-/Scroll-Events */
}
.panel .close { float: right; border: none; background: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.panel .kicker { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: #fff; display: inline-block; padding: 2px 8px; border-radius: 10px; margin-bottom: 8px; }
.panel h2 { font-size: 16.5px; line-height: 1.35; margin-bottom: 8px; }
.panel .meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.panel .badge {
  font-size: 11.5px; background: #eef1f5; border-radius: 10px; padding: 2px 9px; color: #3c4654;
}
.panel .badge.warn { background: #fef3cd; color: #7a5c00; }
.panel .badge.origin { background: #e7f0ff; color: #1e4fa3; }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 0 6px; }
.panel p, .panel li { font-size: 13.5px; line-height: 1.5; }
.panel ul { padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.panel .nodelink {
  display: block; width: 100%; text-align: left; background: #f4f6f9; border: 1px solid var(--line);
  padding: 7px 10px; border-radius: 8px; margin-bottom: 5px; cursor: pointer; font-size: 13px;
  line-height: 1.4;
}
.panel .nodelink:hover { background: #eaf1ff; border-color: #bcd3f7; }
.panel .nodelink .why { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.panel .nodelink .rel-meta { color: var(--muted); font-size: 11px; }
.panel .quelle { font-size: 12.5px; color: #3c4654; background: #f7f8fa; border-left: 3px solid #cfd6df; padding: 6px 9px; margin-bottom: 5px; border-radius: 0 6px 6px 0; }
.panel .quelle b { color: var(--muted); font-weight: 600; font-size: 11px; }
.panel .idline { font-family: ui-monospace, monospace; font-size: 11.5px; color: var(--muted); margin-top: 14px; word-break: break-all; }

/* ── Tabelle ── */
#view-tabelle { overflow: auto; padding: 14px; }
.tb-bereich { margin-bottom: 26px; }
.tb-bereich > h2 {
  font-size: 15px; padding: 6px 10px; border-radius: 8px; color: #fff; display: inline-block;
  margin-bottom: 10px;
}
table.raster { border-collapse: collapse; width: 100%; background: #fff; }
table.raster th, table.raster td {
  border: 1px solid var(--line); padding: 6px 8px; vertical-align: top; font-size: 12.5px;
}
table.raster th { background: #f0f2f5; text-align: left; position: sticky; top: 0; }
table.raster td.tbname { min-width: 170px; max-width: 220px; font-weight: 600; background: #fafbfc; }
table.raster td.tbname .sub { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.chip {
  display: block; text-align: left; width: 100%; border: 1px solid var(--line); background: #fff;
  border-left-width: 4px; border-radius: 6px; padding: 4px 7px; margin: 3px 0; cursor: pointer;
  font-size: 12px; line-height: 1.35;
}
.chip:hover { background: #eef4ff; }
.chip.selected { outline: 2px solid var(--accent); }
.chip .ks { color: var(--muted); font-size: 10.5px; }
.chip.neu { border-style: solid; }
.chip.bestand { background: #fbfcfe; }
.chip.bestand::after { content: " ◦ Bestand"; color: #8b96a5; font-size: 10px; }

@media (max-width: 900px) {
  .panel { position: absolute; right: 0; top: 0; bottom: 0; box-shadow: -6px 0 24px rgba(0,0,0,.15); }
  #search { width: 180px; }
}
