/* racks3d — NOC-style dark UI */
:root {
  --bg: #0a0b1a;
  --panel: rgba(16, 17, 40, .88);
  --panel-raised: rgba(30, 30, 200, .12);
  --border: rgba(200, 200, 200, .16);
  --text: #eceaf4;
  --muted: #a3a6bd;
  --accent: #009bff;
  --hover: #ffb600;
  --brand: #1e1ec8;
  --sand: #e6dcb9;
  --new: #ffb600;
  --pending: #ff4d5e;
  --free: #3ddc84;
  --copper: #2f9bff;
  --mm: #9be22d;
  --sm: #ffd23f;
  --pdu: #ff8a1f;
  --door: #b07cff;
  --active: #ff5fd2;
  --radius: 12px;
  --top: 86px;
  --font: Aptos, "Segoe UI Variable", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
kbd {
  font: 11px var(--font);
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .05);
}
[hidden] { display: none !important; }

#stage, #labels { position: fixed; inset: 0; }
#stage canvas { display: block; outline: none; }
#labels { pointer-events: none; }
#labels > div { pointer-events: none; }

.glass {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

/* ---------- top bar */
#topbar {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 10px;
  right: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 8px 10px;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 170px; }
.brand b { font-size: 15px; letter-spacing: .02em; }
.brand small { display: block; color: var(--muted); font-size: 11px; }
.logo {
  width: 26px; height: 26px; border-radius: 7px;
  background:
    linear-gradient(#0000 0 30%, #fff3 30% 36%, #0000 36% 63%, #fff3 63% 69%, #0000 69%),
    linear-gradient(135deg, var(--brand), var(--accent));
  box-shadow: inset 0 0 0 1px #fff3;
}
.tools { display: flex; flex-wrap: wrap; gap: 4px; }
.tools button, .btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .04);
  border-radius: 8px;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.tools button:hover, .btn:hover { border-color: var(--hover); color: #fff; }
.tools button.on, .btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary { background: var(--brand); border-color: #4a4ae8; }
.btn:disabled { opacity: .45; cursor: default; }

.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  background: rgba(255, 255, 255, .03);
}
.seg button {
  border: 0;
  background: none;
  padding: 5px 11px;
  cursor: pointer;
  color: var(--muted);
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { color: #fff; }
.seg button.on { background: var(--accent); color: #fff; }

.pill {
  display: inline-block;
  min-width: 18px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  background: rgba(255, 255, 255, .1);
}
.pill:empty { display: none; }
.pill.warn { background: var(--new); color: #1a1300; font-weight: 700; }

#search { position: relative; margin-left: auto; flex: 0 1 300px; min-width: 200px; }
#q {
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, .3);
  outline: none;
}
#q:focus { border-color: var(--accent); }
#results {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: min(380px, 92vw);
  max-height: 60vh;
  overflow: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}
#results li { padding: 6px 8px; border-radius: 7px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
#results li small { color: var(--muted); margin-left: auto; text-align: right; }
#results li.on, #results li:hover { background: var(--panel-raised); outline: 1px solid var(--accent); }
#results li.empty { cursor: default; color: var(--muted); }

/* ---------- badges */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  background: var(--brand);
  color: #fff;
  vertical-align: middle;
}
.badge.new { background: var(--new); color: #1a1300; }
.badge.pending { background: var(--pending); }
.badge.free { background: var(--free); color: #04210f; }
.badge.mute { background: rgba(255, 255, 255, .12); color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* ---------- layers */
#layers {
  position: fixed;
  left: 10px;
  top: var(--top);
  width: 238px;
  max-height: calc(100vh - var(--top) - 60px);
  overflow: auto;
  z-index: 10;
  padding: 4px 6px 6px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 6px 4px;
  border: 0;
  background: none;
  font-weight: 600;
  cursor: pointer;
}
.chev::after { content: "▾"; color: var(--muted); }
#layers.collapsed .chev::after { content: "▸"; }
#layers.collapsed #layerList { display: none; }
.layer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}
.layer:hover { background: var(--panel-raised); }
.layer input { accent-color: var(--accent); margin: 0; }
.layer .count { margin-left: auto; color: var(--muted); font-size: 11px; }
.layer-group { margin: 6px 4px 2px; color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }

/* ---------- info card */
#card {
  position: fixed;
  top: var(--top);
  right: 10px;
  width: 320px;
  max-height: calc(100vh - var(--top) - 76px);
  overflow: auto;
  padding: 12px 14px 12px;
  z-index: 40;
}
#card h3 { margin: 6px 0 8px; font-size: 15px; line-height: 1.25; padding-right: 22px; }
#card table { width: 100%; border-collapse: collapse; }
#card td { padding: 3px 0; vertical-align: top; border-bottom: 1px solid rgba(255, 255, 255, .05); }
#card td:first-child { color: var(--muted); width: 38%; padding-right: 8px; }
#card .src { margin: 10px 0 0; color: var(--muted); font-style: italic; font-size: 11px; }
#card .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
#card h4 { margin: 12px 0 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .04);
  cursor: pointer;
  line-height: 1;
}
.close:hover { border-color: var(--hover); }
.cables { list-style: none; margin: 0; padding: 0; }
.cables li {
  display: flex;
  gap: 7px;
  align-items: center;
  padding: 3px 4px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.cables li:hover { background: var(--panel-raised); }
.cables li span:nth-child(2) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cables li small { color: var(--muted); }
.steps { margin: 4px 0 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { position: relative; padding: 3px 0 3px 26px; counter-increment: s; }
.steps li::before {
  content: counter(s);
  position: absolute; left: 0; top: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  font-size: 10px; text-align: center; line-height: 16px;
}
.steps li.link { padding: 0 0 0 26px; color: var(--muted); font-size: 11px; counter-increment: none; }
.steps li.link::before { content: "│"; border: 0; background: none; color: var(--hover); }

/* ---------- rack elevation */
#elev {
  position: fixed;
  left: 10px;
  top: var(--top);
  width: 260px;
  max-height: calc(100vh - var(--top) - 76px);
  overflow: auto;
  z-index: 11;
  padding: 10px;
}
#elev h3 { margin: 0 0 2px; font-size: 14px; }
#elev .sub { color: var(--muted); font-size: 11px; margin-bottom: 8px; }
.elev-list { list-style: none; margin: 0; padding: 0; font-size: 11.5px; }
.elev-list li {
  display: grid;
  grid-template-columns: 54px 10px 1fr;
  gap: 6px;
  align-items: center;
  padding: 2px 4px;
  border-radius: 5px;
  cursor: pointer;
}
.elev-list li:hover { background: var(--panel-raised); }
.elev-list li.sel { background: rgba(255, 182, 0, .16); outline: 1px solid var(--hover); }
.elev-list li .u { color: var(--muted); font-variant-numeric: tabular-nums; }
.elev-list li .sw { width: 10px; height: 10px; border-radius: 2px; }
.elev-list li.gap { color: var(--free); cursor: default; }
.elev-list li.gap .sw { border: 1px dashed var(--free); }
.elev-list li.new { color: var(--new); }

/* ---------- mode bar & placard */
#modebar {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px;
  z-index: 15;
  max-width: calc(100vw - 20px);
}
#modebar .title { font-weight: 600; margin-right: 4px; }
#modebar .muted { color: var(--muted); font-size: 12px; }
#modebar input[type=range] { width: min(320px, 60vw); accent-color: var(--accent); }
.footer-racks { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; justify-content: center; }
.footer-racks div {
  min-width: 74px;
  padding: 3px 6px;
  border-radius: 7px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--border);
  font-size: 11px;
  cursor: pointer;
}
.footer-racks div:hover { border-color: var(--hover); }
.footer-racks b { display: block; font-size: 11px; }
.mini-bar { height: 4px; border-radius: 2px; background: rgba(61, 220, 132, .35); margin-top: 3px; overflow: hidden; }
.mini-bar span { display: block; height: 100%; background: var(--accent); }

#placard {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(460px, calc(100vw - 20px));
  padding: 12px 14px;
  z-index: 14;
}
#placard h3 { margin: 4px 0 6px; font-size: 16px; }
#placard .kv { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 6px 0; }
#placard .kv div { background: rgba(255, 255, 255, .04); border-radius: 8px; padding: 6px; text-align: center; }
#placard .kv b { display: block; font-size: 16px; }
#placard .kv small { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
#placard ul { margin: 4px 0 0; padding-left: 16px; color: var(--muted); font-size: 12px; }

#tooltip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  padding: 5px 8px;
  border-radius: 7px;
  background: rgba(8, 9, 24, .94);
  border: 1px solid var(--hover);
  font-size: 12px;
  max-width: 320px;
}
#hint {
  position: fixed;
  left: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  color: var(--muted);
  font-size: 11px;
  z-index: 5;
  pointer-events: none;
}

/* ---------- 3D labels */
.rack-label {
  text-align: center;
  font-size: 11px;
  line-height: 1.15;
  color: var(--text);
  text-shadow: 0 1px 3px #000;
  white-space: nowrap;
}
.rack-label b { display: block; font-size: 12px; }
.rack-label small { color: var(--muted); font-size: 10px; }
.rack-label .tag { color: var(--new); font-weight: 700; }
.u-label { font-size: 9px; color: var(--muted); font-variant-numeric: tabular-nums; text-shadow: 0 1px 2px #000; }
.item-label {
  font-size: 10px;
  color: var(--text);
  white-space: nowrap;
  padding: 0 4px;
  border-left: 2px solid var(--accent);
  background: rgba(10, 11, 26, .7);
  transform: translateX(50%);
}
.item-label.new { border-color: var(--new); color: var(--new); }
.gap-label {
  font-size: 10px;
  color: var(--free);
  white-space: nowrap;
  padding: 1px 5px;
  border: 1px dashed var(--free);
  border-radius: 4px;
  background: rgba(10, 11, 26, .7);
}
.wall-label { font-size: 11px; color: var(--muted); white-space: nowrap; text-shadow: 0 1px 2px #000; }
.portal-label { font-size: 13px; font-weight: 700; color: var(--accent); white-space: nowrap; text-shadow: 0 0 8px rgba(0, 155, 255, .6); }
.dim-label {
  font-size: 11px;
  color: var(--sand);
  white-space: nowrap;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(10, 11, 26, .75);
  border: 1px solid rgba(230, 220, 185, .4);
}

/* ---------- modal */
#modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(4, 5, 14, .55);
  padding: 16px;
}
.modal-body {
  position: relative;
  width: min(980px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 16px 18px;
}
.modal-body h2 { margin: 0 0 4px; font-size: 18px; }
.modal-body .sub { color: var(--muted); margin: 0 0 14px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 14px; }
.kpi { padding: 10px 12px; border-radius: 10px; background: var(--panel-raised); border: 1px solid var(--border); }
.kpi b { display: block; font-size: 22px; }
.kpi small { color: var(--muted); }
.kpi.warn b { color: var(--new); }
.kpi.bad b { color: var(--pending); }
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 12px; }
table.grid th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.grid td { padding: 6px 8px; border-bottom: 1px solid rgba(255, 255, 255, .05); vertical-align: middle; }
table.grid tr:hover td { background: rgba(255, 255, 255, .02); }
.bar {
  position: relative;
  height: 10px;
  min-width: 120px;
  border-radius: 5px;
  background: rgba(255, 255, 255, .07);
  overflow: visible;
}
.bar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; }
.bar .newcap { position: absolute; top: 0; bottom: 0; border: 1px dashed var(--new); border-left: 0; border-radius: 0 5px 5px 0; }
.bar .mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: #fff; border-radius: 1px; box-shadow: 0 0 4px #000; }
.bar-cell { display: flex; gap: 8px; align-items: center; }
.bar-cell small { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 48px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: 11px; margin: 10px 0 0; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.notes { list-style: none; margin: 0; padding: 0; }
.notes li { display: flex; gap: 10px; padding: 9px 10px; border-radius: 9px; margin-bottom: 6px; background: rgba(255, 255, 255, .03); border: 1px solid var(--border); }
.notes li .ico { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.notes li.warn .ico { background: var(--new); color: #1a1300; }
.notes li.bad .ico { background: var(--pending); }
.notes li.info .ico { background: var(--accent); }
.notes li small { display: block; color: var(--muted); }

/* racks menu (mini plan) */
.plan { display: flex; flex-direction: column; gap: 6px; }
.plan-row { display: flex; gap: 10px; align-items: stretch; }
.plan-row .rowname { width: 70px; flex: none; display: flex; flex-direction: column; justify-content: center; gap: 4px; color: var(--muted); font-size: 11px; }
.plan-cells { display: flex; gap: 3px; flex: 1; min-width: 0; }
.plan-cell {
  flex: 6 1 0;
  min-width: 0;
  padding: 6px 6px 5px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .04);
  cursor: pointer;
  overflow: hidden;
}
.plan-cell.w800 { flex-grow: 8; }
.plan-cell.star { box-shadow: inset 0 3px 0 var(--accent); }
.plan-cell:hover { border-color: var(--hover); background: rgba(255, 182, 0, .08); }
.plan-cell b { display: block; font-size: 12px; }
.plan-cell small { display: block; color: var(--muted); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plan-cell .newn { color: var(--new); font-weight: 700; font-size: 10.5px; }
.aisle-strip { margin-left: 80px; padding: 3px 8px; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; border-radius: 6px; }
.aisle-strip.cold { color: #8fc4ff; background: rgba(30, 107, 255, .12); }
.aisle-strip.hot { color: #ff9f9f; background: rgba(255, 59, 59, .1); }

/* ---------- studio */
#studio { position: fixed; inset: 0; z-index: 30; pointer-events: none; }
#studio > * { pointer-events: auto; }
#studioLabels { position: absolute; inset: 0; pointer-events: none !important; }
#studioLabels * { pointer-events: none; }
.studio-bar {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 8px 44px 8px 12px;
  max-width: calc(100vw - 20px);
}
.studio-hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); color: var(--muted); font-size: 12px; text-align: center; }

.fatal { position: fixed; inset: 0; display: grid; place-items: center; color: var(--pending); }

/* ---------- narrow screens: panels dock at the bottom */
@media (max-width: 760px) {
  #topbar { gap: 6px; }
  .brand { min-width: 0; }
  .brand small { display: none; }
  #search { flex: 1 1 100%; order: 5; }
  #layers {
    top: auto;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-width: calc(100vw - 20px);
    max-height: 40vh;
  }
  #layers:not(.collapsed) { right: 10px; z-index: 16; }
  #card, #elev {
    top: auto;
    left: 10px;
    right: 10px;
    width: auto;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    max-height: 42vh;
  }
  #elev { max-height: 30vh; }
  #modebar { bottom: auto; top: var(--top); }
  #placard { bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  #placard .kv { grid-template-columns: repeat(2, 1fr); }
  #hint { display: none; }
  .plan-row { flex-direction: column; gap: 4px; }
  .plan-row .rowname { width: auto; flex-direction: row; }
  .plan-cells { flex-wrap: wrap; }
  .plan-cell { flex: 1 1 70px; }
  .aisle-strip { margin-left: 0; }
}
