/* ─── Grid layouts for panel rows ─────────────────────────── */
.v2-grid { display: grid; gap: 12px; }
.v2-grid--1 { grid-template-columns: 1fr; }
.v2-grid--2 { grid-template-columns: 1fr; }
.v2-grid--3 { grid-template-columns: 1fr; }
@media (min-width: 720px) {
  .v2-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1000px) {
  .v2-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1200px) {
  .v2-grid--2-1 { grid-template-columns: 2fr 1fr; }
  .v2-grid--1-1 { grid-template-columns: 1fr 1fr; }
}

/* Plotly container.
 * CRITICAL: use explicit `height` not just `min-height`. On iOS Safari,
 * `min-height` alone causes `offsetHeight` to return 0 until a full layout
 * pass completes — and Plotly draws degenerate (blank) charts when it sees
 * a 0-height container. `height` forces a concrete dimension at parse time. */
.v2-plot { width: 100%; height: 320px; min-height: 320px; position: relative; }
.v2-plot--sm  { height: 240px; min-height: 240px; }
.v2-plot--md  { height: 360px; min-height: 360px; }
.v2-plot--lg  { height: 480px; min-height: 480px; }
/* Mobile-first: map is the dominant visual — taller by default */
.v2-plot--map {
  height: min(60vh, 520px);
  min-height: 480px;
}
@media (max-width: 599px) {
  /* Narrow phones: keep map tall but avoid clipping colorbar */
  .v2-plot--map { height: min(58vh, 500px); min-height: 380px; }
}
@media (min-width: 900px) {
  .v2-plot--map { height: 500px; min-height: 500px; }
  .v2-plot--lg  { height: 540px; min-height: 540px; }
}

/* Reduce panel body padding on mobile for the map panel */
@media (max-width: 899px) {
  [data-section="headline-map"] .v2-panel-body,
  .v2-panel--map .v2-panel-body {
    padding: 8px;
  }
}

/* Map state hover/click affordance */
.v2-map-legend {
  display: flex; gap: 10px; flex-wrap: wrap; font-size: 0.74rem; color: var(--text-muted);
  align-items: center;
}
.v2-map-legend-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }

/* Ranked-states (horizontal bars) — use plotly; for fallback list: */
.v2-rank-list {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 460px; overflow-y: auto;
}
.v2-rank-row {
  display: grid; grid-template-columns: 1fr auto; gap: 8px;
  align-items: center; padding: 8px 10px;
  background: var(--bg-panel); border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: 0.84rem;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.v2-rank-row:hover { border-color: var(--accent); }
.v2-rank-bar {
  height: 4px; margin-top: 4px;
  background: linear-gradient(90deg, var(--anti) var(--anti-pct, 50%), var(--pro) var(--anti-pct, 50%));
  border-radius: 2px;
}

/* Bill cards (used in lists / drill-downs) */
.v2-bill-card {
  background: var(--bg-panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.v2-bill-card:hover { border-color: var(--accent); }
.v2-bill-card:active { transform: scale(0.99); }
.v2-bill-key {
  font-family: var(--font-mono); font-size: 0.78rem;
  color: var(--accent); font-weight: 600;
}
.v2-bill-title {
  font-size: 0.92rem; font-weight: 500; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.35;
}
.v2-bill-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* State drilldown */
.v2-drill-stats {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
  margin-bottom: 12px;
}
@media (min-width: 600px) { .v2-drill-stats { grid-template-columns: repeat(4, 1fr); } }
.v2-drill-stat {
  background: var(--bg-panel); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px;
}
.v2-drill-stat .label { font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.v2-drill-stat .value {
  font-size: 1.2rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  letter-spacing: -0.02em;
}

/* Severity meter (bill drill-down) */
.v2-severity-meter {
  display: flex; gap: 3px; align-items: center;
}
.v2-severity-cell {
  width: 18px; height: 8px; border-radius: 2px;
  background: var(--bg-elev); border: 1px solid var(--line);
}
.v2-severity-cell.is-on { background: var(--anti-strong); border-color: var(--anti-strong); }

/* Bill drill-down section */
.v2-bill-section { margin-bottom: 16px; }
.v2-bill-section h3 {
  margin: 0 0 6px 0; font-size: 0.78rem; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--text-muted); font-weight: 600;
}
.v2-bill-meta-grid {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 14px;
  font-size: 0.86rem;
}
.v2-bill-meta-grid dt { color: var(--text-muted); }
.v2-bill-meta-grid dd { margin: 0; color: var(--text); }
.v2-snippet {
  background: var(--bg-input); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: 0.82rem; color: var(--text-muted); line-height: 1.5;
  font-family: var(--font-mono); white-space: pre-wrap;
  max-height: 420px; overflow-y: auto;
}
.v2-snippet mark {
  background: rgba(79,158,255,0.32); color: var(--text);
  border-radius: 2px; padding: 0 1px;
}
/* Text search bar above bill text */
.v2-text-search-wrap {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.v2-text-search {
  flex: 1; background: var(--bg-input); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 6px 10px;
  font-size: 0.84rem; color: var(--text); outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.v2-text-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(35,86,217,0.18);
}
.v2-text-search-count {
  font-size: 0.76rem; color: var(--text-dim); white-space: nowrap;
}
/* Clause rows */
.v2-clause-item {
  background: var(--bg-input); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 6px;
}
.v2-clause-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap;
}
.v2-clause-type {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.4px;
  font-weight: 600; padding: 2px 7px; border-radius: 3px;
  background: var(--bg-panel); color: var(--accent); border: 1px solid rgba(79,158,255,0.2);
}
.v2-clause-topic {
  font-size: 0.72rem; color: var(--text-dim);
}
.v2-clause-snippet {
  font-size: 0.82rem; color: var(--text-muted); line-height: 1.5;
  font-family: var(--font-mono); white-space: pre-wrap;
}
/* Provision type group header */
.v2-ptype-group { margin-bottom: 14px; }
.v2-ptype-group-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim); font-weight: 600; margin-bottom: 6px;
  padding-bottom: 4px; border-bottom: 1px solid var(--line);
}

/* Heatmap legend */
.v2-heat-legend {
  display: flex; gap: 4px; align-items: center;
  font-size: 0.72rem; color: var(--text-muted);
}

/* "Why this state" / quick-summary */
.v2-quickfact {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 12px;
  font-size: 0.84rem;
  align-items: baseline;
}
.v2-quickfact dt { color: var(--text-muted); font-weight: 500; }
.v2-quickfact dd { margin: 0; }

/* ── Enhanced-map supplementary styles (panels.css addition) ─────────────── */

/* Prevent overflow from pinch-scaled plotWrap bleeding out of container */
.emap-plot-wrap {
  overflow: visible;
  will-change: transform;
}

/* Mode-toggle: tighter on mobile, scrollable (reinforcement for older overrides) */
@media (max-width: 640px) {
  .emap-mode-toggle--scroll {
    max-width: calc(100vw - 24px);
  }
  .emap-mode-btn {
    padding: 4px 8px;
    font-size: 0.72rem;
    min-height: 28px;
  }
  .emap-toolbar {
    gap: 6px;
  }
}

/* Float-reset: subtly dimmed when not pinched */
.emap-plot-wrap:not(.emap-pinched) .emap-float-reset {
  opacity: 0.45;
}
.emap-plot-wrap.emap-pinched .emap-float-reset {
  opacity: 1;
  border-color: var(--accent, #3f7cff);
  color: var(--accent, #3f7cff);
}

/* Compare-two toast: flex when visible */
.emap-compare-two-toast:not([hidden]) {
  display: flex;
}

/* Hover-card min-width increase for new pill layout */
.emap-hover-card {
  min-width: 210px;
  max-width: 270px;
}

/* Bullet-proof dark theming for the state-preview pill.
 * Was rendering near-transparent beige over the map's red areas — applying
 * explicit opaque dark background + backdrop blur + light text overrides any
 * variable fallback or specificity issue. */
.emap-hover-card,
.emap-hover-card:not([hidden]) {
  background: #0a0c11 !important;
  background-color: #0a0c11 !important;
  -webkit-backdrop-filter: blur(8px) saturate(120%);
  backdrop-filter: blur(8px) saturate(120%);
  border: 1px solid #2a3142 !important;
  color: #e8edf7 !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.04) inset !important;
  opacity: 1 !important;
}
.emap-hover-card * {
  color: inherit;
}
.emap-hover-card .emap-hc-state,
.emap-hover-card .emap-hc-code,
.emap-hover-card .emap-hc-name {
  color: #ffffff !important;
}
.emap-hover-card .emap-hc-bar-label,
.emap-hover-card .emap-hc-stat-label,
.emap-hover-card .emap-hc-hint,
.emap-hover-card .emap-hc-mech {
  color: #9aa4b5 !important;
}
