:root {
  --bg: #f4f5f7; --panel: #ffffff; --text: #1d2330; --muted: #6b7280;
  --line: #dde1e7; --accent: #0b6bcb; --accent-ink: #ffffff;
  --ok: #e7f6ec; --ok-ink: #1d6b38; --err: #fdecec; --err-ink: #9b1c1c;
  --warn: #fff6e0; --warn-ink: #7a5300; --term: #e9ecf1; --term-line: #9aa3b1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --panel: #1d2129; --text: #e7e9ee; --muted: #9aa1ad;
    --line: #313744; --accent: #4c9eff; --accent-ink: #0b1220;
    --ok: #16301f; --ok-ink: #8fdcaa; --err: #3a1c1c; --err-ink: #f3a3a3;
    --warn: #3a2f14; --warn-ink: #f0cd7a; --term: #2a303b; --term-line: #586173;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.6rem; margin: .2em 0 .5em; }
h2 { font-size: 1.2rem; margin: 0 0 .6em; }
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
nav { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
nav a { text-decoration: none; color: var(--muted); }
nav a.active, nav a:hover { color: var(--text); }
.inline { display: inline; }
.linkbtn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.linkbtn:hover { color: var(--text); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin: 0 0 16px; }
.narrow { max-width: 420px; margin: 40px auto; }
label { display: block; margin: 0 0 12px; font-size: .9rem; color: var(--muted); }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; }
textarea { min-height: 80px; }
input[type=checkbox] { display: inline; width: auto; margin: 0 6px 0 0; }
.btn { display: inline-block; padding: 9px 16px; font: inherit; font-weight: 600; color: var(--accent-ink); background: var(--accent); border: 0; border-radius: 6px; cursor: pointer; text-decoration: none; }
.btn.secondary { background: var(--term); color: var(--text); }
.btn.danger { background: #c62828; color: #fff; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.flash { padding: 10px 14px; border-radius: 6px; margin: 0 0 12px; }
.flash.ok { background: var(--ok); color: var(--ok-ink); }
.flash.err { background: var(--err); color: var(--err-ink); }
.flash.warn { background: var(--warn); color: var(--warn-ink); }
.search { display: flex; gap: 8px; margin: 0 0 16px; }
.search input, .search select { margin: 0; flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.tile { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; color: var(--text); text-decoration: none; }
.tile:hover { border-color: var(--accent); }
.thumb { height: 140px; background: var(--term); display: flex; align-items: center; justify-content: center; color: var(--muted); }
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.tile-body { padding: 10px 12px; }
.device-head { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.device-img { max-width: 260px; max-height: 220px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.cable-img { max-width: 100%; max-height: 320px; border-radius: 8px; border: 1px solid var(--line); }
.terminal-strip { display: flex; flex-wrap: wrap; gap: 4px; }
.terminal { display: flex; flex-direction: column; align-items: center; min-width: 64px; padding: 8px 6px; background: var(--term); border: 1px solid var(--term-line); border-radius: 4px; }
.terminal small { color: var(--muted); font-size: .72rem; text-align: center; }
.screw-ico { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--term-line); margin-bottom: 4px; position: relative; }
.screw-ico::after { content: ""; position: absolute; left: 2px; right: 2px; top: 5px; height: 2px; background: var(--term-line); }
.wiring-wrap { overflow-x: auto; margin: 0 0 12px; }
svg.wiring { width: 100%; min-width: 0; max-width: 640px; height: auto; display: block; }
svg.wiring .h { font-weight: 700; font-size: 15px; fill: var(--text); }
svg.wiring .term { fill: var(--term); stroke: var(--term-line); }
svg.wiring .screw { fill: none; stroke: var(--term-line); stroke-width: 2; }
svg.wiring .tl { font-weight: 700; font-size: 17px; fill: var(--text); }
svg.wiring .tf, svg.wiring .muted { font-size: 13px; fill: var(--muted); }
svg.wiring .core { fill: var(--panel); stroke: var(--line); }
svg.wiring .core.free { stroke-dasharray: 4 4; }
svg.wiring .dot { stroke: #555; }
svg.wiring .cl { font-size: 16px; fill: var(--text); }
svg.wiring .wire { fill: none; stroke-width: 6; stroke-linecap: round; }
svg.wiring .wire-outline { fill: none; stroke: #555; stroke-width: 8; stroke-linecap: round; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .85rem; color: var(--muted); }
.swatch { display: inline-block; width: 16px; height: 16px; border-radius: 50%; border: 1px solid #555; vertical-align: -3px; }
.chip { display: inline-block; padding: 2px 10px; margin: 2px 4px 2px 0; background: var(--term); border-radius: 12px; font-size: .9rem; }
.rows .row { display: grid; gap: 8px; align-items: end; margin-bottom: 8px; }
.rows.terminals .row { grid-template-columns: 110px 1fr auto auto auto; }
.rows.cores .row { grid-template-columns: 1fr 130px 130px auto auto auto; }
.rows .row label { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.preview-img { max-width: 200px; max-height: 160px; display: block; margin: 6px 0; border-radius: 6px; border: 1px solid var(--line); }
/* ---------- Tags & Filter ---------- */
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag { display: inline-block; padding: 1px 9px; border-radius: 11px; background: var(--term); color: var(--text); font-size: .8rem; text-decoration: none; border: 1px solid transparent; cursor: pointer; }
a.tag:hover, .tag.on { border-color: var(--accent); }
.tag.on { background: var(--accent); color: var(--accent-ink); }
.tag .n { color: var(--muted); font-size: .72rem; }
.tag.on .n { color: inherit; opacity: .75; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 12px; }

/* ---------- Baum ---------- */
.tree { display: flex; flex-direction: column; gap: 10px; }
details.dev { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
details.dev[open] { border-color: var(--accent); }
details.dev > summary { display: grid; grid-template-columns: 60px 1fr auto 20px; gap: 14px; align-items: center; padding: 10px 14px 10px 10px; cursor: pointer; list-style: none; }
details.dev > summary::-webkit-details-marker { display: none; }
.dev-thumb { width: 60px; height: 60px; border-radius: 8px; background: #fff; border: 1px solid var(--line); overflow: hidden; display: flex; align-items: center; justify-content: center; }
.dev-thumb img { width: 100%; height: 100%; object-fit: contain; }
.noimg { color: #8a8f99; font-size: .75rem; }
.dev-sum { display: flex; flex-direction: column; min-width: 0; }
.dev-sum strong { font-size: 1.05rem; }
.dev-badges { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.badge { font-size: .78rem; padding: 2px 8px; border-radius: 10px; background: var(--ok); color: var(--ok-ink); white-space: nowrap; }
.badge.empty { background: var(--term); color: var(--muted); }
.badge.pdf { background: var(--err); color: var(--err-ink); }
.chev { width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; }
details[open] > summary .chev { transform: rotate(45deg); }
.panel-slot { padding: 0 14px 14px; border-top: 1px solid var(--line); }
.panel h3 { font-size: 1rem; margin: 18px 0 8px; }
.dev-info { display: flex; flex-wrap: wrap; gap: 16px; padding-top: 14px; }
.dev-photo img { display: block; max-width: 160px; max-height: 140px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.dev-text { flex: 1; min-width: 220px; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 0 0 8px; }
.meta dt { color: var(--muted); font-size: .88rem; }
.meta dd { margin: 0; font-weight: 600; }
.desc { margin: 6px 0; }
.cable-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.cable-card { display: flex; flex-direction: column; border: 2px solid var(--line); border-radius: 10px; overflow: hidden; color: var(--text); text-decoration: none; background: var(--panel); position: relative; }
.cable-card:hover { border-color: var(--accent); }
.cable-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.cable-card.selected::after { content: "✓"; position: absolute; top: 6px; right: 8px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 700; display: flex; align-items: center; justify-content: center; }
.cable-pic { height: 96px; background: #fff; display: flex; align-items: center; justify-content: center; }
.cable-pic img { width: 100%; height: 100%; object-fit: contain; }
.cable-ph { display: flex; gap: 4px; height: 84px; align-items: stretch; }
.cable-ph span { width: 14px; border-radius: 7px; border: 1px solid #555; }
.cable-meta { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.swatches { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 2px; }
.swatches .swatch { width: 12px; height: 12px; }
.wiring-box { margin-top: 16px; padding-top: 4px; border-top: 2px dashed var(--line); }
.cable-fig { margin: 12px 0; }
.cable-fig .cable-img { max-height: 180px; }
.admin-thumb { width: 48px; height: 48px; object-fit: contain; background: #fff; border-radius: 4px; border: 1px solid var(--line); vertical-align: middle; }
.tag-suggest { display: flex; flex-wrap: wrap; gap: 4px; margin: -4px 0 12px; }

@media (max-width: 640px) {
  details.dev > summary { grid-template-columns: 48px 1fr 14px; gap: 10px; }
  .dev-thumb { width: 48px; height: 48px; }
  .dev-badges { grid-column: 2; grid-row: 2; flex-direction: row; justify-content: flex-start; }
  .chev { grid-column: 3; grid-row: 1; }
  .dev-photo img { max-width: 140px; }
  .cable-cards { grid-template-columns: repeat(2, 1fr); }
  .two { grid-template-columns: 1fr; }
  .rows.terminals .row { grid-template-columns: 70px 1fr; }
  .rows.cores .row { grid-template-columns: 1fr 1fr; }
  .search { flex-direction: column; }
}
.preview-pdf { display: block; margin: 6px 0; }


/* ---------- Suchseite mit Auswahllisten ---------- */
.picker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.picker-grid label { margin-bottom: 4px; }
.picker-text { margin: 6px 0 0; }
.chip.active-filter { text-decoration: none; color: var(--text); border: 1px solid var(--accent); }

/* ---------- Kabelbilder ---------- */
.cable-icon { display: block; }
.pic-cell { width: 64px; }
.cable-thumb { width: 56px; height: 56px; object-fit: contain; background: #fff; border-radius: 6px; border: 1px solid var(--line); display: block; }
.cable-preview { display: flex; align-items: center; gap: 12px; margin: 0 0 12px; }

/* ---------- Belegungs-Editor im Geräteformular ---------- */
.wblock { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; background: var(--bg); }
.wblock-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.wblock-head > span:nth-child(2) { flex: 1; }
.wpic { width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; background: #fff; border-radius: 6px; border: 1px solid var(--line); overflow: hidden; }
.wpic img { width: 100%; height: 100%; object-fit: contain; }
.wpic svg { width: 52px; height: 52px; }
.wsel { display: flex; align-items: center; gap: 8px; }
.wsel select { margin: 0; }
.swatch.none { background: transparent; border-style: dashed; }
.wadd { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.wadd label { flex: 1; min-width: 220px; margin: 0; }

@media (max-width: 900px) { .picker-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .picker-grid { grid-template-columns: 1fr; } }

/* ---------- Import aus Link ---------- */
.import-card { border-color: var(--accent); }
.import-table td { vertical-align: top; }
.import-table .imp-cur { color: var(--muted); max-width: 260px; }
.import-table .imp-new { max-width: 380px; white-space: pre-line; }
.imp-img { max-width: 140px; max-height: 120px; background: #fff; border: 1px solid var(--line); border-radius: 6px; display: block; }

/* ---------- Kabelformular: Farbtabelle, Bild ---------- */
.rows.cores .row { grid-template-columns: 1fr 150px 170px auto auto auto; }
.field { display: flex; flex-direction: column; font-size: .9rem; color: var(--muted); }
.flabel { margin-bottom: 4px; }
.cpick { position: relative; }
.cpick-btn { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; text-align: left; }
.cpick-btn:hover { border-color: var(--accent); }
.cpick-btn .swatch { width: 22px; height: 22px; flex: none; }
.cpick-btn .cname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette { display: none; position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; width: 264px; padding: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18); grid-template-columns: repeat(4, 1fr); gap: 4px; }
.cpick.open .palette { display: grid; }
.palette button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px; background: none; border: 2px solid transparent; border-radius: 8px; cursor: pointer; color: var(--text); font: inherit; }
.palette button:hover { background: var(--term); }
.palette button.on { border-color: var(--accent); }
.palette .swatch { width: 28px; height: 28px; }
.palette small { font-size: .7rem; }
details.more { margin-top: 4px; }
details.more > summary { cursor: pointer; color: var(--accent); font-size: .9rem; margin-bottom: 10px; }
.pic-row { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.pic-current { display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: 180px; text-align: center; }
.pic-inputs { flex: 1; min-width: 260px; }
.pic-inputs label .muted { display: block; margin-top: 4px; }
@media (max-width: 640px) {
  .rows.cores .row { grid-template-columns: 1fr 1fr; }
  .rows.cores .row > label:first-of-type { grid-column: 1 / -1; }
}
