/* ====== AV Studio ====== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #10151d;
  --panel: #1a2230;
  --panel2: #202a3b;
  --line: #2c384c;
  --text: #dfe7f2;
  --muted: #8b99ad;
  --accent: #4da3ff;
  --accent2: #ffb84d;
  --danger: #ff6b6b;
  --ok: #38d39f;
}
html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .4px; }
#tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 8px;
  padding: 7px 16px; font-size: 14px; cursor: pointer; font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--panel2); color: var(--accent); border-color: var(--line); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
#projectName {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 7px 10px; width: 180px; font-size: 13px;
}
.btn {
  background: var(--accent); color: #06131f; border: none; border-radius: 8px;
  padding: 8px 14px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.btn:hover { filter: brightness(1.1); }
.btn.ghost { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.btn.wide { width: 100%; }
.btn.danger { background: var(--danger); color: #fff; }

/* ---------- pages ---------- */
.page { display: none; flex: 1; min-height: 0; }
.page.active { display: flex; }

/* ---------- library sidebar ---------- */
#library {
  width: 250px; min-width: 250px; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line);
}
.lib-head { padding: 10px; border-bottom: 1px solid var(--line); }
#libSearch {
  width: 100%; background: var(--bg); border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; padding: 7px 10px; font-size: 13px;
}
#libList { flex: 1; overflow-y: auto; padding: 6px 8px 12px; }
.lib-cat { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 12px 4px 6px; }
.lib-item {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; margin-bottom: 6px; cursor: grab; user-select: none;
  transition: border-color .12s;
}
.lib-item:hover { border-color: var(--accent); }
.lib-item .li-name { font-size: 13px; font-weight: 600; }
.lib-item .li-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.lib-foot { padding: 10px; border-top: 1px solid var(--line); }

/* ---------- wiring canvas ---------- */
#canvasWrap { flex: 1; position: relative; display: flex; flex-direction: column; min-width: 0; }
#wiringToolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.tbtn {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 5px 10px; font-size: 12.5px; cursor: pointer;
}
.tbtn:hover { border-color: var(--accent); }
.tbtn.danger:hover { border-color: var(--danger); color: var(--danger); }
.tsep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.tcheck, .tcheck2 { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }
.tcheck2 { margin: 8px 0 2px; }
#hint { margin-left: auto; font-size: 11.5px; color: #5d6b80; }
#wireCanvas { flex: 1; width: 100%; height: 100%; background: var(--bg); outline: none; }
#wireCanvas.connecting { cursor: crosshair; }

/* legend */
#legend {
  position: absolute; right: 12px; bottom: 12px;
  background: rgba(26,34,48,.92); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font-size: 11.5px; display: flex; flex-direction: column; gap: 4px;
  pointer-events: none;
}
.leg-row { display: flex; align-items: center; gap: 8px; }
.leg-swatch { width: 18px; height: 3px; border-radius: 2px; }

/* SVG node styling */
.node rect.body { fill: #223047; stroke: #3d4f6c; stroke-width: 1.5; rx: 10; }
.node.selected rect.body { stroke: var(--accent2); stroke-width: 2.5; filter: drop-shadow(0 0 6px rgba(255,184,77,.4)); }
.node text.title { fill: var(--text); font-size: 13px; font-weight: 700; }
.node text.subtitle { fill: var(--muted); font-size: 10px; }
.node text.plabel { fill: #aebbce; font-size: 9px; }
.node .porthit { cursor: crosshair; }
.edge { fill: none; stroke-width: 2.5; cursor: pointer; }
.edge.selected { stroke-width: 4; filter: drop-shadow(0 0 5px rgba(255,255,255,.35)); }
.edge-hit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; }
.edge-label { font-size: 9.5px; fill: #c6d2e2; paint-order: stroke; stroke: #10151d; stroke-width: 3px; }
.node, .edge, .edge-hit { user-select: none; }

/* ---------- rack page ---------- */
#rackSidebar {
  width: 270px; min-width: 270px; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 14px;
}
#rackSidebar h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--accent); margin: 18px 0 8px;
}
#rackSidebar h3:first-child { margin-top: 0; }
.rack-card {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; margin-bottom: 6px; cursor: pointer;
}
.rack-card.active { border-color: var(--accent); }
.rack-card .rc-main { flex: 1; min-width: 0; }
.rack-card .rc-name { font-size: 13px; font-weight: 600; }
.rack-card .rc-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.rack-card .rc-x {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 4px 6px; border-radius: 6px;
}
.rack-card .rc-x:hover { color: var(--danger); background: rgba(255,107,107,.12); }
#rackDevList .lib-item { cursor: pointer; }
.ru-badge {
  font-size: 9.5px; color: var(--accent); border: 1px solid var(--line);
  border-radius: 5px; padding: 1px 5px; margin-left: 4px; vertical-align: 1px;
}
#rackMain { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#rackToolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
#hint2 { margin-left: auto; font-size: 11.5px; color: #5d6b80; }
#rackCanvasWrap { flex: 1; overflow: auto; padding: 14px; outline: none; }

/* ---------- LED page ---------- */
#ledSidebar {
  width: 290px; min-width: 290px; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 14px;
}
#ledSidebar h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--accent); margin: 18px 0 8px;
}
#ledSidebar h3:first-child { margin-top: 0; }
.fld { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.fld input, .fld select {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 7px 9px; font-size: 13px; width: 100%;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.specbox {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 11.5px; color: var(--muted); margin-bottom: 8px;
  line-height: 1.55;
}
.specbox b { color: var(--text); font-weight: 600; }
.minihint { font-size: 10.5px; color: #5d6b80; margin: 2px 0 4px; }

#ledMain { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#ledStats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 8px; padding: 10px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.stat {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px;
}
.stat .s-label { font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.stat .s-value { font-size: 16.5px; font-weight: 700; margin-top: 2px; }
.stat .s-sub { font-size: 10.5px; color: var(--muted); margin-top: 1px; }
.stat.warn .s-value { color: var(--accent2); }
#ledCanvasWrap { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 20px; }
#ledCanvas { background: var(--bg); }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(5,9,15,.7); z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.modal-back[hidden], #toast[hidden] { display: none; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px; width: 430px; max-width: 92vw; max-height: 86vh; overflow-y: auto;
}
.modal h2 { font-size: 16px; margin-bottom: 14px; }
.modal .fld { margin-bottom: 10px; }
.modal .m-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---------- inventory page ---------- */
#invMain { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#invToolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
#hint4 { margin-left: auto; font-size: 11.5px; color: #5d6b80; }
#invTableWrap { flex: 1; overflow: auto; padding: 14px; }
.inv-table td { vertical-align: middle; }
.inv-qty {
  width: 64px; background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 5px 8px; font-size: 13px;
}
.inv-actions { display: flex; gap: 4px; justify-content: flex-end; }
.inv-empty { max-width: 560px; margin: 60px auto; text-align: center; color: var(--muted); }
.inv-empty h2 { color: var(--text); font-size: 17px; margin-bottom: 12px; }
.inv-empty p { font-size: 13px; line-height: 1.7; margin-bottom: 10px; }
#invLibList .lib-item { cursor: pointer; }

/* role badges */
.role-badge {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .6px;
  border: 1px solid var(--line); border-radius: 5px; padding: 1.5px 6px;
  color: var(--muted); vertical-align: 1px; margin-left: 4px;
}
.role-badge.owner { color: var(--accent); border-color: var(--accent); }
.role-badge.viewer { color: #8b99ad; }

/* pull list table */
.modal:has(.pull-table) { width: 760px; }
.pull-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.pull-table th {
  text-align: left; padding: 7px 10px; background: var(--panel2);
  color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px;
  position: sticky; top: 0;
}
.pull-table td { padding: 6px 10px; border-top: 1px solid var(--line); }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--accent); color: var(--text);
  border-radius: 10px; padding: 10px 18px; font-size: 13px; z-index: 200;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2c384c; border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }
