/* ==========================================================================
   Jail411 Premium Map Explorer
   Dark-mode data visualization — Palantir / Bloomberg aesthetic
   ========================================================================== */

/* --------------------------------------------------------------------------
   Map Section Container
   -------------------------------------------------------------------------- */
.map-section {
  background: linear-gradient(180deg, #080E1A 0%, #0B1222 30%, #0D1526 70%, #0B1222 100%);
  padding: 60px 0 80px;
  position: relative;
  overflow: hidden;
}

.map-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(59,130,246,0.3), rgba(34,211,238,0.2), rgba(59,130,246,0.3), transparent);
}

.map-section::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(59,130,246,0.15), transparent);
}

.map-section-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
}

/* --------------------------------------------------------------------------
   Section Header
   -------------------------------------------------------------------------- */
.map-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 32px;
  gap: 24px;
}

.map-header-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.mhb-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10B981;
  box-shadow: 0 0 8px rgba(16,185,129,0.6);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px rgba(16,185,129,0.6); }
  50% { opacity: 0.6; box-shadow: 0 0 16px rgba(16,185,129,0.3); }
}

.mhb-text {
  font-family: 'Outfit', 'Source Sans 3', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #10B981;
  text-transform: uppercase;
}

.map-header-title {
  font-family: 'Outfit', 'Source Sans 3', sans-serif;
  font-size: 32px;
  font-weight: 700;
  color: #E2E8F0;
  line-height: 1.2;
  margin: 0 0 6px;
}

.map-header-sub {
  font-size: 15px;
  color: #64748B;
  margin: 0;
  line-height: 1.5;
}

.map-header-right {
  display: flex;
  gap: 16px;
  flex-shrink: 0;
}

.map-stat-pill {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 14px 20px;
  text-align: center;
  min-width: 120px;
}

.msp-number {
  display: block;
  font-family: 'Outfit', sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: #22D3EE;
  line-height: 1.2;
}

.msp-label {
  display: block;
  font-size: 11px;
  color: #64748B;
  font-weight: 500;
  letter-spacing: 0.03em;
  margin-top: 2px;
}

/* --------------------------------------------------------------------------
   Filter Chips
   -------------------------------------------------------------------------- */
.map-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.map-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  color: #94A3B8;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  font-family: 'Source Sans 3', sans-serif;
}

.map-filter-chip::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--chip-color);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.map-filter-chip:hover {
  border-color: rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
}

.map-filter-chip:hover .mfc-dot {
  box-shadow: 0 0 8px var(--chip-color);
}

/* Active state */
.map-filter-chip.active {
  border-color: var(--chip-color);
  background: color-mix(in srgb, var(--chip-color) 12%, transparent);
  color: #E2E8F0;
}

.map-filter-chip.active::before {
  opacity: 0.08;
}

.mfc-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: box-shadow 0.25s ease, opacity 0.25s ease;
  position: relative;
  z-index: 1;
}

.map-filter-chip:not(.active) .mfc-dot {
  opacity: 0.4;
}

.map-filter-chip.active .mfc-dot {
  box-shadow: 0 0 6px var(--chip-color);
}

.mfc-label {
  position: relative;
  z-index: 1;
}

.mfc-count {
  font-size: 11px;
  font-weight: 700;
  color: #64748B;
  position: relative;
  z-index: 1;
  transition: color 0.25s ease;
}

.map-filter-chip.active .mfc-count {
  color: var(--chip-color);
}

.mfc-check {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  color: var(--chip-color);
}

.map-filter-chip.active .mfc-check {
  opacity: 1;
  transform: scale(1);
}

/* Filter action buttons */
.map-filter-actions {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.mfa-btn {
  font-size: 11px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  background: transparent;
  color: #64748B;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Source Sans 3', sans-serif;
  letter-spacing: 0.02em;
}

.mfa-btn:hover {
  color: #94A3B8;
  border-color: rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.04);
}

/* --------------------------------------------------------------------------
   Map Frame
   -------------------------------------------------------------------------- */
.map-frame {
  position: relative;
  background: linear-gradient(135deg, rgba(11,18,34,0.8) 0%, rgba(22,32,51,0.6) 50%, rgba(11,18,34,0.8) 100%);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 16px;
  padding: 32px 40px 40px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.03) inset,
    0 20px 60px rgba(0,0,0,0.4),
    0 0 120px rgba(59,130,246,0.03);
}

/* Subtle grid pattern */
.map-grid-bg {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, black 30%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, black 30%, transparent 70%);
}

/* Ambient glow behind the map */
.map-glow {
  position: absolute;
  width: 600px;
  height: 400px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse, rgba(59,130,246,0.06) 0%, rgba(34,211,238,0.03) 40%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* Corner accents */
.map-corner {
  position: absolute;
  width: 24px;
  height: 24px;
  pointer-events: none;
  z-index: 5;
}

.map-corner::before,
.map-corner::after {
  content: '';
  position: absolute;
  background: rgba(59,130,246,0.3);
}

.map-corner-tl { top: 12px; left: 12px; }
.map-corner-tl::before { top: 0; left: 0; width: 24px; height: 1px; }
.map-corner-tl::after  { top: 0; left: 0; width: 1px; height: 24px; }

.map-corner-tr { top: 12px; right: 12px; }
.map-corner-tr::before { top: 0; right: 0; width: 24px; height: 1px; }
.map-corner-tr::after  { top: 0; right: 0; width: 1px; height: 24px; }

.map-corner-bl { bottom: 12px; left: 12px; }
.map-corner-bl::before { bottom: 0; left: 0; width: 24px; height: 1px; }
.map-corner-bl::after  { bottom: 0; left: 0; width: 1px; height: 24px; }

.map-corner-br { bottom: 12px; right: 12px; }
.map-corner-br::before { bottom: 0; right: 0; width: 24px; height: 1px; }
.map-corner-br::after  { bottom: 0; right: 0; width: 1px; height: 24px; }

/* --------------------------------------------------------------------------
   SVG Map Styling — Choropleth
   -------------------------------------------------------------------------- */
.map-svg-container {
  position: relative;
  z-index: 1;
  width: 100%;
}

.map-svg-container svg {
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 4px 20px rgba(0,0,0,0.3));
}

/* State paths — base style */
.map-svg-container svg path.state {
  stroke: rgba(148,163,184,0.15);
  stroke-width: 1;
  stroke-linejoin: round;
  paint-order: stroke;
  cursor: pointer;
  transition: fill 0.3s ease, stroke 0.3s ease, filter 0.3s ease, opacity 0.4s ease;
  /* Default fill — will be overridden by JS choropleth */
  fill: #1E3A5F;
}

/* Hover glow */
.map-svg-container svg path.state:hover {
  stroke: rgba(59,130,246,0.5);
  stroke-width: 1.5;
  filter: drop-shadow(0 0 8px rgba(59,130,246,0.3));
  z-index: 10;
}

/* Click flash */
.map-svg-container svg path.state.state-click {
  filter: drop-shadow(0 0 20px rgba(34,211,238,0.6)) brightness(1.5);
}

/* Dimmed state (when filters exclude it) */
.map-svg-container svg path.state.state-dimmed {
  fill: #0F1C2E !important;
  opacity: 0.4;
}

/* Entrance animation */
.map-svg-container svg path.state {
  opacity: 0;
}

.map-svg-container.map-entered svg path.state {
  opacity: 1;
}

/* Stagger animation handled via JS with transition-delay */

/* --------------------------------------------------------------------------
   Tooltip — Premium Dark Card
   -------------------------------------------------------------------------- */
.map-tip {
  position: absolute;
  display: none;
  z-index: 100;
  pointer-events: none;
  min-width: 200px;
  max-width: 260px;
}

.map-tip.visible {
  display: block;
  animation: tip-in 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes tip-in {
  from { opacity: 0; transform: translateY(4px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.map-tip-caret {
  display: none; /* Positioned dynamically if needed */
}

.map-tip-header {
  background: linear-gradient(135deg, #111B2E, #162033);
  border: 1px solid rgba(255,255,255,0.1);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  padding: 14px 16px 10px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.map-tip-name {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: #E2E8F0;
}

.map-tip-total {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 18px;
  color: #22D3EE;
  white-space: nowrap;
}

.map-tip-breakdown {
  background: #111B2E;
  border-left: 1px solid rgba(255,255,255,0.1);
  border-right: 1px solid rgba(255,255,255,0.1);
  padding: 6px 16px;
}

.map-tip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12px;
  color: #94A3B8;
}

.map-tip-row-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.map-tip-row-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.map-tip-row-count {
  font-weight: 600;
  color: #CBD5E1;
  font-variant-numeric: tabular-nums;
}

.map-tip-footer {
  background: linear-gradient(135deg, #111B2E, #162033);
  border: 1px solid rgba(255,255,255,0.1);
  border-top: 1px solid rgba(255,255,255,0.05);
  border-radius: 0 0 10px 10px;
  padding: 8px 16px;
  font-size: 11px;
  color: #64748B;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* --------------------------------------------------------------------------
   Remove old map styles that conflict
   -------------------------------------------------------------------------- */
/* The old .how-it-works banner is no longer shown above the map.
   Kept in CSS for backward compat but hidden if template changes. */

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .map-section {
    padding: 40px 0 60px;
  }

  .map-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .map-header-title {
    font-size: 24px;
  }

  .map-header-right {
    width: 100%;
    gap: 12px;
  }

  .map-stat-pill {
    flex: 1;
    min-width: 0;
    padding: 10px 14px;
  }

  .msp-number {
    font-size: 20px;
  }

  .map-filters {
    gap: 6px;
    margin-bottom: 16px;
  }

  .map-filter-chip {
    padding: 6px 10px;
    font-size: 12px;
    gap: 4px;
  }

  .mfc-count {
    display: none;
  }

  .map-filter-actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-start;
  }

  .map-frame {
    padding: 16px;
    border-radius: 12px;
  }

  .map-corner { display: none; }

  .map-tip {
    min-width: 170px;
    max-width: 220px;
  }

  .map-tip-header {
    padding: 10px 12px 8px;
  }

  .map-tip-name { font-size: 14px; }
  .map-tip-total { font-size: 15px; }

  .map-tip-breakdown {
    padding: 4px 12px;
  }

  .map-tip-footer {
    padding: 6px 12px;
    font-size: 10px;
  }
}

@media (max-width: 480px) {
  .map-section-inner {
    padding: 0 16px;
  }

  .map-header-title {
    font-size: 20px;
  }

  .map-header-sub {
    font-size: 13px;
  }

  .map-filter-chip {
    padding: 5px 8px;
    font-size: 11px;
    border-radius: 6px;
  }

  .mfc-check { display: none; }

  .map-frame {
    padding: 12px 8px 16px;
  }

  .map-tip {
    min-width: 150px;
  }
}

/* --------------------------------------------------------------------------
   State Labels — Abbreviation + Count overlay
   -------------------------------------------------------------------------- */
.state-labels {
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
}

.state-labels.labels-visible {
  opacity: 1;
}

.state-label-abbr {
  font-family: 'Outfit', 'Source Sans 3', sans-serif;
  font-size: 10px;
  font-weight: 700;
  fill: #fff;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: all;
  cursor: pointer;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
  transition: fill 0.2s ease, font-size 0.2s ease;
}

.state-label-count {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 8px;
  font-weight: 600;
  fill: rgba(255,255,255,0.6);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: all;
  cursor: pointer;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
  transition: fill 0.2s ease;
}

/* Hover state for labels */
.state-label-abbr.label-hover {
  fill: #22D3EE;
  font-size: 11px;
}

.state-label-count.label-hover {
  fill: #fff;
}

/* Connector lines for small NE states */
.state-label-line {
  stroke: rgba(255,255,255,0.25);
  stroke-width: 0.5;
  stroke-dasharray: 2 2;
}

.state-label-dot {
  fill: rgba(255,255,255,0.5);
}

/* Hide labels on very small screens */
@media (max-width: 640px) {
  .state-labels {
    display: none;
  }
}

/* Show abbreviation only (no counts) on medium screens */
@media (max-width: 900px) and (min-width: 641px) {
  .state-label-count {
    display: none;
  }
  .state-label-abbr {
    font-size: 8px;
  }
}
