:root {
  --bg: #0b1220;
  --panel: rgba(17, 26, 46, 0.92);
  --panel-solid: #111a2e;
  --panel-2: #18243f;
  --line: #1f2d4d;
  --text: #e8eef9;
  --muted: #8a9bbf;
  --accent: #4f8cff;
  --accent-2: #6bd1c2;
  --vf: #2dbf6a;
  --voa: #f0a93b;
  --vr: #e45a5a;
  --eta: #b37cff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.6);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  /* Mobile-first: map fills entire viewport */
  display: block;
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* ============ MAP ============ */
#map {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #0a0f1c;
}

.leaflet-container {
  background: #0a0f1c;
  font-family: inherit;
}

.country-shape {
  stroke: #0a0f1c;
  stroke-width: 0.5;
  cursor: pointer;
  transition: fill 0.15s;
}

.country-shape:hover {
  stroke: #fff;
  stroke-width: 1.5;
}

.country-label {
  background: rgba(11, 18, 32, 0.92);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
  box-shadow: var(--shadow);
}

.country-label::before { display: none; }

/* ============ TOP BAR (floating overlay) ============ */
.topbar {
  position: fixed;
  top: calc(8px + var(--safe-top));
  left: 8px;
  right: 8px;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px) saturate(150%);
  backdrop-filter: blur(14px) saturate(150%);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand h1 {
  font-size: 15px;
  margin: 0;
  letter-spacing: 0.2px;
  font-weight: 600;
  white-space: nowrap;
}

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 12px var(--accent);
  flex-shrink: 0;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.passport-select {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  min-width: 0;
}

.passport-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
  flex-shrink: 0;
}

#passport {
  background: transparent;
  color: var(--text);
  border: none;
  padding: 2px 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  min-width: 0;
  max-width: 160px;
  text-overflow: ellipsis;
}

#passport:focus { outline: none; }

#passport option {
  background: var(--panel-solid);
  color: var(--text);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s;
}

.icon-btn:hover { background: #20304f; }
.icon-btn:active { transform: scale(0.95); }

/* Legend (dropdown) */
.legend {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px) saturate(150%);
  backdrop-filter: blur(14px) saturate(150%);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-width: 320px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.chip::before {
  content: "";
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
}

.chip-vf::before { background: var(--vf); }
.chip-voa::before { background: var(--voa); }
.chip-eta::before { background: var(--eta); }
.chip-vr::before { background: var(--vr); }
.chip-na::before { background: #555; }

/* ============ PANEL — bottom sheet on mobile, side panel on desktop ============ */
.panel {
  position: fixed;
  z-index: 1100;
  background: var(--panel-solid);
  color: var(--text);
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;

  /* Mobile (default): bottom sheet */
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 85vh;
  height: auto;
  border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.4);
  padding-bottom: var(--safe-bottom);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.panel.open {
  transform: translateY(0);
}

.panel.expanded {
  /* On tap/expand: nearly full height */
  max-height: 95vh;
}

/* Drag handle (mobile) */
.panel-handle {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 0 6px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

.panel-handle-bar {
  display: block;
  width: 36px;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
}

.panel-handle:active { cursor: grabbing; }

/* Close button */
.panel-close {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  padding: 0;
  z-index: 2;
}

.panel-close:hover { background: var(--panel-2); color: var(--text); }
.panel-close:active { transform: scale(0.92); }

.panel-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 0 16px;
}

/* Empty state */
.panel-empty {
  padding: 40px 24px 24px;
  color: var(--muted);
  text-align: center;
}

.panel-empty h2 {
  color: var(--text);
  font-size: 20px;
  margin: 0 0 10px;
}

.panel-empty p {
  font-size: 14px;
  line-height: 1.55;
  margin: 8px 0;
}

.panel-empty .hint {
  font-size: 12px;
  margin-top: 18px;
  color: #607090;
}

/* Country header */
.country header {
  padding: 18px 24px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #142042 0%, transparent 100%);
}

.country h2 {
  font-size: 22px;
  margin: 0 0 6px;
  font-weight: 600;
  padding-right: 36px; /* room for close button */
}

.country .meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.country .meta .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #0b1220;
}

.badge-vf   { background: var(--vf); }
.badge-voa  { background: var(--voa); }
.badge-vr   { background: var(--vr); color: #fff; }
.badge-eta  { background: var(--eta); color: #0b1220; }
.badge-na   { background: #6b7896; color: #fff; }

.section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 600;
}

.visa-types {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.visa-type {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}

.visa-type .vname {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.visa-type .vdesc {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 8px;
}

.visa-type .vinfo {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--accent-2);
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.visa-type .vinfo span {
  background: rgba(107, 209, 194, 0.08);
  padding: 2px 8px;
  border-radius: 4px;
}

a.vurl, a.eurl {
  display: inline-block;
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  margin-right: 12px;
  margin-top: 4px;
}

a.vurl:hover, a.eurl:hover {
  text-decoration: underline;
}

.embassy {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
}

.embassy .ename {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
}

.embassy p {
  font-size: 12.5px;
  color: var(--muted);
  margin: 4px 0;
  line-height: 1.5;
}

.embassy p strong {
  color: var(--text);
  font-weight: 500;
}

.links-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: white;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
  min-height: 36px;
}

.btn:hover { background: #3a7ae8; }

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn-ghost:hover { background: rgba(79, 140, 255, 0.1); }

.notice {
  font-size: 12.5px;
  color: var(--muted);
  background: rgba(240, 169, 59, 0.08);
  border: 1px solid rgba(240, 169, 59, 0.3);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.5;
}

.data-warning {
  font-size: 11.5px;
  color: #6b7896;
  font-style: italic;
  margin-top: 8px;
  line-height: 1.5;
}

/* Backdrop for mobile sheet */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1050;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

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

/* ============ DESKTOP (≥900px) ============ */
@media (min-width: 900px) {
  .topbar {
    left: 16px;
    right: 16px;
    padding: 10px 16px;
    border-radius: 12px;
  }

  .brand h1 { font-size: 16px; }

  .passport-label { font-size: 11px; }
  #passport { font-size: 14px; max-width: 240px; }

  .panel {
    /* Side panel: right side, full height */
    left: auto;
    right: 16px;
    top: 76px;
    bottom: 16px;
    width: 420px;
    max-height: none;
    border-radius: 12px;
    border: 1px solid var(--line);
    transform: translateX(120%);
  }

  .panel.open {
    transform: translateX(0);
  }

  .panel-handle { display: none; }
  .panel-close { display: none; } /* x close icon hidden; tap outside or use Esc */
  .backdrop { display: none !important; }

  .panel-content { padding: 0; }
  .country header { padding: 20px 24px 16px; }
  .section { padding: 16px 24px; }
}

@media (min-width: 1200px) {
  .panel { width: 440px; }
}
