:root {
  --bg: #0f1115; --panel: #171a21; --panel-2: #1e222b; --line: #2b303b;
  --text: #e6e9ef; --muted: #939bab; --accent: #4c9aff; --warn: #ffb74d;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; font: 13px/1.45 "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden;
}

/* ---- canvas stage ---- */
#stage { flex: 1; position: relative; min-width: 0; }
canvas { display: block; width: 100%; height: 100%; }
#hint, #scalebar, #busy, #empty {
  position: absolute; padding: 6px 10px; background: rgba(0,0,0,.72);
  border: 1px solid var(--line); border-radius: 6px; color: var(--muted);
  pointer-events: none;
}
#hint { left: 12px; bottom: 12px; max-width: 66%; }
#scalebar { right: 14px; bottom: 14px; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
#busy, #empty {
  left: 50%; top: 50%; transform: translate(-50%,-50%);
  color: var(--text); font-size: 14px; padding: 14px 22px; text-align: center;
}
#drop {
  position: absolute; inset: 0; border: 2px dashed var(--accent);
  background: rgba(76,154,255,.08); display: flex; align-items: center;
  justify-content: center; font-size: 16px; pointer-events: none;
}
/* An id rule with display beats the UA [hidden] rule, so restate it. */
#drop[hidden], #busy[hidden], #empty[hidden] { display: none; }

/* ---- sidebar ---- */
aside {
  width: 336px; background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 14px; flex-shrink: 0;
}
h1 { font-size: 15px; margin: 0 0 2px; }
h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 18px 0 8px; border-bottom: 1px solid var(--line);
  padding-bottom: 5px; display: flex; justify-content: space-between; align-items: center;
}
.sub { color: var(--muted); margin: 0 0 4px; font-size: 12px; }
label { display: block; margin: 8px 0 3px; color: var(--muted); font-size: 12px; }
select {
  width: 100%; padding: 6px 8px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 5px; font: inherit;
}
code {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 3px;
  padding: 0 3px; font-size: 10.5px;
}
input[type=text], input[type=number], input[type=password] {
  width: 100%; padding: 6px 8px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 5px; font: inherit;
}
input[type=range] { width: 100%; }
button {
  padding: 7px 10px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 5px; cursor: pointer; font: inherit;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #07203f; font-weight: 600; }
button.on { border-color: var(--accent); color: var(--accent); }
button.mini { padding: 3px 7px; font-size: 11px; }
.row { display: flex; gap: 6px; }
.row > * { flex: 1; }
.check { display: flex; align-items: center; gap: 7px; margin: 7px 0; color: var(--muted); }
.check input { width: auto; }
.note { color: var(--muted); font-size: 11px; margin-top: 6px; }
.note.warn { color: var(--warn); }
.mut { color: var(--muted); }
.empty { color: var(--muted); font-style: italic; padding: 6px 2px; font-size: 12px; }

/* ---- floors ---- */
.floor {
  display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 5px;
  margin-bottom: 4px; cursor: pointer;
}
.floor:hover { border-color: #3d4557; }
.floor.sel { border-color: var(--accent); background: var(--panel-2); }
.floor .fname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.floor .fmeta { color: var(--muted); font-size: 11px; }
.floor .x {
  padding: 0 5px; background: none; border: none; color: var(--muted); font-size: 12px;
}
.floor .x:hover { color: #ff7043; }

/* ---- lists & tables ---- */
table { width: 100%; border-collapse: collapse; margin-top: 6px; }
td { padding: 4px 2px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
td:last-child { text-align: right; font-weight: 600; }
.sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 7px; }
#camlist div {
  padding: 5px 7px; border: 1px solid var(--line); border-radius: 5px;
  margin-bottom: 4px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px;
}
#camlist div.sel { border-color: var(--accent); background: var(--panel-2); }
#camlist b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#camlist span { color: var(--muted); flex-shrink: 0; }

#layers { max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 5px; }
#layers table { margin: 0; }
#layers td { padding: 3px 5px; font-size: 11px; }
#layers td.nm { color: var(--text); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 400; text-align: left; }
#layers td.ct { text-align: right; color: var(--muted); font-weight: 400; }
#layers th { font-size: 10px; color: var(--muted); font-weight: 500; padding: 4px; position: sticky; top: 0; background: var(--panel); }
#layers th.l { text-align: left; }
#layers input { cursor: pointer; }

/* ---- camera library ---- */
#libSearch { margin-bottom: 8px; }
#palette { display: grid; grid-template-columns: 1fr; gap: 5px; max-height: 300px; overflow-y: auto; }
.cam-chip {
  display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px;
  padding: 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2);
  cursor: grab; user-select: none;
}
.cam-chip:hover { border-color: var(--accent); }
.cam-chip.armed { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.cam-chip:active { cursor: grabbing; }
.cam-chip .glyph { width: 26px; height: 18px; fill: var(--accent); }
.cam-chip .cc-body { min-width: 0; }
.cam-chip b { display: block; font-size: 11.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cam-chip span { display: block; color: var(--muted); font-size: 10.5px; }
.cc-edit {
  padding: 2px 6px; background: none; border: none; color: var(--muted); font-size: 12px;
}
.cc-edit:hover { color: var(--accent); }

/* ---- model editor dialog ---- */
#editor {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 24px;
}
#editor[hidden] { display: none; }
#editor .dlg {
  width: min(760px, 100%); max-height: 100%; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column;
  box-shadow: 0 18px 60px rgba(0,0,0,.55);
}
#editor header, #editor footer,
#users header, #users footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); flex-shrink: 0;
}
#editor footer, #users footer { border-bottom: none; border-top: 1px solid var(--line); }
#users header h3, #editor header h3 { margin: 0; font-size: 15px; }
#users footer .row { width: 100%; }
#editor footer .row { flex: 0 0 auto; width: auto; }
#editor footer .row > button { flex: 0 0 auto; }
#editor h3 { margin: 0; font-size: 15px; }
#editor h4 {
  margin: 16px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--accent); border-bottom: 1px solid var(--line); padding-bottom: 4px;
}
#editor h4:first-child { margin-top: 0; }
#edForm { padding: 14px 16px; overflow-y: auto; }
#edForm .g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
#edForm .g2 > div { min-width: 0; }
#edPreview { margin: 0; flex: 1; }
#edPreview b { color: var(--text); }

/* ---- account bar ---- */
#account {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 0 2px; border-bottom: 1px solid var(--line); margin-bottom: 4px;
}
#whoami { font-weight: 600; margin-right: auto; }
.badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  padding: 2px 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted);
}
.badge.admin { color: var(--accent); border-color: var(--accent); }
.badge.viewer { color: var(--warn); border-color: var(--warn); }

/* Read-only accounts: the canvas is for looking at, not dragging cameras. */
body.viewer .cam-chip { cursor: default; }
body.viewer .cc-edit { display: none; }
body.viewer .floor .x { display: none; }

/* ---- sign-in ---- */
#login {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
#login[hidden] { display: none; }
#login .card {
  width: min(340px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 22px; box-shadow: 0 18px 60px rgba(0,0,0,.5);
}
#login h3 { margin: 0 0 2px; font-size: 16px; }
#login .sub { margin-bottom: 14px; }

/* ---- accounts dialog ---- */
#users {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
#users[hidden] { display: none; }
#users .dlg {
  width: min(660px, 100%); max-height: 100%; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column;
}
#usersBody { padding: 14px 16px; overflow-y: auto; }
#usersBody td, #usersBody th { font-size: 12px; padding: 5px 6px; }
#usersBody td.l, #usersBody th.l { text-align: left; font-weight: 400; }
#usersBody th { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }

/* ---- layer identify ---- */
#layerTip {
  position: absolute; z-index: 5; pointer-events: none;
  background: rgba(12,14,18,.94); border: 1px solid var(--accent);
  border-radius: 6px; padding: 6px 9px; max-width: 280px;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
}
#layerTip[hidden] { display: none; }
#layerTip b { display: block; font-size: 12px; }
#layerTip span { display: block; color: var(--muted); font-size: 11px; }
#layerTip span.k { color: #6c7484; margin-top: 3px; }
#layers tr.hot { background: rgba(76,154,255,.16); }
#layers tr.hot td.nm { color: var(--accent); }
#layers tr.hot td { background: rgba(76,154,255,.22); }
#layers tr.hot td.nm { color: #cfe2ff; font-weight: 600; }
