:root {
  color-scheme: light;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #17202e;
  --muted: #5d6879;
  --border: #dde2ea;
  --accent: #1f5fd1;
  --ocean: #e6eef8;
  --graticule: #d3deec;

  --st-free: #1f6fe0;
  --st-easy: #8cc4f2;
  --st-transit_ok: #f2c230;
  --st-visa: #e0483e;
  --st-banned: #3a2d33;
  --st-self: #20a86b;
  --st-unknown: #c9ced6;
  --st-none: #d6dbe3;
  --stroke: #ffffff;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Tema oscuro: elegido manualmente (data-theme) o por preferencia del sistema si no hay elección. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e131b;
  --surface: #161d28;
  --surface-2: #1e2633;
  --text: #e6ebf2;
  --muted: #97a3b6;
  --border: #2a3444;
  --accent: #6ea4ff;
  --ocean: #0f1f33;
  --graticule: #1a2c44;
  --st-free: #3b82f6;
  --st-easy: #7db5e6;
  --st-transit_ok: #e9b824;
  --st-visa: #e5534b;
  --st-banned: #6b5a62;
  --st-self: #2fbf7f;
  --st-unknown: #3a4352;
  --st-none: #2f3846;
  --stroke: #0e131b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e131b;
    --surface: #161d28;
    --surface-2: #1e2633;
    --text: #e6ebf2;
    --muted: #97a3b6;
    --border: #2a3444;
    --accent: #6ea4ff;
    --ocean: #0f1f33;
    --graticule: #1a2c44;
    --st-free: #3b82f6;
    --st-easy: #7db5e6;
    --st-transit_ok: #e9b824;
    --st-visa: #e5534b;
    --st-banned: #6b5a62;
    --st-self: #2fbf7f;
    --st-unknown: #3a4352;
    --st-none: #2f3846;
    --stroke: #0e131b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand-mark { font-size: 1.4rem; }
.brand-dim { color: var(--muted); font-weight: 500; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.passport-form { display: flex; align-items: center; gap: 10px; }
.theme-toggle {
  flex: none; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer; display: grid; place-items: center;
  transition: background .15s ease, transform .2s ease;
}
.theme-toggle:hover { background: var(--border); }
.theme-toggle:active { transform: rotate(-20deg) scale(.95); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle svg { width: 20px; height: 20px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}
body, .topbar, .card, .side-panel, .map-pane, .footer { transition: background-color .2s ease, border-color .2s ease, color .2s ease; }
.passport-form label { font-size: .9rem; color: var(--muted); }
.passport-form select {
  font: inherit; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); min-width: 240px; max-width: 70vw;
}

/* ---------- Layout del mapa ---------- */
body.page-map { height: 100vh; min-height: 640px; }
main { flex: 1; }
.map-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; grid-template-rows: minmax(0, 1fr); gap: 16px; padding: 16px;
  flex: 1 1 auto; min-height: 520px;
}
.map-pane {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; min-height: 0;
}
.map-intro {
  position: absolute; top: 16px; left: 16px; max-width: 420px; z-index: 2; pointer-events: none;
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
}
.map-intro h1 { margin: 0 0 6px; font-size: 1.25rem; }
.map-intro p { margin: 0; color: var(--muted); font-size: .92rem; }
.map-wrap { position: relative; flex: 1; min-height: 0; }
#map { width: 100%; height: 100%; display: block; background: var(--ocean); cursor: grab; }
#map:active { cursor: grabbing; }
.sphere { fill: var(--ocean); }
.graticule { fill: none; stroke: var(--graticule); stroke-width: .4; }
.country {
  stroke: var(--stroke); stroke-width: .5; cursor: pointer; outline: none;
  transition: fill .25s ease, filter .15s ease, opacity .15s ease;
}
.country.is-hover, .country:focus-visible {
  stroke: var(--text); stroke-width: 1.2px !important; filter: brightness(1.12) drop-shadow(0 0 3px rgba(0,0,0,.35));
}
.map-pane:has(.country.is-hover) .country:not(.is-hover) { opacity: .78; }

.st-free { fill: var(--st-free); background: var(--st-free); }
.st-easy { fill: var(--st-easy); background: var(--st-easy); }
.st-transit_ok { fill: var(--st-transit_ok); background: var(--st-transit_ok); }
.st-visa { fill: var(--st-visa); background: var(--st-visa); }
.st-banned { fill: var(--st-banned); background: var(--st-banned); }
.st-self { fill: var(--st-self); background: var(--st-self); }
.st-unknown { fill: var(--st-unknown); background: var(--st-unknown); }
.st-none { fill: var(--st-none); background: var(--st-none); }
.st-text-free { color: var(--st-free); }
.st-text-easy { color: color-mix(in srgb, var(--st-easy) 70%, var(--text)); }
.st-text-transit_ok { color: color-mix(in srgb, var(--st-transit_ok) 75%, var(--text)); }
.st-text-visa { color: var(--st-visa); }
.st-text-banned, .st-text-unknown, .st-text-self { color: var(--muted); }

.map-controls { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 6px; }
.map-controls button {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 1.1rem; cursor: pointer; box-shadow: var(--shadow);
}
.map-controls button:hover { background: var(--surface-2); }
.map-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

.legend {
  list-style: none; margin: 0; padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 6px 16px;
  font-size: .82rem; color: var(--muted); border-top: 1px solid var(--border);
}
.legend li { display: flex; align-items: center; gap: 6px; }
.sw, .dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; }
.dot { border-radius: 50%; width: 10px; height: 10px; }

/* ---------- Panel derecho ---------- */
.side-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.panel-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0 0 10px; font-size: 1.05rem; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.stats:empty { display: none; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 6px 4px; text-align: center; }
.stat b { display: block; font-size: 1.15rem; }
.stat span { font-size: .68rem; color: var(--muted); line-height: 1.15; display: block; }
#search {
  width: 100%; font: inherit; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
}
#search:focus, .passport-form select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font: inherit; font-size: .78rem; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: transparent; color: var(--text); cursor: pointer;
}
.chip.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.panel-body { overflow-y: auto; padding: 4px 6px 12px; flex: 1; }
.panel-empty { padding: 16px 10px; }
.group h3 { display: flex; align-items: center; gap: 8px; font-size: .9rem; margin: 14px 8px 2px; }
.group .count { margin-left: auto; color: var(--muted); font-weight: 500; font-size: .8rem; }
.group-hint { margin: 0 8px 4px; font-size: .75rem; color: var(--muted); }
.group ul { list-style: none; margin: 0; padding: 0; }
.group a {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: .92rem;
}
.group a:hover, .group a.is-hover, .group a:focus-visible { background: var(--surface-2); outline: none; }
.group .flag { font-size: 1.1rem; width: 1.4em; text-align: center; }
.group .name { flex: 1; }
.group .meta { font-size: .75rem; color: var(--muted); }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none; max-width: 280px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; box-shadow: 0 8px 24px rgba(0,0,0,.18); font-size: .88rem;
}
.tt-title { font-weight: 700; margin-bottom: 4px; }
.tt-status { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.tt-sub { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.tt-cta { color: var(--accent); font-size: .78rem; margin-top: 6px; }

/* ---------- Detalle ---------- */
.detail { max-width: 1180px; width: 100%; margin: 0 auto; padding: 16px 20px 32px; }
.crumbs { margin-bottom: 12px; }
.crumbs a { text-decoration: none; }
.country-hero { display: flex; gap: 18px; align-items: center; margin-bottom: 16px; }
.hero-flag { font-size: 4rem; line-height: 1; }
.country-hero h1 { margin: 0; font-size: 2rem; }
.country-hero p { margin: 4px 0 6px; }
.tag { display: inline-block; font-size: .75rem; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.callout { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }

.status-card {
  background: var(--surface); border: 1px solid var(--border); border-left: 6px solid var(--st-unknown);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.st-border-free { border-left-color: var(--st-free); }
.st-border-easy { border-left-color: var(--st-easy); }
.st-border-transit_ok { border-left-color: var(--st-transit_ok); }
.st-border-visa { border-left-color: var(--st-visa); }
.st-border-banned { border-left-color: var(--st-banned); }
.st-border-self { border-left-color: var(--st-self); }
.status-badge { display: inline-block; padding: 3px 12px; border-radius: 999px; font-weight: 600; font-size: .85rem; color: #fff; }
.status-badge.st-transit_ok, .status-badge.st-easy, .status-badge.st-unknown { color: #1b1b1b; }
.status-headline { font-size: 1.15rem; font-weight: 600; margin: 10px 0; }
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 0 0 6px; }
.status-grid div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.status-grid dt { font-size: .75rem; color: var(--muted); }
.status-grid dd { margin: 2px 0 0; font-weight: 600; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.detail-side { position: sticky; top: 74px; display: flex; flex-direction: column; gap: 18px; }
.detail-main { display: flex; flex-direction: column; gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 10px; font-size: 1.15rem; }
.card h3 { font-size: 1rem; margin: 14px 0 4px; }
.card p { margin: 6px 0; }
.steps { padding-left: 1.3em; margin: 0; }
.steps li { margin: 6px 0; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: 6px 0 6px 28px; position: relative; border-bottom: 1px solid var(--border); }
.checklist li:last-child { border-bottom: 0; }
.checklist li::before { content: "✓"; position: absolute; left: 4px; color: var(--st-self); font-weight: 700; }
.transit-box { border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.transit-box.is-free { background: color-mix(in srgb, var(--st-transit_ok) 18%, transparent); border: 1px solid color-mix(in srgb, var(--st-transit_ok) 50%, transparent); }
.transit-box.is-required { background: color-mix(in srgb, var(--st-visa) 14%, transparent); border: 1px solid color-mix(in srgb, var(--st-visa) 45%, transparent); }
.visa-mini { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; margin: 8px 0; }
.laws { list-style: none; padding: 0; margin: 0; }
.laws li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.laws li:last-child { border-bottom: 0; }
.law-name { font-weight: 600; }
.visa-list { display: flex; flex-direction: column; gap: 8px; }
.visa-item { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.visa-item[open] { background: var(--surface-2); }
.visa-item summary { cursor: pointer; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.visa-cat { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); width: 100%; }
.visa-title { font-weight: 600; }
.links { padding-left: 1.1em; margin: 8px 0; }
.links li { margin: 4px 0; }
.missions { list-style: none; padding: 0; margin: 0 0 8px; }
.missions li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .92rem; }

.footer { padding: 12px 20px; font-size: .78rem; color: var(--muted); text-align: center; border-top: 1px solid var(--border); background: var(--surface); }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  body.page-map { height: auto; }
  .map-layout { grid-template-columns: 1fr; grid-template-rows: auto; height: auto; }
  .map-pane { height: auto; }
  .map-wrap { flex: none; }
  #map { height: auto; aspect-ratio: 960 / 500; }
  .side-panel { max-height: 70vh; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-side { position: static; }
}
@media (max-width: 560px) {
  .topbar { padding: 10px 16px; }
  .topbar-actions { width: 100%; }
  .passport-form { flex: 1; min-width: 0; }
  .passport-form select { flex: 1; min-width: 0; }
  .map-layout, .detail { padding: 12px 16px; }
  .map-intro { position: static; max-width: none; margin: 10px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .hero-flag { font-size: 3rem; }
  .country-hero h1 { font-size: 1.5rem; }
}

/* ---------- Pestañas ---------- */
.tabs { margin-top: 4px; }
.tablist {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; padding: 4px 2px 0;
  border-bottom: 1px solid var(--border); margin-bottom: 18px; scroll-behavior: smooth;
}
.tab {
  font: inherit; flex: none; max-width: 240px; display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  padding: 8px 14px 9px; border: 1px solid transparent; border-bottom: 0; border-radius: 10px 10px 0 0;
  background: transparent; color: var(--muted); cursor: pointer; text-align: left; position: relative; top: 1px;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab[aria-selected="true"] {
  background: var(--surface); color: var(--text); border-color: var(--border); border-bottom: 1px solid var(--surface);
  box-shadow: inset 0 3px 0 var(--accent);
}
.tab-cat { font-size: .66rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tab-name { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab-icon { margin-right: 4px; }
#tab-general, #tab-guia { flex-direction: row; align-items: center; font-weight: 600; font-size: .92rem; }
/* Sin JS se muestran todos los paneles; con JS solo el activo. */
.js .tabpanel:not(.is-active) { display: none; }
.tabpanel + .tabpanel { margin-top: 18px; }
.js .tabpanel + .tabpanel { margin-top: 0; }

/* Listado de visas en la pestaña general */
a.visa-link { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; text-decoration: none; color: var(--text); }
a.visa-link:hover { background: var(--surface-2); border-color: var(--accent); }
.visa-go { margin-left: auto; color: var(--accent); font-size: .85rem; }

/* Panel de cada visa */
.visa-hero h2 { font-size: 1.4rem; margin: 4px 0 8px; }
.visa-hero .lead { font-size: 1.05rem; }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { display: flex; gap: 14px; padding: 0 0 16px; position: relative; }
.timeline li:not(:last-child)::before {
  content: ""; position: absolute; left: 14px; top: 30px; bottom: 2px; width: 2px; background: var(--border);
}
.timeline-n {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: .9rem;
}
.timeline li > div { padding-top: 4px; }
.tips { border-left: 4px solid var(--st-transit_ok); }
.tips ul { margin: 0; padding-left: 1.2em; }
.tips li { margin: 6px 0; }
.facts { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.facts dt { font-size: .75rem; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; }
.guide-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; margin-top: 18px; }

/* ---------- Comentarios ---------- */
.comments { margin-top: 32px; padding-top: 24px; border-top: 2px solid var(--border); }
.comments-head h2 { margin: 0 0 4px; display: flex; align-items: center; gap: 10px; }
.count-pill { font-size: .8rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 10px; }
.comment-form { margin: 14px 0 20px; display: flex; flex-direction: column; gap: 12px; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.field input, .field textarea {
  width: 100%; font: inherit; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); resize: vertical;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-error { color: var(--st-visa); font-size: .85rem; margin-top: 4px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.form-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.btn {
  font: inherit; font-weight: 600; padding: 9px 18px; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff;
}
.btn:hover { filter: brightness(1.08); }
.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.flash { border-radius: 10px; padding: 10px 14px; margin: 10px 0; font-size: .92rem; }
.flash-success { background: color-mix(in srgb, var(--st-self) 16%, transparent); border: 1px solid color-mix(in srgb, var(--st-self) 45%, transparent); }
.flash-error { background: color-mix(in srgb, var(--st-visa) 14%, transparent); border: 1px solid color-mix(in srgb, var(--st-visa) 45%, transparent); }
.comment-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.comment { display: flex; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  background: color-mix(in srgb, var(--accent) 18%, var(--surface)); color: var(--accent);
}
.comment-body { min-width: 0; flex: 1; }
.comment-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.comment-body p { margin: 6px 0 0; overflow-wrap: anywhere; }
.empty-comments { padding: 8px 0; }

@media (max-width: 560px) {
  .tab { max-width: 200px; padding: 7px 10px; }
  .guide-grid { grid-template-columns: 1fr; }
  .comment { padding: 12px; }
}
