/* style.css — Spoor */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #fff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #333;
}

/* ── Map ─────────────────────────────────────────────────────────────── */

#map-container {
  width: 100%;
  height: 100%;
  position: relative;
  touch-action: none;
  /* Clip the zoomed map at the viewport. The SVGs inside use overflow:visible
     so the inner-<g> scale doesn't let the viewBox clip away content that
     scaled past the SVG's bounds — clipping happens here instead. */
  overflow: hidden;
}

#tube-map,
#train-overlay {
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  -webkit-user-select: none;
  /* Let zoomed content render past the SVG's box; #map-container clips it. */
  overflow: visible;
}

/* ── Loading overlay ─────────────────────────────────────────────────── */

#loading-overlay {
  position: fixed;
  inset: 0;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.4s ease;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #ddd;
  border-top-color: #003688; /* Piccadilly blue */
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loading-msg {
  font-size: 14px;
  color: #555;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#loading-overlay.error #loading-spinner {
  display: none;
}

#loading-overlay.error #loading-msg {
  color: #c0392b;
}

/* Respect reduced-motion preference — skip loading overlay fade */
@media (prefers-reduced-motion: reduce) {
  #loading-overlay {
    transition: none;
  }
}

/* ── Error banner ────────────────────────────────────────────────────── */

#error-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(180, 90, 0, 0.9);
  color: #fff;
  font-size: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  padding: 6px 16px;
  border-radius: 12px;
  backdrop-filter: blur(4px);
  z-index: 200;
  pointer-events: none;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#error-banner.visible {
  opacity: 1;
}

/* Prevent SVG map elements from interfering with drag/click events.
   Train layer (#train-layer) is excluded — its children need pointer events. */
#tube-map > g:not(#train-layer),
#tube-map > g:not(#train-layer) * {
  pointer-events: none;
}

/* Train markers are interactive */
#train-layer circle,
#train-layer path {
  pointer-events: all;
  cursor: pointer;
}

/* ── Status bar ──────────────────────────────────────────────────────── */

/* Default position — only used briefly before ui.js moves it into the legend
   stack. After move, #legend #status (below) overrides positioning. */
#status {
  position: fixed;
  bottom: 12px;
  left: 16px;
  background: rgba(0, 0, 0, 0.65);
  color: #eee;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 12px;
  pointer-events: none;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}

/* Inside the legend stack: lay out as a normal flex item, no fixed position.
   Drop the pill background — the legend-items panel already provides one. */
#legend #status {
  position: static;
  background: transparent;
  backdrop-filter: none;
  padding: 0 0 6px 0;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  align-self: stretch;
}

#status[data-type="error"] {
  color: #ff6b6b;
}

#status[data-type="stale"] {
  color: #f39c12;
}

/* ── Legend panel (placeholder — wired in ticket 010) ────────────────── */

/* ── Legend panel ────────────────────────────────────────────────────── */

#legend {
  position: fixed;
  bottom: 12px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  z-index: 100;
  pointer-events: auto;
}

/* Items container — hidden when collapsed, grows upward when expanded.
   Uses max-height transition since display:none can't be animated. */
#legend-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(20, 20, 20, 0.88);
  border-radius: 10px;
  padding: 0 14px;
  margin-bottom: 6px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 2px 12px rgba(0,0,0,0.35);
  /* Collapsed state: clamp height to 0, hide content */
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: max-height 0.22s ease, opacity 0.18s ease, padding 0.22s ease;
}

#legend-items.expanded {
  max-height: 400px; /* generous — actual content is ~250px */
  opacity: 1;
  pointer-events: auto;
  padding: 10px 14px;
}

/* Toggle button */
#legend-toggle {
  background: rgba(20, 20, 20, 0.75);
  border: none;
  color: #ddd;
  font-size: 12px;
  font-family: inherit;
  padding: 5px 14px;
  border-radius: 12px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  user-select: none;
  transition: background 0.15s;
}

#legend-toggle:hover {
  background: rgba(40, 40, 40, 0.85);
}

/* Line rows */
.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  color: #eee;
  cursor: pointer;
  user-select: none;
  padding: 3px 0;
  opacity: 1;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.legend-item.hidden {
  opacity: 0.35;
}

@media (hover: hover) {
  .legend-item:hover {
    opacity: 0.85;
  }
}

.legend-swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Info panel ──────────────────────────────────────────────────────── */

#info-panel {
  position: fixed;
  top: 16px;
  right: 16px;
  background: rgba(20, 20, 20, 0.88);
  border-radius: 10px;
  padding: 14px 16px;
  min-width: 210px;
  max-width: 280px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 2px 16px rgba(0,0,0,0.4);
  /* Always flex so opacity transition fires; pointer-events controls interactivity */
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 13px;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

/* Visible state: fade in, enable interaction */
#info-panel.visible {
  opacity: 1;
  pointer-events: auto;
}

#info-panel button {
  transition: background 0.1s;
}

#info-panel button:hover {
  background: rgba(255,255,255,0.2) !important;
}

/* ── Train markers ───────────────────────────────────────────────────── */

/* Each marker is a <g class="train-marker" data-train-id="…"> */
.train-marker {
  transition: opacity 1s ease;
}

/* Fade-out transition is 3s — overrides the base 1s */
.train-marker[data-leaving] {
  transition: opacity 3s ease !important;
}

/* Train markers need pointer events for click (info panel, follow mode) */
.train-marker,
.train-marker * {
  pointer-events: all;
  cursor: pointer;
}
