/* ======================================================================
   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: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 12px;
}
.mm-header .mm-actions { margin-left: auto; }

/* Freshness chips — clickable filters with live counts */
.mm-fresh-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-secondary);
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.mm-fresh-chip:hover { border-color: var(--accent); }
.mm-fresh-chip.active {
  border-color: var(--accent);
  background: rgba(59,130,246,0.12);
  color: var(--text-primary);
}
.mm-chip-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 1px 6px; border-radius: 999px;
}

/* Station search */
.mm-search-wrap { display: flex; align-items: center; gap: 8px; }
.mm-search {
  width: 280px; padding: 6px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-primary); font-size: 12px;
  outline: none; transition: border-color 0.15s;
}
.mm-search:focus { border-color: var(--accent); }
.mm-search-count { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* --- Needs-attention rail ---------------------------------------------- */
.mm-attention {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  margin-bottom: 12px;
}
.mm-attn-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted); margin-right: 4px;
}
.mm-attn-clear { font-size: 12px; color: #22c55e; font-weight: 600; }
.mm-attn-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  font-size: 11px; color: var(--text-secondary);
  cursor: pointer; transition: border-color 0.15s;
}
.mm-attn-chip:hover { border-color: var(--accent); color: var(--text-primary); }
.mm-attn-chip.expired { border-color: rgba(239,68,68,0.45); }
.mm-attn-chip.missing { border-color: rgba(75,85,99,0.8); }
.mm-attn-chip.stale   { border-color: rgba(245,158,11,0.4); }
.mm-attn-age { font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--text-muted); }
.mm-attn-more { font-size: 11px; color: var(--text-muted); }
.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; }
.mm-line-chip { cursor: pointer; border: 1px solid transparent; transition: border-color 0.15s; }
.mm-line-chip:hover { border-color: var(--border); }
.mm-line-chip.active {
  border-color: var(--accent);
  background: rgba(59,130,246,0.12);
}

/* --- Stage --- */
.mm-map-wrap { position: relative; }
.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: auto;
  min-height: 600px;
  max-height: 78vh;
}

/* Zoom controls — float over the stage, bottom-left */
.mm-zoom-controls {
  position: absolute;
  left: 12px; bottom: 12px;
  display: flex; flex-direction: column; gap: 4px;
  z-index: 40;
}
.mm-zoom-controls button {
  width: 30px; height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s;
}
.mm-zoom-controls button:hover { border-color: var(--accent); }

/* --- Station detail drawer --------------------------------------------- */
.mm-detail {
  position: absolute;
  top: 12px; right: 12px; bottom: 12px;
  width: 330px;
  overflow-y: auto;
  background: rgba(15,23,42,0.97);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  z-index: 45;
  box-shadow: 0 10px 40px rgba(0,0,0,0.45);
}
.mm-det-header { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.mm-det-title { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.mm-det-path {
  display: flex; align-items: center; gap: 6px; margin-top: 4px;
}
.mm-det-path code {
  font-family: 'JetBrains Mono', monospace; font-size: 10px;
  color: var(--text-muted); word-break: break-all;
}
.mm-det-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 22px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.mm-det-close:hover { color: var(--text-primary); }
.mm-det-copy {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text-muted);
  font-size: 11px; cursor: pointer; padding: 1px 6px;
  flex-shrink: 0;
}
.mm-det-copy:hover { border-color: var(--accent); color: var(--text-primary); }
.mm-det-meta {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px 14px; margin-top: 12px;
}
.mm-det-meta > div { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--text-primary); }
.mm-det-lbl { font-size: 9px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.mm-det-slabar {
  margin-top: 10px; height: 5px; border-radius: 3px;
  background: var(--bg-secondary); overflow: hidden;
}
.mm-det-slabar-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.mm-det-slabar-fill.live    { background: #22c55e; }
.mm-det-slabar-fill.fresh   { background: #06b6d4; }
.mm-det-slabar-fill.stale   { background: #f59e0b; }
.mm-det-slabar-fill.expired { background: #ef4444; }

.mm-det-note {
  margin-top: 10px; padding: 8px 10px;
  font-size: 10.5px; line-height: 1.5; color: var(--text-muted);
  background: var(--bg-secondary); border-radius: 6px;
  border: 1px dashed var(--border);
}
.mm-det-slabar-fill.missing,
.mm-det-slabar-fill.unknown { background: #4b5563; }
.mm-det-lines { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.mm-det-section { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border); }
.mm-det-section-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 8px;
}
.mm-det-powers { display: flex; flex-wrap: wrap; gap: 6px; }
.mm-det-power {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--bg-secondary); color: var(--text-secondary);
}
.mm-det-refresher {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 6px;
}
.mm-det-refresher code {
  font-family: 'JetBrains Mono', monospace; font-size: 10px;
  color: #86efac; word-break: break-all; flex: 1;
  background: var(--bg-secondary); padding: 4px 8px; border-radius: 4px;
}
.mm-det-lineage { display: flex; flex-direction: column; gap: 3px; }
.mm-det-lineage-item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: 6px;
  background: none; border: 1px solid transparent;
  color: var(--text-secondary); font-size: 12px;
  cursor: pointer; text-align: left;
  transition: background 0.15s, border-color 0.15s;
}
.mm-det-lineage-item:hover {
  background: var(--bg-secondary);
  border-color: var(--border);
  color: var(--text-primary);
}
.mm-det-lineage-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mm-det-lineage-age {
  font-family: 'JetBrains Mono', monospace; font-size: 10px;
  color: var(--text-muted); flex-shrink: 0;
}
/* 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, opacity 0.2s;
}
.mm-station.mm-dim { opacity: 0.14; }
.mm-station-hit {
  fill: transparent;
}
.mm-station-halo {
  fill: none;
  stroke: transparent;
  stroke-width: 3;
  transition: stroke 0.2s;
}
.mm-station.mm-selected .mm-station-halo {
  stroke: var(--accent, #3b82f6);
  stroke-dasharray: 4 3;
  filter: drop-shadow(0 0 6px rgba(59,130,246,0.8));
}

/* Lineage overlay — the true produces/depends-on edges for the selection */
.mm-lineage-edge {
  fill: none;
  stroke: rgba(148,163,184,0.55);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
  pointer-events: none;
}
.mm-lineage-edge.direct {
  stroke: var(--accent, #3b82f6);
  stroke-width: 2.5;
  stroke-dasharray: 6 4;
}
.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); }
.mm-tooltip-hint {
  margin-top: 6px; font-size: 9px; color: var(--text-muted);
  font-style: italic; opacity: 0.8;
}

/* --- 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; }

/* --- Written inventory (collapsed by line) ---------------------------- */
.mm-led-na { background: #4b5563; color: transparent; box-shadow: none; }

.mm-inv-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}
.mm-inv-totals {
  font-size: 11px; color: var(--text-muted); margin-right: 4px;
}
.mm-inv-input {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-primary);
  padding: 6px 10px; font-size: 12px; min-width: 240px;
}
.mm-inv-input:focus { outline: none; border-color: var(--accent); }

.mm-inv-empty {
  padding: 14px; font-size: 12px; color: var(--text-muted);
}

.mm-inv-group { border-bottom: 1px solid var(--border); }
.mm-inv-group:last-child { border-bottom: none; }
.mm-inv-group[open] { background: rgba(255, 255, 255, 0.015); }

.mm-inv-summary {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer; list-style: none;
  font-size: 12px; user-select: none;
}
.mm-inv-summary::-webkit-details-marker { display: none; }
.mm-inv-summary:hover { background: var(--bg-secondary); }
.mm-inv-summary::before {
  content: '▸'; color: var(--text-muted); font-size: 10px;
  transition: transform 0.15s; display: inline-block;
}
.mm-inv-group[open] > .mm-inv-summary::before { transform: rotate(90deg); }

.mm-inv-bullet {
  width: 10px; height: 10px; border-radius: 3px; flex: none;
}
.mm-inv-name { font-weight: 600; }
.mm-inv-count {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 8px; font-size: 11px;
  color: var(--text-muted);
}
.mm-inv-meta { font-size: 11px; color: var(--text-muted); }
.mm-inv-leds { margin-left: auto; display: flex; gap: 10px; }
.mm-inv-led {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--text-muted);
}

.mm-inv-body { padding: 0 14px 14px; }
.mm-inv-note {
  font-size: 11px; color: var(--text-muted);
  margin: 0 0 10px; max-width: 100ch; line-height: 1.5;
}

.mm-inv-table {
  width: 100%; border-collapse: collapse; font-size: 11px;
}
.mm-inv-table th {
  text-align: left; font-weight: 700; font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted); padding: 6px 10px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.mm-inv-table td {
  padding: 6px 10px; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.mm-inv-table tbody tr:last-child td { border-bottom: none; }
.mm-inv-table tbody tr:hover { background: var(--bg-secondary); }
.mm-inv-table tbody tr[onclick] { cursor: pointer; }
.mm-inv-row-node td { color: var(--text-muted); font-style: italic; }

.mm-inv-key { font-weight: 600; white-space: nowrap; }
.mm-inv-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px; color: var(--text-muted); word-break: break-all;
}
.mm-inv-desc-cell {
  color: var(--text-muted); line-height: 1.5;
  min-width: 220px; max-width: 60ch;
}
.mm-inv-tag {
  display: inline-block; margin-left: 6px; padding: 0 5px;
  border-radius: 3px; background: var(--bg-secondary);
  border: 1px solid var(--border);
  font-size: 9px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--text-muted);
}
.mm-inv-pii {
  display: inline-block; padding: 0 5px; border-radius: 3px;
  background: rgba(244, 63, 94, 0.12); border: 1px solid rgba(244, 63, 94, 0.4);
  color: #fb7185; font-size: 9px; font-weight: 700; letter-spacing: 0.4px;
}

@media (max-width: 900px) {
  .mm-inv-leds { display: none; }
  .mm-inv-input { min-width: 140px; flex: 1; }
  .mm-inv-body { overflow-x: auto; }
}
