* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: system-ui, -apple-system, sans-serif; background: #14181f; color: #e6e9ef; }

#topbar {
  display: flex; align-items: baseline; gap: 1rem;
  padding: 0.6rem 1rem; background: #1c2230; border-bottom: 1px solid #2c3444;
}
#topbar h1 { font-size: 1.05rem; margin: 0; font-weight: 600; }
#summary-line { font-size: 0.8rem; color: #9aa5b8; }

#layout {
  display: flex;
  flex-direction: row;
  height: calc(100vh - 44px);
}

/* Fixed-width panes that JS resizers adjust directly; the 3D viewer is the only flexible
   one (flex:1), so it absorbs whatever space the others don't take. */
#sidebar { flex: 0 0 auto; width: 240px; min-width: 150px; max-width: 520px; }
#graph-pane { flex: 0 0 auto; width: 420px; min-width: 260px; max-width: 900px; }
#detail { flex: 0 0 auto; width: 300px; min-width: 220px; max-width: 640px; }
#viewer-pane { flex: 1 1 auto; min-width: 200px; }

.resizer {
  flex: 0 0 auto; width: 6px; cursor: col-resize; background: #1c2230;
  border-left: 1px solid #2c3444; border-right: 1px solid #2c3444;
}
.resizer:hover, .resizer.active { background: #3a5a8a; }

#sidebar {
  border-right: 1px solid #2c3444; padding: 0.6rem; overflow-y: auto;
}
#search {
  width: 100%; padding: 0.4rem 0.5rem; margin-bottom: 0.5rem;
  background: #232a38; border: 1px solid #313b4f; border-radius: 4px; color: inherit;
}
.room-item {
  padding: 0.35rem 0.5rem; border-radius: 4px; cursor: pointer; font-size: 0.85rem;
  display: flex; justify-content: space-between; gap: 0.4rem;
}
.room-item:hover { background: #232a38; }
.room-item.selected { background: #2a3a55; }
.room-item .badge { font-size: 0.7rem; opacity: 0.85; }
.badge.complete { color: #6fd68a; }
.badge.partial { color: #e0c15c; }
.badge.none { color: #7a869e; }

.room-group-header {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: #9aa5b8;
  padding: 0.5rem 0.3rem 0.25rem; cursor: pointer; user-select: none;
}
.room-group-header:hover { color: #c3cbdb; }
.room-group-header.collapsed { opacity: 0.7; }

#viewer-pane { position: relative; }
#viewer { width: 100%; height: 100%; }
#model-loading-overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 24, 31, 0.82);
  transition: opacity 0.35s ease;
}
#model-loading-overlay.hidden { opacity: 0; pointer-events: none; }
#model-loading-box { width: 280px; text-align: center; }
#model-loading-title { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.7rem; color: #e6e9ef; }
#model-loading-bar-track {
  width: 100%; height: 8px; border-radius: 999px; background: #232a38;
  border: 1px solid #313b4f; overflow: hidden;
}
#model-loading-bar-fill {
  height: 100%; width: 0%; background: #4fa8ff;
  transition: width 0.15s ease;
}
#model-loading-pct { margin-top: 0.4rem; font-size: 0.78rem; color: #9aa5b8; }

@media (prefers-color-scheme: light) {
  #model-loading-overlay { background: rgba(245, 246, 248, 0.85); }
  #model-loading-title { color: #1c2230; }
  #model-loading-bar-track { background: #eef1f6; border-color: #dde2ea; }
  #model-loading-pct { color: #6b7688; }
}
#viewer-hint {
  position: absolute; bottom: 0.6rem; left: 0.8rem; font-size: 0.75rem; color: #7a869e;
  pointer-events: none;
}
#viewer-controls {
  position: absolute; top: 0.6rem; left: 0.8rem; z-index: 2;
  display: flex; align-items: center; gap: 0.5rem;
}
.viewer-btn {
  padding: 0.35rem 0.7rem; font-size: 0.75rem; font-weight: 600; cursor: pointer;
  background: #232a38; color: #e6e9ef; border: 1px solid #313b4f; border-radius: 4px;
}
.viewer-btn:hover { background: #2a3347; }
.viewer-btn.active { background: #3a5a8a; border-color: #4fa8ff; }
#pick-label {
  position: absolute; display: none; z-index: 3; pointer-events: none;
  padding: 0.25rem 0.55rem; background: rgba(11,14,22,0.92); border-radius: 4px;
  font-size: 0.75rem; font-weight: 700; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.viewer-check {
  display: flex; align-items: center; gap: 0.3rem; font-size: 0.75rem; font-weight: 600;
  background: #232a38; border: 1px solid #313b4f; border-radius: 4px; padding: 0.35rem 0.6rem;
  cursor: pointer; user-select: none;
}
#viewer-opacity-controls {
  position: absolute; top: 2.6rem; left: 0.8rem; z-index: 2;
  display: flex; flex-direction: column; gap: 0.3rem;
}
.opacity-slider {
  display: flex; align-items: center; gap: 0.5rem; font-size: 0.72rem; font-weight: 600;
  background: #232a38; border: 1px solid #313b4f; border-radius: 4px; padding: 0.3rem 0.6rem;
}
.opacity-slider input[type="range"] { width: 110px; accent-color: #4fa8ff; }
.opacity-slider span { min-width: 2.4em; text-align: right; color: #9aa5b8; }

#graph-pane {
  border-left: 1px solid #2c3444; padding: 0.6rem 0.8rem; display: flex; flex-direction: column;
  min-height: 0;   /* grid item + flex column: without this, children can't get a real height */
}
#graph-pane h3 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; color: #9aa5b8; margin: 0 0 0.5rem; flex-shrink: 0; }
#graph-legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.7rem;
  font-size: 0.72rem; color: #c3cbdb; margin-bottom: 0.5rem; flex-shrink: 0;
}
.legend-item { display: flex; align-items: center; gap: 0.3rem; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend-sep { color: #3a4356; }
.legend-line { width: 22px; height: 0; display: inline-block; border-top: 2px solid #9aa5b8; }
.legend-line.dashed { border-top-style: dashed; opacity: 0.7; }
#graph-canvas {
  flex: 1; min-height: 0;   /* flex items default to min-height:auto, which collapses an empty div */
  border: 1px solid #2c3444; border-radius: 6px; background: #1a1f2b;
}
#graph-empty { color: #7a869e; font-size: 0.8rem; padding-top: 0.5rem; }
.graph-node-label {
  position: absolute; transform: translate(-50%, 0); font-size: 11px; font-weight: 700;
  white-space: nowrap; text-shadow: 0 1px 3px rgba(0,0,0,0.95), 0 0 4px rgba(0,0,0,0.95);
}

/* #detail's own font-size is adjusted by JS on scroll-wheel; everything below it must use
   em (relative to the nearest ancestor's font-size) rather than rem (always relative to the
   document root) so the zoom actually cascades down to headings/text/pills. */
#detail { border-left: 1px solid #2c3444; padding: 0.8rem; overflow-y: auto; font-size: 0.85rem; }
#detail-empty { color: #7a869e; }
#detail h2 { font-size: 1.15em; margin: 0 0 0.2rem; }
#detail h3 { font-size: 0.94em; text-transform: uppercase; letter-spacing: 0.03em; color: #9aa5b8; margin: 1rem 0 0.3rem; }
.kv { display: flex; justify-content: space-between; padding: 0.15rem 0; border-bottom: 1px dashed #2c3444; font-size: 1em; }
.reason { font-style: italic; color: #c3cbdb; margin-top: 0.3rem; line-height: 1.35; font-size: 1em; }
.pill {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.82em; font-weight: 600;
}
.pill.chosen, .pill.connected { background: #1e3d2b; color: #6fd68a; }
.pill.none { background: #3a2a2a; color: #d98080; }
.evidence-img { width: 100%; border-radius: 6px; margin-top: 0.4rem; border: 1px solid #2c3444; }

/* control-point (관제점) chips in the detail panel */
.pt-eq { margin-top: 0.4rem; font-size: 0.82em; font-weight: 600; color: #8b949e; text-transform: uppercase; letter-spacing: 0.03em; }
.ptrow { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.2rem; }
.ptchip { display: inline-block; padding: 0.08rem 0.4rem; border-radius: 5px; background: #1c2330; border: 1px solid #2c3444; color: #c9d1d9; font-size: 0.78em; }

.agent-bubble {
  position: absolute; transform: translate(-50%, -100%); z-index: 4; pointer-events: none;
  max-width: 240px; padding: 0.4rem 0.6rem; border-radius: 8px;
  background: rgba(20, 24, 31, 0.94); border: 1px solid #ffd23f; color: #f5e8b8;
  font-size: 0.72rem; line-height: 1.35; white-space: pre-line;
  box-shadow: 0 3px 10px rgba(0,0,0,0.5);
}
.agent-bubble::after {
  content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: #ffd23f;
}

@media (prefers-color-scheme: light) {
  html, body { background: #f5f6f8; color: #1c2230; }
  #topbar, #sidebar, #detail, #graph-pane { background: #ffffff; border-color: #dde2ea; }
  #graph-canvas { background: #f7f8fa; border-color: #dde2ea; }
  .resizer { background: #eef1f6; border-color: #dde2ea; }
  .resizer:hover, .resizer.active { background: #bcd2f0; }
  .viewer-btn, .viewer-check, .opacity-slider { background: #ffffff; color: #1c2230; border-color: #dde2ea; }
  .viewer-btn:hover { background: #eef1f6; }
  .opacity-slider span { color: #6b7688; }
  .room-item:hover { background: #eef1f6; }
  .room-item.selected { background: #dbe6fb; }
  #search { background: #f0f2f6; border-color: #dde2ea; color: inherit; }
}
