/* ── Variables ───────────────────────────────────────────────────────── */
:root {
  --bg:         #0d1117;
  --surface:    #111927;
  --surface2:   #0f3460;
  --sidebar-bg: rgba(10, 17, 35, 0.95);
  --accent:     #e94560;
  --accent2:    #f5a623;
  --text:       #dde3ee;
  --text-muted: #6a7a9a;
  --border:     #1e2d45;
  --font-mono:  'Courier New', Courier, monospace;
  --sidebar-w:  300px;
  --toggle-w:   20px;
  --radius:     6px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
}

/* ── Canvas ──────────────────────────────────────────────────────────── */
#bpCanvas {
  position: fixed;
  inset: 0;
  display: block;
  cursor: grab;
}
#bpCanvas.panning { cursor: grabbing; }

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--border);
  z-index: 20;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform var(--transition);
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }

.sidebar-header {
  padding: 15px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent2);
  letter-spacing: 0.05em;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Sidebar toggle ──────────────────────────────────────────────────── */
.sidebar-toggle {
  position: fixed;
  left: var(--sidebar-w);
  top: 50%;
  transform: translateY(-50%);
  z-index: 21;
  width: var(--toggle-w);
  height: 48px;
  background: var(--sidebar-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  padding: 0;
  transition: left var(--transition), color 0.15s;
}
.sidebar-toggle:hover { color: var(--text); }
.sidebar.collapsed + .sidebar-toggle { left: 0; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
button { cursor: pointer; border: none; font-family: inherit; }

.btn-load {
  width: 100%;
  padding: 9px 12px;
  background: var(--accent2);
  color: #1a0f00;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 14px;
  transition: opacity 0.15s;
}
.btn-load:hover { opacity: 0.88; }

.btn-action {
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.78rem;
  transition: color 0.15s, border-color 0.15s;
}
.btn-action:hover { color: var(--text); border-color: var(--text-muted); }

.btn-primary {
  padding: 8px 18px;
  background: var(--accent2);
  color: #1a0f00;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 700;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.88; }

.btn-secondary {
  padding: 8px 14px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 0.85rem;
  transition: border-color 0.15s;
}
.btn-secondary:hover { border-color: var(--text-muted); }

/* ── Info section ────────────────────────────────────────────────────── */
.info-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 4px;
}
.info-item { display: flex; flex-direction: column; gap: 2px; }
.info-item .key {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.info-item .val {
  font-size: 0.88rem;
  color: var(--text);
  word-break: break-word;
}

/* ── Badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-blueprint { background: var(--surface2); color: #82b0ff; }
.badge-book      { background: #2e1a4a; color: #cf82ff; }

/* ── Details / collapse ──────────────────────────────────────────────── */
.detail-section {
  border-top: 1px solid var(--border);
  margin-top: 6px;
}
.detail-section > summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
  outline: none;
}
.detail-section > summary::-webkit-details-marker { display: none; }
.detail-section > summary::after {
  content: '▾';
  font-size: 0.9rem;
  flex-shrink: 0;
  transition: transform 0.2s;
}
.detail-section[open] > summary::after { transform: rotate(-180deg); }

.count-badge {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 4px;
  flex: 1;
}

/* ── Entity list ─────────────────────────────────────────────────────── */
.entity-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-bottom: 8px;
}
.entity-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 7px;
  background: rgba(255,255,255,0.03);
  border-radius: 4px;
  font-size: 0.78rem;
}
.entity-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.entity-count {
  color: var(--accent2);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 0.75rem;
}
.entity-bar-wrap {
  width: 40px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}
.entity-bar {
  height: 100%;
  background: var(--accent2);
  border-radius: 2px;
}
.empty-state {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
  padding: 4px 0 8px;
}

/* ── JSON pre ────────────────────────────────────────────────────────── */
.json-pre {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  padding: 4px 0 10px;
  max-height: 400px;
  overflow-y: auto;
}
.j-key  { color: #82b0ff; }
.j-str  { color: #98c379; }
.j-num  { color: #d19a66; }
.j-bool { color: #c678dd; }
.j-null { color: var(--text-muted); }

/* ── Rendering options ───────────────────────────────────────────────── */
.option-list { padding-bottom: 8px; }

.option-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text);
  user-select: none;
}

.option-label { flex: 1; }

/* Toggle switch */
.toggle-input {
  appearance: none;
  -webkit-appearance: none;
  width: 32px;
  height: 18px;
  background: var(--border);
  border-radius: 9px;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}
.toggle-input::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--text-muted);
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: left 0.2s, background 0.2s;
}
.toggle-input:checked { background: var(--accent2); }
.toggle-input:checked::after { left: 17px; background: #1a0f00; }

/* ── Error box ───────────────────────────────────────────────────────── */
.error-box {
  background: rgba(233, 69, 96, 0.1);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: #ff8080;
  padding: 8px 12px;
  font-size: 0.8rem;
  margin-top: 8px;
  display: none;
}

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 520px;
  max-width: calc(100vw - 32px);
  transform: translateY(10px);
  transition: transform 0.2s;
  overflow: hidden;
}
.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 0.95rem; font-weight: 700; }
.modal-close {
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: var(--text); background: rgba(255,255,255,0.06); }

.modal-body { padding: 16px 20px; }

.field-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.bp-textarea {
  width: 100%;
  height: 110px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 10px;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}
.bp-textarea:focus { border-color: var(--accent2); }

.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}
.footer-actions { display: flex; gap: 8px; }
