html, body { height:100% }
.label{ font-family: Vazirmatn, sans-serif; font-size:12px; text-shadow:0 0 6px #fff }
.map-wrap{ height:calc(100vh - 110px) }
#map{
  height:100vh;
  height:100svh;
  height:100dvh;
  width:100%;
}

/* ✅ CLS Fix: CSS Containment for layout stability */
.ama-main{
  isolation: isolate;
  position: relative;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  contain: layout; /* ✅ Prevent layout shifts */
  /* ✅ حذف pointer-events: none برای جلوگیری از مشکل در موبایل */
}

.ama-panel{
  position: absolute;
  z-index: 1001;
  pointer-events: auto; /* ✅ پنل‌ها همیشه کلیک‌پذیر باشند */
  background: rgba(255,255,255,.9);
  backdrop-filter: saturate(150%) blur(4px);
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,.12);
  padding: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  contain: layout style; /* ✅ Isolate panel layout */
}

.map-panel{ max-height:calc(100dvh - 32px); overflow:auto; }
.ama-layer-dock{ top:16px; right:16px; width:320px; max-width:calc(50% - 24px); color:#000; }
.ama-top-dock{ top:16px; left:16px; width:280px; max-width:calc(50% - 24px); }

/* ✅ بهبود یافته: Prevent map interaction through panels - Mobile-friendly */
#map {
  pointer-events: auto;
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  z-index: 1; /* زیرتر از پنل‌ها */
  touch-action: pan-x pan-y; /* بهبود تاچ در موبایل */
  contain: layout style; /* ✅ Prevent map-induced layout shifts */
}

.ama-panel-bd{ overflow:auto; }

.ama-panel-collapsed .ama-panel-bd{ display:none; }
.ama-panel-collapsed .ama-panel-resize-handle{ display:none; }

.ama-panel-resize-handle{ height:8px; cursor:ns-resize; }

.ama-panel-header{ display:flex; justify-content:space-between; align-items:center; margin-bottom:8px; border-bottom:1px solid rgba(0,0,0,.08); padding-bottom:8px; }
.ama-panel-title{ font:600 16px system-ui; }
.ama-settings-btn{ border:0; background:transparent; cursor:pointer; opacity:.7; }

.ama-tabs{ display:flex; gap:8px; margin-bottom:8px; }
.ama-tab-btn{ flex:1; padding:8px 12px; border-radius:10px; border:0; cursor:pointer; }
.ama-tab-active{ background:#2563eb; color:#fff; }
.ama-tab-inactive{ background:#e5e7eb; }

.ama-checkbox-grid{ display:grid; gap:8px; }

.ama-check-item{ display:flex; align-items:center; gap:8px; }

.ama-top-badge{ padding:.25rem .5rem; border-radius:9999px; background:#dbeafe; color:#1d4ed8; font:600 12px system-ui; }
.ama-top-table{ width:100%; font:500 12px system-ui; color:#374151; }
.ama-top-thead{ background:#f9fafb; color:#4b5563; }
.ama-top-th{ padding:6px; }

/* ✅ Custom Marker Styles - CLS Optimized */
.custom-marker {
  background: transparent !important;
  border: none !important;
  will-change: transform; /* ✅ Optimize for animations */
  contain: layout style paint; /* ✅ Prevent marker layout shifts */
}

/* ✅ CRITICAL: Hide default Leaflet markers (broken icons from Point features) */
/* فقط custom-marker نمایش داده شود، بقیه مخفی شوند */
.leaflet-marker-icon:not(.custom-marker) {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  width: 0 !important;
  height: 0 !important;
  max-width: 0 !important;
  max-height: 0 !important;
  min-width: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
  position: absolute !important;
  left: -9999px !important;
  top: -9999px !important;
}

.marker-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  contain: layout style paint; /* ✅ Isolate marker rendering */
  width: 36px; /* ✅ Reserve space */
  height: 36px; /* ✅ Reserve space */
}

.marker-icon {
  font-size: 28px;
  position: relative;
  z-index: 2;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.4));
  transition: transform 0.2s ease, filter 0.2s ease;
}

.custom-marker:hover .marker-icon {
  transform: scale(1.2);
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.6));
}

.marker-pulse {
  position: absolute;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  opacity: 0.4;
  animation: pulse 2s ease-out infinite;
}

@keyframes pulse {
  0% {
    transform: scale(0.8);
    opacity: 0.6;
  }
  100% {
    transform: scale(2);
    opacity: 0;
  }
}

/* ✅ Custom Popup Styles */
.custom-popup {
  font-family: 'Vazirmatn', 'Vazir', sans-serif;
  min-width: 200px;
  direction: rtl;
  text-align: right;
}

.custom-popup h3 {
  margin: 0 0 8px;
  color: #0ea5e9;
  font-size: 16px;
  font-weight: 600;
  border-bottom: 2px solid #0ea5e9;
  padding-bottom: 4px;
}

.custom-popup p {
  margin: 6px 0;
  font-size: 14px;
  color: #334155;
}

.custom-popup strong {
  color: #1e293b;
  font-weight: 600;
}

/* ✅ Leaflet popup override for RTL */
.leaflet-popup-content-wrapper {
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.leaflet-popup-content {
  margin: 12px 16px;
}

/* ✅ Interactive improvements */
.leaflet-interactive {
  transition: all 0.2s ease;
  cursor: pointer;
}

.leaflet-interactive:hover {
  stroke-width: 3;
  transform: scale(1.05);
}

/* ✅ Polygon borders - force visibility */
.province-border {
  stroke: #ef4444 !important;
  stroke-width: 5px !important;
  stroke-opacity: 1 !important;
  fill-opacity: 0.03 !important;
}

.county-border {
  stroke: #94a3b8 !important;
  stroke-width: 2px !important;
  stroke-opacity: 0.8 !important;
}

/* ✅ Polygon tooltip styling */
.polygon-tooltip {
  background: rgba(15, 23, 42, 0.95) !important;
  border: 2px solid #ef4444 !important;
  border-radius: 8px !important;
  color: #f1f5f9 !important;
  font-family: 'Vazirmatn', 'Vazir', sans-serif !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  padding: 8px 12px !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
  direction: rtl !important;
  text-align: center !important;
}

.polygon-tooltip::before {
  border-top-color: #ef4444 !important;
}

/* ✅ Map Legend Styles */
.map-legend {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-family: 'Vazirmatn', 'Vazir', sans-serif;
  direction: rtl;
  max-width: 280px;
  border: 2px solid #ef4444;
}

.legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid #ef4444;
}

.legend-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
}

.legend-toggle {
  background: none;
  border: none;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  color: #ef4444;
  padding: 0 8px;
  line-height: 1;
}

.legend-toggle:hover {
  color: #dc2626;
}

.legend-content {
  font-size: 13px;
}

.legend-section {
  margin-bottom: 12px;
}

.legend-section h4 {
  margin: 0 0 8px 0;
  font-size: 14px;
  font-weight: 600;
  color: #475569;
}

.legend-item {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
  gap: 8px;
}

.legend-line {
  display: inline-block;
  width: 30px;
  height: 3px;
  border-radius: 2px;
}

.legend-province {
  background: #ef4444;
  height: 5px;
}

.legend-county {
  background: #94a3b8;
  height: 2px;
}

.legend-marker {
  font-size: 20px;
  line-height: 1;
}

.legend-help ul {
  margin: 8px 0 0 0;
  padding-right: 20px;
  font-size: 12px;
  color: #64748b;
  line-height: 1.6;
}

.legend-help li {
  margin-bottom: 4px;
}

/* ✅ Map Info Panel */
.map-info-panel {
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(10px);
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  font-family: 'Vazirmatn', 'Vazir', sans-serif;
  direction: rtl;
  color: #f1f5f9;
  min-width: 220px;
  border: 2px solid #0ea5e9;
}

.map-info-panel h4 {
  margin: 0 0 8px 0;
  font-size: 16px;
  font-weight: 700;
  color: #0ea5e9;
  border-bottom: 2px solid #0ea5e9;
  padding-bottom: 4px;
}

.map-info-panel p {
  margin: 6px 0;
  font-size: 14px;
  line-height: 1.5;
}

.map-info-hint {
  color: #94a3b8;
  font-style: italic;
  text-align: center;
}

/* ✅ Map Control Buttons */
.map-control-btn {
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid #0ea5e9;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: all 0.2s ease;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-control-btn:hover {
  background: #0ea5e9;
  color: white;
  transform: scale(1.1);
}

.map-control-btn:active {
  transform: scale(0.95);
}

/* ✅ Tour/Guide Overlay */
.tour-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.tour-dialog {
  background: white;
  padding: 32px;
  border-radius: 16px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  font-family: 'Vazirmatn', 'Vazir', sans-serif;
  direction: rtl;
  text-align: right;
  animation: slideUp 0.4s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.tour-dialog h2 {
  margin: 0 0 16px 0;
  color: #0f172a;
  font-size: 24px;
}

.tour-dialog p {
  margin: 12px 0;
  color: #475569;
  line-height: 1.6;
}

.tour-dialog ul {
  margin: 12px 0;
  padding-right: 24px;
  color: #475569;
  line-height: 1.8;
}

.tour-dialog li {
  margin-bottom: 8px;
}

.tour-close-btn {
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  color: white;
  border: none;
  padding: 12px 32px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  margin-top: 16px;
  font-family: 'Vazirmatn', 'Vazir', sans-serif;
  transition: all 0.2s ease;
}

.tour-close-btn:hover {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

.tour-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 14px;
  color: #64748b;
  cursor: pointer;
}

.tour-checkbox input {
  cursor: pointer;
}

/* ===== Mobile Sidebar ===== */

/* Hamburger Menu Button - Hidden by default, shown in mobile */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1100;
  width: 48px;
  height: 48px;
  background: rgba(14, 165, 233, 0.95);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.mobile-menu-btn:hover {
  background: rgba(14, 165, 233, 1);
  transform: scale(1.05);
}

.mobile-menu-btn:active {
  transform: scale(0.95);
}

.hamburger-line {
  width: 24px;
  height: 3px;
  background: white;
  border-radius: 2px;
  transition: all 0.3s ease;
}

.mobile-menu-btn.active .hamburger-line:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}

.mobile-menu-btn.active .hamburger-line:nth-child(2) {
  opacity: 0;
}

.mobile-menu-btn.active .hamburger-line:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

/* Mobile Sidebar */
.mobile-sidebar {
  display: none;
  position: fixed;
  top: 0;
  right: -100%;
  width: 85%;
  max-width: 360px;
  height: 100vh;
  background: rgba(15, 23, 42, 0.98);
  backdrop-filter: blur(10px);
  z-index: 1200;
  transition: right 0.3s ease;
  overflow-y: auto;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
}

.mobile-sidebar.open {
  right: 0;
}

.mobile-sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 2px solid #0ea5e9;
  background: rgba(14, 165, 233, 0.1);
  position: sticky;
  top: 0;
  z-index: 10;
}

.mobile-sidebar-title {
  font-size: 20px;
  font-weight: 700;
  color: #0ea5e9;
  margin: 0;
}

.mobile-sidebar-close {
  background: transparent;
  border: none;
  color: #f1f5f9;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.mobile-sidebar-close:hover {
  color: #0ea5e9;
  transform: scale(1.1);
}

.mobile-sidebar-content {
  padding: 16px;
}

#mobile-panels-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#mobile-panels-container .ama-panel {
  position: static !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(14, 165, 233, 0.2);
}

#mobile-panels-container .ama-panel-header {
  border-bottom: 1px solid rgba(14, 165, 233, 0.3);
  background: rgba(14, 165, 233, 0.05);
}

#mobile-panels-container .ama-panel-title {
  color: #0ea5e9;
}

/* Sidebar Overlay */
.mobile-sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1150;
  opacity: 0;
  pointer-events: none; /* ✅ غیرفعال کردن click روی overlay وقتی بسته است */
  transition: opacity 0.3s ease;
}

.mobile-sidebar-overlay.active {
  display: block; /* ✅ فقط وقتی active است نمایش بده */
  opacity: 1;
  pointer-events: auto; /* ✅ فعال کردن click فقط وقتی باز است */
}

/* ===== Responsive Design ===== */

/* Tablet: 768px - 1024px */
@media (max-width: 1024px) {
  .ama-layer-dock {
    width: 280px;
    max-width: calc(50% - 24px);
  }

  .ama-top-dock {
    width: 260px;
    max-width: calc(50% - 24px);
  }

  .ama-panel {
    font-size: 13px;
    max-height: calc(100vh - 32px);
  }

  .ama-panel-title {
    font-size: 15px;
  }

  /* Stack panels vertically on smaller tablets if needed */
  @media (max-width: 900px) {
    .ama-top-dock {
      top: auto;
      bottom: 16px;
      left: 16px;
    }
  }
}

/* Mobile: max-width 768px */
@media (max-width: 768px) {
  /* Show mobile menu button and sidebar */
  .mobile-menu-btn {
    display: flex;
  }

  .mobile-sidebar {
    display: block;
  }

  /* ✅ Overlay را فعال نکن - فقط با .active class فعال می‌شود */
  /* .mobile-sidebar-overlay باید با JavaScript کنترل شود */

  /* Hide original panels in mobile - they'll be in sidebar */
  .ama-layer-dock,
  .ama-top-dock {
    display: none !important;
  }

  /* Main layout adjustments */
  .is-mobile {
    flex-direction: column;
  }

  .is-mobile #map {
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    min-height: 100vh;
  }

  .is-mobile .ama-panel {
    position: static;
    width: 100%;
    margin: 0;
  }

  /* Header adjustments */
  .ama-panel-header {
    padding-bottom: 6px;
    margin-bottom: 6px;
  }

  .ama-panel-title {
    font-size: 14px;
  }

  .ama-settings-btn {
    font-size: 20px;
  }

  /* Tabs responsive */
  .ama-tabs {
    gap: 4px;
  }

  .ama-tab-btn {
    padding: 6px 8px;
    font-size: 12px;
  }

  /* Table responsive */
  .ama-top-table {
    font-size: 11px;
  }

  .ama-top-th {
    padding: 4px;
  }

  /* Checkbox grid */
  .ama-checkbox-grid {
    gap: 6px;
  }

  .ama-checkbox-grid label {
    font-size: 13px;
  }

  /* Markers */
  .marker-icon {
    font-size: 24px;
  }

  .marker-container {
    width: 32px;
    height: 32px;
  }

  /* Legend */
  .map-legend {
    max-width: 240px;
    font-size: 12px;
    padding: 12px;
  }

  /* Tour dialog */
  .tour-dialog {
    padding: 24px;
    font-size: 14px;
  }

  /* Info panel */
  .map-info-panel {
    min-width: 180px;
    padding: 12px;
    font-size: 12px;
  }

  .map-info-panel h4 {
    font-size: 14px;
  }

  .map-info-panel p {
    font-size: 12px;
  }
}

/* Small Mobile: max-width 480px */
@media (max-width: 480px) {
  .is-mobile #map {
    height: 50vh;
    min-height: 350px;
  }

  .ama-layer-dock,
  .ama-top-dock {
    bottom: 4px !important;
    left: 4px !important;
    right: 4px !important;
    width: calc(100% - 8px) !important;
    padding: 8px;
  }

  .ama-top-dock {
    top: 68px !important;
  }

  .ama-panel-title {
    font-size: 13px;
  }

  .ama-tab-btn {
    padding: 5px 6px;
    font-size: 11px;
  }

  .ama-top-table {
    font-size: 10px;
  }

  .ama-checkbox-grid label {
    font-size: 12px;
  }

  .map-legend {
    max-width: 200px;
    padding: 10px;
    font-size: 11px;
  }

  .tour-dialog {
    padding: 20px;
    font-size: 13px;
    width: 95%;
  }

  .tour-dialog h2 {
    font-size: 20px;
  }

  .marker-icon {
    font-size: 20px;
  }

  .marker-container {
    width: 28px;
    height: 28px;
  }

  /* Footer adjustments */
  footer {
    font-size: 10px !important;
    padding: 1rem 0.5rem !important;
    margin-top: 1rem !important;
  }
}
