:root {
  --bg: #121212;
  --panel: #2b2b2b;
  --panel-2: #303030;
  --field: #2f2f2f;
  --field-2: #262626;
  --line: #3d3d3d;
  --line-2: #4a4a4a;
  --text: #ececec;
  --muted: #9b9b9b;
  --dim: #6f6f6f;
  --blue: #3182ce;
  --blue-h: #3b8fdc;
  --red: #e5484d;
  --green: #46a758;
  --radius: 4px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: var(--text); }
::selection { background: rgba(49,130,206,.45); }

/* ---------- Topbar ---------- */
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 28px; padding: 10px 28px; background: rgba(18,18,18,.92); backdrop-filter: blur(10px); border-bottom: 1px solid #222; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 12px; border-radius: 6px; color: var(--muted); font-weight: 500; }
.nav a:hover { color: var(--text); background: #1d1d1d; }
.nav a.active { color: var(--text); background: #262626; }
.status { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(70,167,88,.18); }
.status.offline .dot { background: #d4a72c; box-shadow: 0 0 0 3px rgba(212,167,44,.18); }

main { padding: 26px 40px 80px; max-width: 1760px; margin: 0 auto; }

/* ---------- Buttons & Fields ---------- */
.btn { display: inline-flex; align-items: center; gap: 9px; height: 40px; padding: 0 18px; border-radius: var(--radius); border: 1.5px solid #5a5a5a; background: transparent; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .08s; }
.btn:hover { background: #1f1f1f; border-color: #777; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-h); border-color: var(--blue-h); }
.btn.danger { border-color: #7a3033; color: #ff8a8d; }
.btn.danger:hover { background: #2a1416; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 14px; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: #232323; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn { width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: var(--radius); border: 1px solid var(--line-2); background: transparent; color: var(--muted); cursor: pointer; transition: all .15s; flex: none; }
.icon-btn:hover { color: var(--text); background: #222; }
.icon-btn.danger:hover { color: #ff8a8d; border-color: #7a3033; background: #2a1416; }
.icon-btn.plain { border-color: transparent; }
.icon-btn svg { width: 18px; height: 18px; }
.x-btn { width: 28px; height: 28px; display: grid; place-items: center; border: 0; background: none; color: #8b8b8b; cursor: pointer; border-radius: 4px; }
.x-btn:hover { color: #fff; background: #3a3a3a; }
.x-btn svg { width: 15px; height: 15px; }

.in { width: 100%; height: 40px; padding: 0 12px; background: var(--field); border: 1px solid var(--line-2); border-radius: 2px; outline: none; transition: border-color .15s, background .15s, box-shadow .15s; min-width: 0; }
.in:hover { border-color: #5c5c5c; }
.in:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(49,130,206,.25); background: #333; }
.in::placeholder { color: var(--dim); }
.in.num { font-variant-numeric: tabular-nums; font-weight: 600; }
select.in { appearance: none; -webkit-appearance: none; padding-right: 30px; cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23999' stroke-width='1.4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; text-overflow: ellipsis; }
select.in:disabled { opacity: .45; cursor: default; }
select.in option { background: #2a2a2a; color: var(--text); }
select.in option:disabled { color: #6a6a6a; }
.field-label { display: block; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }

/* ---------- Seitenkopf Projekt ---------- */
.back { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; font-size: 16px; }
.back:hover { color: var(--text); }
.back svg { width: 16px; height: 16px; }
.proj-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin: 26px 0 30px; flex-wrap: wrap; }
.title-in { display: block; width: min(640px, 80vw); background: transparent; border: 1px solid transparent; border-radius: 4px; font-size: 30px; font-weight: 700; letter-spacing: -.01em; padding: 2px 6px; margin-left: -7px; outline: none; }
.title-in:hover { border-color: #333; }
.title-in:focus { border-color: var(--blue); background: #1a1a1a; }
.date-in { background: transparent; border: 1px solid transparent; color: var(--muted); font-size: 16px; padding: 2px 6px; margin: 4px 0 0 -7px; border-radius: 4px; outline: none; }
.date-in:hover { border-color: #333; }
.date-in:focus { border-color: var(--blue); }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Sections ---------- */
.sec { margin-bottom: 44px; }
.sec-title { display: flex; align-items: center; gap: 12px; font-size: 22px; font-weight: 700; margin: 0 0 18px; cursor: pointer; user-select: none; width: fit-content; }
.sec-title .chev { width: 18px; height: 18px; color: var(--muted); transition: transform .2s; }
.sec.collapsed .chev { transform: rotate(-90deg); }
.sec.collapsed .sec-body { display: none; }
.sec-title .count { font-size: 14px; font-weight: 600; color: var(--muted); background: #222; padding: 2px 9px; border-radius: 20px; }

/* ---------- Tabellen (Grid) ---------- */
.tbl-wrap { overflow-x: auto; padding-bottom: 6px; }
.tbl { min-width: var(--minw, 1100px); }
.ch-tbl { --cols: 26px 78px 158px 104px 96px minmax(130px,1.15fr) minmax(150px,1.15fr) 62px 168px minmax(120px,1fr) 44px; --minw: 1240px; }
.out-tbl { --cols: 26px 78px minmax(170px,1fr) minmax(400px,1.7fr) minmax(150px,1fr) 44px; --minw: 1000px; }
.thead, .row { display: grid; grid-template-columns: var(--cols); gap: 0 14px; align-items: center; }
.thead { padding: 0 0 12px; border-bottom: 2px solid #3a3a3a; font-size: 13px; font-weight: 700; letter-spacing: .07em; color: #a3a3a3; text-transform: uppercase; }
.thead > :nth-child(2) { padding-left: 14px; }
.row { position: relative; padding: 13px 0; border-bottom: 1px solid #2a2a2a; background: var(--bg); }
.row::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: var(--rowc, transparent); }
.row:hover { background: #161616; }
.grip { width: 26px; height: 40px; display: grid; place-items: center; color: #555; cursor: grab; touch-action: none; border-radius: 4px; }
.grip:hover { color: #bbb; background: #222; }
.grip svg { width: 14px; height: 14px; }
.row .num { text-align: left; font-size: 17px; }
.row .io { color: #d8d8d8; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.row .io.empty { color: #555; }
.row.dragging { position: fixed; z-index: 200; pointer-events: none; background: #232323; border: 1px solid #444; border-radius: 6px; box-shadow: 0 18px 40px rgba(0,0,0,.6); padding-left: 0; transform: scale(1.01); }
.drop-ph { border: 1.5px dashed #3a6ea0; background: rgba(49,130,206,.08); border-radius: 6px; margin: 2px 0; transition: height .1s; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }
.empty-state { padding: 34px; text-align: center; color: var(--muted); border-bottom: 1px solid #2a2a2a; }

/* Animierte Einfügung */
@keyframes rowIn { from { opacity: 0; transform: translateY(-6px); background: rgba(49,130,206,.18); } to { opacity: 1; transform: none; } }
.row.fresh { animation: rowIn .45s ease-out; }

/* ---------- 48V ---------- */
.p48 { display: inline-flex; align-items: center; gap: 5px; border: 0; background: none; padding: 6px 4px; cursor: pointer; border-radius: 5px; }
.p48:hover .p48-box { border-color: #bdbdbd; }
.p48-box { width: 19px; height: 19px; border: 1.6px solid #8d8d8d; border-radius: 5px; display: grid; place-items: center; transition: background .22s, border-color .22s; }
.p48-box svg { width: 13px; height: 13px; }
.p48-box path { fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 16; stroke-dashoffset: 16; transition: stroke-dashoffset .28s .08s ease-out; }
.p48-bolt { width: 18px; height: 18px; opacity: 0; transform: scale(.5); transition: opacity .2s, transform .2s; }
.p48-bolt path { fill: none; stroke: var(--red); stroke-width: 1.7; stroke-linejoin: round; }
.p48.on .p48-box { background: var(--red); border-color: var(--red); }
.p48.on .p48-box path { stroke-dashoffset: 0; }
.p48.on .p48-bolt { opacity: 1; transform: none; }
.p48.animate .p48-box { animation: p48pop .42s cubic-bezier(.3,1.6,.5,1); }
.p48.animate .p48-bolt { animation: p48spark .75s ease-out; }
@keyframes p48pop { 0% { transform: scale(.6); box-shadow: 0 0 0 0 rgba(229,72,77,.7); } 55% { transform: scale(1.18); } 100% { transform: scale(1); box-shadow: 0 0 0 8px rgba(229,72,77,0); } }
@keyframes p48spark {
  0% { opacity: 0; transform: translateX(-6px) scale(.4) rotate(-12deg); }
  25% { opacity: 1; transform: translateX(0) scale(1.25); filter: drop-shadow(0 0 7px rgba(255,80,80,1)); }
  38% { opacity: .25; }
  50% { opacity: 1; filter: drop-shadow(0 0 5px rgba(255,80,80,.9)); }
  62% { opacity: .5; }
  75% { opacity: 1; transform: scale(1); }
  100% { opacity: 1; filter: drop-shadow(0 0 0 rgba(255,80,80,0)); }
}

/* ---------- Combobox ---------- */
.combo-pop { position: fixed; z-index: 300; background: #262626; border: 1px solid #474747; border-radius: 6px; box-shadow: 0 16px 40px rgba(0,0,0,.55); max-height: 290px; overflow-y: auto; padding: 4px; animation: popIn .12s ease-out; }
@keyframes popIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.combo-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: 4px; cursor: pointer; font-size: 14.5px; }
.combo-item.active { background: var(--blue); color: #fff; }
.combo-item mark { background: none; color: inherit; font-weight: 700; }
.combo-item .tag { font-size: 11.5px; font-weight: 700; color: var(--red); display: inline-flex; align-items: center; gap: 2px; }
.combo-item.active .tag { color: #fff; }
.combo-item .tag svg { width: 12px; height: 12px; }
.combo-item .tag path { fill: none; stroke: currentColor; stroke-width: 1.8; }
.combo-hint { padding: 6px 10px 4px; font-size: 12px; color: var(--muted); border-top: 1px solid #383838; margin-top: 4px; }
.combo-item.add { color: #8fc0ff; }
.combo-item.add.active { color: #fff; }

/* ---------- Ausgänge: Ziele ---------- */
.patches { display: flex; flex-direction: column; gap: 8px; }
.patch { display: grid; grid-template-columns: 158px 104px 120px 28px; gap: 10px; align-items: center; }
.patch .io { font-size: 14.5px; }
.add-patch { align-self: flex-start; background: none; border: 1px dashed #4b4b4b; color: var(--muted); border-radius: 4px; padding: 5px 10px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.add-patch:hover { color: var(--text); border-color: #777; }

/* ---------- Toolbar unter Tabellen ---------- */
.toolbar { display: flex; align-items: center; gap: 14px; margin-top: 22px; flex-wrap: wrap; }
.toolbar .count-in { width: 82px; height: 44px; }
.toolbar .btn { height: 44px; }
.summary { margin-top: 22px; color: var(--muted); font-size: 15.5px; display: flex; gap: 22px; flex-wrap: wrap; }
.summary b { color: #c9c9c9; font-weight: 600; }
.summary .p48sum { color: #ff8a8d; }

/* ---------- Stageboxen ---------- */
.box-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 32px; align-items: start; }
.box-card { background: var(--panel); border: 1px solid #3a3a3a; padding: 22px 24px 18px; animation: rowIn .4s ease-out; }
.box-head { display: flex; align-items: flex-start; gap: 12px; }
.box-head .x-btn { margin-top: 4px; }
.box-head .chev { width: 16px; height: 16px; transition: transform .2s; }
.box-card.collapsed .chev { transform: rotate(-90deg); }
.box-card.collapsed .box-body { display: none; }
.box-title { font-size: 21px; font-weight: 700; line-height: 1.25; }
.box-sub { color: #8f8f8f; font-size: 15px; margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.box-sub span + span::before { content: "·"; margin-right: 8px; }
.box-head .menu-btn { margin-left: auto; }
.box-cols, .port-row { display: grid; grid-template-columns: 30px 40px 78px 1fr 30px; gap: 12px; align-items: center; }
.box-cols { margin-top: 22px; padding: 0 0 8px; border-bottom: 2px solid #3d3d3d; font-size: 13px; font-weight: 700; letter-spacing: .07em; color: #9a9a9a; }
.box-sec { font-size: 13px; font-weight: 700; letter-spacing: .07em; color: #bdbdbd; padding: 14px 0 8px; border-bottom: 1px solid #3d3d3d; }
.port-row { padding: 7px 0; border-bottom: 1px solid #3a3a3a; }
.port-row b { font-size: 16px; }
.port-row .io-in { height: 36px; padding: 0 8px; background: #2b2b2b; border-color: #555; font-variant-numeric: tabular-nums; }
.port-row .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15.5px; }
.port-row .lbl.empty { color: #777; }
.port-row.used .lbl { color: #f0f0f0; }
.swatch { width: 28px; height: 28px; border-radius: 3px; border: 1px solid #555; background: var(--c, #3a3a3a); display: grid; place-items: center; cursor: pointer; color: #777; padding: 0; }
.swatch svg { width: 15px; height: 15px; }
.swatch.set { border-color: transparent; color: rgba(0,0,0,.45); }
.swatch:hover { border-color: #999; }
@keyframes flash { 0% { background: rgba(49,130,206,.35); } 100% { background: transparent; } }
.port-row.flash { animation: flash .9s ease-out; }

.add-box { display: grid; grid-template-columns: minmax(180px, 2.2fr) minmax(180px, 2fr) minmax(100px, .9fr) minmax(120px, 1.2fr) minmax(80px, .8fr) minmax(80px, .8fr) auto; gap: 14px; margin-top: 34px; align-items: end; }
.add-box .in { height: 50px; font-size: 16px; }
.add-box .btn { height: 50px; font-size: 16px; }
.add-box label { display: block; }
.add-box .field-label { font-size: 11px; }

/* ---------- Popover / Menu ---------- */
.pop { position: fixed; z-index: 320; background: #262626; border: 1px solid #474747; border-radius: 8px; box-shadow: 0 16px 40px rgba(0,0,0,.55); padding: 5px; min-width: 200px; animation: popIn .12s ease-out; }
.pop .mi { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0; background: none; border-radius: 5px; cursor: pointer; text-align: left; font-size: 14.5px; }
.pop .mi:hover { background: #333; }
.pop .mi.danger { color: #ff8a8d; }
.pop .mi svg { width: 16px; height: 16px; color: var(--muted); }
.pop hr { border: 0; border-top: 1px solid #3a3a3a; margin: 4px 0; }
.colors { display: grid; grid-template-columns: repeat(5, 30px); gap: 8px; padding: 8px; }
.colors button { width: 30px; height: 30px; border-radius: 5px; border: 2px solid transparent; cursor: pointer; background: var(--c); }
.colors button:hover { border-color: #fff; }
.colors .none { background: #1d1d1d; border-color: #444; color: #888; font-size: 16px; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; z-index: 400; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 20px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(520px, 100%); background: #222; border: 1px solid #3c3c3c; border-radius: 10px; box-shadow: 0 30px 80px rgba(0,0,0,.6); animation: popIn .18s ease-out; max-height: 90vh; display: flex; flex-direction: column; }
.modal.wide { width: min(760px, 100%); }
.modal h3 { margin: 0; padding: 20px 24px 0; font-size: 19px; }
.modal .m-body { padding: 18px 24px; overflow-y: auto; }
.modal .m-body p { color: #bdbdbd; margin: 0 0 12px; }
.modal .m-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 24px 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.map-tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.map-tbl th, .map-tbl td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #333; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.map-tbl th { color: var(--muted); font-weight: 600; }
.radio-row { display: flex; gap: 18px; margin-top: 14px; }
.radio-row label { display: flex; gap: 8px; align-items: center; cursor: pointer; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 500; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #2c2c2c; border: 1px solid #454545; color: var(--text); border-radius: 8px; padding: 10px 14px 10px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.5); display: flex; align-items: center; gap: 14px; font-size: 14.5px; animation: popIn .18s ease-out; }
.toast button { background: none; border: 0; color: #8fc0ff; font-weight: 700; cursor: pointer; padding: 4px 6px; }

/* ---------- Startseite ---------- */
.home-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin: 10px 0 26px; flex-wrap: wrap; }
.home-head h1, .lib-head h1 { margin: 0; font-size: 30px; letter-spacing: -.01em; }
.home-head p, .lib-head p { margin: 6px 0 0; color: var(--muted); }
.new-card { background: var(--panel); border: 1px solid #3a3a3a; padding: 22px 24px; margin-bottom: 34px; }
.new-card h2 { margin: 0 0 16px; font-size: 18px; }
.new-grid { display: grid; grid-template-columns: minmax(200px, 2.4fr) minmax(150px, 1.2fr) minmax(110px, .8fr) minmax(110px, .8fr) auto; gap: 14px; align-items: end; }
.new-grid .in { height: 46px; }
.new-grid .btn { height: 46px; }
.proj-list { display: flex; flex-direction: column; }
.proj-item { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; padding: 18px 6px; border-bottom: 1px solid #2a2a2a; cursor: pointer; transition: background .15s; border-radius: 4px; }
.proj-item:hover { background: #181818; }
.proj-item .pn { font-size: 18px; font-weight: 700; }
.proj-item .pm { color: var(--muted); margin-top: 3px; font-size: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.proj-item .pm span + span::before { content: "·"; margin-right: 8px; }
.proj-actions { display: flex; gap: 6px; }

/* ---------- Bibliothek ---------- */
.lib-head { margin: 10px 0 22px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid #2c2c2c; margin-bottom: 22px; }
.tabs a { padding: 10px 16px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--blue); }
.lib-tools { display: flex; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.lib-tools .search { max-width: 320px; }
.lib-tbl { --minw: 560px; max-width: 920px; }
.lib-mics { --cols: minmax(220px, 1fr) 90px 44px; }
.lib-stands { --cols: minmax(220px, 1fr) 140px 90px 44px; }
.lib-boxes { --cols: minmax(220px, 1fr) 150px 90px 90px 44px; }
.lib-tbl .row { padding: 8px 0; }
.lib-tbl .usage { color: var(--muted); font-size: 13.5px; }
.lib-add { display: grid; gap: 12px; margin-top: 18px; max-width: 920px; align-items: center; }
.lib-add.mics { grid-template-columns: minmax(220px, 1fr) 90px auto; }
.lib-add.stands { grid-template-columns: minmax(220px, 1fr) 140px auto; }
.lib-add.boxes { grid-template-columns: minmax(220px, 1fr) 150px 90px 90px auto; }
.lib-add .p48 { justify-self: start; }
.check-label { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 14px; }

.hint { color: var(--muted); font-size: 13.5px; margin-top: 10px; }
kbd { font: 12px var(--font); background: #2a2a2a; border: 1px solid #444; border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; }

@media (max-width: 900px) {
  main { padding: 18px 16px 70px; }
  .topbar { padding: 10px 16px; gap: 14px; }
  .status .status-text { display: none; }
  .add-box, .new-grid { grid-template-columns: 1fr 1fr; }
  .add-box .btn, .new-grid .btn { grid-column: 1 / -1; justify-content: center; }
  .new-grid > :first-child, .add-box > :first-child { grid-column: 1 / -1; }
  .box-grid { grid-template-columns: 1fr; }
  .title-in { font-size: 24px; }
}
