/*!
 * index-map v0.1.0-draft — component styles
 * Home: Patrick Website/shared/map/  ·  Contract: INTERFACE.md
 *
 * Everything is namespaced under .index-map so it cannot collide with host-page
 * styles. Design tokens are declared ON .index-map (not :root) so the component
 * is self-sufficient when embedded standalone — a host page (TCBI / TSCI) can
 * override any token by setting it on .index-map or an ancestor.
 *
 * Palette is the patriotic-editorial / GitHub-dark scheme shared by both tools
 * (see _map-component-project Phase 0 assessment).
 */

.index-map {
  /* --- structural tokens --- */
  --im-bg:        #0d1117;
  --im-panel:     #161b22;
  --im-panel2:    #1c232c;
  --im-border:    #30363d;
  --im-text:      #e6edf3;
  --im-muted:     #8b949e;
  --im-accent:    #58a6ff;
  --im-bad:       #f85149;
  --im-warn:      #d29922;
  --im-nodata:    #3a3f47;

  /* --- index ramp (low cost -> high cost); host pages already define --r1..--r7,
     these are the component's own fallbacks so it renders standalone --- */
  --r1: #1a3a5c;
  --r2: #2e6e9e;
  --r3: #7dd3fc;
  --r4: #fff7d6;
  --r5: #fdba74;
  --r6: #fb7185;
  --r7: #dc2626;

  display: block;
  color: var(--im-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}

/* --- metric toggle bar --- */
.index-map__controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 10px;
}
.index-map__controls-label {
  font-size: 12px;
  color: var(--im-muted);
  margin-right: 4px;
}
.index-map__metric {
  background: var(--im-panel2);
  border: 1px solid var(--im-border);
  color: var(--im-text);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.index-map__metric:hover { border-color: var(--im-accent); }
.index-map__metric.is-active {
  background: var(--im-accent);
  color: var(--im-bg);
  font-weight: 700;
  border-color: transparent;
}

/* --- breadcrumb --- */
.index-map__breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  min-height: 26px;
}
.index-map__back {
  background: var(--im-panel2);
  border: 1px solid var(--im-border);
  color: var(--im-text);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.index-map__back:hover { border-color: var(--im-accent); }
.index-map__crumb { color: var(--im-accent); cursor: pointer; text-decoration: none; }
.index-map__crumb[role="button"]:hover { text-decoration: underline; }
.index-map__crumb.is-current { color: var(--im-text); font-weight: 600; cursor: default; }
.index-map__crumb-sep { color: var(--im-muted); }

/* --- stage: holds the svg, legend, tooltip, overlay --- */
.index-map__stage {
  position: relative;
  background: var(--im-panel);
  border: 1px solid var(--im-border);
  border-radius: 8px;
  padding: 12px;
}
.index-map__svg {
  display: block;
  width: 100%;
  height: auto;
}

/* --- choropleth regions --- */
.index-map__region {
  stroke: var(--im-bg);
  stroke-width: 0.5;
  cursor: pointer;
  transition: opacity 0.1s;
}
.index-map__region:hover { opacity: 0.85; }
.index-map__region.is-hover {
  stroke: var(--im-text);
  stroke-width: 1.4;
}
.index-map__region.is-selected {
  stroke: var(--im-accent);
  stroke-width: 1.8;
}

/* --- pinned regions (feature layer, v0.2.0) --- */
.index-map__region.is-pinned {
  stroke: var(--im-warn);
  stroke-width: 2;
}
.index-map__region.is-pinned.is-selected {
  stroke: var(--im-accent);
}

/* --- metro overlay (feature layer, v0.2.0) --- */
.index-map__metro {
  stroke: var(--im-text);
  stroke-width: 1.2;
  stroke-dasharray: 3 2;
  cursor: pointer;
  fill-opacity: 0.55;
  transition: fill-opacity 0.1s;
}
.index-map__metro:hover { fill-opacity: 0.8; }

/* --- tooltip --- */
.index-map__tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--im-panel2);
  border: 1px solid var(--im-border);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.45;
  max-width: 240px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 5;
}
.index-map__tooltip strong { color: var(--im-text); }
.index-map__tt-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
  color: var(--im-muted);
}
.index-map__tt-row span:last-child { color: var(--im-text); font-weight: 600; }
.index-map__tt-prov {
  margin-top: 4px;
  font-size: 10px;
  color: var(--im-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* --- legend --- */
.index-map__legend {
  position: absolute;
  right: 20px;
  bottom: 20px;
  background: rgba(13, 17, 23, 0.82);
  border: 1px solid var(--im-border);
  border-radius: 6px;
  padding: 8px 10px;
}
.index-map__legend-title {
  font-size: 11px;
  color: var(--im-muted);
  margin-bottom: 5px;
}
.index-map__legend-ramp { display: flex; }
.index-map__legend-sw {
  width: 22px;
  height: 10px;
  display: inline-block;
}
.index-map__legend-sw:first-child { border-radius: 2px 0 0 2px; }
.index-map__legend-sw:last-child { border-radius: 0 2px 2px 0; }
.index-map__legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--im-muted);
  margin-top: 2px;
}

/* --- overlay: loading + error states --- */
.index-map__overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(13, 17, 23, 0.92);
  border-radius: 8px;
  z-index: 10;
  text-align: center;
  padding: 24px;
}
.index-map__overlay-msg {
  font-size: 13px;
  color: var(--im-muted);
  max-width: 80%;
}
.index-map__overlay.is-error .index-map__overlay-msg { color: var(--im-bad); }
.index-map__overlay-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--im-bad);
  color: var(--im-bad);
  font-weight: 700;
  font-size: 20px;
  line-height: 30px;
}
.index-map__spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--im-border);
  border-top-color: var(--im-accent);
  border-radius: 50%;
  animation: index-map-spin 0.8s linear infinite;
}
@keyframes index-map-spin {
  to { transform: rotate(360deg); }
}

/* --- responsive: the svg uses viewBox + preserveAspectRatio, so it scales on
   its own; no resize handler needed. The legend tucks in on narrow embeds. --- */
@media (max-width: 560px) {
  .index-map__legend { right: 12px; bottom: 12px; padding: 6px 8px; }
  .index-map__legend-sw { width: 16px; }
}

/* ===========================================================================
   Accessibility — keyboard focus + text-equivalent data table (v0.3.0)
   =========================================================================== */

/* Keyboard focus ring on a choropleth region. :focus-visible keeps the ring
   off mouse clicks; the white stroke is layered after .is-selected so it wins. */
.index-map__region:focus { outline: none; }
.index-map__region:focus-visible {
  outline: none;
  stroke: var(--im-text);
  stroke-width: 3;
}
.index-map__metric:focus-visible,
.index-map__back:focus-visible,
.index-map__crumb:focus-visible {
  outline: 2px solid var(--im-accent);
  outline-offset: 2px;
}

/* Text-equivalent data table — the same data the choropleth shows, for screen
   readers and anyone who would rather read a table. Collapsed by default. */
.index-map__data-table {
  margin-top: 10px;
  background: var(--im-panel);
  border: 1px solid var(--im-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
}
.index-map__data-table > summary {
  cursor: pointer;
  color: var(--im-accent);
  font-weight: 600;
  padding: 4px 0;
}
.index-map__data-table > summary:focus-visible {
  outline: 2px solid var(--im-accent);
  outline-offset: 2px;
}
.index-map__data-table-body {
  max-height: 360px;
  overflow: auto;
  margin-top: 8px;
}
.index-map__dt {
  width: 100%;
  border-collapse: collapse;
}
.index-map__dt caption {
  text-align: left;
  color: var(--im-muted);
  font-size: 11px;
  padding: 4px 0 8px;
}
.index-map__dt th,
.index-map__dt td {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid var(--im-border);
}
.index-map__dt thead th {
  position: sticky;
  top: 0;
  background: var(--im-panel2);
  color: var(--im-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.index-map__dt tbody th {
  font-weight: 600;
  color: var(--im-text);
}
.index-map__dt tbody td { color: var(--im-muted); }
.index-map__dt tbody tr:hover td,
.index-map__dt tbody tr:hover th { background: var(--im-panel2); }
/* selected row — map click syncs the data table (v0.3.1) */
.index-map__dt tbody tr.is-selected th[scope="row"],
.index-map__dt tbody tr.is-selected td { background: var(--im-panel2); }
.index-map__dt tbody tr.is-selected th[scope="row"] {
  box-shadow: inset 3px 0 0 0 var(--im-accent);
  color: var(--im-accent);
}
