/* =============================================================================
   MASJID ATLAS — External Netlify add-masjid app
   Map-first experience. Drop a pin → contribution drawer slides up.
   Mobile-first, dark theme matching TMA brand.
   ============================================================================ */

:root {
  /* Tells the browser the page is dark-themed. Chrome/Edge/Safari then
     render native <option> dropdown chrome with a dark background so the
     option text is readable (their default is OS-native light chrome,
     which makes white text on white background invisible). */
  color-scheme: dark;

  /* ── Brand palette ──────────────────────────────────────────────────── */
  --c-navy:        #0D1520;
  --c-navy-deep:   #07111E;
  --c-surface:     #141B25;
  --c-elevated:    #1F2935;
  --c-border:      rgba(255, 255, 255, 0.08);
  --c-border-mid:  rgba(255, 255, 255, 0.16);

  --c-gold:        #C9A84C;
  --c-gold-light:  #E8D070;
  --c-gold-dark:   #A87B20;
  --c-green:       #1D9E75;
  --c-green-hover: #178A65;
  --c-cream:       #F5ECD7;

  --c-text:        #EDF4F8;
  --c-text-mid:    #86A8BC;
  --c-text-dim:    #5A7184;
  --c-danger:      #EF4444;

  /* ── Type scale ──────────────────────────────────────────────────────── */
  --fs-xs:  12px;
  --fs-sm:  14px;
  --fs-md:  16px;
  --fs-lg:  18px;
  --fs-xl:  22px;
  --fs-2xl: 28px;
  --fs-3xl: 32px;

  /* ── Spacing ────────────────────────────────────────────────────────── */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;

  --radius:    8px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Header height — used to offset the map */
  /* Header total height = brand bar (56px) + slim stats ribbon (28px) */
  --hdr-brand-h: 56px;
  --hdr-h:       84px;

  /* ── Type stacks ────────────────────────────────────────────────────── */
  --ff-base:    system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --ff-arabic:  'Amiri', 'Scheherazade New', 'Noto Naskh Arabic', 'Segoe UI', sans-serif;
  --ff-display: Georgia, 'Cormorant Garamond', 'Times New Roman', serif;
}

/* =============================================================================
   RESET
   ============================================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--c-navy);
  color: var(--c-text);
  font-family: var(--ff-base);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  /* Prevent body scroll — the map manages its own panning */
  overflow: hidden;
}

html[dir="rtl"] body { font-family: var(--ff-arabic); }

img, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
input::placeholder, textarea::placeholder { color: var(--c-text-dim); }

/* =============================================================================
   HEADER
   ============================================================================ */
.hdr {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  height: var(--hdr-h);
  background: linear-gradient(180deg, rgba(7, 17, 30, 0.96), rgba(13, 21, 32, 0.88));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
}

.hdr-inner {
  height: var(--hdr-brand-h);
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

/* ── Persistent stats ribbon — slim row below the lang switcher ─────────
   Right-aligned, sits directly under the EN/AR/TR buttons. Visible on
   every screen. Populated by the same fetchStats() that fills the
   larger intro stats-strip. */
.hdr-stats-ribbon {
  height: calc(var(--hdr-h) - var(--hdr-brand-h));
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: flex-end;   /* sit on the right, under lang switcher */
  gap: 16px;
  font-size: 11.5px;
  letter-spacing: 0.02em;
  color: var(--c-text-mid);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
html[dir="rtl"] .hdr-stats-ribbon {
  /* In RTL the lang switcher is on the LEFT; align the ribbon there too. */
  justify-content: flex-start;
}
.hdr-stats-ribbon::-webkit-scrollbar { display: none; }

.hsr-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Breathing dot — soft pulse + halo to signal "live data". One per stat. */
.hsr-dot {
  width:  6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-green);
  box-shadow:
    0 0 0 0 rgba(29, 158, 117, 0.85),
    0 0 6px 1px rgba(29, 158, 117, 0.55);
  animation: hsr-breathe 2.4s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes hsr-breathe {
  0%, 100% {
    transform: scale(1);
    box-shadow:
      0 0 0 0 rgba(29, 158, 117, 0.55),
      0 0 5px 1px rgba(29, 158, 117, 0.45);
    opacity: 0.85;
  }
  50% {
    transform: scale(1.25);
    box-shadow:
      0 0 0 4px rgba(29, 158, 117, 0),
      0 0 9px 2px rgba(29, 158, 117, 0.7);
    opacity: 1;
  }
}

.hsr-num {
  font-weight: 700;
  color: var(--c-gold);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.hsr-num[data-loading="true"] {
  opacity: 0.55;
  animation: hsr-pulse 1.4s ease-in-out infinite;
}
.hsr-label {
  text-transform: lowercase;
  font-weight: 500;
}

@keyframes hsr-pulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

@media (max-width: 480px) {
  .hdr-stats-ribbon { font-size: 10.5px; gap: 10px; padding: 0 12px; }
  .hsr-item         { gap: 4px; }
  .hsr-dot          { width: 5px; height: 5px; }
}

/* Respect user's reduced-motion preference — breathing dot becomes static */
@media (prefers-reduced-motion: reduce) {
  .hsr-dot { animation: none; }
}

/* Personal stat dot — GOLD instead of green. Signals "this number is YOU"
   to distinguish from the four global green-dot stats. */
.hsr-dot--gold {
  background: var(--c-gold);
  animation: hsr-breathe-gold 2.4s ease-in-out infinite;
  box-shadow:
    0 0 0 0 rgba(201, 168, 76, 0.85),
    0 0 6px 1px rgba(201, 168, 76, 0.55);
}
@keyframes hsr-breathe-gold {
  0%, 100% {
    transform: scale(1);
    box-shadow:
      0 0 0 0 rgba(201, 168, 76, 0.55),
      0 0 5px 1px rgba(201, 168, 76, 0.45);
    opacity: 0.85;
  }
  50% {
    transform: scale(1.25);
    box-shadow:
      0 0 0 4px rgba(201, 168, 76, 0),
      0 0 9px 2px rgba(201, 168, 76, 0.75);
    opacity: 1;
  }
}
.hsr-personal .hsr-num   { color: var(--c-gold); }
.hsr-personal .hsr-label { color: var(--c-cream); opacity: 0.7; font-weight: 600; }

/* Visual separator before the personal stat */
.hsr-divider {
  color: var(--c-text-dim);
  opacity: 0.35;
  margin: 0 2px;
  font-size: 14px;
  line-height: 1;
}

/* ── Updates panel inside the intro card ──────────────────────────────────
   Shows recent admin outcomes (approved / rejected / duplicate / needs info)
   for the contributor's previous submissions. Hidden until the my_submissions
   RPC returns at least one non-PENDING item. */
.contrib-updates {
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.10), rgba(29, 158, 117, 0.08));
  border: 1px solid var(--c-gold);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
}
.cu-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--c-gold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}
.cu-icon { font-size: 16px; line-height: 1; }
.cu-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cu-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--c-border);
  font-size: 13px;
  line-height: 1.45;
}
.cu-item--approved        { border-color: rgba(29, 158, 117, 0.45); }
.cu-item--rejected        { border-color: rgba(239, 68, 68, 0.35); }
.cu-item--duplicate       { border-color: rgba(96, 165, 250, 0.35); }
.cu-item--needs_more_info { border-color: rgba(201, 168, 76, 0.45); }

.cu-item-icon {
  font-size: 16px;
  line-height: 1.2;
  flex-shrink: 0;
}
.cu-item-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.cu-item-name   { font-weight: 700; color: var(--c-text); }
.cu-item-status { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--c-text-mid); }
.cu-item-note   { font-size: 12px; color: var(--c-text-mid); font-style: italic; }

/* ── Milestone message on success screen ──────────────────────────────────
   Soft Islamic encouragement when a contributor's total just crossed a
   threshold (1/3/5/10/25/50/100). Never names the Ajar/badge mechanics. */
.success-milestone {
  margin: 14px 0 0;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.12), rgba(245, 236, 215, 0.05));
  border: 1px solid var(--c-gold);
  border-radius: var(--radius);
  font-size: 14px;
  font-style: italic;
  color: var(--c-cream);
  line-height: 1.55;
  text-align: center;
}

.hdr-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  text-decoration: none;
  color: inherit;
}

.hdr-brand-icon {
  font-size: 24px;
  line-height: 1;
}

.hdr-brand-text {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.hdr-brand-main {
  font-family: var(--ff-display);
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--c-cream);
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.hdr-brand-sub {
  font-size: 10px;
  color: var(--c-gold);
  text-transform: uppercase;
  letter-spacing: 0.10em;
  line-height: 1.2;
}

/* βeta pill — sits next to the brand. Subtle pulse to give it life. */
.beta-pill {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(29, 158, 117, 0.18);
  border: 1px solid var(--c-green);
  color: var(--c-green);
  margin-inline-start: var(--sp-2);
  white-space: nowrap;
  flex-shrink: 0;
  align-self: center;
  font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', monospace;
  animation: beta-pulse 3s ease-in-out infinite;
}

@keyframes beta-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(29, 158, 117, 0); }
  50%      { box-shadow: 0 0 0 4px rgba(29, 158, 117, 0.10); }
}

@media (max-width: 380px) {
  .beta-pill { display: none; }
}

/* Language switch */
.lang-switch {
  display: flex;
  gap: 3px;
  background: var(--c-surface);
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--c-border);
}

.lang-btn {
  background: transparent;
  border: none;
  color: var(--c-text-mid);
  font-size: 11px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.04em;
  min-width: 36px;
}

.lang-btn:hover { color: var(--c-text); }

.lang-btn.is-active {
  background: var(--c-gold);
  color: var(--c-navy);
}

/* =============================================================================
   MAP STAGE — full-screen below header
   ============================================================================ */
.map-stage {
  position: fixed;
  inset: var(--hdr-h) 0 0 0;
  overflow: hidden;
  /* Defensive: explicit min sizing so MapLibre's container has dimensions
     even if a parent stylesheet load order does something weird. */
  width:  100%;
  min-height: 240px;
  background: var(--c-navy-deep);
}

.map-container {
  position: absolute;
  inset: 0;
  width:  100%;
  height: 100%;
  background: var(--c-navy-deep);
}

/* MapLibre's own canvas / containers — make sure they fill */
.map-container .maplibregl-map,
.map-container canvas.maplibregl-canvas {
  width:  100% !important;
  height: 100% !important;
}

/* MapLibre's default attribution control — tone it down a bit */
.maplibregl-ctrl-attrib {
  background: rgba(13, 21, 32, 0.85) !important;
  color: var(--c-text-mid) !important;
  font-size: 10px !important;
}
.maplibregl-ctrl-attrib a {
  color: var(--c-gold) !important;
}

.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib {
  margin: 0 8px 8px 0 !important;
}

/* MapLibre default zoom controls — match brand */
.maplibregl-ctrl-group {
  background: var(--c-surface) !important;
  border: 1px solid var(--c-border) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4) !important;
}
.maplibregl-ctrl-group button {
  background: transparent !important;
  color: var(--c-text) !important;
}
.maplibregl-ctrl-group button:hover {
  background: rgba(255, 255, 255, 0.06) !important;
}

/* =============================================================================
   INTRO OVERLAY — dismissible welcome
   ============================================================================ */
.intro-overlay {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(29, 158, 117, 0.18), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(201, 168, 76, 0.14), transparent 60%),
    rgba(13, 21, 32, 0.94);
  backdrop-filter: blur(4px);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  opacity: 1;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.intro-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.intro-card {
  max-width: 480px;
  width: 100%;
  background: linear-gradient(145deg, var(--c-elevated), var(--c-surface));
  border: 1px solid var(--c-border-mid);
  border-radius: var(--radius-xl);
  padding: var(--sp-6);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  max-height: calc(100vh - var(--hdr-h) - var(--sp-7));
  overflow-y: auto;
}

.intro-eyebrow {
  margin: 0;
  font-size: var(--fs-xs);
  color: var(--c-gold);
  text-transform: uppercase;
  letter-spacing: 0.10em;
  font-weight: 700;
}

.intro-title {
  margin: 0;
  font-family: var(--ff-display);
  font-size: var(--fs-2xl);
  font-weight: 700;
  line-height: 1.15;
  color: var(--c-cream);
  letter-spacing: -0.02em;
}

.intro-sub {
  margin: 0;
  color: var(--c-text-mid);
  font-size: var(--fs-sm);
  line-height: 1.7;
}

.intro-steps {
  list-style: none;
  margin: var(--sp-2) 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.intro-steps li {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--c-text);
  line-height: 1.6;
}

.intro-step-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--c-gold);
  color: var(--c-navy);
  font-weight: 800;
  font-size: var(--fs-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.intro-cta {
  margin-top: var(--sp-3);
  align-self: stretch;
  justify-content: center;
}

/* βeta notice — explicit expectation-setting block in the intro card */
.beta-notice {
  margin: 0;
  padding: var(--sp-3) var(--sp-4);
  background: rgba(29, 158, 117, 0.08);
  border: 1px solid rgba(29, 158, 117, 0.30);
  border-inline-start-width: 4px;
  border-radius: var(--radius);
  color: var(--c-text);
  font-size: var(--fs-xs);
  line-height: 1.6;
}

.beta-notice strong {
  color: var(--c-green);
  font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', monospace;
  letter-spacing: 0.04em;
  font-weight: 800;
}

/* βeta note on the success screen */
.success-beta {
  margin: 0;
  padding: var(--sp-3);
  background: rgba(29, 158, 117, 0.08);
  border: 1px solid rgba(29, 158, 117, 0.24);
  border-radius: var(--radius);
  font-size: var(--fs-xs);
  color: var(--c-text-mid);
  line-height: 1.5;
  max-width: 40ch;
}

/* ─────────────────────────────────────────────────────────────────────────
   Live stats strip — sits in the intro card under the steps.
   Fetched from /api/public/stats on page load.
   ───────────────────────────────────────────────────────────────────────── */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-3);
  margin-top: var(--sp-2);
  padding: var(--sp-4);
  background:
    linear-gradient(135deg, rgba(201, 168, 76, 0.07), rgba(29, 158, 117, 0.07));
  border: 1px solid var(--c-border-mid);
  border-radius: var(--radius);
}

@media (max-width: 540px) {
  .stats-strip { grid-template-columns: repeat(2, 1fr); }
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  text-align: center;
  min-width: 0;
}

.stat-num {
  font-size: var(--fs-xl);
  font-weight: 800;
  color: var(--c-gold);
  font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', monospace;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  /* Subtle skeleton state — until numbers populate, em dash sits there */
  transition: color 0.4s ease;
}

.stat-num[data-loading="true"] {
  color: var(--c-text-dim);
  opacity: 0.6;
}

.stat-label {
  font-size: 10px;
  color: var(--c-text-mid);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.3;
  font-weight: 600;
}

.stats-foot {
  margin: var(--sp-2) 0 0;
  font-size: 11px;
  color: var(--c-text-dim);
  text-align: center;
  font-style: italic;
  line-height: 1.5;
}

@media (max-width: 380px) {
  .stat-num   { font-size: var(--fs-lg); }
  .stat-label { font-size: 9px; }
}

/* ─────────────────────────────────────────────────────────────────────────
   Live Activity Ticker (intro card)
   Hidden by default — JS reveals it only when there's activity in last 3 days
   ───────────────────────────────────────────────────────────────────────── */
.atk-root {
  display:         flex;
  align-items:     center;
  gap:             var(--sp-3);
  padding:         10px var(--sp-3);
  margin-top:      var(--sp-3);
  background:
    linear-gradient(135deg,
      rgba(201, 168, 76, 0.07),
      rgba(29, 158, 117, 0.07));
  border:          1px solid rgba(201, 168, 76, 0.22);
  border-radius:   999px;
  font-size:       var(--fs-xs);
  overflow:        hidden;
  min-height:      40px;
}

.atk-root[hidden] { display: none; }

.atk-header {
  display:     flex;
  align-items: center;
  gap:         6px;
  flex-shrink: 0;
  padding-inline-end: var(--sp-2);
  border-inline-end:  1px solid rgba(201, 168, 76, 0.18);
}

.atk-live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--c-green);
  box-shadow: 0 0 0 0 rgba(29, 158, 117, 0.4);
  animation:  atk-pulse 1.6s ease-in-out infinite;
}

@keyframes atk-pulse {
  0%, 100% { box-shadow: 0 0 0 0   rgba(29, 158, 117, 0.40); }
  50%      { box-shadow: 0 0 0 6px rgba(29, 158, 117, 0);    }
}

.atk-live-label {
  font-family:    'JetBrains Mono', 'Cascadia Code', 'Consolas', monospace;
  font-size:      9px;
  font-weight:    700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color:          var(--c-green);
}

.atk-live-sub {
  font-size:      9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color:          var(--c-text-dim);
}

.atk-bubble {
  flex: 1;
  min-width: 0;
  display:    flex;
  align-items: center;
  transition: transform 0.30s ease-out, opacity 0.30s ease-out;
}

.atk-bubble--in       { transform: translateX(40%);  opacity: 0; }
.atk-bubble--visible  { transform: translateX(0);     opacity: 1; }
.atk-bubble--out      { transform: translateX(-40%); opacity: 0; transition-timing-function: ease-in; }

html[dir="rtl"] .atk-bubble--in  { transform: translateX(-40%); }
html[dir="rtl"] .atk-bubble--out { transform: translateX(40%);  }

.atk-bubble-static {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
}

.atk-icon    { font-size: 14px; line-height: 1; flex-shrink: 0; }
.atk-nick    { font-weight: 700; color: var(--c-gold); flex-shrink: 0; }
.atk-verb    { color: var(--c-text-mid); flex-shrink: 0; }
.atk-subject {
  color:         var(--c-text);
  font-style:    italic;
  overflow:      hidden;
  text-overflow: ellipsis;
  white-space:   nowrap;
  min-width:     0;
  flex:          1;
}
.atk-flag    { font-size: 13px; flex-shrink: 0; }
.atk-time    { color: var(--c-text-dim); flex-shrink: 0; font-variant-numeric: tabular-nums; font-size: 11px; }

@media (max-width: 480px) {
  .atk-verb     { display: none; }
  .atk-live-sub { display: none; }
  .atk-time     { display: none; }
}

/* =============================================================================
   MAP CONTROLS — floating GPS + Search
   ============================================================================ */
.map-controls {
  position: absolute;
  top: var(--sp-4);
  left: var(--sp-4);
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.map-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 10px 16px;
  background: var(--c-surface);
  border: 1px solid var(--c-border-mid);
  border-radius: 999px;
  color: var(--c-text);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.map-btn:hover {
  background: var(--c-elevated);
  border-color: var(--c-gold);
}

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

.map-btn.is-busy {
  pointer-events: none;
  opacity: 0.7;
}

@media (max-width: 540px) {
  .map-btn-label { display: none; }
  .map-btn {
    padding: 12px;
    width: 44px;
    height: 44px;
    justify-content: center;
  }
}

/* =============================================================================
   SEARCH PANEL — slides down from top
   ============================================================================ */
.search-panel {
  position: absolute;
  top: var(--sp-4);
  left: 50%;
  transform: translateX(-50%);
  z-index: 18;
  width: min(540px, calc(100% - var(--sp-7)));
  background: var(--c-surface);
  border: 1px solid var(--c-border-mid);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.search-panel[hidden] { display: none; }

.search-input {
  width: 100%;
  background: transparent;
  border: none;
  padding: 14px 44px 14px 16px;
  color: var(--c-text);
  font-size: var(--fs-md);
  outline: none;
}

.search-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--c-text-mid);
  cursor: pointer;
  font-size: 16px;
}

.search-close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--c-text);
}

.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
  border-top: 1px solid var(--c-border);
}

.search-results[hidden] { display: none; }

.search-result {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--c-border);
  transition: background 0.12s;
}

.search-result:hover { background: rgba(201, 168, 76, 0.06); }
.search-result:last-child { border-bottom: none; }

.search-result-name {
  font-size: var(--fs-sm);
  color: var(--c-text);
  font-weight: 600;
}

.search-result-detail {
  font-size: var(--fs-xs);
  color: var(--c-text-mid);
  margin-top: 2px;
}

/* =============================================================================
   LONG-PRESS HINT
   ============================================================================ */
.lp-hint {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  background: rgba(13, 21, 32, 0.92);
  border: 1px solid var(--c-gold);
  border-radius: 999px;
  padding: 10px 20px;
  color: var(--c-gold);
  font-size: var(--fs-sm);
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  animation: lp-pulse 2s ease-in-out infinite;
  pointer-events: none;
}

@keyframes lp-pulse {
  0%, 100% { transform: translateX(-50%) translateY(0); opacity: 0.95; }
  50%      { transform: translateX(-50%) translateY(-4px); opacity: 1; }
}

/* =============================================================================
   DROPPED PIN MARKER (custom HTML marker for MapLibre)
   ============================================================================ */
.pin-marker {
  width: 32px;
  height: 40px;
  cursor: grab;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
  transform: translateY(-20px);
}

.pin-marker svg {
  width: 100%;
  height: 100%;
}

.pin-marker:active {
  cursor: grabbing;
  transform: translateY(-22px) scale(1.05);
}

/* =============================================================================
   PIN ACTIONS — floating bar at bottom after pin drop
   ============================================================================ */
.pin-actions {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 12;
  padding: var(--sp-4);
  background: linear-gradient(180deg, transparent, rgba(13, 21, 32, 0.92) 50%);
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.pin-actions:not([hidden]) {
  display: block;
}

.pin-actions.is-visible {
  transform: translateY(0);
}

.pin-actions-inner {
  max-width: 540px;
  margin: 0 auto;
  background: var(--c-elevated);
  border: 1px solid var(--c-gold);
  border-radius: var(--radius-lg);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.pin-actions-loc {
  font-size: var(--fs-sm);
  color: var(--c-cream);
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  justify-content: center;
}

.pin-actions-loc::before {
  content: "📍";
  font-size: 18px;
}

.pin-actions-row {
  display: flex;
  gap: var(--sp-3);
}

.pin-actions-row .btn { flex: 1; }

/* =============================================================================
   DRAWER — slides up to host the wizard
   ============================================================================ */
.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(7, 17, 30, 0.66);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.drawer-overlay:not([hidden]) {
  display: block;
}

.drawer-overlay.is-visible { opacity: 1; }

.drawer {
  position: fixed;
  z-index: 41;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--c-surface);
  border-top: 1px solid var(--c-border-mid);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.6);
  height: 92vh;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.drawer:not([hidden]) {
  display: flex;
}

.drawer.is-open {
  transform: translateY(0);
}

@media (min-width: 720px) {
  .drawer {
    left: auto;
    right: 0;
    top: 0;
    bottom: 0;
    width: min(540px, 100%);
    height: 100%;
    border-radius: 0;
    border-top: none;
    border-left: 1px solid var(--c-border-mid);
    transform: translateX(100%);
  }
  .drawer.is-open { transform: translateX(0); }

  html[dir="rtl"] .drawer {
    right: auto;
    left: 0;
    border-left: none;
    border-right: 1px solid var(--c-border-mid);
    transform: translateX(-100%);
  }
  html[dir="rtl"] .drawer.is-open { transform: translateX(0); }
}

.drawer-hdr {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface);
  position: sticky;
  top: 0;
  z-index: 2;
}

/* Drag handle on mobile */
.drawer-hdr::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 50%;
  width: 40px;
  height: 4px;
  background: var(--c-border-mid);
  border-radius: 999px;
  transform: translateX(-50%);
}

@media (min-width: 720px) {
  .drawer-hdr::before { display: none; }
}

.drawer-hdr-text {
  min-width: 0;
}

.drawer-title {
  margin: 0;
  font-family: var(--ff-display);
  font-size: var(--fs-xl);
  font-weight: 700;
  color: var(--c-cream);
}

.drawer-sub {
  margin: 2px 0 0;
  font-size: var(--fs-xs);
  color: var(--c-gold);
  font-weight: 500;
}

.drawer-close {
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--c-border-mid);
  border-radius: 50%;
  color: var(--c-text);
  font-size: var(--fs-md);
  cursor: pointer;
  flex-shrink: 0;
}

.drawer-close:hover {
  background: var(--c-elevated);
  color: var(--c-gold);
  border-color: var(--c-gold);
}

/* =============================================================================
   WIZARD (inside drawer)
   ============================================================================ */
.wiz {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-5) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

/* Progress */
.wiz-progress {
  height: 4px;
  width: 100%;
  background: var(--c-border);
  border-radius: 999px;
  overflow: hidden;
}

.wiz-progress-bar {
  height: 100%;
  width: 20%;
  background: linear-gradient(90deg, var(--c-gold-dark), var(--c-gold), var(--c-gold-light));
  border-radius: 999px;
  transition: width 0.3s ease;
}

.wiz-step-label {
  margin: 0;
  font-size: var(--fs-xs);
  color: var(--c-text-mid);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.wiz-step-name {
  color: var(--c-gold);
  margin-inline-start: var(--sp-2);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}

/* Step */
.wiz-step {
  display: none;
  flex-direction: column;
  gap: var(--sp-4);
}

.wiz-step.is-active { display: flex; }

.wiz-step-title {
  margin: 0;
  font-family: var(--ff-display);
  font-size: var(--fs-xl);
  font-weight: 700;
  color: var(--c-cream);
  letter-spacing: -0.01em;
}

.wiz-step-sub {
  margin: 0;
  color: var(--c-text-mid);
  font-size: var(--fs-sm);
  line-height: 1.6;
}

.wiz-subhead {
  margin: var(--sp-3) 0 0;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--c-gold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Wizard nav */
.wiz-nav {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  padding-top: var(--sp-4);
  margin-top: auto;
  border-top: 1px solid var(--c-border);
  position: sticky;
  bottom: 0;
  background: var(--c-surface);
  padding-bottom: var(--sp-2);
}

.wiz-error {
  margin: 0;
  padding: var(--sp-3) var(--sp-4);
  background: rgba(239, 68, 68, 0.10);
  border: 1px solid rgba(239, 68, 68, 0.30);
  color: #FCA5A5;
  border-radius: var(--radius);
  font-size: var(--fs-sm);
}

/* =============================================================================
   LOCATION SUMMARY (top of wizard step 1)
   ============================================================================ */
.loc-summary {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: rgba(29, 158, 117, 0.08);
  border: 1px solid rgba(29, 158, 117, 0.30);
  border-radius: var(--radius);
}

.loc-summary-icon {
  font-size: 22px;
  flex-shrink: 0;
}

.loc-summary-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.loc-summary-coords {
  font-family: monospace;
  font-size: var(--fs-xs);
  color: var(--c-text-mid);
}

.loc-summary-place {
  font-size: var(--fs-sm);
  color: var(--c-text);
  font-weight: 600;
}

.loc-summary-edit {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--c-border-mid);
  border-radius: var(--radius);
  color: var(--c-text-mid);
  padding: 6px 12px;
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
}

.loc-summary-edit:hover {
  color: var(--c-gold);
  border-color: var(--c-gold);
}

/* =============================================================================
   FIELDS
   ============================================================================ */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
}

@media (max-width: 480px) {
  .field-row { grid-template-columns: 1fr; }
}

.field--inline { flex: 1; }

.field-label {
  font-size: var(--fs-sm);
  color: var(--c-text);
  font-weight: 600;
  display: flex;
  gap: 6px;
  align-items: baseline;
  flex-wrap: wrap;
}

.field-label-sm {
  font-size: 11px;
  color: var(--c-text-mid);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  margin-bottom: 2px;
}

.field-required { color: var(--c-gold); font-weight: 700; }

.field-hint {
  font-size: var(--fs-xs);
  color: var(--c-text-dim);
  font-weight: 400;
}

.field-hint-block {
  margin: 0;
  font-size: var(--fs-xs);
  color: var(--c-text-mid);
  line-height: 1.5;
  font-style: italic;
}

.field-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--c-text);
  font-size: var(--fs-md);
  transition: border-color 0.15s, background 0.15s;
  outline: none;
}

.field-input:hover  { background: rgba(255, 255, 255, 0.06); }
.field-input:focus  { border-color: var(--c-gold); background: rgba(201, 168, 76, 0.05); }

.field-input--ar    { font-family: var(--ff-arabic); font-size: var(--fs-lg); }
.field-input--reveal { margin-top: 6px; }

select.field-input {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--c-gold) 50%),
                    linear-gradient(135deg, var(--c-gold) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 2px),
                       calc(100% - 13px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-inline-end: 36px;
}

html[dir="rtl"] select.field-input {
  background-position: 18px calc(50% - 2px), 13px calc(50% - 2px);
  padding-inline-end: 14px;
  padding-inline-start: 36px;
}

/* The <option> elements inside <select> render in the browser's native
   dropdown overlay — they DON'T inherit the parent <select> colors on
   Chrome/Edge. Explicit dark bg + light text so the list is readable. */
select.field-input option {
  background-color: var(--c-navy-deep);
  color: var(--c-text);
}
select.field-input option:checked,
select.field-input option:hover {
  background-color: var(--c-navy);
  color: var(--c-cream);
}

textarea.field-input {
  resize: vertical;
  min-height: 72px;
}

.field-error {
  margin: 0;
  font-size: var(--fs-xs);
  color: var(--c-danger);
  font-weight: 600;
}

.field-input[aria-invalid="true"] { border-color: var(--c-danger); }

/* =============================================================================
   TRI-STATE
   ============================================================================ */
.tri-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tri-group-label {
  margin: 0;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--c-text);
}

.tri-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tri-pills button {
  flex: 1;
  min-width: 60px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--c-border);
  color: var(--c-text-mid);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: 600;
  transition: all 0.15s;
}

.tri-pills button:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--c-text);
}

.tri-pills button.is-active[data-tri-val="true"] {
  background: rgba(29, 158, 117, 0.18);
  border-color: var(--c-green);
  color: var(--c-green);
}

.tri-pills button.is-active[data-tri-val="false"] {
  background: rgba(239, 68, 68, 0.14);
  border-color: var(--c-danger);
  color: var(--c-danger);
}

.tri-pills button.is-active[data-tri-val="null"] {
  background: rgba(255, 255, 255, 0.10);
  border-color: var(--c-border-mid);
  color: var(--c-text);
}

.tri-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-3);
}

@media (max-width: 420px) {
  .tri-grid { grid-template-columns: 1fr; }
}

/* =============================================================================
   IQAMAH GRID
   ============================================================================ */
.iqamah-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--sp-2);
}

@media (max-width: 540px) {
  .iqamah-grid { grid-template-columns: repeat(3, 1fr); }
}

.iqamah-grid .field-input {
  padding: 8px 10px;
  font-size: var(--fs-sm);
}

/* =============================================================================
   CONDITIONAL VISIBILITY
   ============================================================================ */
.conditional {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding-inline-start: var(--sp-4);
  border-inline-start: 2px solid var(--c-gold);
  margin-block: var(--sp-2);
}

.conditional[hidden] { display: none; }

/* =============================================================================
   EMAIL PERMANENCE NOTICE
   ============================================================================ */
.permanence {
  margin-top: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: rgba(201, 168, 76, 0.06);
  border: 1px solid rgba(201, 168, 76, 0.30);
  border-inline-start-width: 4px;
  border-radius: var(--radius);
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
}

.permanence-icon {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
  flex-shrink: 0;
}

.permanence-body p {
  margin: 0 0 6px;
  font-size: var(--fs-xs);
  color: var(--c-text);
  line-height: 1.6;
}

.permanence-body p strong { color: var(--c-gold); }

.permanence-link {
  font-size: var(--fs-xs);
  color: var(--c-gold);
  font-weight: 700;
  text-decoration: none;
}

.permanence-link:hover { text-decoration: underline; }

/* =============================================================================
   CONSENT BLOCK
   ============================================================================ */
.consent {
  background: var(--c-elevated);
  border: 1px solid var(--c-border-mid);
  border-radius: var(--radius);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.consent-title {
  margin: 0;
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--c-cream);
  font-family: var(--ff-display);
}

.consent-meta {
  display: flex;
  gap: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--c-text-mid);
  flex-wrap: wrap;
  align-items: center;
}

.consent-version {
  font-family: monospace;
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
}

.consent-text {
  max-height: 220px;
  overflow-y: auto;
  padding: var(--sp-3);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  line-height: 1.7;
  color: var(--c-text);
  white-space: pre-wrap;
}

.consent-text:empty::before {
  content: "Loading consent text…";
  color: var(--c-text-dim);
  font-style: italic;
}

.consent-text[lang="ar"] {
  font-family: var(--ff-arabic);
  font-size: var(--fs-md);
  direction: rtl;
  text-align: right;
}

.consent-checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--c-border);
}

.consent-checkbox-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  accent-color: var(--c-gold);
  cursor: pointer;
  margin-top: 1px;
}

.consent-checkbox-row label {
  font-size: var(--fs-sm);
  color: var(--c-text);
  cursor: pointer;
  line-height: 1.5;
}

.legal-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  font-size: var(--fs-xs);
  color: var(--c-text-dim);
  padding-top: var(--sp-2);
}

.legal-links a {
  color: var(--c-text-mid);
  text-decoration: none;
}

.legal-links a:hover {
  color: var(--c-gold);
  text-decoration: underline;
}

/* =============================================================================
   BUTTONS
   ============================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 22px;
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, border-color 0.15s;
  text-decoration: none;
  border: 1px solid transparent;
}

.btn-sm {
  padding: 8px 14px;
  font-size: var(--fs-xs);
}

.btn-primary {
  background: var(--c-gold);
  color: var(--c-navy);
  border-color: var(--c-gold);
}

.btn-primary:hover:not(:disabled) {
  background: var(--c-gold-light);
  border-color: var(--c-gold-light);
  transform: translateY(-1px);
}

.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--c-text);
  border-color: var(--c-border-mid);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--c-gold);
  color: var(--c-gold);
}

.btn-submit {
  background: linear-gradient(90deg, var(--c-gold), var(--c-gold-light));
  color: var(--c-navy);
  padding: 14px 28px;
  font-size: var(--fs-md);
  border: none;
}

.btn-submit:disabled { opacity: 0.55; }

/* =============================================================================
   SUCCESS OVERLAY
   ============================================================================ */
.success-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(7, 17, 30, 0.94);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}

.success-overlay[hidden] { display: none; }

.success-card {
  background: linear-gradient(145deg, var(--c-elevated), var(--c-surface));
  border: 1px solid var(--c-border-mid);
  border-radius: var(--radius-xl);
  padding: var(--sp-6);
  max-width: 480px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  align-items: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.success-icon { font-size: 64px; line-height: 1; }

.success-title {
  margin: 0;
  font-family: var(--ff-display);
  font-size: var(--fs-2xl);
  color: var(--c-gold);
}

.success-body {
  margin: 0;
  color: var(--c-text-mid);
  line-height: 1.7;
  font-size: var(--fs-sm);
  max-width: 40ch;
}

.success-dup {
  margin: 0;
  padding: var(--sp-3) var(--sp-4);
  background: rgba(201, 168, 76, 0.10);
  border: 1px solid rgba(201, 168, 76, 0.30);
  border-radius: var(--radius);
  font-size: var(--fs-xs);
  color: var(--c-cream);
  line-height: 1.5;
}

.success-id {
  margin: 0;
  font-size: var(--fs-xs);
  color: var(--c-text-dim);
}

.success-id code {
  font-family: monospace;
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--c-text);
}

.success-actions {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  justify-content: center;
}

/* =============================================================================
   RTL fine-tuning
   ============================================================================ */
html[dir="rtl"] .field-input {
  text-align: right;
}

html[dir="rtl"] input[type="email"],
html[dir="rtl"] input[type="url"],
html[dir="rtl"] input[type="tel"],
html[dir="rtl"] input[type="time"] {
  text-align: left;
  direction: ltr;
}

html[dir="rtl"] .map-controls {
  left: auto;
  right: var(--sp-4);
}

html[dir="rtl"] .success-id code,
html[dir="rtl"] .loc-summary-coords {
  direction: ltr;
  display: inline-block;
}
