/* =============================================================================
   TATWIR Verse — Stage 1
   Brand tokens (edit these to rebrand)
   ============================================================================= */
:root {
  /* Brand */
  --primary: #0b1f3a;
  --primary-2: #122a4a;
  --primary-3: #1a3a63;
  --accent: #c9a227;
  --accent-soft: #e0c56a;
  --accent-dim: rgba(201, 162, 39, 0.18);

  /* Surface / text */
  --surface: rgba(255, 255, 255, 0.92);
  --surface-solid: #ffffff;
  --surface-2: #f4f6f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: rgba(11, 31, 58, 0.12);
  --shadow: 0 16px 40px rgba(11, 31, 58, 0.16);
  --focus: 0 0 0 3px rgba(201, 162, 39, 0.5);

  /* Type colors (map markers) */
  --type-villas: #c9a227;
  --type-apartments: #2f6fed;
  --type-commercial: #0d9488;

  /* Status */
  --status-available: #16a34a;
  --status-soon: #d97706;
  --status-soldout: #94a3b8;

  /* Layout */
  --topbar-h: 64px;
  --panel-w: min(380px, 92vw);
  --radius: 16px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 320ms;

  --font-ar: "IBM Plex Sans Arabic", "Inter", system-ui, sans-serif;
  --font-en: "Inter", "IBM Plex Sans Arabic", system-ui, sans-serif;

  color-scheme: light;
}

html[data-theme="dark"] {
  --primary: #071526;
  --primary-2: #0d2240;
  --primary-3: #16365c;
  --accent: #d4b84a;
  --accent-soft: #f0d980;
  --accent-dim: rgba(212, 184, 74, 0.22);

  --surface: rgba(15, 27, 45, 0.92);
  --surface-solid: #0f1b2d;
  --surface-2: #152438;
  --text: #e8eef7;
  --text-muted: #94a3b8;
  --border: rgba(232, 238, 247, 0.12);
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);

  --type-villas: #d4b84a;
  --type-apartments: #60a5fa;
  --type-commercial: #2dd4bf;

  color-scheme: dark;
}

/* =============================================================================
   Reset / shell (iframe-friendly)
   ============================================================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--primary);
  color: var(--text);
  font-family: var(--font-en);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

html[lang="ar"],
html[dir="rtl"] {
  font-family: var(--font-ar);
}

#app {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--primary);
}

/* =============================================================================
   Map
   ============================================================================= */
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.maplibregl-ctrl-attrib {
  font-size: 10px !important;
  background: color-mix(in srgb, var(--surface-solid) 80%, transparent) !important;
  color: var(--text-muted) !important;
}

.maplibregl-ctrl-group {
  border-radius: 12px !important;
  overflow: hidden;
  box-shadow: var(--shadow) !important;
  border: 1px solid var(--border) !important;
}

.maplibregl-ctrl-group button {
  width: 36px !important;
  height: 36px !important;
  background: var(--surface-solid) !important;
}

.maplibregl-ctrl-bottom-right {
  bottom: 12px !important;
  right: 12px !important;
}

html[dir="rtl"] .maplibregl-ctrl-bottom-right {
  right: auto !important;
  left: 12px !important;
}

/* =============================================================================
   Top bar
   ============================================================================= */
.topbar {
  position: absolute;
  top: 0;
  inset-inline: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--surface-solid) 88%, transparent) 0%,
    color-mix(in srgb, var(--surface-solid) 55%, transparent) 70%,
    transparent 100%
  );
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--primary-2), var(--primary));
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 8px 18px rgba(11, 31, 58, 0.25);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.brand-mark img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

/* RETAL-style floating city chips on country overview */
.city-chip {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #0b1f3a;
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 118px;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(11, 31, 58, 0.22);
  font: inherit;
  text-align: start;
  transition: transform 200ms ease, box-shadow 200ms ease;
}

.city-chip:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 14px 32px rgba(11, 31, 58, 0.28);
}

.city-chip:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.city-chip-region {
  display: block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #64748b;
  margin-bottom: 2px;
}

.city-chip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.city-chip-name {
  font-size: 0.86rem;
  font-weight: 700;
}

.city-chip-count {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: #0b1f3a;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
}

html[data-theme="dark"] .city-chip {
  background: rgba(15, 27, 45, 0.92);
  border-color: rgba(212, 184, 74, 0.35);
  color: #e8eef7;
}

html[data-theme="dark"] .city-chip-count {
  background: var(--accent);
  color: #1a1208;
}

html[data-theme="dark"] .city-chip-region {
  color: #94a3b8;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-text strong {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--primary);
}

html[data-theme="dark"] .brand-text strong {
  color: var(--accent-soft);
}

.brand-text span {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

/* =============================================================================
   Buttons
   ============================================================================= */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-solid) 88%, transparent);
  color: var(--text);
  border-radius: 999px;
  min-height: 40px;
  padding: 0 14px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  transition:
    background var(--dur) ease,
    border-color var(--dur) ease,
    transform 180ms ease,
    box-shadow var(--dur) ease,
    filter var(--dur) ease;
}

.btn:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  background: var(--surface-solid);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible,
.card:focus-visible,
.panel-close:focus-visible,
.list-toggle:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.btn-icon {
  width: 40px;
  padding: 0;
}

.btn-gold {
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
  color: #1a1208;
  border-color: transparent;
}

.btn-gold:hover {
  filter: brightness(1.05);
}

/* =============================================================================
   Project list dock
   ============================================================================= */
.list-dock {
  position: absolute;
  z-index: 35;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.list-dock > * {
  pointer-events: auto;
}

.list-dock-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.list-toggle {
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-solid) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  border-radius: 999px;
  min-height: 40px;
  padding: 0 14px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.list-count {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: color-mix(in srgb, var(--accent) 75%, var(--text));
  font-size: 0.72rem;
  font-weight: 700;
}

.list-note {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--surface-solid) 80%, transparent);
  border: 1px dashed color-mix(in srgb, var(--accent) 40%, var(--border));
  border-radius: 999px;
  padding: 4px 10px;
}

.project-list {
  margin: 0;
  padding: 10px;
  list-style: none;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  gap: 8px;
  scrollbar-width: thin;
}

.project-list[hidden] {
  display: none !important;
}

/* Desktop: vertical side list */
@media (min-width: 901px) {
  .list-dock {
    top: calc(var(--topbar-h) + 12px);
    bottom: 18px;
    inset-inline-start: 16px;
    width: min(320px, 28vw);
  }

  .project-list {
    flex-direction: column;
    max-height: 100%;
    flex: 1;
    min-height: 0;
  }
}

/* Mobile: horizontal bottom strip */
@media (max-width: 900px) {
  .list-dock {
    bottom: 12px;
    inset-inline: 12px;
    max-height: none;
  }

  .list-note {
    display: none;
  }

  .project-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: none;
    padding-bottom: 12px;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
  }

  .project-list > li {
    flex: 0 0 min(240px, 72vw);
    scroll-snap-align: start;
  }
}

.card {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 12px 12px 14px;
  cursor: pointer;
  text-align: start;
  color: inherit;
  font: inherit;
  width: 100%;
  display: grid;
  gap: 6px;
  transition:
    border-color var(--dur) ease,
    background var(--dur) ease,
    transform 200ms var(--ease),
    box-shadow var(--dur) ease;
  position: relative;
}

.card::before {
  content: "";
  position: absolute;
  inset-block: 10px;
  inset-inline-start: 0;
  width: 3px;
  border-radius: 999px;
  background: transparent;
  transition: background var(--dur) ease;
}

.card:hover {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(11, 31, 58, 0.12);
}

.card.is-active {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--border));
  background: color-mix(in srgb, var(--accent-dim) 70%, var(--surface-2));
}

.card.is-active::before {
  background: var(--accent);
}

.card-title {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--primary);
  line-height: 1.3;
}

html[data-theme="dark"] .card-title {
  color: var(--text);
}

.card-meta {
  font-size: 0.76rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
}

.pill[data-type="villas"] {
  background: color-mix(in srgb, var(--type-villas) 18%, transparent);
  color: var(--type-villas);
}

.pill[data-type="apartments"] {
  background: color-mix(in srgb, var(--type-apartments) 18%, transparent);
  color: var(--type-apartments);
}

.pill[data-type="commercial"] {
  background: color-mix(in srgb, var(--type-commercial) 18%, transparent);
  color: var(--type-commercial);
}

/* =============================================================================
   Detail panel
   ============================================================================= */
.panel {
  position: absolute;
  z-index: 36;
  width: var(--panel-w);
  background: var(--surface);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 1;
  transition:
    transform var(--dur) var(--ease),
    opacity 250ms ease,
    visibility 250ms;
}

/* Desktop drawer: left for RTL, right for LTR */
@media (min-width: 901px) {
  .panel {
    top: calc(var(--topbar-h) + 12px);
    bottom: 18px;
  }

  /* RTL: panel on the left; LTR: panel on the right (list is on the opposite side) */
  html[dir="rtl"] .panel {
    left: 16px;
    right: auto;
  }

  html[dir="ltr"] .panel {
    right: 16px;
    left: auto;
  }

  html[dir="rtl"] .panel[hidden] {
    transform: translateX(-28px);
  }

  html[dir="ltr"] .panel[hidden] {
    transform: translateX(28px);
  }
}

/* Mobile bottom sheet */
@media (max-width: 900px) {
  .panel {
    top: auto;
    bottom: 0;
    inset-inline: 0 !important;
    width: 100%;
    max-height: min(58vh, 520px);
    border-radius: 18px 18px 0 0;
  }

  html[dir="rtl"] .panel[hidden],
  html[dir="ltr"] .panel[hidden] {
    transform: translateY(28px);
  }

  /* Lift above card strip when panel open — cards stay usable via toggle */
  body.panel-open .list-dock {
    opacity: 0.35;
    pointer-events: none;
  }
}

.panel[hidden] {
  display: flex !important;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.panel-close {
  position: absolute;
  top: 10px;
  inset-inline-end: 10px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-solid) 90%, transparent);
  color: var(--text);
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
}

.panel-media {
  position: relative;
  height: 160px;
  flex: 0 0 auto;
  background: linear-gradient(145deg, var(--primary-2), var(--primary));
  overflow: hidden;
}

.panel-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.panel-media img.is-hidden {
  display: none;
}

.panel-media-fallback {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background:
    radial-gradient(circle at 30% 30%, rgba(201, 162, 39, 0.25), transparent 50%),
    linear-gradient(145deg, var(--primary-2), var(--primary));
  color: var(--accent);
  font-size: 2rem;
  font-weight: 700;
}

.panel-media-fallback.is-visible {
  display: grid;
}

.panel-body {
  padding: 16px 18px 20px;
  overflow: auto;
  overscroll-behavior: contain;
  display: grid;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.panel-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.badge-type[data-type="villas"] {
  background: color-mix(in srgb, var(--type-villas) 18%, transparent);
  color: var(--type-villas);
}

.badge-type[data-type="apartments"] {
  background: color-mix(in srgb, var(--type-apartments) 18%, transparent);
  color: var(--type-apartments);
}

.badge-type[data-type="commercial"] {
  background: color-mix(in srgb, var(--type-commercial) 18%, transparent);
  color: var(--type-commercial);
}

.badge-status[data-status="available"] {
  background: color-mix(in srgb, var(--status-available) 18%, transparent);
  color: var(--status-available);
}

.badge-status[data-status="soon"] {
  background: color-mix(in srgb, var(--status-soon) 18%, transparent);
  color: var(--status-soon);
}

.badge-status[data-status="soldout"] {
  background: color-mix(in srgb, var(--status-soldout) 18%, transparent);
  color: var(--status-soldout);
}

.panel-title {
  margin: 0;
  font-size: 1.3rem;
  line-height: 1.25;
  color: var(--primary);
}

html[data-theme="dark"] .panel-title {
  color: var(--text);
}

.panel-city {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.panel-models {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text);
}

.panel-models strong {
  color: var(--accent);
  font-size: 1.05rem;
}

.panel-desc {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.65;
  font-size: 0.92rem;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

/* =============================================================================
   Toast / splash
   ============================================================================= */
.toast {
  position: absolute;
  z-index: 50;
  top: calc(var(--topbar-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  max-width: min(420px, 90vw);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.85rem;
  text-align: center;
}

.toast[hidden] {
  display: none !important;
}

.splash {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(201, 162, 39, 0.18), transparent 45%),
    radial-gradient(ellipse at 70% 80%, rgba(26, 58, 99, 0.55), transparent 50%),
    linear-gradient(160deg, #071526 0%, #0b1f3a 45%, #122a4a 100%);
  color: #f8fafc;
  transition: opacity 0.7s ease, visibility 0.7s ease;
}

.splash.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-inner {
  text-align: center;
  padding: 24px;
  max-width: 480px;
}

.splash-logo {
  width: 76px;
  height: 76px;
  margin: 0 auto 18px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #122a4a, #071526);
  border: 1px solid rgba(201, 162, 39, 0.55);
  animation: pulse-glow 2.2s ease-in-out infinite;
}

.splash-logo svg {
  width: 44px;
  height: 44px;
}

.splash h1 {
  margin: 0 0 8px;
  font-size: clamp(1.55rem, 4vw, 2.1rem);
  letter-spacing: 0.04em;
}

.splash p {
  margin: 0 0 22px;
  color: rgba(248, 250, 252, 0.72);
  line-height: 1.6;
}

.splash-progress {
  width: min(240px, 70vw);
  height: 3px;
  margin: 0 auto;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.splash-progress > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-soft));
  animation: load-bar 1.8s ease-in-out forwards;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 720px) {
  .brand-text span {
    display: none;
  }

  .btn#btn-reset span {
    font-size: 0.8rem;
  }
}

@keyframes load-bar {
  from { width: 0%; }
  to { width: 100%; }
}

@keyframes pulse-glow {
  0%, 100% {
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35), 0 0 0 0 rgba(201, 162, 39, 0.35);
  }
  50% {
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35), 0 0 0 10px rgba(201, 162, 39, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
