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

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: #e8e8ec;
  display: grid;
  grid-template-areas:
    "toolbar toolbar"
    "sidebar canvas";
  grid-template-rows: 40px 1fr;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  overflow: hidden;
}

body.sidebar-hidden {
  grid-template-columns: 0 1fr;
}

/* ── Toolbar ───────────────────────────────────────────── */

#toolbar {
  grid-area: toolbar;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid #ddd;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

#toolbar-title {
  font-weight: 700;
  font-size: 14px;
  color: #0a3d62;
  margin-right: 6px;
  user-select: none;
  flex-shrink: 0;
}

#active-file-label {
  margin-left: auto;
  font-size: 12px;
  color: #666;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 360px;
  flex-shrink: 1;
}

#toolbar button {
  padding: 3px 8px;
  font-size: 14px;
  border: 1px solid #ccc;
  border-radius: 5px;
  background: white;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.4;
}

#toolbar button:hover { background: #f0f4f8; }
#toolbar button.active {
  background: #0a84ff;
  color: white;
  border-color: #0a84ff;
}

#auto-reload-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: #555;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
  white-space: nowrap;
}
#auto-reload-label input[type="checkbox"] {
  cursor: pointer;
  accent-color: #0a84ff;
}

#sse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ccc;
  flex-shrink: 0;
  margin-left: 2px;
  transition: background 0.3s;
}
#sse-dot.connected { background: #22c55e; }

#btn-sidebar { margin-left: 4px; }

/* ── Sidebar ────────────────────────────────────────────── */

#sidebar {
  grid-area: sidebar;
  background: white;
  border-right: 1px solid #ddd;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

body.sidebar-hidden #sidebar { display: none; }

#sidebar-header {
  padding: 6px;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}

#file-filter {
  width: 100%;
  padding: 5px 8px;
  font-size: 13px;
  border: 1px solid #ccc;
  border-radius: 5px;
  outline: none;
}
#file-filter:focus { border-color: #0a84ff; box-shadow: 0 0 0 2px rgba(10,132,255,0.15); }

#file-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.list-loading {
  display: block;
  padding: 10px 12px;
  font-size: 13px;
  color: #999;
  font-style: italic;
}

.file-item {
  display: block;
  padding: 6px 12px;
  font-size: 13px;
  color: #1a3a55;
  cursor: pointer;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-left: 3px solid transparent;
  transition: background 0.1s;
}
.file-item:hover { background: #f0f7ff; }
.file-item.active {
  background: #e6f0ff;
  border-left-color: #0a84ff;
  font-weight: 600;
  color: #0a3d62;
}

/* ── Canvas ─────────────────────────────────────────────── */

#canvas {
  grid-area: canvas;
  position: relative;
  overflow: hidden;
  background: #e8e8ec;
}

#canvas-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #aaa;
  font-size: 14px;
  pointer-events: none;
  user-select: none;
}

#svg-stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#svg-stage.pan-enabled  { cursor: grab; }
#svg-stage.pan-dragging { cursor: grabbing; }

#canvas svg {
  display: block;
  background: white;
  overflow: visible;
}

/* ── Minimap ─────────────────────────────────────────────── */

#minimap {
  position: fixed;
  right: 12px;
  bottom: 12px;
  width: 180px;
  height: 120px;
  background: rgba(255, 255, 255, 0.93);
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  padding: 6px;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
#minimap svg { width: 100%; height: 100%; display: block; }
.minimap-vp {
  fill: rgba(10, 132, 255, 0.15);
  stroke: #0a84ff;
  stroke-width: 0.8;
}
