:root {
  --bg: #090C0B;
  --surface: #101512;
  --surface-2: #161D19;
  --border: #1F2823;
  --text: #D6E0DA;
  --text-2: #8C988F;
  --comment: #5B665E;
  --accent: #35F0A0;
  --accent-ink: #04140C;
  --accent-soft: rgba(53, 240, 160, 0.12);
  --cyan: #5BE3D4;
  --amber: #F4C56B;
  --orange: #FF9E63;
  --red: #FF6B6B;
  --radius: 9px;
  --mono: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--mono);
  background-image:
    linear-gradient(rgba(53, 240, 160, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(53, 240, 160, 0.02) 1px, transparent 1px);
  background-size: 24px 24px;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }

#app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar .prompt { color: var(--accent); }
.topbar .sep { color: var(--comment); }
.topbar .muted { color: var(--text-2); }
.topbar .spacer { flex: 1; }

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  transition: box-shadow .12s, border-color .12s, color .12s;
}
.btn:hover { color: var(--accent); border-color: var(--accent); }
.btn:focus-visible, .btn.active {
  outline: none;
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 20px var(--accent);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { box-shadow: 0 0 20px var(--accent); }

main { display: grid; grid-template-columns: 1fr 360px; flex: 1; min-height: 0; }
#scene { position: relative; min-height: 0; background: var(--bg); }
#scene canvas { display: block; width: 100% !important; height: 100% !important; }

.sidebar {
  border-left: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column; gap: 14px;
}
.panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.panel h2 {
  font-size: 12px; font-weight: 600;
  margin: 0 0 8px; color: var(--text-2);
  text-transform: lowercase; letter-spacing: 0.04em;
}
.prefix { color: var(--accent); margin-right: 6px; }
.muted { color: var(--text-2); }
.small { font-size: 11px; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.list li {
  padding: 6px 8px; border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  color: var(--text);
}
.list li:hover { border-color: var(--border); background: var(--surface); }
.list li.active { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 12px var(--accent-soft); }
.list .meta { color: var(--comment); margin-left: auto; font-size: 11px; }
.list .swatch { width: 10px; height: 10px; border-radius: 2px; background: var(--accent); flex-shrink: 0; }

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.legend li { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.avail { background: var(--accent); }
.dot.borrowed { background: var(--amber); }
.dot.used { background: var(--cyan); }
.dot.consumed { background: var(--comment); }

#selection-detail .kv { display: grid; grid-template-columns: 90px 1fr; gap: 4px 10px; font-size: 12px; }
#selection-detail .kv dt { color: var(--text-2); }
#selection-detail .kv dd { margin: 0; word-break: break-word; }
#selection-detail h3 { margin: 0 0 6px; color: var(--accent); font-size: 13px; }
#selection-detail .actions { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
#selection-detail pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 8px; font-size: 11px; color: var(--text-2);
  max-height: 160px; overflow: auto; white-space: pre-wrap;
}

dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 18px 20px;
  min-width: 360px;
  box-shadow: 0 0 30px var(--accent-soft);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
dialog h2 { margin: 0 0 14px; font-size: 14px; color: var(--accent); }
dialog form { display: flex; flex-direction: column; gap: 10px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--text-2); }
dialog input {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 6px 8px;
}
dialog input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 12px var(--accent-soft); }
dialog .row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 8px 0 0; padding: 0; }

.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 8px 14px; color: var(--accent);
  box-shadow: 0 0 20px var(--accent-soft);
  z-index: 1000;
}
.toast.err { border-color: var(--red); color: var(--red); box-shadow: 0 0 20px rgba(255, 107, 107, 0.25); }

.badge {
  font-size: 10px; padding: 1px 6px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-2);
}
.badge.unplaced { border-color: var(--amber); color: var(--amber); }
.badge.box { border-color: var(--cyan); color: var(--cyan); }
.badge.item { border-color: var(--accent); color: var(--accent); }

.help-overlay {
  position: absolute; bottom: 10px; left: 10px;
  background: rgba(16, 21, 18, 0.85);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; color: var(--text-2); font-size: 11px;
  pointer-events: none;
}
.help-overlay b { color: var(--accent); }

/* ---- floor plan view ---- */
#plan {
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.plan-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.plan-toolbar .sep { color: var(--comment); }
.plan-toolbar .spacer { flex: 1; }
.plan-toolbar .btn { padding: 4px 10px; }
.plan-canvas-wrap { position: relative; flex: 1; min-height: 0; }
#plan-canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.plan-help {
  position: absolute; bottom: 10px; left: 10px;
  background: rgba(16, 21, 18, 0.85);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; color: var(--text-2); font-size: 11px;
  pointer-events: none; max-width: 70%;
}
.plan-help b { color: var(--accent); }
