/* ======================================================================
   Metro Map — formal topology of the Data OS universe
   Subway-line visualization of every parquet/JSON output and the
   pipelines that produce them, with live freshness LEDs per station.
   ====================================================================== */

#panel-map { padding-bottom: 24px; }

/* --- Header strip ----------------------------------------------------- */
.mm-header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 12px;
}
.mm-legend { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 12px; color: var(--text-secondary); }
.mm-legend-title { color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-size: 10px; margin-right: 4px; }
.mm-legend-item { display: inline-flex; align-items: center; gap: 6px; }

.mm-led {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block; box-shadow: 0 0 6px currentColor;
}
.mm-led-live    { background: #22c55e; color: #22c55e; }
.mm-led-fresh   { background: #06b6d4; color: #06b6d4; }
.mm-led-stale   { background: #f59e0b; color: #f59e0b; }
.mm-led-expired { background: #ef4444; color: #ef4444; }
.mm-led-missing { background: #4b5563; color: transparent; box-shadow: none; }
.mm-led-unknown { background: #6b7280; color: transparent; box-shadow: none; }

/* Pulse animation for live nodes — heartbeat that says "fresh data" */
@keyframes mm-pulse {
  0%, 100% { transform: scale(1);   opacity: 1;   }
  50%      { transform: scale(1.4); opacity: 0.55;}
}

/* --- Primary badge ---------------------------------------------------- */
.mm-primary-badge {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  min-width: 240px;
}
.mm-primary-led {
  width: 12px; height: 12px; border-radius: 50%;
  background: #4b5563;  /* unknown by default */
}
.mm-primary-badge.active .mm-primary-led {
  background: #22c55e; box-shadow: 0 0 10px #22c55e;
  animation: mm-pulse 2s ease-in-out infinite;
}
.mm-primary-badge.stale .mm-primary-led { background: #f59e0b; box-shadow: 0 0 10px #f59e0b; }
.mm-primary-badge.dead .mm-primary-led  { background: #ef4444; box-shadow: 0 0 10px #ef4444; }
.mm-primary-info { line-height: 1.2; }
.mm-primary-line1 { font-size: 12px; font-weight: 600; color: var(--text-primary); }
.mm-primary-line2 { font-size: 10px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace; }

.mm-actions { display: flex; gap: 8px; }
.mm-btn { padding: 6px 12px; font-size: 12px; }

/* --- Lines legend (key for subway-line colors) ----------------------- */
.mm-lines-legend {
  display: flex; flex-wrap: wrap; gap: 10px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 12px;
}
.mm-line-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px; border-radius: 999px;
  background: var(--bg-secondary);
  font-size: 12px;
}
.mm-line-bullet {
  width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid currentColor;
  background: var(--bg-card);
}
.mm-line-name { font-weight: 600; color: var(--text-primary); }
.mm-line-meta { color: var(--text-muted); font-size: 11px; }

/* --- Stage --- */
.mm-stage {
  position: relative;
  background:
    radial-gradient(ellipse at top left, rgba(59,130,246,0.08), transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(168,85,247,0.06), transparent 60%),
    var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  overflow-y: hidden;
  min-height: 600px;
}
/* Subtle scrollbar so the metro can extend past the viewport without
   eating visual space. */
.mm-stage::-webkit-scrollbar { height: 8px; }
.mm-stage::-webkit-scrollbar-track { background: transparent; }
.mm-stage::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
.mm-stage::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.mm-svg {
  display: block;
  min-width: 100%;
  /* width and height are set inline by the renderer based on the
     actual layout extents so the stage scrolls when the map is wide. */
}

/* --- SVG primitives --- */
.mm-line-path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 6;
  opacity: 0.85;
  transition: opacity 0.2s, stroke-width 0.2s;
}
.mm-line-path.dimmed   { opacity: 0.18; }
.mm-line-path.hovered  { opacity: 1.0; stroke-width: 8; }

.mm-station {
  cursor: pointer;
  transition: transform 0.15s;
}
.mm-station-hit {
  fill: transparent;
}
.mm-station-ring {
  stroke-width: 3;
  fill: var(--bg-card);
}
.mm-station-ring.interchange {
  stroke-width: 4;
  fill: #f8fafc;
}
.mm-station-led {
  /* Inner LED indicating freshness */
}
.mm-station-led.live    { fill: #22c55e; filter: drop-shadow(0 0 4px #22c55e); animation: mm-pulse 2.4s ease-in-out infinite; transform-origin: center; transform-box: fill-box; }
.mm-station-led.fresh   { fill: #06b6d4; filter: drop-shadow(0 0 3px #06b6d4); }
.mm-station-led.stale   { fill: #f59e0b; filter: drop-shadow(0 0 3px #f59e0b); }
.mm-station-led.expired { fill: #ef4444; filter: drop-shadow(0 0 3px #ef4444); animation: mm-pulse 1.2s ease-in-out infinite; transform-origin: center; transform-box: fill-box; }
.mm-station-led.missing { fill: #4b5563; }
.mm-station-led.unknown { fill: #6b7280; }
.mm-station-led.na      { fill: #94a3b8; }

.mm-station-label {
  fill: var(--text-primary);
  font-size: 11px;
  font-weight: 500;
  pointer-events: none;
  text-anchor: middle;
}
.mm-station-label-bg {
  fill: var(--bg-card);
  fill-opacity: 0.85;
  pointer-events: none;
}
.mm-station-label.host {
  fill: var(--text-muted);
  font-size: 9px;
  text-anchor: middle;
}

.mm-source {
  /* Sources are square-ish terminals */
}
.mm-source-rect {
  rx: 6; ry: 6;
  stroke-width: 3;
  fill: var(--bg-secondary);
}
.mm-source-label {
  fill: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
}

/* --- Tooltip --- */
.mm-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15,23,42,0.96);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-primary);
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
  max-width: 320px;
  z-index: 50;
}
.mm-tooltip-name { font-weight: 700; margin-bottom: 4px; }
.mm-tooltip-path { color: var(--text-muted); font-family: 'JetBrains Mono', monospace; font-size: 10px; margin-bottom: 6px; word-break: break-all; }
.mm-tooltip-row { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; }
.mm-tooltip-row .lbl { color: var(--text-muted); }
.mm-tooltip-lines {
  margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border);
  display: flex; gap: 6px; flex-wrap: wrap;
}
.mm-tooltip-line-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; padding: 2px 6px; border-radius: 999px;
  background: var(--bg-secondary);
}
.mm-tooltip-powers { margin-top: 6px; font-size: 10px; color: var(--text-muted); }

/* --- Daemon strip --- */
.mm-daemon-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}
.mm-daemon-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.mm-daemon-title { font-size: 13px; font-weight: 700; margin-bottom: 10px; color: var(--text-primary); }
.mm-daemon-sub   { font-weight: 400; color: var(--text-muted); font-size: 11px; }
.mm-daemon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 10px;
}
.mm-daemon-grid > div { display: flex; flex-direction: column; }
.mm-daemon-lbl { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.mm-daemon-val { font-size: 13px; font-weight: 600; font-family: 'JetBrains Mono', monospace; color: var(--text-primary); }

.mm-claims { display: flex; flex-wrap: wrap; gap: 8px; }
.mm-claim {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 999px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  font-size: 11px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.mm-claim:hover { border-color: var(--accent); }
.mm-claim.claimed {
  background: rgba(34,197,94,0.10);
  border-color: rgba(34,197,94,0.5);
}
.mm-claim.claimed .mm-claim-led { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.mm-claim-led { width: 8px; height: 8px; border-radius: 50%; background: #4b5563; }
.mm-claim-name { font-weight: 600; }
