:root {
  --bg: #0f1115;
  --panel: #161a22;
  --panel2: #1d2230;
  --border: #2a3040;
  --grid: #242b3d;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --accent: #3b82f6;
  --good: #22c55e;
  --bad: #ef4444;
}

:root.light {
  --bg: #eef0f5;
  --panel: #ffffff;
  --panel2: #f2f4f9;
  --border: #d3d9e5;
  --grid: #dde2ec;
  --text: #1b2233;
  --muted: #5d6780;
  --accent: #2563eb;
}
:root.light .drag-ghost { background: var(--panel); }

* { box-sizing: border-box; }
img { -webkit-user-drag: none; user-select: none; }
.item, .pm-photo, .v-face, .pm-chassis, .slots { -webkit-user-drag: none; }
body:not(.editmode) .item, body:not(.editmode) .slots { user-select: none; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
body.dragging { cursor: grabbing; user-select: none; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); }
label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); flex: 1; }
label > input, label > select, label > textarea { color: var(--text); font-size: 13px; }
h1 { font-size: 20px; margin: 0; }
h3 { margin: 0 0 8px; font-size: 14px; }
small { font-size: 11px; }
.muted { color: var(--muted); }
.pad { padding: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 10px; }
.spacer { flex: 1; }

.btn {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 11px;
  cursor: pointer;
  white-space: nowrap;
  color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: #fca5a5; border-color: #7f1d1d; }
.btn.icon { padding: 6px 9px; }
.btn.sm { padding: 3px 8px; font-size: 12px; }

.banner {
  background: #7c2d12;
  color: #fed7aa;
  padding: 6px 12px;
  font-size: 12px;
  text-align: center;
}

#toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s;
  z-index: 300;
  max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  width: min(520px, 92vw);
}
dialog::backdrop { background: #000a; }
dialog textarea, dialog input, dialog select { width: 100%; }
dialog textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* ---------- home ---------- */
.home { max-width: 900px; margin: 0 auto; padding: 20px 16px; }
.home-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}
.card:hover { border-color: var(--accent); }
.card .del { position: absolute; top: 8px; right: 8px; background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; }
.card .del:hover { color: var(--bad); }

/* ---------- editor frame ---------- */
.editor { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.ed-head {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}
.h-name { font-weight: 600; width: 240px; }
.h-sm { width: 110px; }
.save-state { font-size: 11px; color: var(--muted); min-width: 52px; }
.editor-body { flex: 1; display: flex; min-height: 0; position: relative; }

/* ---------- library ---------- */
.lib {
  width: 262px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.lib-top { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--border); }
.lib-top input { flex: 1; }
#libList { overflow-y: auto; flex: 1; }
.lib-cat {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 8px 10px 3px;
  position: sticky;
  top: 0;
  background: var(--panel);
}
.lib-device {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 10px;
  cursor: grab;
  border-left: 3px solid var(--c, #64748b);
  touch-action: none;
}
.lib-device:hover { background: var(--panel2); }
.ld-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ld-main b { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ld-main small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.u-badge { font-size: 10px; color: var(--muted); }
.mini {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 5px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  color: var(--text);
  flex: none;
}
.mini:hover { border-color: var(--accent); }

/* ---------- racks ---------- */
.racks {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  gap: 26px;
  align-items: flex-start;
  touch-action: pan-y pan-x;
}
body:not(.editmode) .racks { touch-action: pan-y; overflow-x: hidden; }
body:not(.editmode) .item, body:not(.editmode) .slots, body:not(.editmode) .rack { touch-action: pan-y; }
.rack { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; flex: none; }
.rack-head { display: flex; gap: 5px; align-items: center; padding: 7px 8px; flex-wrap: wrap; }
.rack-name { width: 130px; font-weight: 600; padding: 4px 6px; }
.rack-h { padding: 4px 4px; }
.tabs { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.tab { background: none; border: none; padding: 4px 10px; cursor: pointer; color: var(--muted); }
.tab.on { background: var(--accent); color: #fff; }
.cool-wrap { padding-bottom: 3px; align-items: stretch; }
.cool-rail {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #38bdf8;
  text-align: center;
}
.cool-slot { position: relative; }
.item.cool-item {
  position: relative;
  inset: auto;
  left: auto;
  right: auto;
  top: auto;
  margin: 0;
  border-style: dashed;
  border-left-style: solid;
}
.rack-body { display: flex; padding: 0 6px 10px; }
.rail { width: 22px; flex: none; }
.rail div {
  font-size: 9px;
  color: var(--muted);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}
.slots {
  position: relative;
  width: 320px;
  border: 1px solid #3a4256;
  border-top-width: 4px;
  border-bottom-width: 4px;
  background-color: var(--panel2);
  background-image: linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
}

/* ---------- items ---------- */
.item {
  position: absolute;
  left: 2px;
  right: 2px;
  margin-top: 1px;
  border: 1px solid var(--c, #64748b);
  border-left: 4px solid var(--c, #64748b);
  border-radius: 3px;
  background: color-mix(in srgb, var(--c, #64748b) 20%, var(--panel2));
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 7px;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  z-index: 1;
}
.item .i-label { font-size: 11px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; z-index: 2; }
.item .i-model { font-size: 9px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; z-index: 2; }
.item .i-u { margin-left: auto; font-size: 9px; color: var(--muted); flex: none; position: relative; z-index: 2; }
@media (min-width: 900px) {
  .racks { flex-wrap: wrap; align-content: flex-start; }
  .board-card { flex: 0 1 460px; max-width: 520px; }
  .board-card h2 { display: flex; align-items: center; gap: 8px; }
  .board-card h2 .zoom-btn { margin-left: auto; }
  .item { padding: 0 11px; gap: 9px; }
  .item .i-label { font-size: 14px; }
  .item .i-model { font-size: 11px; }
  .item .i-u { font-size: 11px; }
  .rail { width: 28px; }
  .rail div { font-size: 11px; }
  .rack-title b { font-size: 15px; max-width: 340px; }
  .wire-legend { font-size: 13px; }
  .wl-text { font-size: 13px; }
  .wl-dev { font-size: 13.5px; }
}
.item .i-note { font-size: 9px; color: #fbbf24; flex: none; position: relative; z-index: 2; }
.item.own { z-index: 2; }
.item.rail-strip {
  left: auto;
  width: 46%;
  z-index: 5;
  box-shadow: -4px 0 10px #0006;
}
.item.rail-strip .i-model { display: none; }
.item.sel { outline: 2px solid #ffffffaa; z-index: 4; }
.item.lifting { opacity: 0.35; }
.item.ghosted {
  background: transparent;
  border: 1.5px dashed var(--c, #64748b);
  border-left-width: 4px;
  z-index: 3;
  justify-content: flex-end;
}
.ghost-pill {
  background: var(--panel);
  border: 1px solid var(--c, #64748b);
  border-radius: 99px;
  font-size: 9px;
  line-height: 1;
  padding: 3px 8px;
  color: var(--text);
  white-space: nowrap;
  max-width: 62%;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.editmode .item.ghosted { pointer-events: none; }
body:not(.editmode) .item, body:not(.editmode) .chip, body:not(.editmode) .lib-device { touch-action: auto; cursor: pointer; }
.item.rear { border-style: dashed; border-left-style: solid; }
.item.rear::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg, transparent 0 7px, #ffffff10 7px 10px);
  pointer-events: none;
}
/* device art — SVG clipart (has-art) or a real photo (has-img), both via --img */
.item.has-art { background-image: var(--img); background-size: 100% 100%; }
.item.has-img { background-image: var(--img); background-size: cover; background-position: center; }
.item.has-img::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, #000d, #0009 55%, #0003); z-index: 1; }
.item.has-img .i-model { text-shadow: 0 1px 3px #000, 0 0 6px #000c; }
.item.vert { width: 46px; left: auto; padding: 4px 2px; flex-direction: column; justify-content: flex-start; z-index: 2; }
.item.vert .i-label { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 10px; max-height: calc(100% - 6px); white-space: nowrap; overflow: hidden; }
.item.vert .i-model, .item.vert .i-u, .item.vert .i-note { display: none; }
.item.has-art .i-label, .item.has-img .i-label { color: #f1f4fa; text-shadow: 0 1px 2px #000c; }
.item.has-art .i-model, .item.has-img .i-model,
.item.has-art .i-u, .item.has-img .i-u { color: #aab4c8; text-shadow: 0 1px 2px #000c; }
.item.f-blank .i-label, .item.f-vent .i-label, .item.f-brush .i-label { font-weight: 400; color: #9aa4b8; }

.preview {
  position: absolute;
  left: 0;
  right: 0;
  border: 2px dashed var(--good);
  background: #22c55e1e;
  z-index: 5;
  pointer-events: none;
  border-radius: 3px;
}
.preview.bad { border-color: var(--bad); background: #ef44441e; }

.drag-ghost {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  background: #232a3a;
  border: 1px solid var(--accent);
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 12px;
  box-shadow: 0 10px 30px #000a;
  display: flex;
  gap: 8px;
  align-items: center;
  max-width: 260px;
}
.drag-ghost span { color: var(--muted); font-size: 10px; }

/* ---------- staging ---------- */
.staging-bar {
  min-height: 58px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  overflow-x: auto;
  flex: none;
}
.staging-bar.hot { outline: 2px dashed var(--accent); outline-offset: -3px; }
.stag-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); flex: none; }
.chip {
  flex: none;
  display: flex;
  gap: 7px;
  align-items: center;
  padding: 7px 11px;
  background: color-mix(in srgb, var(--c, #64748b) 20%, var(--panel2));
  border: 1px solid var(--c, #64748b);
  border-radius: 7px;
  cursor: grab;
  font-size: 12px;
  touch-action: none;
}
.chip span { color: var(--muted); font-size: 10px; }
.chip.sel { outline: 2px solid #ffffffaa; }

/* ---------- detail panel ---------- */
.detail {
  width: 285px;
  border-left: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.detail .row { align-items: flex-end; }
.detail-close { display: none; align-self: flex-end; }
.swatches { display: flex; gap: 5px; flex-wrap: wrap; }
.sw { width: 22px; height: 22px; border-radius: 5px; border: 1px solid #0006; cursor: pointer; }
.sw.on { outline: 2px solid #fff; }
.sw.none { background: var(--panel2); color: var(--muted); font-size: 10px; }
.nudges { display: flex; gap: 4px; }
.conn-mini { background: var(--panel2); border: 1px solid var(--border); border-radius: 7px; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.conn-mini small { color: var(--muted); }

/* ---------- connections panel ---------- */
.conn-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(660px, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--border);
  z-index: 100;
  transform: translateX(100%);
  transition: 0.22s;
  display: flex;
  flex-direction: column;
}
.conn-panel.open { transform: none; box-shadow: -18px 0 50px #000b; }
.conn-head { display: flex; gap: 8px; align-items: center; padding: 12px; border-bottom: 1px solid var(--border); }
.conn-head h3 { flex: 1; margin: 0; }
.conn-rows { overflow-y: auto; flex: 1; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.conn-row { background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.cr-grid { display: grid; grid-template-columns: 1fr 76px auto 1fr 76px; gap: 5px; align-items: center; }
.cr-grid .arrow { text-align: center; color: var(--muted); }
.cr-grid select, .cr-grid input { width: 100%; font-size: 12px; padding: 5px 6px; }
.cr-cable { grid-column: 1 / 2; }
.cr-note { grid-column: 2 / 5; }
.cr-grid > .danger { grid-column: 5; justify-self: end; }

/* ---------- live/edit mode chrome ---------- */
.live-title { display: flex; flex-direction: column; min-width: 0; }
.live-title b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.rack-title { display: flex; flex-direction: column; padding: 2px 6px; min-width: 0; }
.rack-title b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.edit-banner { background: #7c2d12; color: #fed7aa; text-align: center; font-size: 11px; padding: 3px; letter-spacing: 0.04em; }
:root.light .edit-banner { background: #ffedd5; color: #9a3412; }
.kebab-wrap { position: relative; }
.kebab-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 14px 40px #0009;
  z-index: 200;
  min-width: 210px;
  max-width: calc(100vw - 16px);
  overflow: hidden;
}
/* The header wraps on a phone, so the button can sit mid-row — anchor the
   menu to the viewport instead of the button or it runs off the edge. */
@media (max-width: 900px) {
  .kebab-menu {
    position: fixed;
    top: auto;
    bottom: 14px;
    left: 8px;
    right: 8px;
    min-width: 0;
    max-width: none;
    border-radius: 14px;
  }
  .kebab-menu .k-item { padding: 15px 16px; font-size: 15px; }
}
.k-item { display: block; width: 100%; text-align: left; background: none; border: none; padding: 11px 14px; cursor: pointer; color: var(--text); font-size: 13px; }
.k-item:hover { background: var(--panel2); }
.k-ver { padding: 6px 14px 8px; font-size: 10px; color: var(--muted); border-top: 1px solid var(--border); }

/* ---------- item viewer ---------- */
.viewer-backdrop {
  position: fixed;
  inset: 0;
  background: #000a;
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.viewer {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  width: min(480px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 24px 80px #000c;
}
.v-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.v-face {
  width: 100%;
  aspect-ratio: 3 / 1;
  border-radius: 8px;
  border: 1px solid var(--border);
  border-left: 5px solid var(--c, #64748b);
  background-size: 100% 100%;
  background-position: center;
}
.v-face.has-photo { background-size: contain; background-repeat: no-repeat; background-color: #10141b; }
.v-face.v-vert { aspect-ratio: 1 / 2.6; max-height: 300px; width: 110px; align-self: center; }
.v-face.v-rear { opacity: 0.95; }
.v-notes { margin: 0; font-size: 12px; color: var(--muted); background: var(--panel2); border-radius: 8px; padding: 8px 10px; }
.v-wires { background: var(--panel2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; font-size: 12px; }
.v-wires small { color: var(--muted); }
.v-wires > .btn { margin-top: 10px; align-self: flex-start; }
@media (max-width: 900px) {
  .viewer-backdrop { align-items: flex-end; padding: 0; }
  .viewer { width: 100%; border-radius: 14px 14px 0 0; max-height: 78vh; }
}

/* ---------- tabs + systems ---------- */
.tabbar {
  display: flex;
  gap: 6px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  overflow-x: auto;
  flex: none;
}
.room-wrap { position: relative; display: inline-flex; align-items: center; flex: none; }
.room-sel {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  padding: 4px 20px 4px 6px;
  cursor: pointer;
  max-width: 180px;
}
.room-sel:focus { outline: none; }
.room-caret { position: absolute; right: 4px; pointer-events: none; color: var(--muted); font-size: 12px; }
.ttab {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 5px 13px;
  cursor: pointer;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}
.ttab.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.pm-page {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  flex: 1;
  max-width: 860px;
}
.pm-page h2 { margin: 0 0 10px; font-size: 16px; }
.rack.cabinet .slots { border-left-width: 1px; border-right-width: 1px; }
.rack-room { width: 90px; padding: 4px 6px; color: var(--muted); }
.zoom-btn { margin-left: auto; }
@media (max-width: 899px) { .zoom-btn { display: none; } }

/* ---------- port maps ---------- */
.outlets-box { background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.pm-section { margin-bottom: 12px; }
.pm-section h4, .conn-rows h4 { margin: 10px 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.pm-grid { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px; background: var(--panel2); border: 1px solid var(--border); border-radius: 10px; }
.pm-grid.two-row { display: grid; grid-auto-flow: column; grid-template-rows: repeat(2, auto); justify-content: start; overflow-x: auto; }
.pm-port {
  width: 60px;
  min-height: 54px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  padding: 4px 2px;
}
.pm-port b { font-size: 11px; }
.pm-port small { font-size: 9px; color: var(--muted); max-width: 54px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pm-port i { font-size: 8px; font-style: normal; color: #38bdf8; font-weight: 600; }
.pm-port.set.pm-power { border-color: #ef4444; }
.pm-port.set.pm-network { border-color: #3b82f6; }
.pm-port.act { outline: 3px solid var(--accent); outline-offset: 1px; }
.pm-chassis {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 12px;
  background: #171b23;
  border: 1px solid #0c0f14;
  border-top-color: #262c38;
  border-radius: 10px;
  overflow-x: auto;
}
.pm-bank { display: flex; gap: 5px; }
.pm-bank.two-row { display: grid; grid-auto-flow: column; grid-template-rows: repeat(2, auto); gap: 5px; }
.pm-sep { flex: none; width: 10px; align-self: stretch; }
.pm-sep.wide { width: 22px; border-left: 1px solid #262c38; margin-left: 10px; }
.pm-chassis .pm-port { background: #0c0f14; border-color: #39404f; color: #e6e9f0; }
.pm-chassis .pm-port small { color: #8b93a7; }
.pm-chassis .pm-port.set { border-color: #3b82f6; background: #14243f; }
.pm-chassis .pm-port.pm-sfp { min-height: 44px; width: 66px; border-style: dashed; }
.pm-chassis.pm-vertical { flex-direction: column; align-items: stretch; max-width: 440px; padding: 12px; }
.pm-bankv { display: flex; flex-direction: column; gap: 5px; }
.pm-bankv.pairs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.pm-vertical .pm-port { flex-direction: row; width: auto; min-height: 42px; justify-content: flex-start; gap: 9px; padding: 4px 10px; }
.pm-vertical .pm-port b { min-width: 20px; text-align: right; font-size: 12px; }
.pm-vertical .pm-port small { font-size: 11.5px; max-width: none; flex: 1; text-align: left; }
.pm-vertical .pm-port i { font-size: 9px; flex: none; }
.pm-vertical .pm-port.pm-sfp { width: auto; min-height: 42px; }
.pm-sepv { height: 10px; flex: none; }
.pm-sepv.wide { height: 16px; border-top: 1px solid #262c38; margin-top: 8px; }
.pm-photo { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: #10141b; }
.pm-photo img { display: block; width: 100%; }
.pm-spot {
  position: absolute;
  border: 2.5px solid #ff7a00;
  background: #ff7a001f;
  border-radius: 7px;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 2px;
}
.pm-spot b { font-size: 11px; text-shadow: 0 1px 3px #000; }
.pm-spot.set { background: #ff7a0059; }
.pm-spot.act { outline: 3px solid var(--accent); outline-offset: 1px; }
.pm-caption { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 8px 4px; }
.pm-cap-item { font-size: 12px; }
.pm-cap-item b { color: #ff7a00; margin-right: 4px; }
.cap-tag { color: #38bdf8; border-color: #38bdf8; }
.pm-edit { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 8px; padding: 9px; background: var(--panel2); border: 1px solid var(--accent); border-radius: 8px; }
.pm-edit b { flex: none; }
.pm-edit select, .pm-edit input { flex: 1; min-width: 130px; }
.ports-panel #pmDevSel { flex: 1; min-width: 0; }
/* Wires draw above every device, including rail strips, and route in a
   gutter to the right of the rack so they never cross the gear. */
.wire-overlay { position: absolute; top: 0; left: 0; z-index: 8; pointer-events: none; overflow: visible; }
.rack-body:has(.wire-overlay) { padding-right: 74px; }
.steps-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2px 2px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.steps-left { font-size: 11px; color: var(--muted); font-weight: 700; }
.step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel);
  margin-bottom: 6px;
  cursor: pointer;
}
.step:hover { border-color: var(--accent); }
.step.focus { border-color: var(--accent); border-width: 2px; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.step.done { opacity: 0.55; background: var(--panel2); border-style: dashed; }
.step.done .step-body { color: var(--muted); }
.step.done .step-body b { font-weight: 500; }
.step.done .step-cable { filter: grayscale(1); }
.step.done .step-thumb { filter: grayscale(1); }
.step-box {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}
.step.done .step-box { background: var(--good); border-color: var(--good); color: #fff; }
.step-body { min-width: 0; flex: 1; }
.step-cable {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.step-leg { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; font-size: 13px; line-height: 1.6; }
.step-tag {
  flex: none;
  width: 42px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: var(--panel2);
  border-radius: 4px;
  padding: 1px 0;
  text-align: center;
}
.step-tag.to { color: var(--accent); }
.step-port {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
}
.step-note { font-size: 11.5px; color: var(--muted); font-style: italic; margin-top: 3px; padding-left: 48px; }
.step-note.nopad { padding-left: 0; }
.step-thumb {
  flex: none;
  width: 78px;
  height: 34px;
  border-radius: 5px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--c, #64748b);
  background-color: #10141b;
  background-size: cover;
  background-position: center;
}
.step-thumb.ph { background: linear-gradient(180deg, var(--panel2), var(--panel)); }
.step-pos {
  flex: none;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  font-weight: 800;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  min-width: 46px;
  text-align: center;
}
.step-sku { font-family: ui-monospace, Consolas, monospace; font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.steps-left { display: inline-flex; align-items: center; gap: 8px; }
.steps-sub { font-weight: 400; color: var(--muted); font-size: 11px; }
.step.ovrc { cursor: default; }
.ovrc-name { color: var(--accent); font-family: inherit; }
.ovrc-fields { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.ovrc-fields label { flex: 1 1 190px; font-size: 10px; }
.ovrc-fields .row-in { display: flex; gap: 5px; }
.ovrc-fields input {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  padding: 7px 8px;
}
.scan-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scan-overlay video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 38%;
  height: 24%;
  border: 3px solid #22c55e;
  border-radius: 12px;
  box-shadow: 0 0 0 100vmax #0009;
}
.scan-hint {
  position: absolute;
  bottom: 8%;
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-shadow: 0 1px 4px #000;
}
.wire-key {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  padding: 2px 0 8px;
  margin-bottom: 6px;
  border-bottom: 1px dashed var(--border);
}
.wk-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.wk-line { width: 20px; height: 3px; border-radius: 2px; display: inline-block; }
.wire-legend { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border); }
.wl-row { display: flex; gap: 8px; align-items: baseline; }
.wl-row small { color: var(--muted); font-size: 11.5px; }
.wl-text { display: flex; flex-wrap: wrap; gap: 5px; align-items: baseline; font-size: 12px; line-height: 1.6; }
.wl-dev { font-weight: 600; color: var(--text); }
.wl-loc {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  background: var(--panel2);
  border-radius: 4px;
  padding: 1px 5px;
}
.wl-port {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 10.5px;
  color: var(--muted);
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  white-space: nowrap;
}
.wl-port.from { min-width: 76px; text-align: center; flex: none; }
.wl-cable {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1.5px solid;
  border-radius: 4px;
  padding: 1px 6px;
  white-space: nowrap;
}
.wl-outlet {
  font-weight: 800;
  font-size: 11.5px;
  color: #ff7a00;
  border: 1.5px solid #ff7a00;
  border-radius: 5px;
  padding: 1px 7px;
  white-space: nowrap;
}
.wl-arrow { color: var(--muted); font-weight: 700; }
.wl-n {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
}
.wg { margin-bottom: 10px; }
.wg:last-child { margin-bottom: 0; }
.wg-head {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 0 5px 2px;
}
.wg-row {
  display: grid;
  grid-template-columns: minmax(0, 104px) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: baseline;
  padding: 7px 8px 7px 9px;
  border-left: 3px solid var(--cc, #8b93a7);
  border-radius: 0 6px 6px 0;
  background: var(--panel);
  margin-bottom: 3px;
}
.wg-row.empty { opacity: 0.5; }
.wg-port {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  overflow-wrap: anywhere;
  line-height: 1.35;
}
.wg-dest { min-width: 0; line-height: 1.35; }
.wg-name { font-size: 12.5px; font-weight: 600; overflow-wrap: anywhere; }
.wg-loc { font-size: 10px; font-weight: 700; color: var(--muted); margin-left: 5px; white-space: nowrap; }
.wg-sub { font-size: 10.5px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; margin-top: 1px; }
.wg-sub.note { font-family: inherit; font-style: italic; }
.wg-open { font-size: 11px; color: var(--muted); }
.wg-cable {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  align-self: baseline;
}
@media (max-width: 420px) {
  .wg-row { grid-template-columns: minmax(0, 88px) minmax(0, 1fr) auto; gap: 8px; }
}

/* ---------- build sheet ---------- */
.sheet { max-width: 780px; margin: 0 auto; padding: 0 12px 48px; }
.sh-head { display: flex; gap: 8px; align-items: center; padding: 10px 0; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.sh-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sh-title b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sh-title small { color: var(--muted); }
.sh-notes { color: var(--muted); font-size: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.sh-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; }
.sh-card h2 { font-size: 15px; margin: 0 0 8px; }
.sh-card h2 small { color: var(--muted); font-weight: 400; font-size: 11px; }
.sh-card table { width: 100%; border-collapse: collapse; }
.sh-card th, .sh-card td { text-align: left; padding: 7px 8px; border-top: 1px solid var(--border); vertical-align: top; font-size: 13px; }
.sh-card thead th { border-top: none; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; }
.u-cell { white-space: nowrap; font-weight: 600; }
.notes-cell { color: var(--muted); font-size: 12px; }
.tag { display: inline-block; background: var(--panel2); border: 1px solid var(--border); border-radius: 4px; padding: 0 6px; font-size: 10px; margin-left: 6px; color: var(--muted); }
.w-group { border-top: 1px solid var(--border); padding: 8px 0; }
.w-group h3 { font-size: 13px; margin: 0 0 6px; }
.w-group h3 small { color: var(--muted); font-weight: 400; }
.wire { display: flex; gap: 7px; padding: 6px 0 6px 6px; align-items: baseline; }
.w-from { color: var(--muted); font-size: 12px; min-width: 74px; flex: none; }
.w-arrow { color: var(--muted); flex: none; }
.w-to { flex: 1; font-size: 13px; min-width: 0; display: flex; flex-wrap: wrap; gap: 5px; align-items: baseline; }
.sh-card ul { margin: 0; padding-left: 18px; }
.sh-card li { margin: 5px 0; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  /* Live view on phones: let the document scroll natively — no nested
     pan container for a finger to grab. */
  body:not(.editmode) .editor { height: auto; min-height: 100dvh; }
  body:not(.editmode) .editor-body { display: block; }
  body:not(.editmode) .racks {
    overflow: visible;
    display: block;
    padding: 12px 10px 20px;
    touch-action: auto;
  }
  body:not(.editmode) .rack { margin-bottom: 16px; }
  body:not(.editmode) .ed-head { position: sticky; top: 0; z-index: 20; }
  body:not(.editmode) .tabbar { position: sticky; top: 47px; z-index: 19; }
  body:not(.editmode) .staging-bar { display: none; }

  .ed-head { padding: 6px; gap: 5px; }
  .h-name { width: 150px; flex: 1; }
  .h-sm { display: none; }
  .lib {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 86vw);
    z-index: 90;
    transform: translateX(-105%);
    transition: 0.22s;
    box-shadow: 18px 0 50px #000b;
  }
  .lib.open { transform: none; }
  .detail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: auto;
    max-height: 62vh;
    z-index: 95;
    transform: translateY(105%);
    transition: 0.22s;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
  }
  .detail.open { transform: none; box-shadow: 0 -18px 50px #000b; }
  .detail-close { display: block; }
  .racks { padding: 10px; gap: 16px; }
  .cr-grid { grid-template-columns: 1fr 70px; }
  .cr-grid .arrow { display: none; }
  .cr-note { grid-column: 1 / 3; }
  .cr-grid > .danger { grid-column: 2; }
}

/* ---------- print ---------- */
.print-only { display: none; }
@media print {
  :root {
    --bg: #fff;
    --panel: #fff;
    --panel2: #fff;
    --border: #999;
    --grid: #ccc;
    --text: #000;
    --muted: #444;
  }
  @page { margin: 12mm; }
  body { background: #fff !important; color: #000; font-size: 10pt; }

  /* Paper is a spreadsheet: the graphical elevation never prints. */
  .no-print, .lib, .detail, .staging-bar, .ed-head, .conn-panel, #toast, .banner,
  .racks, .rack, .tabbar, .edit-banner, .viewer-backdrop, .sh-head, .wire-legend,
  .pm-photo, .pm-chassis, .pm-edit, .v-face { display: none !important; }
  .print-only { display: block; }
  .editor, .sheet { height: auto; display: block; padding: 0; max-width: none; }
  .editor-body { display: block; }

  .print-head { padding: 0 0 10px; border-bottom: 2px solid #000; margin-bottom: 12px; }
  .print-head h1 { font-size: 15pt; margin: 0 0 2px; }
  .print-head div { font-size: 9pt; color: #333; }
  .p-scope {
    margin-top: 6px;
    padding: 5px 8px;
    border-left: 3px solid #666;
    background: #f6f6f6 !important;
    font-size: 8pt;
    line-height: 1.45;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .print-notes h3 {
    margin: 14px 0 4px;
    font-size: 11pt;
    border-bottom: 1px solid #000;
    padding-bottom: 2px;
    break-after: avoid;
  }
  .print-notes table {
    width: 100%;
    border-collapse: collapse;
    font-size: 9pt;
    margin-bottom: 4px;
    break-inside: auto;
  }
  .print-notes thead { display: table-header-group; }
  .print-notes tr { break-inside: avoid; }
  .print-notes th, .print-notes td {
    border: 1px solid #666;
    padding: 3px 6px;
    text-align: left;
    vertical-align: top;
    background: #fff;
  }
  .print-notes th {
    background: #e8e8e8 !important;
    font-size: 8pt;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .print-notes tbody tr:nth-child(even) td {
    background: #f6f6f6 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .print-notes ul { margin: 4px 0; padding-left: 16px; font-size: 9pt; }
  /* Rack tables: every row is as tall as the unit it represents, so the
     page reads like the rack. Let it run onto a second sheet. */
  .p-rack-table tbody tr { height: calc(var(--uh, 1) * 9mm); }
  .p-rack-table tbody td { vertical-align: middle; }
  .p-rack-table tbody td.p-note { vertical-align: top; padding-top: 4px; }
  .p-block { break-inside: auto; margin-bottom: 14px; }
  .p-block h3 { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
  .p-sub { font-size: 8pt; font-weight: 400; color: #555; text-transform: none; letter-spacing: 0; }
  .p-u { font-family: ui-monospace, Consolas, monospace; font-weight: 700; white-space: nowrap; text-align: center; }
  .p-side { font-size: 7.5pt; text-transform: uppercase; letter-spacing: 0.06em; color: #555; }
  .p-sku { font-family: ui-monospace, Consolas, monospace; font-size: 7.5pt; color: #555; }
  .p-port { font-family: ui-monospace, Consolas, monospace; font-size: 8pt; }
  .p-cable { font-weight: 700; font-size: 8pt; text-transform: uppercase; letter-spacing: 0.04em; }
  .p-note { font-size: 8pt; color: #333; font-style: italic; }
  .p-blank { color: #888; font-style: italic; }
  .p-summary { font-size: 8.5pt; margin: 3px 0 0; color: #222; }

  /* Sheet view prints as the same tables, no cards or shading. */
  .sheet .sh-card, .sheet .sh-notes {
    background: #fff !important;
    border: none;
    padding: 0;
    margin: 0 0 10px;
    break-inside: auto;
  }
  .sheet .sh-card h2 { font-size: 11pt; border-bottom: 1px solid #000; padding-bottom: 2px; break-after: avoid; }
  .sheet .sh-card table { font-size: 9pt; border-collapse: collapse; width: 100%; }
  .sheet .sh-card th, .sheet .sh-card td { border: 1px solid #666; padding: 3px 6px; }
  .sheet .sh-card thead th { background: #e8e8e8 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet .wg-row { border-left: none; background: #fff !important; padding: 2px 0; }
  .sheet .wg-cable, .sheet .wl-cable, .sheet .wl-outlet, .sheet .wl-loc, .sheet .wl-port {
    border: 1px solid #999;
    color: #000 !important;
    background: #fff !important;
  }
}

/* Deleted-schedule recovery */
.trash-list { max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.trash-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel2);
}
.name-len { font-size: 10px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; align-self: center; }
.name-len.over { color: var(--bad); font-weight: 800; }

.v-cool { margin: 10px 0 4px; border-top: 1px solid var(--line); padding-top: 8px; }
.v-cool .steps-head { margin-bottom: 6px; }
.v-cool .step { padding: 7px 4px; }

.step-port.dest { background: #ff7a00; color: #fff; font-weight: 700; }
.step-warn { margin: 4px 0 0 2px; padding: 5px 8px; border-left: 3px solid #ff7a00;
  background: rgba(255,122,0,.10); font-size: 12px; line-height: 1.35; }
.step-tag.to { background: #ff7a00; color: #fff; }

.port-shot-wrap { margin: 6px 0 2px; }
.port-shot { position: relative; width: 100%; background-repeat: no-repeat;
  background-color: #0b0d12; border-radius: 6px; border: 1px solid var(--line); }
.ps-mark { position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border: 3px solid #ff7a00; border-radius: 50%; box-shadow: 0 0 0 2px rgba(0,0,0,.55);
  pointer-events: none; }
.ps-cap { font-size: 11.5px; line-height: 1.35; margin-top: 4px; opacity: .85; }
@media print { .port-shot { break-inside: avoid; } }

.port-shot-wrap { padding-top: 20px; }
.port-shot { overflow: visible; }
.ps-arrow { position: absolute; top: -19px; margin-left: -8px; color: #ff7a00;
  font-size: 20px; line-height: 1; text-shadow: 0 1px 3px rgba(0,0,0,.5);
  pointer-events: none; animation: psbob 1.5s ease-in-out infinite; }
@keyframes psbob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(3px); } }
@media (prefers-reduced-motion: reduce) { .ps-arrow { animation: none; } }
.step-arrow { color: #ff7a00; font-size: 20px; font-weight: 700; line-height: 1;
  margin: 1px 0 1px 13px; }
@media print { .ps-arrow { animation: none; } }

/* The checklists are children of .rack, which is as wide as the rack drawing
   plus the wire gutter and lives in a horizontal scroller. On a phone that put
   half of every step off-screen to the right — including the port photos.
   Pin them to the left edge and hold them to the viewport. */
.wire-legend {
  position: sticky;
  left: 0;
  width: min(100%, calc(100vw - 26px));
  box-sizing: border-box;
}

.scope-tabs { display: flex; gap: 6px; padding: 2px 2px 6px; }
.scope-tabs .scope { flex: 1; padding: 8px 6px; border: 1px solid var(--line); border-radius: 8px;
  background: transparent; color: inherit; font: inherit; font-size: 12.5px; cursor: pointer; }
.scope-tabs .scope.on { background: #6d5efc; border-color: #6d5efc; color: #fff; font-weight: 600; }
.scope-hint { font-size: 11.5px; opacity: .75; padding: 0 3px 8px; line-height: 1.35; }

.why-link { border: none; background: none; color: #6d5efc; font: inherit; font-size: 12px;
  padding: 2px 4px; margin: 2px 0 0 13px; cursor: pointer; text-decoration: underline; }
.step-note .why-link { margin-left: 6px; }

.ps-arrow.side { top: auto; margin: 0; transform: translateY(-50%); animation: psbobx 1.5s ease-in-out infinite; }
@keyframes psbobx { 0%,100% { transform: translate(0,-50%); } 50% { transform: translate(-3px,-50%); } }
@media (prefers-reduced-motion: reduce) { .ps-arrow.side { animation: none; } }

/* thumb-scale arrows — these are read at arm's length on a phone */
.ps-arrow { font-size: 30px; margin-left: -12px; top: -28px; }
.ps-arrow.side { font-size: 26px; }
.port-shot-wrap { padding-top: 30px; }
.step-arrow { font-size: 26px; }

.scan-hint .scan-photo { background: #6d5efc; border-color: #6d5efc; color: #fff; font-weight: 600; }
.scan-msg { display: block; margin-bottom: 8px; }
