/* ============================================================
   Design tokens — dark, professional, Blender/Unreal-ish palette
   ============================================================ */
:root {
  --bg-0: #16171b;      /* deepest background (viewport) */
  --bg-1: #1e2025;      /* panels */
  --bg-2: #262930;      /* panel headers / inputs */
  --bg-3: #32363f;      /* hover */
  --border: #3a3f4a;
  --text-hi: #e8e9ec;
  --text-lo: #9aa0ab;
  --accent: #4c8dff;
  --accent-hover: #6ba0ff;
  --danger: #ff5c5c;
  --success: #4cd97b;
  --radius: 6px;
  --toolbar-h: 48px;
  --statusbar-h: 26px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg-0);
  color: var(--text-hi);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  overflow: hidden;
  user-select: none;
}

button {
  background: var(--bg-2);
  color: var(--text-hi);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}
button:hover { background: var(--bg-3); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-hover); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

input[type="text"], input[type="search"], select, input[type="range"] {
  background: var(--bg-2);
  color: var(--text-hi);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  width: 100%;
  font-size: 12px;
}

label { display: block; margin: 8px 0 4px; color: var(--text-lo); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--text-lo); }
.hidden { display: none !important; }

/* ============================================================
   Toolbar
   ============================================================ */
#toolbar {
  height: var(--toolbar-h);
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
}
.brand { font-weight: 600; letter-spacing: .02em; }
.toolbar-actions { display: flex; gap: 6px; }

/* ============================================================
   Layout grid
   ============================================================ */
#layout {
  position: absolute;
  top: var(--toolbar-h);
  bottom: var(--statusbar-h);
  left: 0; right: 0;
  display: flex;
}

#sidebar-left, #sidebar-right {
  background: var(--bg-1);
  overflow-y: auto;
  flex-shrink: 0;
}
#sidebar-left { width: 280px; border-right: 1px solid var(--border); padding: 10px; }
#sidebar-right { width: 300px; border-left: 1px solid var(--border); padding: 10px; }

.divider {
  width: 4px; cursor: col-resize; background: transparent;
  flex-shrink: 0;
}
.divider:hover, .divider.dragging { background: var(--accent); }

#viewport {
  flex: 1;
  position: relative;
  background: var(--bg-0);
}
#renderCanvas { width: 100%; height: 100%; display: block; outline: none; touch-action: none; }

#drop-hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-lo);
  border: 2px dashed var(--border);
  margin: 12px;
  border-radius: var(--radius);
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
}
#drop-hint.active { opacity: 1; }

#viewport-hud {
  position: absolute; top: 8px; left: 8px;
  background: rgba(20,21,25,0.7);
  padding: 4px 10px; border-radius: var(--radius);
  font-size: 11px;
}

/* ============================================================
   Status bar
   ============================================================ */
#statusbar {
  position: absolute; bottom: 0; left: 0; right: 0; height: var(--statusbar-h);
  background: var(--bg-1); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px; font-size: 11px; color: var(--text-lo);
}

/* ============================================================
   Sidebar: tabs, search, asset list
   ============================================================ */
.panel-tabs { display: flex; gap: 2px; margin-bottom: 8px; }
.panel-tabs .tab {
  flex: 1; background: var(--bg-2); border: 1px solid var(--border);
  padding: 6px; border-radius: var(--radius); cursor: pointer; color: var(--text-lo);
}
.panel-tabs .tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.panel-search { margin-bottom: 8px; }
.panel-filters { margin-bottom: 10px; }

.asset-list { display: flex; flex-direction: column; gap: 6px; }
.asset-card {
  display: flex; gap: 8px; align-items: center;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px; cursor: grab;
}
.asset-card:hover { border-color: var(--accent); }
.asset-card.selected { border-color: var(--accent); background: var(--bg-3); }
.asset-thumb {
  width: 40px; height: 40px; border-radius: 4px; background: var(--bg-0);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  flex-shrink: 0; overflow: hidden;
}
.asset-thumb img { width: 100%; height: 100%; object-fit: cover; }
.asset-meta { flex: 1; min-width: 0; }
.asset-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-tags { font-size: 10px; color: var(--text-lo); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-fav { background: none; border: none; cursor: pointer; color: var(--text-lo); font-size: 14px; padding: 2px 4px; }
.asset-fav.active { color: gold; }
.asset-cache-btn { background: none; border: none; cursor: pointer; font-size: 13px; padding: 2px 4px; opacity: 0.85; }
.asset-cache-btn:hover { opacity: 1; }

/* ============================================================
   Inspector
   ============================================================ */
#sidebar-right h3 { margin-top: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-lo); }
.inspector-row { display: flex; gap: 6px; margin-bottom: 6px; }
.inspector-row > div { flex: 1; }
.inspector-group { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; }

/* ============================================================
   Modals
   ============================================================ */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 50;
}
.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--bg-1); border: 1px solid var(--border); border-radius: 8px;
  width: 420px; max-height: 80vh; overflow-y: auto;
  padding: 16px; z-index: 51;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal h3 { margin-top: 0; }
.modal-body { display: flex; flex-direction: column; gap: 4px; }
.modal-body .row { display: flex; gap: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ============================================================
   Phase 2: context menu, recovery banner
   ============================================================ */
.context-menu {
  position: fixed;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  padding: 4px;
  z-index: 100;
  min-width: 180px;
}
.context-menu-item {
  padding: 7px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.context-menu-item:hover { background: var(--bg-3); }
.context-menu-item.danger { color: var(--danger); }
.context-menu-sep { height: 1px; background: var(--border); margin: 4px 2px; }

#recovery-banner {
  position: fixed;
  top: calc(var(--toolbar-h) + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-1);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 60;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  font-size: 12px;
}

/* ============================================================
   Phase 5: in-headset UI (WebXR DOM Overlay)
   ============================================================ */
body.xr-session-active {
  /* DOM Overlay content is pointed at with a controller ray rather than a
     mouse, so targets need to be noticeably bigger to hit reliably. */
  font-size: 16px;
}
body.xr-session-active button {
  padding: 12px 18px;
  font-size: 15px;
}
body.xr-session-active #sidebar-left,
body.xr-session-active #sidebar-right {
  width: 340px !important;
}
body.xr-session-active .asset-card { padding: 12px; }
body.xr-session-active #drop-hint,
body.xr-session-active .divider {
  display: none; /* drag-and-drop and mouse-drag resizing don't apply in-headset */
}

.scene-item, .light-preset-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px; background: var(--bg-2); border-radius: var(--radius); margin-bottom: 6px;
}
