/* ============================================================
   SpatialEngage · BIM — IFC Model Viewer
   Same design language as the 4D Timeliner viewer: blue-steel
   dark, hairline grids, amber + cyan signal accents, monospace
   technical readouts.
   ============================================================ */

:root {
  --bg-0: #0b0f14;
  --bg-1: #10161e;
  --bg-2: #151d27;
  --bg-3: #1b2531;
  --line: #243140;
  --line-soft: #1c2733;
  --text-0: #e8eef5;
  --text-1: #aeb9c6;
  --text-2: #6b7888;
  --accent: #f6a623; /* amber signal */
  --accent-2: #38bdf8; /* cyan signal */
  --ok: #34d399;
  --danger: #f4615f;

  --ff-ui: 'Archivo', system-ui, sans-serif;
  --ff-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --topbar-h: 60px;
  --tree-w: 320px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg-0);
  color: var(--text-0);
  font-family: var(--ff-ui);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* App grid -------------------------------------------------- */
#app {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 78% -10%, rgba(56, 189, 248, 0.06), transparent 60%),
    radial-gradient(900px 500px at 5% 110%, rgba(246, 166, 35, 0.05), transparent 55%),
    var(--bg-0);
}

/* Top bar --------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 22px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand-text { display: flex; align-items: baseline; gap: 11px; }
.brand-mark { width: 30px; height: 30px; object-fit: contain; display: block; }
.brand-text h1 { font-size: 16px; font-weight: 800; letter-spacing: 0.16em; line-height: 1; }
.brand-text p {
  font-size: 10.5px; color: var(--text-2); letter-spacing: 0.04em;
  font-family: var(--ff-mono); position: relative; padding-left: 12px;
}
.brand-text p::before {
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 1px; height: 12px; background: var(--line);
}

.model-name {
  margin-left: auto;
  font-family: var(--ff-mono); font-size: 12px; color: var(--text-1);
  max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.topbar-stats { display: flex; gap: 26px; }
.stat { display: flex; flex-direction: column; align-items: center; }
.stat-num { font-family: var(--ff-mono); font-size: 18px; font-weight: 600; color: var(--text-0); }
.stat-lbl { font-size: 9px; letter-spacing: 0.18em; color: var(--text-2); text-transform: uppercase; margin-top: 2px; }

/* Stage: tree | viewport | properties ----------------------- */
.stage { display: grid; grid-template-columns: var(--tree-w) 1fr auto; min-height: 0; min-width: 0; }

/* Structure tree (left) ------------------------------------- */
.tree-panel {
  display: flex; flex-direction: column; min-height: 0;
  background: linear-gradient(180deg, var(--bg-1), var(--bg-0));
  border-right: 1px solid var(--line);
}
.tree-search { flex: none; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
.tree-search input {
  width: 100%; padding: 7px 10px;
  background: var(--bg-0); border: 1px solid var(--line); border-radius: 6px;
  color: var(--text-0); font-family: var(--ff-mono); font-size: 11.5px;
  outline: none;
}
.tree-search input:focus { border-color: var(--accent-2); }
.tree-search input::placeholder { color: var(--text-2); }

.tree-scroll { flex: 1; overflow-y: auto; padding: 6px 0 16px; }
.tree-empty { padding: 14px 16px; font-size: 12px; color: var(--text-2); }

.tree-node { user-select: none; }
.tree-row {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 8px; cursor: pointer;
  font-size: 12px; line-height: 1.35; color: var(--text-1);
  border-left: 2px solid transparent;
}
.tree-row:hover { background: var(--bg-2); color: var(--text-0); }
.tree-row.selected { background: var(--bg-3); color: var(--text-0); border-left-color: var(--accent); }
.tree-row.dimmed > .tree-label { opacity: 0.38; }

.tree-caret {
  flex: none; width: 14px; text-align: center;
  font-size: 9px; color: var(--text-2);
  transition: transform 0.12s ease;
}
.tree-node.open > .tree-row .tree-caret { transform: rotate(90deg); }
.tree-caret.leaf { visibility: hidden; }

.tree-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-label .cls { font-family: var(--ff-mono); font-size: 10.5px; color: var(--accent-2); }
.tree-count {
  flex: none; font-family: var(--ff-mono); font-size: 10px; color: var(--text-2);
  background: var(--bg-3); border: 1px solid var(--line-soft);
  border-radius: 8px; padding: 0 7px; line-height: 16px;
}

.tree-eye {
  flex: none; border: none; background: none; cursor: pointer;
  width: 20px; height: 20px; display: grid; place-items: center;
  color: var(--text-2); opacity: 0; transition: opacity 0.1s ease;
}
.tree-row:hover .tree-eye, .tree-eye.off { opacity: 1; }
.tree-eye:hover { color: var(--text-0); }
.tree-eye.off { color: var(--danger); }
.tree-eye svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.tree-children { display: none; }
.tree-node.open > .tree-children { display: block; }
.tree-children .tree-row { padding-left: 22px; }
.tree-children .tree-children .tree-row { padding-left: 38px; }
.tree-children .tree-children .tree-children .tree-row { padding-left: 54px; }
.tree-children .tree-children .tree-children .tree-children .tree-row { padding-left: 70px; }

.tree-more {
  display: block; width: 100%; text-align: left; border: none; background: none;
  color: var(--accent-2); font-family: var(--ff-mono); font-size: 10.5px;
  padding: 4px 10px 4px 70px; cursor: pointer;
}
.tree-more:hover { text-decoration: underline; }

/* Viewport --------------------------------------------------- */
.viewport { position: relative; overflow: hidden; min-width: 0; background:
  linear-gradient(180deg, #0d141c 0%, #0a0e13 100%); }
#three-canvas { display: block; width: 100%; height: 100%; }

.viewport::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 160px 20px rgba(0,0,0,0.55);
}

.viewport-hint {
  position: absolute; left: 16px; bottom: 14px;
  font-family: var(--ff-mono); font-size: 10.5px; color: var(--text-2);
  letter-spacing: 0.04em; padding: 5px 10px;
  background: rgba(13,20,28,0.6); border: 1px solid var(--line-soft);
  border-radius: 5px; backdrop-filter: blur(4px);
}

/* Toolbar */
.toolbar {
  position: absolute; top: 14px; left: 14px; z-index: 6;
  display: flex; gap: 4px; padding: 4px;
  background: rgba(16,22,30,0.92); border: 1px solid var(--line);
  border-radius: 9px; backdrop-filter: blur(8px);
}
.tool-btn {
  width: 34px; height: 34px; border: none; border-radius: 6px;
  background: transparent; color: var(--text-1); cursor: pointer;
  display: grid; place-items: center; transition: all 0.12s ease;
}
.tool-btn:hover:not(:disabled) { background: var(--bg-3); color: var(--accent); }
.tool-btn:disabled { color: var(--text-2); opacity: 0.4; cursor: default; }
.tool-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* Drag & drop overlay */
.drop-overlay {
  position: absolute; inset: 0; z-index: 8;
  display: grid; place-items: center;
  background: rgba(11,15,20,0.75); backdrop-filter: blur(3px);
  border: 2px dashed var(--accent-2); margin: 10px; border-radius: 12px;
  pointer-events: none;
}
.drop-overlay div {
  font-family: var(--ff-mono); font-size: 14px; letter-spacing: 0.14em;
  color: var(--accent-2);
}

/* Loader ----------------------------------------------------- */
.loader {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: radial-gradient(circle at center, rgba(11,15,20,0.7), rgba(11,15,20,0.96));
  z-index: 5; transition: opacity 0.5s ease;
}
.loader.done { opacity: 0; pointer-events: none; }
.loader-inner { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.loader-ring {
  width: 52px; height: 52px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { display: flex; flex-direction: column; align-items: center; gap: 9px; }
#loader-stage { font-family: var(--ff-mono); font-size: 11px; letter-spacing: 0.2em; color: var(--text-1); }
.loader-bar { width: 220px; height: 4px; background: var(--bg-3); border-radius: 4px; overflow: hidden; }
.loader-bar i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.2s ease; }
.loader-pct { font-family: var(--ff-mono); font-size: 11px; color: var(--text-2); }
.loader-note { font-size: 11px; color: var(--text-2); max-width: 320px; text-align: center; line-height: 1.5; }

/* Properties panel (right) ----------------------------------- */
.props-panel {
  width: 300px; min-height: 0;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--bg-1), var(--bg-0));
  border-left: 1px solid var(--line);
}
.props-head {
  position: relative; flex: none;
  padding: 14px 16px 12px; border-bottom: 1px solid var(--line-soft);
}
.props-eyebrow { font-size: 9px; letter-spacing: 0.22em; color: var(--accent-2); }
.props-head h3 {
  font-family: var(--ff-mono); font-size: 13px; font-weight: 600;
  margin: 6px 18px 0 0; word-break: break-all;
}
.props-class {
  display: inline-block; margin-top: 7px;
  font-family: var(--ff-mono); font-size: 10px; color: var(--accent-2);
  background: var(--bg-3); border: 1px solid var(--line-soft);
  border-radius: 8px; padding: 1px 8px;
}
.props-class:empty { display: none; }
.props-close {
  position: absolute; top: 8px; right: 10px; border: none; background: none;
  color: var(--text-2); font-size: 18px; cursor: pointer; line-height: 1;
}
.props-close:hover { color: var(--text-0); }
.props-body { flex: 1; overflow-y: auto; padding: 8px 0 14px; }
.props-empty { padding: 14px 16px; font-size: 12px; color: var(--text-2); }
.props-cat { border-bottom: 1px solid var(--line-soft); }
.props-cat summary {
  cursor: pointer; list-style: none; padding: 9px 16px;
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--text-2); font-weight: 600; user-select: none;
}
.props-cat summary::-webkit-details-marker { display: none; }
.props-cat summary::before {
  content: '▸'; display: inline-block; margin-right: 7px;
  transition: transform 0.15s ease;
}
.props-cat[open] summary::before { transform: rotate(90deg); }
.props-cat summary:hover { color: var(--text-1); }
.props-rows { padding: 0 16px 10px; display: flex; flex-direction: column; gap: 5px; }
.props-row { display: flex; gap: 10px; font-size: 11.5px; line-height: 1.45; }
.props-n { flex: 0 0 44%; color: var(--text-2); word-break: break-word; }
.props-v { flex: 1; font-family: var(--ff-mono); font-size: 11px; word-break: break-word; cursor: copy; }

/* Fatal error ------------------------------------------------ */
.fatal {
  position: fixed; inset: auto 16px 16px 16px; z-index: 50;
  background: rgba(45, 16, 16, 0.95); border: 1px solid var(--danger);
  border-radius: 10px; padding: 14px 16px;
  font-family: var(--ff-mono); font-size: 12px; color: #ffd9d8;
  white-space: pre-wrap;
}

/* Scrollbars ------------------------------------------------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: var(--bg-0); }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 5px; border: 2px solid var(--bg-0); }
::-webkit-scrollbar-thumb:hover { background: var(--line); }
