:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --panel-2: #f8f7f4;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --line: #e4e1da;
  --accent: #d9480f;
  --accent-soft: #fde7dc;
  --route: #3b5bdb;
  --shadow: 0 6px 24px rgba(20, 20, 10, .12);
  --btn-bg: #b93d0c; --btn-fg: #ffffff; --btn-hover: #9c3309; /* white on this is 5.6:1 */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412; --panel: #1e1e1b; --panel-2: #262622; --text: #eceae4; --muted: #9b998f;
    --line: #34332e; --accent: #ff8a4c; --accent-soft: #3a2518; --route: #7c9cff;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5); color-scheme: dark;
    --btn-bg: #ff8a4c; --btn-fg: #1d1d1b; --btn-hover: #ffa06e; /* dark text on bright orange: 7.3:1 */
  }
}
:root[data-theme="dark"] {
  --btn-bg: #ff8a4c; --btn-fg: #1d1d1b; --btn-hover: #ffa06e;
  --bg: #141412; --panel: #1e1e1b; --panel-2: #262622; --text: #eceae4; --muted: #9b998f;
  --line: #34332e; --accent: #ff8a4c; --accent-soft: #3a2518; --route: #7c9cff;
  --shadow: 0 6px 24px rgba(0, 0, 0, .5); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.layout { display: grid; grid-template-columns: 1fr 380px; height: 100vh; }
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--panel-2); }

/* Status card over the map */
.status {
  position: absolute; top: 16px; left: 16px; z-index: 500; max-width: min(440px, calc(100% - 32px));
  background: var(--panel); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow);
}
.status .kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.status h1 { margin: 4px 0 2px; font-size: 26px; line-height: 1.15; letter-spacing: -.01em; }
.status p { margin: 4px 0 0; color: var(--muted); }
.status .progress { height: 6px; background: var(--line); border-radius: 3px; margin: 12px 0 6px; overflow: hidden; }
.status .progress span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.status .ends { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); }
.status .ends b { color: var(--text); font-weight: 600; }
.status .back { margin-top: 10px; }

/* Sidebar */
.side { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 8px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.side-head h2 { margin: 0; font-size: 18px; }
.icon-btn { border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 8px; width: 34px; height: 34px; display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { color: var(--text); }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.trips { list-style: none; margin: 0; padding: 4px 12px 12px; display: grid; gap: 8px; }
.trip { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); overflow: hidden; }
.trip.open { border-color: var(--accent); }
.trip-head {
  all: unset; box-sizing: border-box; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  width: 100%; padding: 12px 14px; cursor: pointer;
}
.trip-head:hover { background: var(--panel-2); }
.trip-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.trip-head h3 { margin: 0; font-size: 15px; line-height: 1.3; grid-column: 1; }
.trip-head .dest { margin: 0; color: var(--muted); font-size: 13px; grid-column: 1; }
.trip-head .meta { margin: 4px 0 0; font-size: 13px; grid-column: 1; }
.trip-head .count { grid-column: 2; grid-row: 1 / span 3; align-self: center; text-align: right; }
.count b { display: block; font-size: 22px; line-height: 1; font-variant-numeric: tabular-nums; }
.count small { color: var(--muted); font-size: 12px; }
.count.now b { color: var(--accent); font-size: 15px; }

.trip-body { border-top: 1px solid var(--line); padding: 6px 14px 14px; background: var(--panel-2); }
.day { margin: 12px 0 4px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.item { display: grid; grid-template-columns: 26px 1fr; gap: 8px; padding: 6px 0; }
.item { margin: 0 -8px; padding: 6px 8px; border-radius: 8px; transition: background .3s; }
.item.hl { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.item .ico { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); color: var(--route); }
.item .ico svg { width: 15px; height: 15px; }
.item h4 { margin: 0; font-size: 14px; font-weight: 600; }
.item .t { margin: 0; font-size: 13px; }
.item .n { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.trip-body .empty { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.trip-body .ext { display: inline-block; margin-top: 12px; font-size: 13px; color: var(--route); }

.past { margin: 4px 0 0; }
.past summary { padding: 12px 18px; cursor: pointer; color: var(--muted); font-weight: 600; }
.side-foot { margin-top: auto; padding: 12px 18px 16px; color: var(--muted); font-size: 12px; }
.side-foot .err { color: var(--accent); }
.muted { color: var(--muted); }

button.link { all: unset; color: var(--route); cursor: pointer; font-size: 13px; }
button.link:focus-visible { outline: 2px solid var(--route); }

/* Map markers */
.me { position: relative; width: 18px; height: 18px; }
.me::before, .me::after { content: ""; position: absolute; inset: 0; border-radius: 50%; }
.me::before { background: var(--accent); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.me::after { background: var(--accent); opacity: .35; animation: pulse 2s ease-out infinite; }
@keyframes pulse { from { transform: scale(1); opacity: .45; } to { transform: scale(3.4); opacity: 0; } }
.plane { color: var(--accent); filter: drop-shadow(0 1px 2px rgba(0,0,0,.45)); }
.plane svg { width: 34px; height: 34px; display: block; }
.apt { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; font: 600 11px/1.4 system-ui, sans-serif; white-space: nowrap; box-shadow: var(--shadow); }
.leaflet-container { font: inherit; }
path.leaflet-interactive:focus { outline: none; } /* the panel highlight is the feedback */
.leaflet-tile-pane { filter: var(--tile-filter, saturate(.75)); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --tile-filter: invert(1) hue-rotate(180deg) brightness(.9) saturate(.5); }
}
:root[data-theme="dark"] { --tile-filter: invert(1) hue-rotate(180deg) brightness(.9) saturate(.5); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 62vh auto; height: auto; }
  .side { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .side-head { position: static; }
  .status { top: 12px; left: 12px; right: 12px; max-width: none; padding: 12px 14px; }
  .status h1 { font-size: 21px; }
}

/* ------------------------------------------------------------ TV slideshow (tv.php, tv.js) */
/* Sized in vw so it looks the same on any TV. Content keeps clear of the edges TVs may crop, and
   --tv-shift-x/y move it a little on every slide change so nothing burns in. */
.tv, .tv body { overflow: hidden; cursor: none; }
.tv .layout { grid-template-columns: 1fr; height: 100vh; }
.tv .side, .tv .status .back { display: none !important; }
.tv .status { top: 4vw; left: 4vw; max-width: 44vw; padding: 1.8vw 2.2vw; border-radius: 1.2vw;
  transform: translate(var(--tv-shift-x, 0), var(--tv-shift-y, 0)); }
.tv .status .kicker { font-size: 1.05vw; }
.tv .status h1 { font-size: 3.2vw; margin: .4vw 0 .3vw; }
.tv .status p { font-size: 1.35vw; }
.tv .status .progress { height: .5vw; margin: 1.2vw 0 .7vw; border-radius: .25vw; }
.tv .status .ends { font-size: 1.15vw; }
.tv .me { width: 1.4vw; height: 1.4vw; }
.tv .plane svg { width: 2.8vw; height: 2.8vw; }
.tv .apt { font-size: .9vw; padding: .1vw .4vw; }
.tv .leaflet-control-attribution { font-size: .7vw; }

.tv-slides { position: fixed; inset: 0; z-index: 1500; pointer-events: none; } /* above Leaflet's controls (1000) */
.tv-slide { position: absolute; inset: 0; background: var(--bg); opacity: 0; transition: opacity .9s ease; }
.tv-slide.on { opacity: 1; }
.tv-inner { position: absolute; inset: 4.5vw 6vw 5vw; display: flex; flex-direction: column; justify-content: center;
  transform: translate(var(--tv-shift-x, 0), var(--tv-shift-y, 0)); transition: transform .9s ease; }
.tv-kicker { margin: 0; font-size: 1.2vw; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.tv-slide h1 { margin: .5vw 0 2.2vw; font-size: 3.4vw; line-height: 1.1; letter-spacing: -.01em; }

.tv-trips { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.1vw; }
.tv-trips li { display: flex; justify-content: space-between; align-items: center; gap: 2vw;
  background: var(--panel); border: 1px solid var(--line); border-radius: 1vw; padding: 1.3vw 1.8vw; }
.tv-trips h2 { margin: 0; font-size: 1.9vw; }
.tv-trips p { margin: .3vw 0 0; font-size: 1.3vw; color: var(--muted); }
.tv-count { text-align: right; flex: none; }
.tv-count b { display: block; font-size: 3vw; line-height: 1; font-variant-numeric: tabular-nums; }
.tv-count b.now { color: var(--accent); font-size: 2.2vw; }
.tv-count small { font-size: 1.1vw; color: var(--muted); }

.tv-kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1.2vw; }
.tv-kpis div { background: var(--panel); border: 1px solid var(--line); border-radius: 1vw; padding: 1.6vw 1.8vw; }
.tv-kpis .big, .tv-kpis div:last-child { grid-column: span 2; } /* two rows of five columns */
.tv-kpis b { display: block; font-size: 4vw; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tv-kpis .big b { font-size: 6vw; }
.tv-kpis span { font-size: 1.3vw; color: var(--muted); }

.tv-visited .tv-inner { inset: 0; }
.tv-map { position: absolute; inset: 0; background: var(--bg); }
.tv-caption { position: absolute; top: 4.5vw; left: 6vw; z-index: 500; background: var(--panel);
  padding: 1.6vw 2.2vw; border-radius: 1.2vw; box-shadow: var(--shadow); }
.tv-caption h1 { margin: .4vw 0 0; font-size: 2.8vw; }

.tv-rank { list-style: none; margin: 0; padding: 0; display: grid; gap: .9vw; }
.tv-rank li { display: grid; grid-template-columns: 3vw 1fr auto; align-items: center; gap: .3vw 1.2vw; font-size: 1.7vw; }
.tv-rank .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.tv-rank .l { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tv-rank .l small { color: var(--muted); font-size: 1.2vw; margin-left: .4vw; }
.tv-rank .v { color: var(--muted); font-size: 1.4vw; font-variant-numeric: tabular-nums; }
.tv-rank .bar { grid-column: 2 / -1; height: .45vw; background: var(--panel-2); border-radius: .25vw; overflow: hidden; }
.tv-rank .bar i { display: block; height: 100%; background: var(--accent); border-radius: .25vw; }
.tv-rank .flag { width: 2.2vw; height: 1.65vw; margin-right: .8vw; vertical-align: -.2vw; border-radius: .2vw;
  object-fit: cover; box-shadow: 0 0 0 1px var(--line); }

.tv-dots { position: fixed; left: 50%; bottom: 1.8vw; z-index: 1600; display: flex; gap: .6vw; transform: translateX(-50%); }
.tv-dots i { width: .6vw; height: .6vw; border-radius: 50%; background: var(--muted); opacity: .35; transition: opacity .6s, background .6s; }
.tv-dots i.on { background: var(--accent); opacity: 1; }
@media (prefers-reduced-motion: reduce) { .tv-slide, .tv-inner { transition: none; } }

/* ------------------------------------------------------------ sign-in, approval, devices */
.auth-page { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: 100%; max-width: 440px; padding: 28px 26px; box-shadow: var(--shadow); }
.auth .kicker { margin: 0 0 6px; font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.auth h1 { margin: 0 0 8px; font-size: 24px; }
.auth p { color: var(--muted); margin: 0 0 14px; }
.auth a { color: var(--route); }
.auth-form { display: grid; gap: 14px; margin-top: 18px; }
.auth-form .hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; } /* honeypot: off-screen, not display:none */
.auth-form label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
.auth-form input { font: inherit; font-weight: 400; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2); color: var(--text); }
.auth-form input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.auth button { font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 8px; border: 1px solid var(--btn-bg);
  background: var(--btn-bg); color: var(--btn-fg); cursor: pointer; }
.auth button:not(.secondary):hover { background: var(--btn-hover); border-color: var(--btn-hover); }
.auth button.secondary { background: transparent; color: var(--text); border-color: var(--line); }
.auth button:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.auth-error { color: var(--accent) !important; font-weight: 600; }
.auth-actions { display: flex; gap: 10px; margin: 18px 0 14px; }
.auth-actions button { flex: 1; }
.auth-details { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 16px 0 0; font-size: 14px; }
.auth-details dt { color: var(--muted); }
.auth-details dd { margin: 0; overflow-wrap: anywhere; }
.auth-small { font-size: 13px; }
.auth-wait { display: flex; align-items: center; gap: 10px; color: var(--text) !important; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
.dev-list { list-style: none; margin: 14px 0; padding: 0; display: grid; gap: 8px; }
.dev { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.dev button { padding: 6px 12px; font-size: 13px; }
.dev-actions { display: flex; gap: 6px; flex: none; }
.dev-pending { border-style: dashed; }
.dev-denied { opacity: .6; }

/* ------------------------------------------------------------ admin (admin/) */
.admin-page { min-height: 100%; }
.admin-page [hidden] { display: none !important; } /* button/layout styles must never un-hide things */
.admin-top { flex-wrap: wrap; row-gap: 8px; position: sticky; top: 0; z-index: 10; }
.admin-top h1 a { color: inherit; text-decoration: none; }
.admin-nav { flex-wrap: wrap; flex: 1; }
.admin-top-actions { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.admin-top-actions a.muted { text-decoration: none; }
.admin-main { max-width: 1000px; margin: 0 auto; padding: 20px 20px 48px; display: grid; gap: 16px; }
.admin-main h2 { margin: 4px 0 0; font-size: 22px; }
.admin-main h2 .muted { font-size: 16px; font-weight: 500; }
.admin-main .card h3 { margin: 0 0 8px; font-size: 16px; }
.admin-now { margin: 0; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); }
.kpis.admin-kpis { grid-template-columns: repeat(4, 1fr); } /* beats the stats page's .kpis */
.admin-kpis .kpi { grid-column: span 1; }
.admin-filters { display: flex; gap: 10px; flex-wrap: wrap; }
.admin-page input:not([type=checkbox]):not([type=radio]), .admin-page select, .admin-page textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); min-width: 0; }
.admin-filters input, .admin-filters select { flex: 1 1 220px; }
.admin-page input:focus, .admin-page select:focus, .admin-page textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
/* :where() keeps this general button look low-priority, so .primary and the Trips/Days-style toggles win. */
.btn, .admin-page :where(button:not(.link, .trip-head, .result, .choice, .reveal, [role=radio])) {
  font: inherit; font-weight: 600; font-size: 14px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer; text-decoration: none; display: inline-block; }
.btn.primary, .admin-page button.primary { background: var(--btn-bg); border-color: var(--btn-bg); color: var(--btn-fg); }
.btn.primary:hover, .admin-page button.primary:not(:disabled):hover { background: var(--btn-hover); border-color: var(--btn-hover); }
.admin-page button.secondary { background: transparent; }
.btn.big { width: 100%; padding: 14px 18px; font-size: 16px; }
.admin-page button:disabled { opacity: .5; cursor: default; }
.admin-page button.link { font-size: 14px; }
.admin-page button.link.danger { color: var(--accent); margin-left: 6px; }
.admin-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.admin-list li { padding: 9px 0; border-bottom: 1px solid var(--line); }
.admin-list li:last-child { border-bottom: 0; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .03em; padding: 1px 7px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); vertical-align: 1px; }
.tag-now { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag-restaurant { color: var(--route); }
.admin-trips { padding: 0; }
.admin-trips .trip-head h3 { font-size: 16px; }
.hotel .admin-list li { font-size: 14px; }
.notice { margin: 0; padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); }
.admin-main .auth-error ul { margin: 4px 0 0; padding-left: 18px; }

.visits-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.visits-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.visits-tools select { min-width: 220px; }
.visits-map { height: 420px; background: var(--panel-2); }
#city-map { height: 360px; }
.map-card { padding: 0; overflow: hidden; }
.visit-list .visit { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.visit-list .visit:hover .visit-main b { color: var(--accent); }
.visit-main { min-width: 0; }
.pill { flex: none; font: inherit; font-size: 12.5px; font-weight: 600; padding: 4px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); cursor: pointer; }
.pill.danger:hover, .pill.danger:focus-visible { color: #fff; background: var(--accent); border-color: var(--accent); outline: none; }
.visit-dialog { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto; padding: 22px 22px 18px;
  color: var(--text); box-shadow: var(--shadow); position: relative; }
.visit-dialog::backdrop { background: rgba(10, 10, 8, .55); }
.visit-dialog h3 { margin: 0 32px 14px 0; font-size: 18px; }
.dlg-close { position: absolute; top: 12px; right: 14px; }
.dlg-close button { font-size: 18px !important; color: var(--muted) !important; }
.dlg-actions { display: flex; align-items: center; gap: 10px; }

/* Places: breadcrumbs, filter chips, and a colour + letter per type */
:root { --t-hotel: #3b5bdb; --t-attraction: #b93d0c; --t-restaurant: #2b8a3e; --pin-fg: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --t-hotel: #7c9cff; --t-attraction: #ff8a4c; --t-restaurant: #69db7c; --pin-fg: #1d1d1b; } }
:root[data-theme="dark"] { --t-hotel: #7c9cff; --t-attraction: #ff8a4c; --t-restaurant: #69db7c; --pin-fg: #1d1d1b; }
.crumbs { font-size: 20px; font-weight: 700; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.crumbs a { color: var(--route); text-decoration: none; font-weight: 600; }
.crumbs a:hover { text-decoration: underline; }
.crumbs .sep { color: var(--muted); font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.chips button { font: inherit; font-size: 13.5px; padding: 5px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.chips button[aria-checked="true"] { background: var(--text); color: var(--panel); border-color: var(--text); }
.chips button[aria-checked="true"] .muted { color: inherit; opacity: .7; }
.chips button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pin { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font: 700 11px/1 system-ui, sans-serif;
  color: var(--pin-fg); background: var(--t-attraction); box-shadow: 0 0 0 2px var(--panel), 0 1px 4px rgba(0,0,0,.35); }
.pin.mini { width: 18px; height: 18px; font-size: 10px; flex: none; font-style: normal; }
.pin-hotel { background: var(--t-hotel); }
.pin-restaurant { background: var(--t-restaurant); }
.visit-list .visit { justify-content: flex-start; }
.visit-list .visit .visit-main { flex: 1; }
.visit-list .visit > .pin { align-self: flex-start; margin-top: 2px; }
.country-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px 16px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.country-grid a, .card h3 a { color: var(--route); text-decoration: none; font-weight: 600; }
.country-grid a:hover, .card h3 a:hover { text-decoration: underline; }
.dlg-type { margin-bottom: 14px; }
.dlg-city { display: grid; gap: 4px; margin-bottom: 14px; font-weight: 600; }
.dlg-city select { font-weight: 400; }
#outs.choices { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
#out-wrap { margin-top: 12px; }
#trips.picked .choice:not(.on) { display: none; }
.place-tabs { display: flex; gap: 4px; margin: 14px 0 4px; border-bottom: 1px solid var(--line); }
.place-tabs button { all: unset; cursor: pointer; padding: 8px 14px; margin-bottom: -1px; font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent; }
.place-tabs button:hover { color: var(--text); }
.place-tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.place-tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 6px 6px 0 0; }
.place-tabs .muted { font-weight: 400; font-size: 13px; }
#trips-view { margin-top: 14px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* Country page: one collapsible row per city */
.city-groups { padding: 4px 0; }
.city-group + .city-group { border-top: 1px solid var(--line); }
.group-head { display: flex; align-items: center; gap: 8px; padding-right: 14px; }
.group-toggle { all: unset; box-sizing: border-box; flex: 1; min-width: 0; display: flex; align-items: center; flex-wrap: wrap;
  gap: 4px 10px; padding: 12px 14px; cursor: pointer; border-radius: 8px; }
.group-toggle:hover { background: var(--panel-2); }
.group-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.group-toggle svg { flex: none; color: var(--muted); transform: rotate(-90deg); transition: transform .15s; }
.group-toggle[aria-expanded="true"] svg { transform: none; }
@media (prefers-reduced-motion: reduce) { .group-toggle svg { transition: none; } }
.group-counts { display: inline-flex; gap: 10px; margin-left: auto; }
.count-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.group-open { flex: none; color: var(--route); font-size: 13px; font-weight: 600; text-decoration: none; }
.group-open:hover { text-decoration: underline; }
.city-group > .visit-list { padding: 0 14px 8px 42px; }
.visit-actions { display: flex; align-items: center; gap: 6px; flex: none; align-self: flex-start; }
.visit-list .expand { all: unset; box-sizing: border-box; display: inline-flex; align-items: center; gap: 2px; cursor: pointer;
  min-width: 44px; height: 32px; padding: 0 6px 0 10px; border-radius: 999px; color: var(--muted); border: 1px solid transparent; }
.visit-list .expand:hover { color: var(--text); border-color: var(--line); }
.visit-list .expand:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.visit-list .expand svg { transition: transform .15s; }
.visit-list .expand[aria-expanded="true"] svg { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) { .visit-list .expand svg { transition: none; } }
.stays { list-style: none; margin: 6px 0 2px; padding: 0 0 0 12px; border-left: 2px solid var(--line);
  max-height: 260px; overflow-y: auto; font-size: 14px; color: var(--muted); }
.admin-list .stays li { padding: 2px 0; border: 0; }
#step-day, #out-wrap { scroll-margin-top: 12px; }

/* Admin Stats page: same as the public one, a little wider than other admin pages */
.admin-main:has(.admin-stats) { max-width: 1200px; }
.admin-stats { padding: 0; max-width: none; }
.map-legend { background: var(--panel); color: var(--text); padding: 6px 10px; border-radius: 8px; box-shadow: var(--shadow);
  font-size: 12px; display: flex; gap: 12px; }
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.map-legend .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 1.5px var(--panel); }
.map-legend .dot.logged { background: var(--route); }

/* Trips: list on the left, the selected trip in a reading pane on the right */
.admin-filters { display: flex; gap: 8px; align-items: center; flex: 1 1 380px; max-width: 520px; }
.admin-filters input[type=search] { flex: 1 1 auto; min-width: 0; width: auto; margin: 0; }
.admin-filters select { flex: 0 0 auto; width: auto; margin: 0; }
.reading { display: grid; grid-template-columns: minmax(260px, 360px) 1fr; gap: 16px; align-items: start; }
.trip-rows { list-style: none; margin: 0; padding: 6px; max-height: calc(100vh - 170px); overflow-y: auto; position: sticky; top: 78px; }
.trip-row { all: unset; box-sizing: border-box; display: grid; gap: 2px; width: 100%; padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.trip-row:hover { background: var(--panel-2); }
.trip-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.trip-row.on { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.trip-row b { font-size: 14.5px; }
.trip-row .muted { font-size: 12.5px; }
.reading-pane { min-height: 300px; }
.reading-pane h3 { margin: 0 0 2px; font-size: 20px; }
.reading-pane .ext { color: var(--route); font-size: 13px; }
.pane-back { display: none !important; }

.steps { margin: 0; padding-left: 20px; display: grid; gap: 14px; }
.steps label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.results { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.result, .choice { all: unset; box-sizing: border-box; display: block; width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); cursor: pointer; }
.result:hover, .choice:hover, .result:focus-visible, .choice:focus-visible { border-color: var(--accent); }
.choices { display: grid; gap: 6px; }
#days.choices { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.choice.on { border-color: var(--accent); background: var(--accent-soft); }
.day-choice { text-align: center; }
#step-day { display: grid; gap: 10px; }

.checkin { max-width: 520px; width: 100%; margin: 0 auto; display: grid; gap: 12px; }
.checkin .seg { justify-self: start; }
.checkin-search { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.checkin #confirm:not([hidden]) { display: grid; gap: 10px; }
.checkin #confirm label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }

.settings-import { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin: 16px 0; }
.settings-import h3 { margin: 0 0 2px; font-size: 16px; }
.settings-import p { margin: 0; }
.settings-form { display: grid; gap: 16px; }
.settings-form fieldset { margin: 0; display: grid; gap: 6px; }
.settings-form legend { float: left; width: 100%; padding: 0 0 6px; margin: 0 0 4px; font-weight: 700; font-size: 16px; border-bottom: 1px solid var(--line); }
.settings-form legend + * { clear: both; }
.settings-form label { display: grid; gap: 5px; font-weight: 600; font-size: 14px; margin-top: 8px; }
.settings-form label.check { display: flex; align-items: center; gap: 8px; }
.settings-form small { font-size: 12.5px; margin-top: -2px; }
.settings-form textarea { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.secret { display: flex; gap: 8px; align-items: center; }
.secret input { flex: 1; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.settings-actions { display: flex; gap: 10px; position: sticky; bottom: 0; padding: 12px 0; background: var(--bg); }

@media (max-width: 860px) {
  .admin-top { position: static; }
  .admin-nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .admin-nav a { flex: none; }
  .admin-main { padding: 14px 14px 40px; }
  .kpis.admin-kpis { grid-template-columns: repeat(2, 1fr); }
  /* Trips on a phone: the list, or the open trip (with a back button), one at a time */
  .reading { grid-template-columns: 1fr; }
  .trip-rows { position: static; max-height: none; }
  .reading .reading-pane { display: none; }
  .reading.has-trip .trip-rows { display: none; }
  .reading.has-trip .reading-pane { display: block; }
  .reading.has-trip .pane-back { display: inline-block !important; margin-bottom: 10px; }
  .visits-tools { width: 100%; }
  .visits-tools select { flex: 1; min-width: 0; }
  .visits-map { height: 320px; }
  #city-map { height: 280px; }
}

/* ------------------------------------------------------------ stats page */
/* Same nav as the stats page top bar, sized to match its height */
.side-top { display: flex; justify-content: flex-end; padding: 12px 18px; border-bottom: 1px solid var(--line); }

.stats-page { min-height: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 24px; border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar h1 { margin: 0; font-size: 20px; }
.nav { display: flex; gap: 4px; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 8px; font-size: 14px; }
.nav a:hover { color: var(--text); background: var(--panel-2); }
.nav a[aria-current="page"] { color: var(--text); background: var(--panel-2); font-weight: 600; }

.stats { max-width: 1200px; margin: 0 auto; padding: 20px 24px 32px; display: grid; gap: 16px; }
/* One scrolling row of years; "All time" stays pinned at the left. */
.periods { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; padding-bottom: 4px;
  mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); }
.periods button { flex: none; }
.periods button:first-child { position: sticky; left: 0; z-index: 1; box-shadow: 6px 0 8px -2px var(--bg); }
.periods button { border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 14px; cursor: pointer; }
.periods button:hover { color: var(--text); }
.periods button[aria-selected="true"] { background: var(--text); border-color: var(--text); color: var(--panel); }

/* Desktop: map on the left, stats in a two-column panel beside it. Trips is the wide headline tile. */
.overview { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: stretch; }
.overview .map-card { order: -1; display: flex; }
.overview #stats-map { flex: 1; height: auto; min-height: 460px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-content: start; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.kpi-trips { grid-column: 1 / -1; }
.kpi b { display: block; font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi-trips b { font-size: 40px; }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi small { display: block; color: var(--muted); font-size: 12px; }
a.kpi { color: inherit; text-decoration: none; position: relative; }
a.kpi::after { content: "↓"; position: absolute; top: 10px; right: 12px; color: var(--muted); font-size: 13px; }
a.kpi:hover { border-color: var(--accent); }
a.kpi:hover::after { color: var(--accent); }
a.kpi:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: 0 0 0 3px transparent; } }
.lists .card { scroll-margin-top: 16px; }

@media (max-width: 1000px) {
  .overview { grid-template-columns: 1fr; }
  .overview .map-card { order: 0; }
  .overview #stats-map { min-height: 380px; }
  .kpis { grid-template-columns: repeat(6, 1fr); }
  .kpi { grid-column: span 2; }
  .kpi-trips, .kpi.time { grid-column: span 3; }
}

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; }
.card h2 { margin: 0 0 10px; font-size: 15px; }
.map-card { padding: 0; overflow: hidden; }
#stats-map { height: 440px; background: var(--panel-2); }

.measure { display: flex; align-items: center; gap: 10px; font-size: 14px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: var(--panel); }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 14px; padding: 5px 14px;
  border-radius: 999px; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--text); color: var(--panel); }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.lists { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-items: start; }
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rank li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 6px 8px; margin: 0 -8px; border-radius: 8px; }
.rank li[data-key] { cursor: pointer; }
.rank li[data-key]:hover, .rank li[data-key]:focus-visible { background: var(--panel-2); outline: none; }
.rank .lbl { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .val { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.rank .bar { grid-column: 1 / -1; height: 4px; background: var(--panel-2); border-radius: 2px; overflow: hidden; }
.rank .bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
#airlines li.open { background: var(--panel-2); }
.flights { grid-column: 1 / -1; list-style: none; margin: 8px 0 2px; padding: 0; max-height: 320px; overflow-y: auto;
  border-top: 1px solid var(--line); cursor: auto; }
.flights li { display: grid; grid-template-columns: 96px 1fr; gap: 0 10px; padding: 6px 0; margin: 0; border-bottom: 1px solid var(--line); font-size: 13px; border-radius: 0; }
.flights .fd { color: var(--muted); font-variant-numeric: tabular-nums; grid-row: span 2; }
.flights .fr b { font-weight: 600; margin-right: 4px; }
.flights .ft { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flag { width: 20px; height: 15px; margin-right: 8px; vertical-align: -2px; border-radius: 2px; object-fit: cover;
  box-shadow: 0 0 0 1px var(--line); } /* the hairline keeps white-edged flags (Japan, Canada) visible */
.cc { display: inline-block; min-width: 26px; margin-right: 6px; padding: 0 4px; border: 1px solid var(--line); border-radius: 4px; font-size: 11px; font-weight: 600; text-align: center; color: var(--muted); }

.table-wrap { overflow-x: auto; }
.years { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.years th, .years td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.years th:first-child { text-align: left; }
.years thead th { color: var(--muted); font-weight: 600; font-size: 13px; }
.years tr.total th, .years tr.total td { font-weight: 700; border-bottom: 0; }
.years tr.sel { background: var(--accent-soft); }
.foot { font-size: 12px; margin: 0; }
.err { color: var(--accent); }

@media (max-width: 860px) {
  .topbar { padding: 12px 16px; }
  .stats { padding: 16px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpis .kpi, .kpis .kpi.time { grid-column: span 1; }
  .kpis .kpi-trips { grid-column: 1 / -1; }
  .lists { grid-template-columns: 1fr; }
  #stats-map { height: 320px; }
}

/* Admin: Import history */
.import { max-width: 760px; }
.import-steps { padding-left: 22px; display: grid; gap: 10px; }
.import-steps li::marker { font-weight: 700; }
.import kbd { font: 600 12.5px/1 system-ui, sans-serif; padding: 2px 6px; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; background: var(--panel); }
.script-box { margin: 6px 0; }
.script-box details { margin-top: 8px; }
.script-box summary { cursor: pointer; color: var(--route); font-size: 13px; }
.script-box pre { max-height: 280px; overflow: auto; padding: 12px; font-size: 12px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; }
.import-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.import-form input[type=file] { width: auto; flex: 1 1 260px; }
