/* Map page and Container */
.map {
  padding: 24px;
  text-align: center;
  position: relative;
  z-index: 5;
}

#map-container {
  background: var(--map-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 24px;
  backdrop-filter: blur(12px);
  box-shadow: var(--glow-red);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#map-loading {
  color: #b8b0b0;
  font-weight: 500;
}

#map-container svg {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.map-page-main {
  padding: 18px;
  text-align: center;
  position: relative;
}

/* --- Overlay Panel (Dual Tooltip & Detailed Card Modes) --- */
#map-overlay-panel {
  position: absolute;
  color: var(--text-primary);
  background: var(--map-overlay-bg);
  border: 1px solid var(--accent-gold);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), var(--glow-red);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  overflow: hidden;
  /* Smooth transitions for moving, scaling, and fading */
  transition: opacity 0.5s cubic-bezier(0.165, 0.84, 0.44, 1),
    transform 0.5s cubic-bezier(0.165, 0.84, 0.44, 1),
    left 0.5s cubic-bezier(0.165, 0.84, 0.44, 1),
    top 0.5s cubic-bezier(0.165, 0.84, 0.44, 1),
    width 0.5s cubic-bezier(0.165, 0.84, 0.44, 1),
    height 0.5s cubic-bezier(0.165, 0.84, 0.44, 1),
    padding 0.5s cubic-bezier(0.165, 0.84, 0.44, 1),
    border-color 0.5s ease;
}

/* Tooltip Mode (Compact, next to belly) */
#map-overlay-panel.tooltip-mode {
  width: 140px;
  height: 40px;
  padding: 0 12px;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.5px;
  pointer-events: none;
  /* Mouse passes through to the SVG shape */
  border-color: rgba(197, 168, 128, 0.4);
  background: var(--map-overlay-bg);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

html[lang="fa"] #map-overlay-panel.tooltip-mode {
  font-family: var(--font-fa);
  letter-spacing: 0;
}

#map-overlay-panel.tooltip-mode .map-popup-close {
  opacity: 0;
  pointer-events: none;
}

#map-overlay-panel.tooltip-mode .map-popup-content-wrap {
  gap: 0;
}

#map-overlay-panel.tooltip-mode .map-popup-shape-column {
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
  flex: 0;
}

#map-overlay-panel.tooltip-mode .map-popup-info-column {
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 0;
}

#map-overlay-panel.tooltip-mode .map-popup-title {
  font-size: 14px;
  border-bottom: 1px solid transparent;
  padding-bottom: 0;
  margin-top: 0;
  text-align: center;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#map-overlay-panel.tooltip-mode .map-popup-details-block {
  display: block;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  margin: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, max-height 0.35s ease;
}

/* Overlay Card Mode (Large, wide centered panel) */
#map-overlay-panel.overlay-mode {
  width: calc(100% - 80px);
  max-width: 720px;
  height: 280px;
  padding: 32px;
  border-radius: 12px;
  left: 50% !important;
  top: 50% !important;
  transform: translate(-50%, -50%) scale(1) !important;
  pointer-events: auto;
  /* Clickable elements inside */
  display: flex;
  flex-direction: column;
  justify-content: center;
  opacity: 1;
}

.map-popup-content-wrap {
  display: flex;
  align-items: center;
  gap: 32px;
  width: 100%;
  height: 100%;
  transition: all 0.35s ease;
}

html[dir="rtl"] .map-popup-content-wrap {
  flex-direction: row-reverse;
}

.map-popup-shape-column {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 220px;
  max-height: 220px;
  opacity: 1;
  transition: all 0.35s ease;
  position: relative;
  /* background glow behind the shape */
  background: radial-gradient(circle, rgba(158, 12, 12, 0.1) 0%, transparent 70%);
}

/* Ensure the cloned SVG path renders clearly with beautiful high-contrast styling */
.map-popup-shape-column svg {
  display: block;
  width: 75%;
  height: 75%;
  max-width: 165px;
  max-height: 165px;
  overflow: visible;
}

.cloned-province-path {
  fill: var(--accent-crimson-hover) !important;
  filter: drop-shadow(0 0 8px rgba(158, 12, 12, 0.5)) !important;
  transform-origin: center;
  transform-box: fill-box;
}

.map-popup-info-column {
  flex: 1.2;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: all 0.35s ease;
}

.map-popup-title {
  font-family: var(--font-title);
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid rgba(158, 12, 12, 0.2);
  padding-bottom: 8px;
  margin-top: 4px;
  transition: all 0.35s ease;
  width: 100%;
}

html[lang="fa"] .map-popup-title {
  font-family: var(--font-fa);
  font-size: 22px;
}

#map-overlay-panel.overlay-mode .map-popup-details-block {
  display: flex;
  flex-direction: column;
  gap: 16px;
  opacity: 1;
  animation: fade-in-details 0.35s ease forwards;
}

@keyframes fade-in-details {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Children of Card Mode */
.map-popup-close {
  position: absolute;
  top: 14px;
  right: 20px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 28px;
  font-weight: 300;
  cursor: pointer;
  line-height: 1;
  transition: opacity 0.3s ease, color 0.2s ease, transform 0.2s ease;
  z-index: 10;
  opacity: 1;
}

.map-popup-close:hover {
  color: var(--text-primary);
  transform: scale(1.1);
}

html[dir="rtl"] .map-popup-close {
  right: auto;
  left: 20px;
}

.map-popup-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  background: var(--map-stat-bg);
  border: 1px solid rgba(158, 12, 12, 0.35);
  border-radius: 12px;
  gap: 4px;
}

.map-popup-count {
  font-size: 36px;
  font-weight: 700;
  color: #ff6b6b;
  line-height: 1;
  text-shadow: 0 0 10px rgba(255, 107, 107, 0.2);
}

.map-popup-label {
  font-size: 12.5px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 500;
}

html[lang="fa"] .map-popup-label {
  font-family: var(--font-fa);
  letter-spacing: 0;
  font-size: 13px;
}

.map-popup-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  background: var(--accent-crimson);
  color: #fff;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(158, 12, 12, 0.3);
  transition: all 0.25s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.map-popup-btn:hover {
  background: var(--accent-crimson-hover);
  box-shadow: 0 6px 16px rgba(158, 12, 12, 0.55);
  transform: translateY(-1.5px);
}

html[lang="fa"] .map-popup-btn {
  font-family: var(--font-fa);
  letter-spacing: 0;
  text-transform: none;
}

/* Responsive adjustments for popup overlay */
@media (max-width: 768px) {
  #map-overlay-panel.overlay-mode {
    width: calc(100% - 32px);
    max-width: none;
    left: 16px !important;
    right: 16px !important;
    top: auto !important;
    bottom: 16px !important;
    transform: translateY(0) !important;
    padding: 20px;
    min-height: auto;
    height: auto;
    /* let height collapse on mobile */
  }

  .map-popup-content-wrap {
    flex-direction: column !important;
    gap: 16px;
  }

  .map-popup-shape-column {
    height: 120px;
    width: 100%;
  }

  .map-popup-info-column {
    width: 100%;
    gap: 12px;
  }
}

#map-container {
  width: 100%;
  max-width: 900px;
  height: 70vh;
  margin: 0 auto;
  position: relative;
}

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

@media (max-width: 768px) {
  #map-container {
    height: auto;
    aspect-ratio: 1200 / 1070.6;
  }

  .map-page-main {
    padding: 10px !important;
  }
}

/* --- SVG Map Badges --- */
.map-province-badge {
  filter: drop-shadow(0px 2px 5px rgba(0, 0, 0, 0.65));
}

.map-province-badge circle {
  transition: transform 250ms cubic-bezier(0.165, 0.84, 0.44, 1), fill 250ms ease, stroke 250ms ease;
}

.map-province-badge text {
  pointer-events: none;
  user-select: none;
  font-weight: 600;
}

/* Smooth overlay close state */
#map-overlay-panel.overlay-mode.closing {
  opacity: 0 !important;
  transform: translate(-50%, -50%) scale(0.9) !important;
  pointer-events: none;
}

@media (max-width: 768px) {
  #map-overlay-panel.overlay-mode.closing {
    transform: translateY(20px) scale(0.95) !important;
  }
}

/* Province Numbers (Hidden on screen, shown in print) */
.map-province-number {
  display: none;
}

/* Explanatory caption shown only when printing the map. */
.map-print-caption {
  display: none;
}

@media print {
  :root {
    --map-province-target: #e7e7e7 !important;
    --map-province-base: #c8c8c8 !important;
    --map-province-void: #f5ebe0 !important;
    --map-province-target-opacity: 0.95 !important;
    --map-province-base-opacity: 0.8 !important;
  }

  #map-overlay-panel,
  #map-loading,
  .cloned-province-path {
    display: none !important;
  }

  #map-container {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    height: auto !important;
    margin: 0 auto !important;
  }

  #map-container svg {
    filter: none !important;
    opacity: 1 !important;
    width: 100% !important;
    height: auto !important;
  }

  /* Ensure original map layout is printed without hover/selected highlighting */
  #map-container svg .map-province {
    stroke: #d2d2d2 !important;
    stroke-width: 0.5px !important;
    transform: none !important;
    filter: none !important;
  }

  #map-container svg .map-target {
    fill: var(--map-province-target) !important;
    opacity: var(--map-province-target-opacity, 0.95) !important;
  }

  #map-container svg .map-base {
    fill: var(--map-province-base) !important;
    opacity: var(--map-province-base-opacity, 0.8) !important;
  }

  #map-container svg .map-void {
    fill: var(--map-province-void) !important;
    opacity: 0.15 !important;
    stroke: none !important;
  }

  .map-province-number {
    display: block !important;
    font-size: 20px !important;
    font-family: 'Vazirmatn', 'Plus Jakarta Sans', sans-serif !important;
    fill: #777 !important;
    text-anchor: middle !important;
    dominant-baseline: middle !important;
    font-weight: 700 !important;
  }

  /* Center the map (and its caption) on its own page so it doesn't sit at the
     top with empty space below. */
  .map-page-main {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 100vh !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  #map-container svg {
    max-height: 80vh !important;
  }

  .map-print-caption {
    display: block !important;
    margin: 28px auto 0 !important;
    max-width: 600px !important;
    text-align: center !important;
    font-size: 11pt !important;
    line-height: 1.5 !important;
    color: #555 !important;
  }
}