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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  height: 100vh;
  overflow: hidden;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Top Bar ── */
#topbar {
  display: flex;
  flex-direction: column;
  background: #1a1d27;
  border-bottom: 1px solid #2d3148;
  flex-shrink: 0;
  z-index: 10;
}

#topbar-row1 {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  height: 46px;
  border-bottom: 1px solid #1e2235;
}

#topbar-row2 {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  height: 38px;
}

.app-title { font-weight: 700; font-size: 14px; color: #818cf8; letter-spacing: 0.3px; white-space: nowrap; flex: 0 0 auto; }

#sim-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: center;
}

#sim-controls label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: #94a3b8;
  white-space: nowrap;
}

#sim-controls input[type="number"],
#sim-controls select {
  background: #252836;
  border: 1px solid #3d4268;
  border-radius: 6px;
  color: #e2e8f0;
  padding: 4px 6px;
  font-size: 12px;
  width: 60px;
}

#sim-controls select { width: 64px; }

/* ── Behaviour ratios ── */
.behaviour-ratios {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #252836;
  border: 1px solid #3d4268;
  border-radius: 8px;
  padding: 4px 8px;
}

.ratio-label {
  font-size: 11px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 2px;
}

.ratio-field {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  color: #94a3b8;
  white-space: nowrap;
}

.ratio-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.skim-label .ratio-dot { background: #fbbf24; }
.swim-label .ratio-dot { background: #60a5fa; }
.dive-label .ratio-dot { background: #a78bfa; }

.ratio-field input[type="number"] {
  background: transparent;
  border: none;
  border-bottom: 1px solid #3d4268;
  border-radius: 0;
  color: #e2e8f0;
  padding: 0 2px;
  font-size: 12px;
  width: 32px;
  text-align: center;
}
.ratio-field input:focus { outline: none; border-bottom-color: #6366f1; }

.sim-time {
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #818cf8;
  min-width: 48px;
}

.row2-divider {
  width: 1px;
  height: 20px;
  background: #2d3148;
  flex-shrink: 0;
}

#metrics {
  display: flex;
  gap: 16px;
  align-items: center;
}

.metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.metric-label { font-size: 9px; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px; }
.metric span:last-child { font-size: 13px; font-weight: 600; color: #e2e8f0; }

.skim-metric span:last-child { color: #fbbf24; }
.swim-metric span:last-child { color: #60a5fa; }
.dive-metric span:last-child { color: #a78bfa; }

/* ── Buttons ── */
.btn {
  padding: 5px 12px;
  border-radius: 7px;
  border: none;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  background: #252836;
  color: #94a3b8;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #2d3148; color: #e2e8f0; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: #4f46e5; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #6366f1; }
.btn-danger { background: #7f1d1d; color: #fca5a5; }
.btn-danger:hover:not(:disabled) { background: #991b1b; }

/* ── Main Layout ── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Left Toolbar ── */
#toolbar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 8px;
  background: #1a1d27;
  border-right: 1px solid #2d3148;
  width: 72px;
  align-items: center;
}

.tool-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  align-items: center;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  font-size: 10px;
  width: 56px;
  transition: all 0.15s;
}
.tool-btn:hover { background: #252836; color: #cbd5e1; border-color: #3d4268; }
.tool-btn.active { background: #1e2040; color: #818cf8; border-color: #4f46e5; }
.tool-btn[data-tool="exhibit"].active { color: #f59e0b; border-color: #d97706; background: #2a2010; }
.tool-btn.danger { color: #f87171; }
.tool-btn.danger:hover { background: #2d1f1f; border-color: #7f1d1d; }

/* ── Canvas ── */
#canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #0f1117;
  background-image:
    linear-gradient(rgba(45,49,72,0.4) 1px, transparent 1px),
    linear-gradient(90deg, rgba(45,49,72,0.4) 1px, transparent 1px);
  background-size: 40px 40px;
}

#main-canvas {
  position: absolute;
  top: 0; left: 0;
  cursor: crosshair;
}

#canvas-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26,29,39,0.85);
  border: 1px solid #2d3148;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 12px;
  color: #64748b;
  pointer-events: none;
  transition: opacity 0.3s;
  white-space: nowrap;
}

/* ── Behaviour Legend ── */
#behaviour-legend {
  position: absolute;
  top: 12px;
  right: 12px;
  display: none;
  flex-direction: row;
  gap: 12px;
  background: rgba(26,29,39,0.85);
  border: 1px solid #2d3148;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  pointer-events: none;
}
.legend-skim { color: #fbbf24; }
.legend-swim { color: #60a5fa; }
.legend-dive { color: #a78bfa; }

/* ── Right Panel ── */
#right-panel {
  width: 270px;
  background: #1a1d27;
  border-left: 1px solid #2d3148;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
#right-panel.hidden { display: none; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid #2d3148;
}
.panel-header h3 { font-size: 14px; font-weight: 600; color: #e2e8f0; }
.close-btn { background: none; border: none; color: #64748b; cursor: pointer; font-size: 16px; line-height: 1; }
.close-btn:hover { color: #e2e8f0; }

.panel-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  flex: 1;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #94a3b8;
}
.field-label input,
.field-label select {
  background: #252836;
  border: 1px solid #3d4268;
  border-radius: 6px;
  color: #e2e8f0;
  padding: 7px 10px;
  font-size: 13px;
  width: 100%;
}
.field-label input:focus,
.field-label select:focus {
  outline: none;
  border-color: #6366f1;
}

.type-hint {
  font-size: 12px;
  color: #64748b;
  background: #252836;
  border-radius: 6px;
  padding: 8px 10px;
}

.dwell-hint {
  font-size: 11px;
  color: #475569;
  margin-top: 4px;
}

/* ── Service level / LoS ── */
.los-info-box {
  margin-top: 6px;
  font-size: 11px;
  color: #94a3b8;
  background: #252836;
  border-radius: 6px;
  padding: 7px 10px;
  line-height: 1.6;
  min-height: 32px;
}

#cfg-capacity-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #94a3b8;
}
#cfg-capacity-row input {
  background: #252836;
  border: 1px solid #3d4268;
  border-radius: 6px;
  color: #e2e8f0;
  padding: 7px 10px;
  font-size: 13px;
  width: 100%;
}
#cfg-capacity-row input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Exhibits Panel Section ── */
#exhibits-section {
  border-top: 1px solid #2d3148;
  padding-top: 14px;
  margin-top: 2px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.exhibits-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.exhibits-title {
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge {
  background: #2d3148;
  color: #818cf8;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
}

#exhibits-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.exhibit-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #252836;
  border: 1px solid #3d4268;
  border-radius: 6px;
  padding: 5px 8px;
}

.exhibit-drag {
  color: #475569;
  cursor: grab;
  font-size: 14px;
  flex-shrink: 0;
  user-select: none;
}
.exhibit-drag:active { cursor: grabbing; }

.exhibit-dot {
  width: 8px; height: 8px;
  background: #f59e0b;
  border-radius: 50%;
  flex-shrink: 0;
}

.exhibit-name-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #e2e8f0;
  font-size: 12px;
  outline: none;
  min-width: 0;
}
.exhibit-name-input:focus { color: #fff; }

.exhibit-remove {
  background: none;
  border: none;
  color: #475569;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
}
.exhibit-remove:hover { color: #f87171; }

.field-hint {
  font-size: 11px;
  color: #475569;
  line-height: 1.5;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #7f1d1d;
  color: #fca5a5;
  border: 1px solid #991b1b;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 13px;
  z-index: 1000;
  pointer-events: none;
  transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; }
.toast.info { background: #1e1e40; color: #818cf8; border-color: #4f46e5; }

/* ── Session Report Modal ── */
.report-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9,11,17,0.80);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.report-overlay.hidden { display: none; }

.report-card {
  background: #1a1d27;
  border: 1px solid #3d4268;
  border-radius: 16px;
  padding: 28px 32px;
  width: 560px;
  max-width: 95vw;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}

.report-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}
.report-title {
  font-size: 20px;
  font-weight: 700;
  color: #e2e8f0;
  margin-bottom: 3px;
}
.report-subtitle {
  font-size: 12px;
  color: #64748b;
}

.report-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.kpi {
  background: #252836;
  border: 1px solid #2d3148;
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-value {
  font-size: 22px;
  font-weight: 700;
  color: #818cf8;
  font-variant-numeric: tabular-nums;
}
.kpi-label {
  font-size: 10px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.report-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #475569;
  margin-bottom: 10px;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.report-table th {
  text-align: left;
  color: #64748b;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 4px 10px 8px;
  border-bottom: 1px solid #2d3148;
}
.report-table td {
  padding: 8px 10px;
  color: #cbd5e1;
  border-bottom: 1px solid #1e2235;
}
.report-table tr:last-child td { border-bottom: none; }

.rep-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.rep-dot-skim { background: #fbbf24; }
.rep-dot-swim { background: #60a5fa; }
.rep-dot-dive { background: #a78bfa; }

/* ── Floor plan controls ── */
.fp-controls {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(26,29,39,0.92);
  border: 1px solid #2d3148;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  z-index: 20;
}
.fp-controls.hidden { display: none; }
.fp-label { color: #818cf8; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
.fp-field { display: flex; align-items: center; gap: 6px; color: #94a3b8; }
.fp-field input[type="range"] { width: 80px; accent-color: #6366f1; }

/* ── Scale calibration dialog ── */
.scale-dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #1a1d27;
  border: 1px solid #4f46e5;
  border-radius: 12px;
  padding: 18px 22px;
  z-index: 50;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  min-width: 280px;
}
.scale-dialog.hidden { display: none; }
.scale-prompt { font-size: 13px; color: #e2e8f0; margin-bottom: 10px; font-weight: 500; }
.scale-input-row { display: flex; align-items: center; gap: 8px; }
.scale-unit { color: #64748b; font-size: 13px; flex-shrink: 0; }
.scale-dialog input[type="number"] {
  background: #252836; border: 1px solid #3d4268; border-radius: 6px;
  color: #e2e8f0; padding: 6px 8px; font-size: 13px;
}

/* ── Copyright ── */
#copyright {
  position: absolute;
  bottom: 10px;
  right: 14px;
  font-size: 11px;
  color: #2d3148;
  pointer-events: none;
  user-select: none;
  letter-spacing: 0.3px;
}

/* ── File controls ── */
#file-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.saved-badge {
  font-size: 11px;
  color: #34d399;
  opacity: 1;
  transition: opacity 0.5s;
  white-space: nowrap;
}
.saved-badge.hidden { opacity: 0; pointer-events: none; }
