/* ==========================================================================
   VisaMap v2 — mobile-first, native-feel UI
   Palette mirrors CATEGORY_INFO in data.js (keep in sync).
   ========================================================================== */

:root {
  /* ── Category colors (ordered ease-of-access scale) ── */
  --c-free:         #34d399;
  --c-arrival:      #a7f3d0;
  --c-eta:          #fcd34d;
  --c-evisa:        #fb923c;
  --c-required:     #ef4444;
  --c-no_admission: #7f1d1d;
  --c-self:         #c084fc;
  --c-none:         #1c2b45;

  /* ── Surfaces / ink (dark, cohesive with ocean) ── */
  --ocean:      #0a1628;
  --surface-1:  rgba(18, 28, 48, 0.86);   /* glass panels */
  --surface-2:  #101b30;                   /* solid sheets */
  --stroke:     rgba(255, 255, 255, 0.10);
  --ink:        #f4f7fb;
  --ink-2:      #9db0cc;
  --ink-3:      #64748b;
  --accent:     #38bdf8;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--ocean);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* No accidental text selection on a map UI (inputs re-enabled below) */
body { user-select: none; -webkit-user-select: none; }
input { user-select: text; -webkit-user-select: text; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* ── Map ──────────────────────────────────────────────────────────────── */
#map { position: fixed; inset: 0; }
.maplibregl-ctrl-attrib,
.maplibregl-ctrl-bottom-left,
.maplibregl-ctrl-bottom-right { display: none !important; }
.maplibregl-canvas { outline: none; }

/* ── Loading ──────────────────────────────────────────────────────────── */
.loading {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column; gap: 16px;
  align-items: center; justify-content: center;
  background: radial-gradient(120% 90% at 50% 40%, #12213c 0%, var(--ocean) 70%);
  color: var(--ink-2); font-size: 15px;
  transition: opacity .5s ease;
}
.loading.hidden { opacity: 0; pointer-events: none; }
.loading-spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.12);
  border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Top: passport pill ───────────────────────────────────────────────── */
.app-top {
  position: fixed; z-index: 40;
  top: calc(var(--safe-t) + 12px);
  left: calc(var(--safe-l) + 12px);
  right: calc(var(--safe-r) + 12px);
  display: flex; justify-content: center;
  pointer-events: none;
}
.passport-pill {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  max-width: 100%;
  padding: 9px 14px 9px 12px;
  background: var(--surface-1);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--stroke);
  border-radius: 999px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
  transition: transform .12s var(--ease-spring), background .2s;
}
.passport-pill:active { transform: scale(0.97); }
.pill-flag { font-size: 26px; line-height: 1; }
.pill-text { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.pill-label { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.pill-name { font-size: 16px; font-weight: 650; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 62vw; }
.pill-chevron { width: 16px; height: 16px; color: var(--ink-2); flex: none; }

/* ── Map controls (right rail) ────────────────────────────────────────── */
.map-controls {
  position: fixed; z-index: 40;
  right: calc(var(--safe-r) + 12px);
  top: calc(var(--safe-t) + 82px);
  display: flex; flex-direction: column; gap: 8px;
}
.ctrl-btn {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  font-size: 20px; font-weight: 600; color: var(--ink);
  background: var(--surface-1);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--stroke);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  transition: transform .12s var(--ease-spring), background .2s;
}
.ctrl-btn:active { transform: scale(0.9); background: rgba(56,189,248,0.18); }

/* ── Legend ───────────────────────────────────────────────────────────── */
.legend-toggle {
  position: fixed; z-index: 39;
  left: calc(var(--safe-l) + 12px);
  bottom: calc(var(--safe-b) + 96px);
  padding: 7px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; color: var(--ink-2);
  background: var(--surface-1);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--stroke);
}
.legend {
  position: fixed; z-index: 39;
  left: calc(var(--safe-l) + 12px);
  bottom: calc(var(--safe-b) + 134px);
  display: flex; flex-direction: column; gap: 7px;
  padding: 12px 14px; border-radius: 16px;
  background: var(--surface-1);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--stroke);
  box-shadow: 0 8px 28px rgba(0,0,0,0.4);
  font-size: 12.5px; color: var(--ink);
  transform-origin: bottom left;
  transition: opacity .2s, transform .24s var(--ease-spring);
}
.legend.hidden { opacity: 0; transform: translateY(8px) scale(0.96); pointer-events: none; }
.legend-item { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.legend-dot { width: 12px; height: 12px; border-radius: 4px; flex: none; box-shadow: 0 0 0 1px rgba(255,255,255,0.12) inset; }

/* ── Stats bar (bottom) ───────────────────────────────────────────────── */
.stats {
  position: fixed; z-index: 40;
  left: 0; right: 0;
  bottom: 0;
  display: flex; gap: 6px;
  padding: 10px calc(var(--safe-r) + 10px) calc(var(--safe-b) + 10px) calc(var(--safe-l) + 10px);
  background: linear-gradient(to top, var(--ocean) 40%, rgba(10,22,40,0.0));
  overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.stats::-webkit-scrollbar { display: none; }
.stat {
  flex: 1 1 0; min-width: 58px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 6px;
  background: var(--surface-1);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--stroke);
  border-top: 2px solid var(--cat, var(--stroke));
  border-radius: 13px;
  transition: transform .12s var(--ease-spring);
}
.stat:active { transform: scale(0.95); }
.stat[data-cat="free"]         { --cat: var(--c-free); }
.stat[data-cat="arrival"]      { --cat: var(--c-arrival); }
.stat[data-cat="eta"]          { --cat: var(--c-eta); }
.stat[data-cat="evisa"]        { --cat: var(--c-evisa); }
.stat[data-cat="required"]     { --cat: var(--c-required); }
.stat[data-cat="no_admission"] { --cat: var(--c-no_admission); }
.stat-num { font-size: 20px; font-weight: 750; line-height: 1; font-variant-numeric: tabular-nums; color: var(--ink); }
.stat-label { font-size: 10.5px; color: var(--ink-2); letter-spacing: .01em; }

/* ── Desktop hover tooltip ────────────────────────────────────────────── */
.tooltip {
  position: fixed; z-index: 45; top: 0; left: 0;
  min-width: 180px; max-width: 260px;
  padding: 14px 16px; border-radius: 16px;
  background: var(--surface-1);
  backdrop-filter: blur(18px) saturate(160%); -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--stroke);
  box-shadow: 0 12px 36px rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none;
  transition: opacity .16s;
  text-align: center;
}
.tooltip.visible { opacity: 1; }
.tooltip-flag { font-size: 32px; line-height: 1; }
.tooltip-name { font-size: 16px; font-weight: 650; margin: 6px 0 8px; }
.tooltip-note {
  font-size: 12.5px; color: var(--ink-2); margin-top: 8px; line-height: 1.4;
  white-space: pre-line;
  max-height: 7.5em; overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 78%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 78%, transparent 100%);
}

/* ── Badges ───────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  font-size: 13px; font-weight: 650; line-height: 1;
  color: #06121f;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: rgba(0,0,0,0.35); }
.badge-free         { background: var(--c-free); }
.badge-arrival      { background: var(--c-arrival); }
.badge-eta          { background: var(--c-eta); }
.badge-evisa        { background: var(--c-evisa); color: #1a0d02; }
.badge-required     { background: var(--c-required); color: #fff; }
.badge-no_admission { background: var(--c-no_admission); color: #fff; }
.badge-self         { background: var(--c-self); color: #1a0533; }
.badge-none         { background: #2a3a57; color: var(--ink-2); }

/* ── Sheets (shared) ──────────────────────────────────────────────────── */
.backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(3, 8, 18, 0.5);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity .28s ease;
}
.backdrop.visible { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; z-index: 51;
  left: 0; right: 0; bottom: 0;
  background: var(--surface-2);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--stroke);
  box-shadow: 0 -14px 44px rgba(0,0,0,0.55);
  transform: translateY(100%);
  transition: transform .38s var(--ease-spring);
  padding-bottom: var(--safe-b);
  will-change: transform;
  touch-action: none;
}
.sheet.open { transform: translateY(0); }
.sheet-handle {
  width: 38px; height: 5px; border-radius: 3px;
  background: rgba(255,255,255,0.22);
  margin: 9px auto 4px;
}

/* Detail sheet */
.detail-sheet { max-width: 560px; margin: 0 auto; padding: 0 20px 22px; }
.sheet-header { display: flex; align-items: center; gap: 14px; padding: 8px 0 14px; }
.sheet-flag { font-size: 44px; line-height: 1; flex: none; }
.sheet-titles { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.sheet-country-name { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.15; }
.sheet-note {
  font-size: 14px; color: var(--ink-2); line-height: 1.5;
  white-space: pre-line;
  padding: 14px 0 4px;
  border-top: 1px solid var(--stroke);
}

/* Picker sheet */
.picker-sheet {
  top: calc(var(--safe-t) + 10px);
  display: flex; flex-direction: column;
  border-radius: 22px 22px 0 0;
}
.picker-head {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 16px 12px;
}
.search-wrap { position: relative; flex: 1; display: flex; align-items: center; }
.search-icon { position: absolute; left: 12px; width: 18px; height: 18px; color: var(--ink-3); pointer-events: none; }
.picker-search {
  flex: 1; width: 100%;
  padding: 12px 14px 12px 38px;
  font-size: 16px; color: var(--ink);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--stroke);
  border-radius: 13px;
  outline: none;
}
.picker-search::placeholder { color: var(--ink-3); }
.picker-search:focus { border-color: var(--accent); background: rgba(56,189,248,0.08); }
.picker-cancel { font-size: 15px; font-weight: 600; color: var(--accent); padding: 6px; flex: none; }
.picker-list {
  list-style: none; margin: 0; padding: 0 8px 8px;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  flex: 1;
}
.picker-row {
  display: flex; align-items: center; gap: 13px;
  width: 100%; text-align: left;
  padding: 12px 12px;
  border-radius: 13px;
  font-size: 16px; color: var(--ink);
}
.picker-row:active { background: rgba(255,255,255,0.07); }
.picker-row.selected { background: rgba(56,189,248,0.14); color: var(--accent); font-weight: 650; }
.picker-row-flag { font-size: 26px; line-height: 1; flex: none; }
.picker-row-check { margin-left: auto; color: var(--accent); font-size: 18px; }
.picker-empty { padding: 30px 16px; text-align: center; color: var(--ink-3); font-size: 14px; }

/* ── Desktop refinements ──────────────────────────────────────────────── */
@media (min-width: 640px) {
  .stat-num { font-size: 22px; }
  .sheet, .picker-sheet { max-width: 460px; left: auto; right: 20px; bottom: 20px; border-radius: 22px; }
  .picker-sheet { top: 80px; }
  .detail-sheet { margin: 0; }
  .backdrop { background: rgba(3, 8, 18, 0.35); }
}
