/* Room Layout Tool — UI chrome.
   Dark tool chrome around a light viewport, the way most CAD/3D tools sit. */

:root {
  --bg:            #14161a;
  --panel:         #1b1e24;
  --panel-2:       #212630;
  --panel-3:       #2a303b;
  --line:          #333a47;
  --line-soft:     #262c36;
  --text:          #e7eaf0;
  --text-dim:      #98a2b3;
  --text-faint:    #6b7482;
  --accent:        #4d8dff;
  --accent-soft:   #21324f;
  --warn:          #f0a53c;
  --danger:        #ef5f5f;
  --ok:            #4ec38a;
  --radius:        7px;
  --radius-sm:     5px;
  --topbar-h:      46px;
  --status-h:      26px;
  --sidebar-w:     288px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* Keyboard focus has to be visible on the chrome, not just in the fields. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 3px; }
button:focus-visible { outline-offset: 2px; }

/* Measurements are read in columns; keep the digits in their tracks. */
.status-stats, .oitem .sz, .lib-item .sz, .hud .chip,
input[type="number"] { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.topbar::-webkit-scrollbar { display: none; }

.brand { display: flex; align-items: center; gap: 8px; padding-right: 4px; flex: none; }
.brand-mark {
  width: 18px; height: 18px; border-radius: 5px;
  background: linear-gradient(140deg, var(--accent), #7f5bff);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.brand-name { font-weight: 620; letter-spacing: .2px; white-space: nowrap; }

.tb-group { display: flex; flex: none; background: var(--panel-2); border-radius: var(--radius); padding: 2px; gap: 2px; }
.tb-sep { width: 1px; height: 22px; background: var(--line); flex: none; }
.tb-spacer { flex: 1 1 auto; min-width: 4px; }

.tb-btn {
  appearance: none; border: 0; background: transparent; color: var(--text-dim);
  padding: 5px 9px; border-radius: var(--radius-sm); cursor: pointer;
  white-space: nowrap; font-size: 12px; font-weight: 500;
}
.tb-btn:hover { background: var(--panel-3); color: var(--text); }
.tb-btn.on { background: var(--accent); color: #fff; }
.tb-btn:disabled { opacity: .38; cursor: default; background: transparent; }
.tb-help { border-radius: 50%; width: 26px; height: 26px; padding: 0; background: var(--panel-2); flex: none; }

.tb-field { display: flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 12px; flex: none; }
.tb-field select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 4px 6px;
}

/* ---------------------------------------------------------------- layout */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--sidebar-w);
  height: calc(100vh - var(--topbar-h) - var(--status-h));
  height: calc(100dvh - var(--topbar-h) - var(--status-h));
}

.sidebar {
  background: var(--panel);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--panel-3) transparent;
}
.sidebar.left  { border-right: 1px solid var(--line); }
.sidebar.right { border-left: 1px solid var(--line); }
.sidebar::-webkit-scrollbar { width: 9px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 9px; border: 3px solid var(--panel); }

.stage { position: relative; min-width: 0; background: #0f1115; }
.viewport { position: absolute; inset: 0; }
.viewport canvas { display: block; touch-action: none; }

.mode-banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff; padding: 6px 14px; border-radius: 999px;
  font-size: 12px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.35);
  pointer-events: none; z-index: 5;
}

.hud {
  position: absolute; left: 10px; bottom: 10px;
  display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none;
}
.hud .chip {
  background: rgba(20,22,26,.82); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 10px; font-size: 11px; font-family: var(--mono);
  backdrop-filter: blur(6px);
}
.hud .chip.warn { border-color: var(--warn); color: var(--warn); }
.hud .chip.bad  { border-color: var(--danger); color: var(--danger); }

/* ---------------------------------------------------------------- panels */

.panel { border-bottom: 1px solid var(--line-soft); }
.panel > h2 {
  margin: 0; font-size: 11px; font-weight: 650; letter-spacing: .7px; text-transform: uppercase;
  color: var(--text-faint); padding: 11px 12px 7px;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.panel > h2 .count { font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--text-faint); }
.panel .body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 9px; }
.panel.collapsible > h2 { cursor: pointer; }
.panel.collapsible > h2::after { content: "▾"; color: var(--text-faint); font-size: 10px; }
.panel.collapsed > h2::after { content: "▸"; }
.panel.collapsed .body { display: none; }

.hint { color: var(--text-faint); font-size: 11.5px; line-height: 1.5; margin: 0; }
.hint code { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }

/* fields */

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label { font-size: 11px; color: var(--text-dim); }
.field .with-unit { position: relative; display: flex; align-items: center; }
.field .with-unit .unit {
  position: absolute; right: 8px; font-size: 10.5px; color: var(--text-faint); pointer-events: none;
}
input[type="text"], input[type="number"], select, textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 6px 8px; outline: none; min-width: 0;
}
input[type="number"] { padding-right: 26px; font-family: var(--mono); font-size: 12px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); background: #1a1f29; }
input[type="color"] {
  width: 100%; height: 30px; padding: 2px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; }

.row { display: grid; gap: 8px; }
.row.c2 { grid-template-columns: 1fr 1fr; }
.row.c3 { grid-template-columns: 1fr 1fr 1fr; }
.row.c4 { grid-template-columns: repeat(4, 1fr); }

.check { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-dim); cursor: pointer; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: var(--radius-sm); padding: 7px 10px; cursor: pointer; font-size: 12px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--panel-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger:hover { background: #3a2226; border-color: var(--danger); color: #ffb4b4; }
.btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.wide { width: 100%; }
.btn.sm { padding: 4px 7px; font-size: 11px; }
.btn:disabled { opacity: .4; cursor: default; }

.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

/* library */

.library { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.lib-item {
  display: flex; flex-direction: column; gap: 3px; align-items: flex-start;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; cursor: pointer; text-align: left; color: var(--text);
}
.lib-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.lib-item .ic { width: 100%; height: 30px; }
.lib-item .nm { font-size: 11.5px; font-weight: 550; line-height: 1.2; }
.lib-item .sz { font-size: 10px; color: var(--text-faint); font-family: var(--mono); }

/* library tiles carry an edit affordance and a "how many are placed" count */
.lib-item { position: relative; }
.lib-item .lib-edit {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; padding: 0;
  border: 0; border-radius: 5px; background: transparent; color: var(--text-faint);
  cursor: pointer; font-size: 11px; line-height: 1; opacity: 0; transition: opacity .12s ease;
}
.lib-item:hover .lib-edit, .lib-item .lib-edit:focus-visible { opacity: 1; }
.lib-item .lib-edit:hover { background: var(--panel-3); color: var(--text); }
.lib-item .lib-count {
  position: absolute; top: 5px; left: 5px; min-width: 15px; height: 15px; padding: 0 4px;
  border-radius: 8px; background: var(--accent); color: #fff; font-size: 9.5px; font-weight: 700;
  display: grid; place-items: center;
}

/* the banner on an object that follows a library item */
.linked {
  background: var(--accent-soft); border: 1px solid #35507d; border-radius: var(--radius);
  padding: 8px 9px; display: flex; flex-direction: column; gap: 6px; font-size: 11.5px;
  color: var(--text-dim);
}
.linked b { color: var(--text); }
.linked .hint { margin: 0; }
.hint.strong { color: var(--text-dim); }

@media (prefers-reduced-motion: reduce) {
  .lib-item .lib-edit { transition: none; }
}

/* object list */

.olist { display: flex; flex-direction: column; gap: 2px; }
.oitem {
  display: flex; align-items: center; gap: 7px; padding: 5px 7px; border-radius: var(--radius-sm);
  cursor: pointer; border: 1px solid transparent; min-width: 0;
}
.oitem:hover { background: var(--panel-2); }
.oitem.sel { background: var(--accent-soft); border-color: var(--accent); }
.oitem .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.35); }
.oitem .nm { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.oitem .sz { font-size: 10px; color: var(--text-faint); font-family: var(--mono); flex: none; }
.oitem .mini {
  border: 0; background: transparent; color: var(--text-faint); cursor: pointer; padding: 2px 3px;
  border-radius: 4px; font-size: 11px; line-height: 1; flex: none;
}
.oitem .mini:hover { background: var(--panel-3); color: var(--text); }
.oitem .mini.active { color: var(--accent); }
.oitem .mini.off {
  color: var(--text-faint);
  text-decoration: line-through;
  text-decoration-color: var(--danger);
  text-decoration-thickness: 1.5px;
}
.oitem.hidden-obj .nm { opacity: .45; text-decoration: line-through; }
.oitem .badge { font-size: 9px; padding: 1px 4px; border-radius: 4px; flex: none; font-weight: 700; }
.oitem .badge.bad  { background: #3a2226; color: #ff9a9a; }
.oitem .badge.warn { background: #3a3222; color: var(--warn); }

/* groups: a header row with its members tucked under it */
.oitem.ogroup { font-weight: 600; margin-top: 3px; }
.oitem.ogroup .nm { font-size: 12px; }
.oitem .mini.chev { width: 14px; padding: 2px 0; text-align: center; color: var(--text-dim); }
.oitem .swatch.ring { background: transparent; border: 2px solid var(--line); box-shadow: none; }
.oitem.in-group { margin-left: 10px; border-left: 1px solid var(--line); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding-left: 8px; }
.oitem.in-group.sel { border-left-color: var(--accent); }

/* issues */

.issues { display: flex; flex-direction: column; gap: 5px; }
.issue {
  display: flex; gap: 7px; align-items: flex-start; padding: 7px 8px; border-radius: var(--radius-sm);
  background: var(--panel-2); border-left: 2px solid var(--line); cursor: pointer; font-size: 11.5px;
  line-height: 1.4;
}
.issue:hover { background: var(--panel-3); }
.issue.bad  { border-left-color: var(--danger); }
.issue.warn { border-left-color: var(--warn); }
.issue .dot { width: 6px; height: 6px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--warn); }
.issue.bad .dot { background: var(--danger); }
.issue b { font-weight: 600; }
.empty-note { color: var(--ok); font-size: 11.5px; display: flex; align-items: center; gap: 6px; }

/* image thumb */

.thumb {
  width: 100%; height: 92px; border-radius: var(--radius); border: 1px solid var(--line);
  background: #0d0f13 center/contain no-repeat; margin-bottom: 2px;
}

/* dialog */

.dialog {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 12px; padding: 0; max-width: min(880px, 92vw); box-shadow: 0 24px 70px rgba(0,0,0,.6);
}
.dialog::backdrop { background: rgba(6,8,12,.66); }
.dialog form { padding: 18px 20px 16px; }
.dialog h2 { margin: 0 0 12px; font-size: 16px; }
.dialog h3 { margin: 0 0 6px; font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: .6px; }
.help-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px 22px; }
.help-grid ul { margin: 0; padding-left: 16px; color: var(--text-dim); font-size: 12px; line-height: 1.6; }
.help-grid ul.keys { list-style: none; padding-left: 0; }
.dialog menu { display: flex; justify-content: flex-end; margin: 16px 0 0; padding: 0; }
kbd {
  font-family: var(--mono); font-size: 10.5px; background: var(--panel-2); border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; color: var(--text);
}
code { font-family: var(--mono); }

/* The numbers panel lines value against label, so the values get their own
   column rather than trailing the text. */
.numbers-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.numbers-row .value { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--text-dim); }

/* statusbar */

.statusbar {
  height: var(--status-h); display: flex; align-items: center; gap: 14px; padding: 0 12px;
  background: var(--panel); border-top: 1px solid var(--line); font-size: 11px; color: var(--text-faint);
  overflow: hidden; white-space: nowrap;
}
.status-stats { font-family: var(--mono); }
.status-hint { overflow: hidden; text-overflow: ellipsis; }

/* narrow screens: sidebars become overlays toggled from the topbar */

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: absolute; top: var(--topbar-h); bottom: var(--status-h); width: min(320px, 86vw);
    z-index: 20; box-shadow: 0 0 40px rgba(0,0,0,.5); transition: transform .18s ease;
  }
  @media (prefers-reduced-motion: reduce) {
    .sidebar { transition: none; }
  }
  .sidebar.left  { left: 0;  transform: translateX(-102%); }
  .sidebar.right { right: 0; transform: translateX(102%); }
  .sidebar.open  { transform: none; }
  .mobile-toggle { display: inline-flex !important; }
}
.mobile-toggle { display: none; }
