/* ============================================================
   4D Construction Timeline Viewer
   Aesthetic: engineering / BIM control-room. Blue-steel dark,
   precise 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;

  --tt-construct1: #f6a623;
  --tt-construct: #38bdf8;
  --tt-base: #34d399;
  --tt-untyped: #9aa5b1;

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

  --topbar-h: 60px;
  --transport-h: 52px;
  --gantt-h: 230px;
  --panel-w: 300px;
}

* { 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 var(--transport-h) var(--gantt-h);
  height: 100vh;
  width: 100vw;
  max-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);
}

.clock {
  margin-left: auto;
  display: flex; flex-direction: column; align-items: flex-end;
  padding: 0 22px; border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  height: 100%; justify-content: center;
}
.clock-label { font-size: 9.5px; letter-spacing: 0.22em; color: var(--text-2); }
.clock-value {
  font-family: var(--ff-mono); font-weight: 600; font-size: 19px;
  color: var(--accent); letter-spacing: 0.02em; margin-top: 2px;
  text-shadow: 0 0 18px rgba(246,166,35,0.25);
}

.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 (viewport + panel) ---------------------------------- */
/* Middle `auto` track is the BIM properties panel; it collapses to 0 while hidden.
   Columns are assigned explicitly — otherwise, while the props panel is
   display:none, grid auto-placement would slide the side panel into the middle
   track and leave the last track empty. */
.stage { display: grid; grid-template-columns: 1fr auto var(--panel-w); min-height: 0; min-width: 0; }
.stage > .viewport { grid-column: 1; }
.stage > .props-panel { grid-column: 2; }
.stage > .panel { grid-column: 3; }

.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 { /* subtle grain / vignette */
  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);
}

/* Selection card */
.selection-card {
  position: absolute; top: 16px; left: 16px; width: 270px;
  background: rgba(16,22,30,0.92); border: 1px solid var(--line);
  border-radius: 10px; padding: 15px 16px 16px;
  backdrop-filter: blur(8px);
  box-shadow: 0 18px 40px -18px rgba(0,0,0,0.8);
}
.selection-close {
  position: absolute; top: 8px; right: 10px; border: none; background: none;
  color: var(--text-2); font-size: 18px; cursor: pointer; line-height: 1;
}
.selection-close:hover { color: var(--text-0); }
.selection-eyebrow { font-size: 9px; letter-spacing: 0.22em; color: var(--accent-2); }
.selection-card h3 {
  font-family: var(--ff-mono); font-size: 14px; font-weight: 600;
  margin: 6px 0 8px; word-break: break-all;
}
.selection-path {
  font-family: var(--ff-mono); font-size: 10.5px; color: var(--text-2);
  line-height: 1.5; word-break: break-all; margin-bottom: 10px;
}
.selection-tasks { display: flex; flex-direction: column; gap: 6px; }
.selection-task {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; padding: 5px 8px; border-radius: 6px;
  background: var(--bg-3); border: 1px solid var(--line-soft);
}
.selection-task .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.selection-actions { margin-top: 10px; }
.selection-actions:empty { display: none; }
.selection-hide-btn {
  width: 100%; padding: 7px 10px; border-radius: 6px; cursor: pointer;
  font-family: var(--ff-ui); font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text-1);
  transition: all 0.15s ease;
}
.selection-hide-btn:hover { border-color: var(--danger); color: var(--danger); }

/* 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); }

/* Side panel ------------------------------------------------ */
/* BIM properties panel (selected object) --------------------- */
.props-panel {
  width: 280px; 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-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; }

.panel {
  background: linear-gradient(180deg, var(--bg-1), var(--bg-0));
  border-left: 1px solid var(--line);
  overflow-y: auto; padding: 4px 0 12px;
}
.panel-block { padding: 16px 18px; border-bottom: 1px solid var(--line-soft); }
.panel-title {
  font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--text-2); font-weight: 600; margin-bottom: 12px;
}

.mode-toggle { display: flex; gap: 4px; padding: 3px; background: var(--bg-0); border: 1px solid var(--line); border-radius: 8px; }
.mode-btn {
  flex: 1; padding: 7px 6px; font-family: var(--ff-ui); font-size: 11.5px; font-weight: 600;
  color: var(--text-2); background: transparent; border: none; border-radius: 6px; cursor: pointer;
  transition: all 0.15s ease; letter-spacing: 0.01em;
}
.mode-btn:hover { color: var(--text-1); }
.mode-btn.active { color: #0b0f14; background: var(--accent); box-shadow: 0 2px 8px -2px var(--accent); }
.mode-hint { font-size: 11px; color: var(--text-2); line-height: 1.5; margin-top: 10px; }

.legend { list-style: none; display: flex; flex-direction: column; gap: 9px; }
.legend li { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--text-1); }
.legend .swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; box-shadow: 0 0 0 1px rgba(255,255,255,0.07); }

.active-list { list-style: none; display: flex; flex-direction: column; gap: 7px; max-height: 230px; overflow-y: auto; }
.active-list li.active-row {
  display: flex; align-items: center; gap: 9px; font-size: 12.5px;
  padding: 7px 9px; border-radius: 6px; background: var(--bg-2);
  border: 1px solid var(--line-soft); cursor: pointer;
}
.active-list li.active-row:hover { border-color: var(--line); background: var(--bg-3); }
.active-row .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.active-row .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.active-row .ct { font-family: var(--ff-mono); font-size: 10.5px; color: var(--text-2); }
.active-empty { font-size: 12px; color: var(--text-2); font-style: italic; }

.diag-grid { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; }
.diag-grid dt { font-size: 12px; color: var(--text-1); }
.diag-grid dd { font-family: var(--ff-mono); font-size: 12.5px; color: var(--text-0); text-align: right; }
#diag-unmatched.warn { color: var(--danger); }

/* Transport ------------------------------------------------- */
.transport {
  display: flex; align-items: center; gap: 16px; padding: 0 18px;
  background: var(--bg-1); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.tp-btn {
  width: 34px; height: 34px; flex: none; border-radius: 7px;
  border: 1px solid var(--line); background: var(--bg-3); color: var(--text-0);
  display: grid; place-items: center; cursor: pointer; transition: all 0.15s ease;
}
.tp-btn:hover { border-color: var(--accent); color: var(--accent); }
.tp-btn svg { width: 17px; height: 17px; fill: currentColor; }
.tp-btn.play { background: var(--accent); color: #0b0f14; border-color: var(--accent); }
.tp-btn.play:hover { filter: brightness(1.08); color: #0b0f14; }
.tp-btn.play .i-pause { display: none; }
.tp-btn.play.playing .i-play { display: none; }
.tp-btn.play.playing .i-pause { display: block; }

.scrub {
  flex: 1; -webkit-appearance: none; appearance: none; height: 5px; border-radius: 5px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) var(--p, 0%), var(--bg-3) var(--p, 0%));
  cursor: pointer;
}
.scrub::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--text-0); border: 3px solid var(--accent); cursor: grab;
  box-shadow: 0 0 10px rgba(246,166,35,0.5);
}
.scrub::-moz-range-thumb { width: 15px; height: 15px; border-radius: 50%; background: var(--text-0); border: 3px solid var(--accent); }

.speed { display: flex; align-items: center; gap: 8px; }
.speed-lbl { font-size: 9px; letter-spacing: 0.16em; color: var(--text-2); }
.speed-val {
  font-family: var(--ff-mono); font-size: 12px; font-weight: 600; color: var(--accent-2);
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; min-width: 46px;
}
.speed-val:hover { border-color: var(--accent-2); }

.range-labels { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; min-width: 92px; }
.range-labels span { font-family: var(--ff-mono); font-size: 10px; color: var(--text-2); }

/* Gantt resize handle (main viewer) ------------------------ */
/* The viewer adds a 5th grid row for the drag handle. */
#app.has-resizer {
  grid-template-rows: var(--topbar-h) 1fr var(--transport-h) 12px var(--gantt-h);
}
.gantt-resizer {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
}
.gantt-resizer-grip {
  width: 46px; height: 4px; border-radius: 4px;
  background: var(--line);
  transition: background 0.15s ease;
  pointer-events: none;
}
.gantt-resizer:hover .gantt-resizer-grip,
.gantt-resizer.dragging .gantt-resizer-grip { background: var(--accent); }
.gantt-collapse {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg-3); color: var(--text-2);
  cursor: pointer; padding: 0;
  z-index: 2;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.gantt-collapse:hover { color: var(--accent); border-color: var(--accent); }
.gantt-collapse svg { width: 16px; height: 16px; fill: currentColor; transition: transform 0.2s ease; }
#app.gantt-collapsed .gantt-collapse svg { transform: rotate(180deg); }
#app.gantt-collapsed .gantt-wrap { border-top: none; }

/* Gantt ----------------------------------------------------- */
.gantt-wrap { position: relative; background: var(--bg-1); display: flex; min-height: 0; min-width: 0; overflow: hidden; }
.gantt-axis-corner {
  position: absolute; top: 0; left: 0; z-index: 3;
  font-size: 9px; letter-spacing: 0.2em; color: var(--text-2);
  padding: 7px 12px; background: var(--bg-1); border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line); pointer-events: none;
}
/* Width now always fits the container (gantt.js refits on resize), so only
   vertical scrolling is ever needed. */
.gantt-scroll { flex: 1; min-width: 0; overflow-y: auto; overflow-x: hidden; }
#gantt-svg { display: block; font-family: var(--ff-mono); }

/* Gantt SVG element styling */
.g-grid { stroke: var(--line-soft); stroke-width: 1; }
.g-grid.major { stroke: var(--line); }
.g-axis-label { fill: var(--text-2); font-size: 10px; }
.g-axis-label.major { fill: var(--text-1); font-weight: 600; }
.g-row-label { fill: var(--text-1); font-size: 11px; font-family: var(--ff-ui); }
.g-row-bg:nth-child(even) { fill: rgba(255,255,255,0.012); }
.g-bar { rx: 3; cursor: pointer; transition: opacity 0.15s; }
.g-bar:hover { opacity: 0.82; }
.g-bar.dim { opacity: 0.4; }
.g-hidebtn { color: var(--text-2); cursor: pointer; opacity: 0.4; transition: opacity 0.12s, color 0.12s; }
.g-hidebtn:hover { opacity: 1; color: var(--text-0); }
.g-hidebtn.active { opacity: 1; color: var(--accent); }
.g-hidebtn-hit { fill: transparent; }
.g-hidebtn-icon { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.g-playhead { stroke: var(--accent); stroke-width: 1.5; }
.g-playhead-head { fill: var(--accent); }
.g-rowsep { stroke: var(--line-soft); stroke-width: 1; }

/* Fatal error overlay */
.fatal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(11,15,20,0.96); color: var(--text-0); padding: 40px;
  font-family: var(--ff-mono); font-size: 13px; line-height: 1.6; text-align: center;
  white-space: pre-wrap;
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-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); }

/* Settings drawer (main viewer) ----------------------------- */
.settings-btn {
  width: 54px; height: 100%; flex: none; align-self: stretch;
  margin-right: -22px; /* flush against the topbar's right edge (cancels its padding) */
  border: none; border-left: 1px solid var(--line);
  background: transparent; color: var(--text-1);
  display: grid; place-items: center; cursor: pointer;
  transition: all 0.15s ease;
}
.settings-btn:hover { color: var(--accent); background: var(--bg-3); }
.settings-btn svg {
  width: 18px; height: 18px; fill: none;
  stroke: currentColor; stroke-width: 2; stroke-linecap: round;
}

.settings-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(5, 8, 12, 0.5);
  backdrop-filter: blur(2px);
}

.settings-drawer {
  position: fixed; top: 0; right: 0; height: 100%; z-index: 45;
  width: min(340px, 90vw);
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 48px -18px rgba(0, 0, 0, 0.6);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0.24, 1);
  overflow-y: auto;
}
.settings-drawer.open { transform: translateX(0); }

.settings-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--line);
}
.settings-head-text h2 {
  font-size: 13px; font-weight: 800; letter-spacing: 0.2em; text-transform: uppercase;
}
.settings-head-text p {
  font-family: var(--ff-mono); font-size: 10px; color: var(--text-2);
  letter-spacing: 0.06em; margin-top: 3px;
}
.settings-close {
  width: 30px; height: 30px; flex: none; border-radius: 7px;
  border: 1px solid var(--line); background: transparent; color: var(--text-2);
  font-size: 17px; line-height: 1; cursor: pointer;
  display: grid; place-items: center; transition: all 0.15s ease;
}
.settings-close:hover { border-color: var(--danger); color: var(--danger); }

.settings-group { padding: 18px 20px; border-bottom: 1px solid var(--line-soft); }
.settings-group-title {
  font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--text-2); font-weight: 600; margin-bottom: 12px;
}

.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 11px 12px; border-radius: 8px; cursor: pointer;
  background: var(--bg-0); border: 1px solid var(--line);
  transition: border-color 0.15s ease;
}
.setting-row:hover { border-color: var(--text-2); }
.setting-row + .setting-row { margin-top: 8px; }
.mode-hint + .setting-row { margin-top: 12px; }
.setting-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.setting-name { font-size: 12.5px; font-weight: 600; color: var(--text-0); }
.setting-desc { font-size: 10.5px; color: var(--text-2); line-height: 1.4; }

.setting-row.static { cursor: default; }
.settings-action {
  flex: none; padding: 7px 14px; border-radius: 7px; cursor: pointer;
  font-family: var(--ff-ui); font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text-1);
  transition: all 0.15s ease;
}
.settings-action:hover { border-color: var(--accent); color: var(--accent); }

/* iOS-style switch (styled checkbox) */
.switch {
  -webkit-appearance: none; appearance: none;
  width: 40px; height: 22px; flex: none; border-radius: 22px;
  background: var(--bg-3); border: 1px solid var(--line);
  position: relative; cursor: pointer; outline: none;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.switch::before {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-1);
  transition: transform 0.18s ease, background 0.18s ease;
}
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::before { transform: translateX(18px); background: #0b0f14; }
.switch:focus-visible { box-shadow: 0 0 0 2px rgba(246, 166, 35, 0.35); }
