/* ==========================================================================
   EqualEarthMap.in - Interactive Map Styles
   Responsive SVG Pan-Zoom, Search Overlay, and Details Drawer
   ========================================================================== */

.map-wrapper {
  position: relative;
  width: 100%;
  height: clamp(560px, 80vh, 880px);
  min-height: 520px;
  background-color: var(--map-ocean-bg);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  user-select: none;
}

.map-wrapper:fullscreen,
.map-wrapper:-webkit-full-screen,
.map-wrapper.fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-width: none !important;
  max-height: none !important;
  z-index: 999999 !important;
  border-radius: 0 !important;
  border: none !important;
  margin: 0 !important;
  padding: 0 !important;
  background-color: var(--map-ocean-bg) !important;
}

.map-wrapper:fullscreen .map-canvas-container,
.map-wrapper:-webkit-full-screen .map-canvas-container,
.map-wrapper.fullscreen .map-canvas-container {
  width: 100% !important;
  height: 100% !important;
}

.map-wrapper:fullscreen .map-svg,
.map-wrapper:-webkit-full-screen .map-svg,
.map-wrapper.fullscreen .map-svg {
  width: 100% !important;
  height: 100% !important;
}

/* SVG viewport & canvas */
.map-canvas-container {
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

.map-canvas-container.panning {
  cursor: grabbing;
}

.map-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Map Base Elements */
.map-ocean {
  fill: var(--map-ocean-bg);
  transition: fill var(--transition-normal);
}

.map-outline {
  stroke: var(--surface-border, #334155);
  stroke-width: 1.2px;
  transition: stroke var(--transition-normal);
}

.map-graticules {
  stroke: var(--surface-border-subtle, #1e293b);
  stroke-width: 0.5px;
  stroke-dasharray: 2, 3;
  opacity: 0.4;
  transition: stroke var(--transition-normal);
}

/* Modern Animation Keyframes */
@keyframes countryPulseDark {
  0%, 100% {
    filter: drop-shadow(0 0 6px rgba(0, 210, 255, 0.75)) drop-shadow(0 0 14px rgba(56, 189, 248, 0.4));
  }
  50% {
    filter: drop-shadow(0 0 14px rgba(0, 210, 255, 0.95)) drop-shadow(0 0 28px rgba(0, 210, 255, 0.65));
  }
}

@keyframes countryPulseLight {
  0%, 100% {
    filter: drop-shadow(0 2px 6px rgba(2, 132, 199, 0.45));
  }
  50% {
    filter: drop-shadow(0 4px 14px rgba(2, 132, 199, 0.75));
  }
}

/* Map Country Paths */
.map-country {
  fill: var(--map-land-default);
  stroke: var(--map-stroke);
  stroke-width: 0.6px;
  stroke-linejoin: round;
  transition: fill var(--transition-fast), stroke var(--transition-fast), filter var(--transition-fast);
  cursor: pointer;
}

.map-country:hover, .map-country:focus, .map-country.path-hovered {
  fill: var(--map-land-hover);
  stroke: var(--accent-cyan);
  stroke-width: 1.3px;
  outline: none;
  filter: drop-shadow(0 0 8px var(--accent-cyan-subtle));
}

.map-country.active {
  fill: var(--map-land-active) !important;
  stroke: var(--map-stroke-active) !important;
  stroke-width: 1.8px !important;
  animation: countryPulseDark 2.5s ease-in-out infinite;
}

[data-theme="light"] .map-country.active {
  animation: countryPulseLight 2.5s ease-in-out infinite !important;
}

.map-country.active-secondary {
  fill: var(--map-land-secondary) !important;
  stroke: var(--map-stroke-active) !important;
  stroke-width: 1.8px !important;
  filter: drop-shadow(0 0 12px rgba(251, 191, 36, 0.8));
}

[data-theme="light"] .map-country.active-secondary {
  filter: drop-shadow(0 3px 10px rgba(217, 119, 6, 0.55)) !important;
}

/* Google Maps Country Labels Layer */
.map-labels {
  user-select: none;
}

.map-country-label {
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-weight: 500;
  text-anchor: middle;
  dominant-baseline: central;
  paint-order: stroke fill;
  stroke-linejoin: round;
  stroke-linecap: round;
  letter-spacing: 0.025em;
  cursor: pointer;
  pointer-events: all;
  transition: fill var(--transition-fast), stroke var(--transition-fast), opacity var(--transition-normal);
}

/* Dark Mode (Default) */
.map-country-label {
  fill: #f1f3f4 !important;
  stroke: #0c1524 !important;
  stroke-width: 2.6px;
}

.map-country-label:hover,
.map-country-label.label-hovered {
  fill: #38bdf8 !important;
  stroke: #030712 !important;
  stroke-width: 3.2px !important;
}

.map-country-label.active-label {
  fill: #38bdf8 !important;
  stroke: #020617 !important;
  stroke-width: 3.5px !important;
  font-weight: 700 !important;
  opacity: 1 !important;
}

/* Day Mode (Soft Greyish Theme) */
[data-theme="light"] .map-country-label {
  fill: #1e293b !important;
  stroke: #ffffff !important;
  stroke-width: 2.8px;
}

[data-theme="light"] .map-country-label:hover,
[data-theme="light"] .map-country-label.label-hovered {
  fill: #0284c7 !important;
  stroke: #ffffff !important;
  stroke-width: 3.4px !important;
}

[data-theme="light"] .map-country-label.active-label {
  fill: #0284c7 !important;
  stroke: #ffffff !important;
  stroke-width: 3.5px !important;
  font-weight: 700 !important;
  opacity: 1 !important;
}

/* Progressive Disclosure Hierarchy like Google Maps */
/* Level 1: Major powers - always visible at world overview */
.map-country-label.level-1 {
  opacity: 0.95;
}

/* Level 2: Regional prominent nations - clean & legible at world view */
.map-country-label.level-2 {
  opacity: 0.85;
}

/* Level 3: Compact & high-density nations - hidden at world view to eliminate clutter, revealed on zoom */
.map-country-label.level-3 {
  opacity: 0;
  pointer-events: none;
}

/* When zoomed in */
.map-canvas-container.is-zoomed .map-country-label.level-3 {
  opacity: 0.92;
  pointer-events: all;
}

.map-canvas-container.is-zoomed .map-country-label.level-2,
.map-canvas-container.is-zoomed .map-country-label.level-1 {
  opacity: 1;
}

.map-wrapper.hide-labels .map-labels {
  display: none !important;
}

/* Floating Map Search Overlay */
.map-search-container {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 20;
  width: min(340px, calc(100% - 2rem));
}

.map-search-bar {
  position: relative;
  display: flex;
  align-items: center;
  background-color: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.map-search-bar:focus-within {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px var(--accent-cyan-subtle);
}

.map-search-icon {
  padding-left: 0.875rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

.map-search-input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 0.938rem;
  outline: none;
}

.map-search-input::placeholder {
  color: var(--text-muted);
}

.map-search-clear {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
}

.map-search-clear.visible {
  display: block;
}

.map-search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background-color: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  max-height: 280px;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  display: none;
  z-index: 30;
}

.map-search-results.visible {
  display: block;
}

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.875rem;
  cursor: pointer;
  border-bottom: 1px solid var(--surface-border-subtle);
  transition: background-color var(--transition-fast);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover, .search-result-item.selected {
  background-color: var(--accent-cyan-subtle);
}

.result-item-main {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.result-flag {
  font-size: 1.2rem;
  line-height: 1;
}

.result-name {
  font-weight: 500;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.result-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Floating Map Controls */
.map-controls {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 20;
}

.map-ctrl-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform var(--transition-spring), background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

.map-ctrl-btn:hover {
  background-color: var(--bg-card-hover);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
  transform: scale(1.1);
  box-shadow: var(--shadow-lg), 0 0 14px var(--accent-cyan-subtle);
}

.map-ctrl-btn:active {
  transform: scale(0.92);
}

/* Country Details Drawer / Panel */
.country-drawer {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  width: min(390px, calc(100% - 2rem));
  background-color: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 1.35rem;
  box-shadow: var(--shadow-xl), 0 0 32px rgba(0, 0, 0, 0.3);
  z-index: 25;
  transform: translateY(115%) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: transform 420ms cubic-bezier(0.16, 1, 0.3, 1), opacity 320ms cubic-bezier(0.16, 1, 0.3, 1), background-color var(--transition-fast);
  max-height: calc(100% - 2rem);
  overflow-y: auto;
}

.country-drawer.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.drawer-title-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.drawer-flag {
  font-size: 1.8rem;
  line-height: 1;
}

.drawer-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.drawer-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.drawer-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.drawer-close:hover {
  color: var(--text-primary);
}

.drawer-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.drawer-stat-item {
  background-color: var(--bg-elevated);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--surface-border-subtle);
}

.drawer-stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-bottom: 0.15rem;
}

.drawer-stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.drawer-description {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 1rem;
}

.drawer-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Floating Tooltip */
@keyframes tooltipPop {
  0% {
    opacity: 0;
    transform: translate(-50%, -105%) scale(0.92);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -120%) scale(1);
  }
}

.map-tooltip {
  position: absolute;
  pointer-events: none;
  background-color: var(--bg-card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--surface-border);
  color: var(--text-primary);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-md);
  font-size: 0.813rem;
  box-shadow: var(--shadow-lg), 0 0 16px var(--accent-cyan-subtle);
  z-index: 35;
  display: none;
  transform: translate(-50%, -120%);
  white-space: nowrap;
  animation: tooltipPop 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

.map-tooltip .tooltip-area {
  color: var(--accent-cyan);
  font-weight: 700;
  margin-left: 0.4rem;
}

/* Mobile Adjustments */
@media (max-width: 640px) {
  .map-wrapper {
    height: 60vh;
    min-height: 400px;
    border-radius: var(--radius-md);
    width: 100% !important;
    max-width: 100% !important;
  }

  .map-controls {
    top: 0.5rem;
    right: 0.5rem;
    gap: 0.35rem;
  }

  .map-ctrl-btn {
    width: 34px;
    height: 34px;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
  }

  .map-search-container {
    top: 0.5rem;
    left: 0.5rem;
    width: calc(100% - 3.75rem);
    max-width: none;
  }

  .map-search-input {
    font-size: 0.82rem;
    padding: 0.45rem 0.6rem;
  }

  .country-drawer {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 1rem;
    max-height: 65vh;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.5);
  }
}
