:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --ink: #1d2329;
  --muted: #5d6670;
  --line: #e2ded5;
  --sea: #e9eef2;
  --stroke: #ffffff;
  --focus: #1f5fbf;

  --c-free: #1a9850;
  --c-arrival: #91cf60;
  --c-evisa: #f2c94c;
  --c-required: #f07a45;
  --c-banned: #8e2c5a;
  --c-none: #cfcbc3;
  --c-selected: #24456e;
  --c-idle: #d8d3c8;

  --radius: 10px;
  --shadow: 0 6px 24px rgba(20, 25, 30, .12);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171b;
    --surface: #1c2026;
    --ink: #e8eaed;
    --muted: #9aa3ad;
    --line: #2c323a;
    --sea: #181c21;
    --stroke: #14171b;
    --focus: #7fb0ff;
    --c-free: #2fae66;
    --c-arrival: #8cc45c;
    --c-evisa: #e6c14e;
    --c-required: #e7743f;
    --c-banned: #c0548a;
    --c-none: #3b4149;
    --c-selected: #7aa7e8;
    --c-idle: #343a42;
    --shadow: 0 6px 24px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14171b; --surface: #1c2026; --ink: #e8eaed; --muted: #9aa3ad; --line: #2c323a;
  --sea: #181c21; --stroke: #14171b; --focus: #7fb0ff;
  --c-free: #2fae66; --c-arrival: #8cc45c; --c-evisa: #e6c14e; --c-required: #e7743f;
  --c-banned: #c0548a; --c-none: #3b4149; --c-selected: #7aa7e8; --c-idle: #343a42;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--focus); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header */
.top {
  display: flex; flex-wrap: wrap; gap: 12px 24px;
  align-items: center; justify-content: space-between;
  padding: 16px 24px 12px;
}
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.lede { margin: 2px 0 0; color: var(--muted); }
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.search { position: relative; }
.search input {
  width: 240px; max-width: 100%;
  padding: 9px 12px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.search input:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
#search-list, .combo-list {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0;
  margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); max-height: 280px; overflow: auto;
}
#search-list li, .combo-list li { padding: 7px 10px; border-radius: 6px; cursor: pointer; }
#search-list li[aria-selected="true"], #search-list li:hover,
.combo-list li[aria-selected="true"], .combo-list li:hover { background: var(--sea); }

.toggle {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
}
.toggle button {
  font: inherit; font-weight: 500; color: var(--muted);
  padding: 6px 14px; border: 0; border-radius: 6px; background: transparent; cursor: pointer;
}
.toggle button[aria-checked="true"] { background: var(--c-selected); color: var(--surface); }
.toggle button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* Layout */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  padding: 0 24px 16px;
  min-height: 0;
}
.map-wrap {
  position: relative;
  background: var(--sea);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  min-height: 420px;
  display: flex; flex-direction: column;
}
#map { width: 100%; flex: 1; display: block; min-height: 380px; }
#map.zoomed { cursor: grab; }
#map.zoomed:active { cursor: grabbing; }
/* Colour toggles over the map, top left (zoom buttons are top right). */
.map-ctl {
  position: absolute; top: 10px; left: 10px; right: 58px; z-index: 2;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start;
  pointer-events: none;
}
.map-ctl > * { pointer-events: auto; }
.map-ctl [hidden] { display: none; }
.map-ctl .toggle { box-shadow: 0 1px 3px rgba(0, 0, 0, .12); flex-wrap: wrap; }
.metric-ctl { display: flex; }

.zoom-ctl {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}
.zoom-ctl button {
  width: 34px; height: 34px; border: 0; padding: 0;
  font: inherit; font-size: 20px; line-height: 1; color: var(--ink);
  background: transparent; cursor: pointer;
}
.zoom-ctl button + button { border-top: 1px solid var(--line); }
.zoom-ctl button[hidden] { display: none; }
.zoom-ctl button:hover:not(:disabled) { background: var(--line); }
.zoom-ctl button:disabled { color: var(--muted); opacity: .45; cursor: default; }
.zoom-ctl button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

.country {
  fill: var(--c-idle);
  stroke: var(--stroke);
  stroke-width: .6;
  cursor: pointer;
  transition: fill .25s ease;
  vector-effect: non-scaling-stroke;
}
.country:hover, .country.hover { filter: brightness(1.08); stroke: var(--ink); stroke-width: 1.2; }
.country:focus { outline: none; }
.country:focus-visible { stroke: var(--focus); stroke-width: 2; }
.country.selected { fill: var(--c-selected); }
.country.cat-free { fill: var(--c-free); }
.country.cat-arrival { fill: var(--c-arrival); }
.country.cat-evisa { fill: var(--c-evisa); }
.country.cat-required { fill: var(--c-required); }
.country.cat-banned { fill: var(--c-banned); }
.country.cat-none { fill: var(--c-none); }
.marker { stroke-width: 1.2; }

.legend {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  list-style: none; margin: 0; padding: 10px 14px 12px;
  font-size: 13px; color: var(--muted);
}
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
.sw-free { background: var(--c-free); }
.sw-arrival { background: var(--c-arrival); }
.sw-evisa { background: var(--c-evisa); }
.sw-required { background: var(--c-required); }
.sw-banned { background: var(--c-banned); }
.sw-none { background: var(--c-none); }
.sw-selected { background: var(--c-selected); }

/* Panel */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  overflow: auto;
  max-height: calc(100vh - 140px);
}
.panel h2 { margin: 0 0 4px; font-size: 20px; }
.panel .sub { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.empty p { color: var(--muted); }

.bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; margin: 4px 0 16px; background: var(--c-none); }
.bar span { display: block; height: 100%; }

.group { margin: 0 0 14px; }
.group h3 {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 6px; font-size: 14px; font-weight: 600;
}
.group h3 .count { margin-left: auto; color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.group ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.group li button {
  font: inherit; font-size: 13px; color: var(--ink);
  background: var(--sea); border: 1px solid transparent; border-radius: 6px;
  padding: 3px 8px; cursor: pointer; text-align: left;
}
.group li button:hover { border-color: var(--line); }
.group li button:focus-visible { outline: 2px solid var(--focus); }
.group li .stay { color: var(--muted); font-size: 12px; }
.panel .src { font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; margin-top: 6px; }

/* Tooltip */
.tooltip {
  position: fixed; z-index: 30; pointer-events: none;
  max-width: 300px; padding: 10px 12px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  font-size: 13px;
}
.tooltip .tt-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.tooltip .tt-cat { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.tooltip .tt-row { color: var(--muted); margin-top: 3px; }
.tooltip .tt-notes { margin-top: 6px; color: var(--muted); }

/* Footer */
.foot {
  display: flex; flex-wrap: wrap; gap: 4px 16px;
  padding: 0 24px 18px; font-size: 12.5px; color: var(--muted);
}

[hidden] { display: none !important; }

/* Participants mode */
.country.host { stroke: var(--ink); stroke-width: 2.4; }
.sw-host { background: transparent; border: 2px solid var(--ink); }
.legend .grad { gap: 8px; }
.legend .gl { color: var(--ink); font-weight: 500; }
.gradient { width: 120px; height: 10px; border-radius: 5px; display: inline-block; background: var(--c-none); }

.part-add { margin: 4px 0 8px; }
.part-add input { width: 100%; background: var(--bg); }
.part-tools { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin: 0 0 8px; }
.part-total { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.btn {
  font: inherit; font-size: 13px; font-weight: 500; color: var(--ink);
  padding: 6px 12px; background: var(--sea); border: 1px solid var(--line); border-radius: 7px; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.part-list {
  list-style: none; margin: 0 0 14px; padding: 4px;
  max-height: 300px; overflow: auto;
  border: 1px solid var(--line); border-radius: 8px;
}
.part-list li {
  display: grid; grid-template-columns: 1fr 28px 56px 28px 28px; gap: 4px; align-items: center;
  background: var(--sea);
  padding: 3px 4px 3px 8px; border-radius: 6px;
}
.part-list li + li { margin-top: 3px; }
.part-list li label { font-weight: 600; }
.part-list label { font-size: 13.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.part-list input {
  width: 100%; padding: 4px 4px; font: inherit; font-size: 13.5px; text-align: center;
  font-variant-numeric: tabular-nums; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  -moz-appearance: textfield; appearance: textfield;
}
.part-list input::-webkit-inner-spin-button, .part-list input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.part-list input:focus { outline: 2px solid var(--focus); outline-offset: 0; }
.step {
  width: 28px; height: 28px; padding: 0; font: inherit; font-size: 17px; line-height: 1; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
}
.step:hover:not(:disabled) { border-color: var(--muted); }
.step:disabled { opacity: .35; cursor: default; }
.step:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.step.remove { color: var(--muted); border-color: transparent; background: transparent; }
.step.remove:hover { color: var(--ink); border-color: var(--line); }

.metric-row { display: flex; align-items: center; gap: 10px; margin: 4px 0 2px; }
.metric-row .lbl { font-size: 13px; color: var(--muted); }
.toggle.small button { padding: 4px 10px; font-size: 13px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 12px; }
h3.sec { font-size: 14px; margin: 14px 0 6px; }

.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.rank-btn {
  width: 100%; display: grid; grid-template-columns: 22px 1fr auto; grid-template-rows: auto auto;
  column-gap: 8px; row-gap: 4px; align-items: center;
  font: inherit; font-size: 13.5px; color: var(--ink); text-align: left;
  background: var(--bg); border: 1px solid transparent; border-radius: 7px; padding: 6px 9px; cursor: pointer;
}
.rank-btn:hover { border-color: var(--line); }
.rank-btn:focus-visible { outline: 2px solid var(--focus); }
.rank-list li.active .rank-btn { border-color: var(--ink); }
.rank-btn .rk { color: var(--muted); font-variant-numeric: tabular-nums; }
.rank-btn .val { font-variant-numeric: tabular-nums; font-weight: 600; }
.rank-btn .bar.mini { grid-column: 2 / 4; height: 6px; margin: 0; }

.host-box { margin-top: 10px; padding-top: 4px; border-top: 1px solid var(--line); }
.chip-static { display: inline-block; font-size: 13px; background: var(--sea); border-radius: 6px; padding: 3px 8px; }
.actions { display: flex; gap: 8px; margin: 14px 0 4px; }

/* Mobile */
/* Wide windows: the page is exactly one window tall. The map takes all the
   height left after the header and footer (scaling to fit, centred), and the
   side panel scrolls on its own. Very short windows fall back to page scroll. */
/* Detailed participant list */
.list-toggle { margin: 0; }
.det-box .part-tools { flex-direction: column; align-items: flex-start; gap: 6px; }
.det-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.det-btns .btn { padding: 5px 10px; }
.det-notes .hint { margin: 2px 0 6px; }
.people-list {
  list-style: none; margin: 0 0 14px; padding: 4px;
  max-height: 420px; overflow: auto;
  border: 1px solid var(--line); border-radius: 8px;
}
.people-list li {
  display: grid; grid-template-columns: auto 1fr 28px; gap: 5px 8px; align-items: center;
  background: var(--sea); padding: 6px 4px 6px 8px; border-radius: 6px;
}
.people-list li + li { margin-top: 4px; }
.people-list .p-name { grid-column: 1 / 3; }
.people-list .remove { grid-column: 3; grid-row: 1; }
.people-list .p-lbl { grid-column: 1; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.people-list .p-res, .people-list .p-cits { grid-column: 2 / 4; min-width: 0; }
.people-list input, .people-list select {
  font: inherit; font-size: 13.5px; color: var(--ink); min-width: 0; max-width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px;
}
.people-list .p-name { font-weight: 600; }
.people-list input:focus, .people-list select:focus { outline: 2px solid var(--focus); outline-offset: 0; }
.p-cits { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.cit-chip {
  display: inline-flex; align-items: center; gap: 2px; font-size: 13px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 2px 4px 2px 9px;
}
.cit-chip:not(:has(.cit-x)) { padding-right: 9px; }
.cit-x {
  width: 20px; height: 20px; padding: 0; font: inherit; font-size: 14px; line-height: 1; color: var(--muted);
  background: transparent; border: 0; border-radius: 10px; cursor: pointer;
}
.cit-x:hover { color: var(--ink); background: var(--sea); }
.cit-x:focus-visible { outline: 2px solid var(--focus); }
.p-addcit { color: var(--muted) !important; }

/* Flight search links */
.trip-box { margin: 14px 0 6px; }
.trip-box h3.sec { margin-top: 0; }
.trip { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.trip label { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.trip input, .ap-pick {
  font: inherit; font-size: 13px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px;
}
.trip input:focus, .ap-pick:focus { outline: 2px solid var(--focus); outline-offset: 0; }
.ap-pick { max-width: 170px; text-overflow: ellipsis; }
.arrive .ap-pick { max-width: 220px; }
.arrive { font-size: 13px; margin: 2px 0 10px; }
.arrive .muted { color: var(--muted); }
.group ul.fl-rows { display: grid; gap: 4px; }
.fl-rows li { display: grid; gap: 3px; justify-items: start; }
.fl-rows li + li { border-top: 1px solid var(--line); padding-top: 5px; }
.fl-act { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 13px; color: var(--muted); padding-left: 8px; }
.gf-link { font-size: 13px; color: var(--link, var(--ink)); white-space: nowrap; }
.group li .gf-link { margin-left: 2px; text-decoration: none; padding: 2px 4px; border-radius: 5px; }
.group li .gf-link:hover { background: var(--sea); text-decoration: underline; }
.fl-rows .gf-link { text-decoration: underline; }

@media (min-width: 861px) and (min-height: 520px) {
  body { height: 100vh; height: 100dvh; min-height: 0; }
  .layout { grid-template-rows: minmax(0, 1fr); }
  .map-wrap { min-height: 0; }
  #map { flex: 1 1 0; height: auto; min-height: 0; }
  .panel { max-height: none; min-height: 0; }
}

@media (max-width: 860px) {
  .top { padding: 14px 16px 10px; }
  .controls { width: 100%; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .layout { grid-template-columns: 1fr; padding: 0 16px 16px; }
  .map-wrap { min-height: 0; }
  /* Small screens: toggles sit in the container's top-left, above the map rather than over it. */
  .map-ctl { position: static; padding: 10px 58px 0 10px; }
  #map { min-height: 0; aspect-ratio: 1 / 1.05; max-height: 78vh; max-height: 78dvh; }
  .panel { max-height: none; }
  .part-list { max-height: 260px; }
  .step { width: 32px; height: 32px; }
  .part-list li { grid-template-columns: 1fr 32px 56px 32px 32px; }
  .foot { padding: 0 16px 18px; }
}

/* "Open all searches" under the arrival line */
.open-all { margin: 6px 0 10px; }
.open-all .open-note { margin: 6px 0 0; font-size: 12px; }
