:root {
  --sand: #EAE9D1;
  --sand-light: #F7F5F0;
  --olive: #425242;
  --olive-soft: #E5E8DC;
  --crimson: #772A26;
  --petra: #B54B2E;
  --basalt: #21201C;
  --muted: #5C5B52;
  --outline: #C2B394;
  --surface: #FFFFFF;
  --green-acc: #1B6B3A;
  --warm-card: #FBF4E4;
  --warm-border: #D4A359;
  --warm-badge-bg: #F3E2BC;
  --warm-badge-text: #9A5B13;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --sand: #181A16;
    --sand-light: #20231D;
    --olive: #6D856D;
    --olive-soft: #2A3229;
    --basalt: #F3F2E8;
    --muted: #B8B6A8;
    --outline: #4B4639;
    --surface: #22251F;
    --warm-card: #2C241B;
    --warm-border: #8C6937;
    --warm-badge-bg: #47341B;
    --warm-badge-text: #F4C57A;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  font-family: 'Cairo', system-ui, -apple-system, sans-serif;
  background: var(--sand); color: var(--basalt);
  overflow: hidden; user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

.ltr { direction: ltr; unicode-bidi: embed; font-family: 'IBM Plex Sans', sans-serif; }

.offline-banner {
  background: var(--crimson); color: #fff; text-align: center;
  padding: calc(4px + var(--safe-top)) 10px 5px; font-size: 11.5px; font-weight: 700; z-index: 30;
}

/* App Shell */
#app-shell { position: relative; width: 100%; height: 100%; display: flex; flex-direction: column; overscroll-behavior: none; }
.tab-view { position: relative; flex: 1; overflow: hidden; display: none; }
.tab-view.active { display: block; }
.scroll-view { height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; padding: calc(14px + var(--safe-top)) 16px 24px; }

/* Map */
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.picker-map {
  width: 100%; height: 210px; border-radius: 14px; overflow: hidden;
  border: 1.4px solid var(--outline); touch-action: none; position: relative;
}
.maplibregl-ctrl-attrib, .maplibregl-ctrl-logo { display: none !important; }

/* Top Search & Filter Bar */
.top-overlay {
  position: absolute; top: calc(8px + var(--safe-top)); left: 0; right: 0;
  z-index: 10; pointer-events: none;
}
.top-overlay > * { pointer-events: auto; }

.search-box {
  margin: 0 12px; display: flex; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border: 1.4px solid var(--outline); border-radius: 16px;
  padding: 6px 12px; box-shadow: 0 4px 14px rgba(0,0,0,0.14);
}
.search-box input {
  flex: 1; border: none; outline: none; background: transparent;
  color: var(--basalt); font-family: inherit; font-size: 16px; padding: 5px 2px;
}
.search-clear {
  border: none; background: transparent; color: var(--muted); font-size: 18px;
  cursor: pointer; padding: 2px 6px; display: none;
}
.search-dropdown {
  margin: 5px 12px 0; background: var(--surface); border: 1px solid var(--outline);
  border-radius: 14px; box-shadow: 0 8px 20px rgba(0,0,0,0.18);
  overflow: hidden; display: none; max-height: 280px; overflow-y: auto;
}
.search-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--outline); cursor: pointer;
}
.search-item:last-child { border-bottom: none; }
.search-item:active { background: var(--olive-soft); }

.chips-row {
  display: flex; gap: 7px; overflow-x: auto; padding: 9px 12px 4px;
  scrollbar-width: none;
}
.chips-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 700;
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  color: var(--basalt); border: 1px solid var(--outline);
  cursor: pointer; white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.chip.active { background: var(--olive); color: #fff; border-color: var(--olive); }
.chip.active-crimson { background: var(--crimson); color: #fff; border-color: var(--crimson); }
.chip select {
  border: none; background: transparent; color: inherit; font-family: inherit;
  font-size: 12.5px; font-weight: 700; outline: none; cursor: pointer;
}

/* Side FABs (Left side in RTL, Right side in LTR) */
.side-fabs {
  position: absolute; left: 12px; bottom: 26px; z-index: 10;
  display: flex; flex-direction: column; gap: 9px;
}
[dir="ltr"] .side-fabs { left: auto; right: 12px; }

/* Language Switcher Pill inside Search Bar & About */
.lang-select-pill {
  border: 1px solid var(--outline); background: var(--olive-soft); color: var(--olive);
  border-radius: 10px; padding: 4px 7px; font-family: 'IBM Plex Sans', 'Cairo', sans-serif;
  font-size: 12px; font-weight: 800; outline: none; cursor: pointer; flex-shrink: 0;
}
.lang-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 8px;
}
.lang-btn {
  padding: 7px 4px; border-radius: 10px; border: 1.2px solid var(--outline);
  background: var(--surface); color: var(--basalt); font-family: 'IBM Plex Sans', 'Cairo', sans-serif;
  font-size: 11.5px; font-weight: 700; cursor: pointer; text-align: center;
}
.lang-btn.active {
  background: var(--olive); color: #fff; border-color: var(--olive);
}
html[dir="ltr"], html[dir="ltr"] body {
  font-family: 'IBM Plex Sans', 'Cairo', system-ui, -apple-system, sans-serif;
}
.fab-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--outline);
  background: var(--surface); color: var(--olive);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2); cursor: pointer; font-family: inherit;
}
.fab-btn.lucky {
  background: var(--crimson); color: #fff; border-color: var(--crimson);
  font-size: 10px; font-weight: 800; line-height: 1.1;
}
.fab-btn:active { transform: scale(0.95); }

/* Map Style Attribution */
.map-badge {
  position: absolute; right: 10px; bottom: 14px; z-index: 9;
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
}
[dir="ltr"] .map-badge { right: auto; left: 10px; }
.style-pill {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--outline); border-radius: 10px;
  padding: 3px 10px; font-size: 11.5px; font-weight: 700;
}
.attrib-pill {
  background: rgba(0,0,0,0.58); color: #fff; border-radius: 7px;
  padding: 2px 7px; font-size: 10px;
}

/* Bottom Navigation */
.bottom-nav {
  display: flex; background: var(--surface); border-top: 1px solid var(--outline);
  padding: 6px 8px calc(6px + var(--safe-bottom)); z-index: 20;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: none; background: transparent; color: var(--muted);
  font-family: inherit; font-size: 11.5px; font-weight: 700; cursor: pointer; padding: 4px;
}
.nav-item .nav-pill {
  padding: 4px 18px; border-radius: 999px; font-size: 18px; transition: 0.15s;
}
.nav-item.active { color: var(--olive); }
.nav-item.active .nav-pill { background: var(--olive); color: #fff; }

/* Mosaic Strip */
.mosaic-strip {
  width: 100%; height: 13px; background: url('/assets/madaba_mosaic_border.png') repeat-x center/auto 100%;
  flex-shrink: 0;
}

/* Bottom Sheet / Modal */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.48); z-index: 40;
  display: none; align-items: flex-end; justify-content: center;
}
.sheet-backdrop.open { display: flex; }
.sheet {
  width: 100%; max-width: 560px; max-height: 86vh; background: var(--surface);
  border-radius: 22px 22px 0 0; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 -8px 28px rgba(0,0,0,0.28); animation: slideUp 0.2s ease-out;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; padding: 14px 18px calc(22px + var(--safe-bottom)); }

/* Place Detail Elements */
.acc-green-badge {
  display: inline-flex; align-items: center; gap: 4px; background: var(--green-acc);
  color: #fff; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 800;
}
.weather-pill {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
  background: var(--olive-soft); border: 1px solid var(--outline);
  border-radius: 10px; padding: 5px 10px; font-size: 12px; font-weight: 700;
}
.safety-banner {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  background: rgba(119, 42, 38, 0.09); border: 1px solid rgba(119, 42, 38, 0.35);
  font-size: 12.5px; line-height: 1.6;
}
.warm-cta-card {
  margin-top: 12px; padding: 12px; border-radius: 14px;
  background: var(--warm-card); border: 1.3px solid var(--warm-border);
}
.warm-badge {
  display: inline-block; background: var(--warm-badge-bg); color: var(--warm-badge-text);
  padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; margin-bottom: 6px;
}
.warm-grad-btn {
  width: 100%; margin-top: 8px; padding: 11px 14px; border: none; border-radius: 12px;
  background: linear-gradient(90deg, var(--petra), var(--crimson));
  color: #fff; font-family: inherit; font-size: 13.5px; font-weight: 800; cursor: pointer;
}
.btn-primary {
  width: 100%; padding: 11px 14px; border: none; border-radius: 12px;
  background: var(--olive); color: #fff; font-family: inherit; font-size: 14px; font-weight: 800; cursor: pointer;
}
.btn-outline {
  padding: 9px 12px; border-radius: 11px; border: 1.2px solid var(--outline);
  background: var(--surface); color: var(--basalt); font-family: inherit;
  font-size: 13px; font-weight: 700; cursor: pointer;
}

/* Dialog */
.dialog-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.62); z-index: 60;
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.dialog-backdrop.open { display: flex; }
.dialog-card {
  width: 100%; max-width: 460px; max-height: 88vh; background: var(--surface);
  border-radius: 20px; border: 1.2px solid var(--outline); overflow: hidden;
  display: flex; flex-direction: column;
}
.dialog-content { overflow-y: auto; overscroll-behavior-y: contain; padding: 16px 18px; }

/* Form fields — 16px prevents iOS Safari forced input zoom! */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 700; margin-bottom: 4px; color: var(--olive); }
.field input, .field textarea, .field select {
  width: 100%; padding: 10px 12px; border-radius: 12px; border: 1.2px solid var(--outline);
  background: var(--surface); color: var(--basalt); font-family: inherit; font-size: 16px;
}
.card-box {
  background: var(--surface); border: 1px solid var(--outline); border-radius: 16px;
  padding: 14px; margin-bottom: 12px;
}
.toast {
  position: fixed; bottom: calc(74px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--basalt); color: var(--sand-light); padding: 9px 16px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; z-index: 90; display: none; max-width: 90%; text-align: center;
}
.ios-install-banner {
  background: var(--warm-card); border: 1px solid var(--warm-border);
  border-radius: 14px; padding: 11px 13px; margin-bottom: 12px; font-size: 12.5px;
}
.install-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--warm-card); border-top: 1.2px solid var(--warm-border);
  padding: 8px 12px; z-index: 25;
}
.rain-alert-banner {
  margin-top: 9px; padding: 10px 12px; border-radius: 12px;
  background: #FDECEC; border: 1.3px solid #C62828; color: #8E1B1B;
  font-size: 12.5px; line-height: 1.6;
}
@media (prefers-color-scheme: dark) {
  .rain-alert-banner {
    background: #3E1818; border-color: #E07070; color: #FFB4AB;
  }
}
.golden-card {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  background: rgba(217, 155, 0, 0.11); border: 1px solid rgba(217, 155, 0, 0.42);
  font-size: 12px; line-height: 1.65;
}
.golden-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px;
}
.golden-cell {
  background: var(--surface); border-radius: 8px; padding: 5px 8px; font-weight: 700;
}
.hp-trap {
  position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; pointer-events: none;
}
