:root {
  --uh: 26px;                 /* pixel height of one rack unit */
  --rack-w: 360px;            /* width of one cabinet's slot column */
  --grid: 24px;               /* canvas grid step; mirrors GRID in app.js */

  --bg: #0e1116;
  --bg-2: #151a21;
  --panel: #161b22;
  --line: #262d38;
  --line-soft: #1f252e;
  --text: #e6edf3;
  --text-dim: #8b98a8;
  --accent: #4c8dff;
  --danger: #e5534b;
  --metal: #1c222b;
}

* { box-sizing: border-box; }

/* ───────── scrollbars ─────────
   Chrome/Safari/Edge: transparent track and corner, with a faint thumb that only firms
   up on hover, so a scrolled panel never shows a pale bar against the dark theme.
   `background-clip: content-box` over a transparent border is what insets the thumb. */
::-webkit-scrollbar {
  width: 11px;
  height: 11px;
  background: transparent;
}
::-webkit-scrollbar-track,
::-webkit-scrollbar-track-piece,
::-webkit-scrollbar-corner {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(230, 237, 243, .14);
  background-clip: content-box;
  border: 3px solid transparent;
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(230, 237, 243, .28); background-clip: content-box; }
::-webkit-scrollbar-thumb:active { background: rgba(230, 237, 243, .38); background-clip: content-box; }
::-webkit-scrollbar-button { display: none; }

/* Firefox, which ignores the pseudo-elements above */
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: rgba(230, 237, 243, .22) transparent; }
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ───────── top bar ───────── */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark { color: var(--accent); font-size: 16px; }
.brand-name { font-weight: 650; letter-spacing: .2px; }
.brand-sub { color: var(--text-dim); font-size: 11px; }

.topbar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

.btn {
  appearance: none;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.btn:hover { background: #1d242e; border-color: #37404e; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn-danger { color: #ffb3ae; border-color: #4a2725; }
.btn-danger:hover { background: #33201f; border-color: #6b3733; }
.btn-row { display: flex; gap: 6px; margin-top: 14px; }
.btn-row .btn { flex: 1; }

/* ───────── layout ───────── */
.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 232px 1fr 252px;
}

.panel {
  background: var(--panel);
  padding: 14px;
  overflow-y: auto;
}
.panel-left { border-right: 1px solid var(--line); }
.panel-right { border-left: 1px solid var(--line); }

.panel-title {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: .9px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.group-title {
  margin: 18px 0 8px;
  font-size: 11px;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--text-dim);
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
}
.hint { margin: 0 0 12px; color: var(--text-dim); font-size: 11.5px; }
.empty { color: var(--text-dim); font-size: 12px; line-height: 1.7; }

/* ───────── palette ───────── */
.palette { display: flex; flex-direction: column; gap: 5px; }
.palette.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 5px;
}
.p-item.compact {
  height: 28px;
  justify-content: center;
  padding: 0 4px;
}
.p-item.compact .p-u { flex: 0 0 auto; color: var(--text); }

.p-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 5px;
  background: var(--bg-2);
  cursor: grab;
  user-select: none;
  touch-action: none;
  white-space: nowrap;
  overflow: hidden;
}
.p-item:hover { background: #1d242e; border-color: #37404e; }
.p-item:active { cursor: grabbing; }
.p-item .p-u {
  flex: 0 0 26px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  font-size: 11px;
  color: var(--text-dim);
}
.p-item .p-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; }

/* ───────── fields ───────── */
.field { display: block; margin-bottom: 10px; }
.field > span {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.field input[type="text"],
.field input[type="number"],
.field select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 6px 8px;
  font: inherit;
  font-size: 12px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.field-row { display: flex; align-items: center; gap: 8px; }
.field-row > span { margin: 0; font-size: 12px; color: var(--text); }
.field-row input { width: auto; }

.dual { display: flex; gap: 6px; }
.dual input { min-width: 0; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 20px; height: 20px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.swatch[aria-pressed="true"] { border-color: #fff; }

.btn-accent { border-color: #2c4f8f; background: #1b2a44; color: #d7e6ff; }
.btn-accent:hover { background: #22355a; border-color: #3a63ad; }

.stats { color: var(--text-dim); font-size: 12px; }
.rack-stats { margin-top: 10px; border-top: 1px solid var(--line-soft); padding-top: 8px; }
.rack-stat {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 8px;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.rack-stat:hover { background: var(--bg-2); }
.rack-stat.is-active { background: var(--bg-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.rack-stat > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rack-stat > em {
  grid-column: 1 / -1;
  font-style: normal;
  font-size: 10.5px;
  color: #75828f;
}
.rack-stat.over > em { color: #ffb3ae; }
.rack-stat.over > b::after { content: ' ⚠'; }
.stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.stats .bar {
  height: 6px;
  border-radius: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  overflow: hidden;
  margin: 8px 0 10px;
}
.stats .bar > i { display: block; height: 100%; background: var(--accent); }
.stats .bar > i.over { background: var(--danger); }
.power-line { margin: 2px 0 0; }
.power-line.over { color: #ffb3ae; }
.power-line.over b { color: #ffb3ae; }

/* ───────── stage + rack ───────── */
.stage {
  min-width: 0;
  overflow: auto;
  padding: 28px;
  cursor: grab;                     /* dragging the empty canvas pans */
  background:
    radial-gradient(1200px 500px at 50% -10%, #131922 0%, var(--bg) 70%);
}
.stage.panning { cursor: grabbing; }

/* Cabinets are absolutely positioned on a grid inside a sized canvas. Centring is done
   in sizeCanvas() by setting margin-left to the available slack. Neither flexbox
   `justify-content: center` nor `margin: 0 auto` works here: both centre the overflow
   once the content is wider than the stage, putting its left edge out of scroll range. */
.canvas {
  position: relative;
  margin: 0;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,.045) 1px, transparent 0);
  background-size: var(--grid) var(--grid);
}

.rack {
  position: absolute;
  width: calc(var(--rack-w) + 68px);
  cursor: default;
  background: var(--metal);
  border: 1px solid #313a47;
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
}
.rack.active {
  border-color: #3b5c98;
  box-shadow: 0 0 0 1px #3b5c98, 0 18px 50px rgba(0,0,0,.5);
}
.rack.active .rack-head { box-shadow: inset 3px 0 0 var(--accent); padding-left: 10px; }
.rack.active .rack-head-name { color: var(--text); }
.rack:not(.active) .rack-head-name { color: #b7c2d0; }

/* "add another cabinet" tile, parked right of the last cabinet */
.add-tile {
  position: absolute;
  width: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  color: var(--text-dim);
  border: 1px dashed #38414f;
  border-radius: 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.add-tile:hover { border-color: var(--accent); color: var(--text); background: rgba(76,141,255,.06); }
.add-plus { font-size: 24px; line-height: 1; }

.rack-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 6px 10px;
  cursor: move;                     /* the cabinet's drag handle */
  touch-action: none;
  user-select: none;
}
.rack.dragging-cab {
  opacity: .92;
  z-index: 50;
  box-shadow: 0 0 0 1px var(--accent), 0 26px 60px rgba(0,0,0,.6);
}
.rack.dragging-cab.invalid-cab {
  box-shadow: 0 0 0 1px var(--danger), 0 26px 60px rgba(0,0,0,.6);
}
.rack-head-name { font-weight: 650; font-size: 14px; outline: none; }
.rack-head-name[contenteditable="true"] {
  background: #0b0e13;
  box-shadow: 0 0 0 1px var(--accent);
  border-radius: 3px;
  padding: 0 3px;
  cursor: text;
}
.rack-head-meta { color: var(--text-dim); font-size: 11px; font-variant-numeric: tabular-nums; }
.rack-foot {
  padding: 8px 6px 2px;
  color: var(--text-dim);
  font-size: 10.5px;
  text-align: right;
}
.rack-foot.over { color: #ffb3ae; }

.rack-body {
  display: grid;
  grid-template-columns: 30px 1fr 30px;
  background: #0b0e13;
  border: 1px solid #313a47;
  border-radius: 6px;
  padding: 6px;
  gap: 4px;
}

.rail {
  position: relative;
  background: linear-gradient(#1b2129, #141a21);
  border: 1px solid #2b333f;
  border-radius: 4px;
}
.rail .u-num {
  position: absolute;
  left: 0; right: 0;
  height: var(--uh);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  color: #5d6b7c;
  border-bottom: 1px dotted #232b35;
  user-select: none;
}
.rail .u-num:first-child { border-bottom: none; }

.slots {
  position: relative;
  background-color: #0f141a;
  background-image: repeating-linear-gradient(
    to top,
    #1a212a 0, #1a212a 1px,
    transparent 1px, transparent var(--uh)
  );
  border: 1px solid #2b333f;
  border-radius: 4px;
  touch-action: none;
}
.slots.drop-active { box-shadow: inset 0 0 0 1px var(--accent); }

.placement {
  position: absolute;
  left: 2px; right: 2px;
  border-radius: 4px;
  border: 1px dashed var(--accent);
  background: rgba(76,141,255,.14);
  pointer-events: none;
  z-index: 5;
}
.placement.invalid {
  border-color: var(--danger);
  background: rgba(229,83,75,.16);
}

/* ───────── devices ───────── */
.device {
  position: absolute;
  left: 2px; right: 2px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,.14);
  border-left: 4px solid var(--dev);
  background: linear-gradient(#222a35, #1a212a);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 7px;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.device:hover { background: linear-gradient(#27303d, #1e2631); }
.device.selected {
  border-color: var(--accent);
  border-left-color: var(--dev);
  box-shadow: 0 0 0 1px var(--accent), 0 6px 18px rgba(0,0,0,.45);
  z-index: 4;
}
.device.dragging { opacity: .28; }

.device .dev-face {
  flex: 0 0 auto;
  align-self: stretch;
  width: 58px;
  margin: 4px 0;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,.08);
  background: #12171e;
}
.device.t-server .dev-face {
  background-image: repeating-linear-gradient(to bottom, rgba(255,255,255,.10) 0 2px, transparent 2px 6px);
}
.device.t-switch .dev-face,
.device.t-firewall .dev-face {
  background-image: repeating-linear-gradient(to right, rgba(255,255,255,.13) 0 3px, transparent 3px 7px);
}
.device[data-u="1"] .dev-face { margin: 3px 0; }

.device .dev-text { min-width: 0; flex: 1 1 auto; }
.device .dev-label {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  outline: none;
}
.device .dev-label[contenteditable="true"] {
  background: #0b0e13;
  box-shadow: 0 0 0 1px var(--accent);
  border-radius: 3px;
  padding: 0 3px;
  cursor: text;
  text-overflow: clip;
}
.device .dev-sub {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.device[data-u="1"] .dev-sub { display: none; }

.device .dev-tag {
  flex: 0 0 auto;
  font-size: 9.5px;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--text-dim);
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 3px;
  padding: 1px 5px;
}
.device[data-u="1"] .dev-tag { display: none; }

.device .dev-led {
  flex: 0 0 auto;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--dev);
  box-shadow: 0 0 6px var(--dev);
}

/* drag ghost that follows the cursor */
.drag-ghost {
  position: fixed;
  z-index: 999;
  pointer-events: none;
  opacity: .9;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,.2);
  border-left: 4px solid var(--dev);
  background: linear-gradient(#2a3240, #1d242e);
  box-shadow: 0 10px 30px rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
}

/* ───────── preview mode: cabinets only ───────── */
body.preview .topbar,
body.preview .panel { display: none; }
body.preview .layout { grid-template-columns: 1fr; }
body.preview .stage { padding: 34px; }
body.preview .add-tile { display: none; }
body.preview .canvas { background-image: none; }
body.preview .rack-head { cursor: default; }

/* nothing is selectable or editable, so drop every affordance that implies otherwise */
body.preview .rack.active { border-color: #313a47; box-shadow: 0 18px 50px rgba(0,0,0,.5); }
body.preview .rack.active .rack-head { box-shadow: none; padding-left: 6px; }
body.preview .rack:not(.active) .rack-head-name { color: var(--text); }
body.preview .device { cursor: default; }
body.preview .device:hover { background: linear-gradient(#222a35, #1a212a); }

.exit-preview {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 500;
  background: var(--panel);
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
  opacity: .35;
  transition: opacity .15s ease;
}
.exit-preview:hover { opacity: 1; color: var(--text); border-color: #37404e; }

/* ───────── share dialog ───────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(6, 9, 13, .66);
}
.modal[hidden] { display: none; }

.modal-card {
  width: 100%;
  max-width: 560px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px 18px;
  box-shadow: 0 30px 70px rgba(0,0,0,.6);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-head h2 { margin: 0; font-size: 14px; font-weight: 650; }
.modal-x {
  background: none;
  border: 0;
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.modal-x:hover { color: var(--text); }

.modal-note { margin: 10px 0; color: var(--text-dim); font-size: 11.5px; line-height: 1.6; }
.modal-warn { color: #f5c07a; }

#shareUrl {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 8px 9px;
  font: 11.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-x: auto;
}
#shareUrl:focus { outline: none; border-color: var(--accent); }
.modal-card .field-row { margin: 12px 0 0; }

/* ───────── toast ───────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #1d242e;
  border: 1px solid #37404e;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  z-index: 1000;
}

@media (max-width: 1080px) {
  .layout { grid-template-columns: 190px 1fr 220px; }
  :root { --rack-w: 290px; }
}
