:root {
  --hover-fill: rgba(255, 255, 255, 0.28);
  --hover-stroke: #ffffff;
  --modal-bg: #ffffff;
  --modal-radius: 14px;
  --text-dark: #1c1c1c;
  --text-muted: #6b6b6b;
  --border-light: #e5e5e5;
  --accent-green: #2f7d5f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f4f4f4;
  font-family: "Tahoma", "Segoe UI", Arial, sans-serif;
  color: var(--text-dark);
}

/* ===== Map container ===== */
.map-container {
  position: relative;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  line-height: 0; /* removes inline-image gap */
  aspect-ratio: 1360.63 / 1345; /* crop to just the map area; hides the
    printed area tables that sit below the map in the source page */
  overflow: hidden;
}

.bg-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
  pointer-events: none; /* all interaction happens on the SVG overlay */
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.version-label {
  position: fixed;
  bottom: 6px;
  left: 8px;
  font-size: 11px;
  color: #b0b0b0;
  opacity: 0.6;
  pointer-events: none;
  user-select: none;
  z-index: 5;
  font-family: inherit;
}

/* ===== Plot layer (one polygon per plot — independent objects) ===== */
.plot-polygon {
  fill: transparent;
  stroke: transparent;
  stroke-width: 2;
  cursor: pointer;
  pointer-events: all; /* guarantees hit-testing regardless of paint/alpha edge cases */
  transition: fill 0.15s ease, stroke 0.15s ease;
  vector-effect: non-scaling-stroke;
}

.plot-polygon:hover,
.plot-polygon.is-hovered {
  fill: var(--hover-fill);
  stroke: var(--hover-stroke);
}

/* ===== Facility layer (single clickable shape, no plot breakdown) ===== */
.facility-polygon {
  fill: transparent;
  stroke: transparent;
  stroke-width: 2;
  cursor: pointer;
  pointer-events: all;
  transition: fill 0.15s ease, stroke 0.15s ease;
  vector-effect: non-scaling-stroke;
}

.facility-polygon:hover,
.facility-polygon.is-hovered {
  fill: rgba(255, 255, 255, 0.22);
  stroke: var(--hover-stroke);
}

/* ===== Badge layer (the block-number circle — opens the full block modal) ===== */
.block-badge {
  fill: rgba(255, 255, 255, 0.01); /* effectively invisible but always painted, so hit-testing is reliable across browsers */
  stroke: transparent;
  stroke-width: 2;
  cursor: pointer;
  pointer-events: all;
  transition: fill 0.15s ease, stroke 0.15s ease, transform 0.15s ease;
  transform-box: fill-box;
  transform-origin: center;
}

.block-badge:hover,
.block-badge.is-hovered {
  fill: rgba(255, 255, 255, 0.35);
  stroke: var(--hover-stroke);
  transform: scale(1.15);
}

/* ===== Modal ===== */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-backdrop.is-open {
  display: flex;
}

.modal {
  position: relative;
  background: var(--modal-bg);
  border-radius: var(--modal-radius);
  padding: 24px;
  max-width: 480px;
  width: 100%;
  max-height: 82vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  direction: rtl;
  text-align: right;
}

.modal-close {
  position: absolute;
  top: 14px;
  left: 14px;
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.modal-close:hover {
  color: var(--text-dark);
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
}

.modal-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 18px;
}

.modal-stats {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}

.modal-stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 2px;
}

.modal-stat-value {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.modal-table-wrap {
  max-height: 300px;
  overflow-y: auto;
}

.modal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.modal-table th {
  text-align: right;
  color: var(--text-muted);
  font-weight: 600;
  padding: 6px 8px;
  border-bottom: 2px solid var(--border-light);
  position: sticky;
  top: 0;
  background: var(--modal-bg);
}

.modal-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-light);
}

.modal-facility-note {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
  color: #fff;
}

.badge.usage-سكني {
  background: #6aa9c9;
}

.badge.usage-تجاري {
  background: #d9534f;
}

.badge.usage-facility {
  background: #4a4368;
}

.modal-action {
  display: inline-block;
  margin-top: 18px;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  background: var(--accent-green);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.modal-action:hover {
  opacity: 0.9;
}

.precision-note {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 10px;
}

/* ===== Debug toggle button ===== */
.debug-toggle-btn {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1100;
  background: #1c1c1c;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  opacity: 0.85;
}

.debug-toggle-btn:hover {
  opacity: 1;
}

.debug-toggle-btn.is-active {
  background: #c0392b;
}

/* ===== Debug mode: show every polygon's real boundary permanently ===== */
body.debug-mode .plot-polygon {
  fill: rgba(46, 204, 113, 0.18);
  stroke: #2ecc71;
  stroke-width: 1.5;
}

body.debug-mode .facility-polygon {
  fill: rgba(155, 89, 182, 0.18);
  stroke: #9b59b6;
  stroke-width: 1.5;
}

body.debug-mode .block-badge {
  fill: rgba(255, 200, 0, 0.5);
  stroke: #ffb300;
}

/* Block outline layer: hidden outside debug mode, shows the block-level
   polygon (used for the badge) so plot-tiling can be checked against it. */
.block-outline {
  fill: none;
  stroke: #39ff14;
  stroke-width: 3;
  stroke-dasharray: 6 4;
  paint-order: stroke;
  pointer-events: none;
  display: none;
  vector-effect: non-scaling-stroke;
}

.block-outline-halo {
  fill: none;
  stroke: #000000;
  stroke-width: 5.5;
  stroke-dasharray: 6 4;
  pointer-events: none;
  display: none;
  vector-effect: non-scaling-stroke;
}

body.debug-mode .block-outline,
body.debug-mode .block-outline-halo {
  display: block;
}
