:root {
  --bg: #fff;
  --fg: #1d2330;
  --muted: #5f6b7a;
  --surface: #f3f5f8;
  --accent: #1f6feb;
  --accent-dark: #1858c0;
  --danger: #c62828;
  --success-bg: #e7f6ec;
  --error-bg: #fdecec;
  --warning-bg: #fff6dd;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: .5rem 0 1rem; }
h2 { font-size: 1.25rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
.wrap { max-width: 1150px; margin: 0 auto; padding: 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mono { font-family: ui-monospace, monospace; font-size: .85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.num { text-align: right; white-space: nowrap; }

/* Header / navigation */
.site-header { background: #17202f; color: #fff; }
.header-inner { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; min-height: 3.25rem; }
.brand { display: inline-flex; align-items: center; gap: .55rem; color: #fff; font-weight: 700; text-decoration: none; font-size: 1.15rem; margin-right: auto; }
.brand img { display: block; width: 2rem; height: 2rem; }
.main-nav { display: flex; align-items: center; flex-wrap: wrap; gap: .25rem 1rem; }
.main-nav a, .main-nav .link { color: #dfe6f0; text-decoration: none; font-size: .95rem; }
.main-nav a:hover, .main-nav .link:hover { color: #fff; text-decoration: underline; }
.nav-sep { width: 1px; height: 1.2rem; background: #4a5568; }
.lang-switch { display: inline-flex; gap: .4rem; font-size: .85rem; }
.lang-switch strong { color: #fff; }
.nav-toggle { display: none; background: transparent; border: 0; color: #fff; }
.nav-toggle:hover { background: rgba(255,255,255,.1); }
@media (max-width: 760px) {
  .nav-toggle { display: inline-block; }
  .main-nav { display: none; width: 100%; flex-direction: column; align-items: flex-start; padding: .5rem 0 1rem; }
  .main-nav.open { display: flex; }
  .nav-sep { width: 100%; height: 1px; }
}
.site-footer { padding: 2rem 1rem; color: var(--muted); }
.site-footer a { color: inherit; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem 1rem;
  position: fixed;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  max-width: none;
  padding: .65rem max(1rem, calc((100% - 1150px) / 2 + 1rem));
  background: var(--bg);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, .12);
}
.admin-toolbar a, .admin-toolbar .link { color: var(--muted); text-decoration: none; }
.admin-toolbar a:hover, .admin-toolbar .link:hover { color: var(--fg); text-decoration: underline; }
.admin-session main { padding-bottom: 8rem; }
main { padding-top: 3rem; padding-bottom: 1.5rem; }

/* Cards, flash */
.card { border: 0; padding: 1rem 0; margin: 0 0 1.75rem; }
.card.narrow { max-width: 460px; margin-left: auto; margin-right: auto; }
fieldset.card { min-width: 0; }
fieldset.card legend { font-weight: 600; padding: 0; }
.danger-zone h2 { color: var(--danger); }
.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.flash-success { background: var(--success-bg); }
.flash-error { background: var(--error-bg); }
.flash-warning, .notice { background: var(--warning-bg); border-radius: var(--radius); padding: .6rem .9rem; }
.badge { display: inline-block; font-size: .75rem; padding: 0 .45rem; border-radius: 999px; background: #e8ecf1; color: var(--muted); vertical-align: middle; font-weight: 500; }
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.stats-overview { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: .75rem; margin: 1.5rem 0; }
.stats-metric { display: flex; flex-direction: column; gap: .25rem; padding: .85rem 1rem; border-radius: var(--radius); background: var(--surface); }
.stats-metric span { color: var(--muted); font-size: .875rem; }
.stats-metric strong { font-size: 1.6rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stats-highlights { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .15rem 1.5rem; }
.stats-highlights p { margin: .25rem 0; }

/* Forms */
.form label { display: block; margin-bottom: .8rem; font-weight: 500; }
.form label small { display: block; font-weight: 400; color: var(--muted); }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  display: block; width: 100%; padding: .5rem .6rem; margin-top: .25rem; font: inherit;
  border: 0; border-radius: 6px; background: var(--surface); color: inherit;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.check, .form label.check { display: inline-flex; align-items: center; gap: .4rem; font-weight: 400; margin-right: 1rem; }
.checks { display: flex; flex-wrap: wrap; gap: .3rem; }
button, .button {
  display: inline-block; font: inherit; font-weight: 500; padding: .5rem 1rem; border-radius: 6px; cursor: pointer;
  border: 0; background: var(--accent); color: #fff; text-decoration: none; line-height: 1.3;
}
button:hover, .button:hover { background: var(--accent-dark); }
button.secondary, .button.secondary { background: var(--surface); color: var(--accent); }
button.secondary:hover, .button.secondary:hover { background: #eef4ff; }
button.danger { background: var(--danger); }
button.link { background: none; border: none; padding: 0; color: var(--accent); font-weight: 400; text-decoration: underline; }
.danger-text, button.link.danger-text { color: var(--danger); }
form.inline { display: inline; }
.form-actions { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; }
.field-error { color: var(--danger); font-size: .875rem; display: block; margin-top: .2rem; font-weight: 400; }
.grid-2, .grid-3 { display: grid; gap: 0 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* Trip form */
.trip-form [hidden] { display: none !important; }
.period { padding: .75rem 0; margin-bottom: .75rem; }
.row-actions { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.chips { list-style: none; padding: 0; margin: 0 0 .6rem; display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { display: inline-flex; align-items: center; gap: .5rem; padding: .25rem .6rem; border-radius: 999px; background: var(--surface); }
.chip label.check { margin: 0; font-size: .85rem; }
.chip-name { font-weight: 500; }
.chip-remove { text-decoration: none !important; color: var(--muted) !important; }
.transport { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 .75rem; align-items: end; padding: .5rem 0; margin-bottom: 1rem; }
.transport label { margin-bottom: .5rem; }
.transport:not([data-mode=plane]) .plane-only { display: none; }
@media (max-width: 760px) { .transport { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
input[data-iata] { text-transform: none; }

/* Tables */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; }
table.simple th, table.simple td { text-align: left; padding: .6rem; vertical-align: top; }
table.simple th { color: var(--muted); font-size: .85rem; }
table.simple tbody tr:nth-child(even) { background: #fafbfc; }
table.simple td.num, table.simple th.num { text-align: right; }
.sort-button { padding: 0; border: 0; background: transparent; color: inherit; font: inherit; font-weight: 600; text-align: inherit; cursor: pointer; }
.sort-button:hover { background: transparent; color: var(--accent); }
.sort-button::after { content: " ⇅"; color: #9aa3af; font-size: .8em; }
th[aria-sort=ascending] .sort-button::after { content: " ↑"; color: var(--accent); }
th[aria-sort=descending] .sort-button::after { content: " ↓"; color: var(--accent); }
.table-filter { max-width: 320px; margin-bottom: .75rem; }
.history { font-size: .95rem; }
.history th, .history td { padding: .15rem .55rem; vertical-align: top; text-align: left; }
.history thead th { font-size: .85rem; color: var(--muted); padding-bottom: .8rem; }
.history .year-row th { font-size: 1rem; padding: 1.25rem .55rem .5rem; }
.history-public .year-cell { color: var(--muted); text-align: center; vertical-align: top; font-size: 1rem; padding-top: .85rem; }
.history tr.trip-first td { padding-top: .85rem; }
.history td.dates { white-space: nowrap; }
.history td.col-transport { text-align: center; vertical-align: middle; line-height: 0; }
.history td.col-transport .transport-icon { display: block; margin: 0 auto; }
.transport-icon { width: 1.25rem; height: 1.25rem; color: #3d4654; vertical-align: -.25em; flex-shrink: 0; }
.history td.num { text-align: right; }
.history td.territory { white-space: nowrap; }
.history .period-dates { display: block; }
.history-public td.dates { min-width: 11rem; }
.history tr.is-hidden td { color: var(--muted); }
.history td.actions { white-space: nowrap; font-size: .875rem; }
.history-actions { display: flex; gap: 1rem; align-items: center; }
.history-actions a, .history-actions button.link { display: inline-flex; gap: .3rem; align-items: center; text-decoration: none; line-height: inherit; }
.action-icon { width: 1rem; height: 1rem; flex-shrink: 0; }
.legend { font-size: .85rem; margin-top: .5rem; }
.flag { vertical-align: -2px; border-radius: 2px; }

/* Maps */
.map { position: relative; height: 420px; border-radius: var(--radius); background: #e5e9ee; }
.map-small { height: 260px; margin: .5rem 0; }
@media (max-width: 640px) { .map { height: 320px; } .map-small { height: 220px; } }
.marker-stayed { background: #1f6feb; }
#profile-map .marker-cluster div { width: 20px; height: 20px; color: #fff; }
#profile-map .marker-cluster span { line-height: 20px; }
.profile-fullscreen-control button {
  display: block; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 2px;
  background: #fff; color: #000; font-size: 22px; line-height: 30px;
}
.profile-fullscreen-control button:hover { background: #f4f4f4; }
.map.map-fullscreen { position: fixed; inset: 0; width: 100%; height: 100%; margin: 0; border: 0; border-radius: 0; z-index: 10000; }
body.map-fullscreen-open { overflow: hidden; }

/* Profile */
.profile-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: .25rem 1rem; margin: 2rem 0 1rem; }
.profile-head h1, .profile-head p { margin: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: .25rem; margin: .75rem 0 1rem; }
.tabs a, .tabs button { padding: .35rem .8rem; border-radius: 999px; background: #e8ecf1; color: var(--fg); text-decoration: none; border: 0; font-weight: 500; }
.tabs a:hover, .tabs button:hover { background: #dbe2ea; }
.tabs button[aria-selected=true] { background: var(--accent); color: #fff; }
section[id] { scroll-margin-top: 1rem; }
.stat-row { display: grid; grid-template-columns: 1.75rem minmax(0, 1fr); gap: .75rem; margin: 1.25rem 0 1.75rem; }
.stat-row > .stat-icon { width: 1.75rem; height: 1.75rem; margin-top: .05rem; }
.stat-summary { font-size: 1.1rem; font-weight: 400; margin: 0 0 .6rem; line-height: 1.6; }
.stat-summary strong { font-size: 1.35rem; }
h3.stat-summary { font-weight: 600; }
.stat-line { display: flex; flex-wrap: wrap; gap: .35rem 2rem; margin: 0; font-size: .9rem; }
.stat-item { white-space: nowrap; }

/* Public page colour theme (custom properties set inline on .profile-page) */
.profile-page h1 { color: var(--fg); }
.profile-page .profile-title-name { color: var(--theme-text); }
.profile-page .profile-title-origin { color: var(--fg); font-size: .5em; font-weight: 400; }
.profile-page .stat-icon { color: var(--theme-text); }
.profile-page .territory-badge:not(.is-disabled) .continent-icon { color: rgb(var(--marker-medium)); }
.profile-page .marker-cluster-small { background-color: transparent; }
.profile-page .marker-cluster-small div { background-color: rgb(var(--marker-small) / var(--marker-alpha)); }
.profile-page .marker-cluster-medium { background-color: rgb(var(--marker-medium) / .2); }
.profile-page .marker-cluster-medium div { background-color: rgb(var(--marker-medium) / var(--marker-alpha)); }
.profile-page .marker-cluster-large { background-color: rgb(var(--marker-large) / .2); }
.profile-page .marker-cluster-large div { background-color: rgb(var(--marker-large) / var(--marker-alpha)); }
.theme-picker { border: 0; padding: 0; margin: 0 0 1rem; display: flex; flex-wrap: wrap; gap: .4rem .5rem; }
.theme-picker legend { font-weight: 500; padding: 0; margin-bottom: .4rem; }
.theme-picker small { flex-basis: 100%; }
.form label.theme-swatch { display: inline-flex; align-items: center; gap: .4rem; margin: 0; padding: .3rem .7rem .3rem .4rem; border-radius: 999px; background: var(--surface); font-weight: 400; cursor: pointer; }
.theme-swatch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.theme-swatch-dot { width: 1.1rem; height: 1.1rem; border-radius: 50%; background: var(--swatch); }
.theme-swatch:has(input:checked) { box-shadow: 0 0 0 2px var(--swatch); background: #fff; font-weight: 600; }
.theme-swatch:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.stat-icon { width: 1.25rem; height: 1.25rem; color: var(--accent); flex-shrink: 0; vertical-align: -.2em; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: .1rem 0; }
ul.columns { columns: 2 160px; column-gap: 1rem; }
ul.columns li { break-inside: avoid; }
.bars li { display: grid; grid-template-columns: 6.5rem 1fr 2.5rem; align-items: center; gap: .5rem; }
.bar { background: #e8ecf1; border-radius: 4px; height: .7rem; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }
.country-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.country-badges { display: flex; flex-wrap: wrap; gap: .45rem; }
.territory-badge { position: relative; border-radius: 999px; }
.territory-badge-label { display: flex; align-items: center; gap: .35rem; border-radius: 999px; background: var(--surface); padding: .3rem .65rem; font-size: .9rem; cursor: default; }
.territory-badge:hover .territory-badge-label, .territory-badge:focus .territory-badge-label { background: #e8ecf1; }
.territory-badge img.flag { width: 20px; height: 15px; }
.territory-badge .flag-placeholder { width: 20px; height: 15px; font-size: .55rem; border-radius: 2px; }
.territory-badge-count { color: var(--muted); font-size: .75rem; }
.continent-icon { width: 1.15rem; height: 1.15rem; color: #3d4654; flex-shrink: 0; }
.territory-badge.is-disabled { opacity: .3; }
.territory-badge:hover .territory-badge-details, .territory-badge:focus .territory-badge-details { display: block; }
.territory-badge-details { display: none; position: absolute; z-index: 2; top: calc(100% + .25rem); left: 0; width: max-content; max-width: min(18rem, 85vw); padding: .45rem .65rem; border-radius: 6px; background: #fff; box-shadow: 0 4px 16px rgba(0,0,0,.08); font-size: .85rem; }
.country-card { padding: .75rem; text-align: center; }
.country-card h3 { margin: .4rem 0 .2rem; font-size: .95rem; }
.country-card p { margin: 0; font-size: .85rem; color: var(--muted); }
.country-flag img.flag { width: 64px; height: 48px; }
.flag-placeholder { display: inline-flex; width: 64px; height: 48px; align-items: center; justify-content: center; background: #e8ecf1; border-radius: 4px; font-weight: 700; color: var(--muted); }

/* Trip detail */
.details { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.period-view { padding: .8rem 0; }
.place-list { margin: .3rem 0 0; }
.note { white-space: pre-wrap; }

/* Place picker dialog */
dialog.picker { width: min(640px, 96vw); max-height: 92vh; overflow: auto; border: 0; border-radius: var(--radius); padding: 1rem 1.25rem; }
dialog.picker::backdrop { background: rgba(15, 23, 42, .45); }
.picker-head { display: flex; justify-content: space-between; align-items: center; }
.picker-head h2 { margin: 0; }
.picker-context { display: block; margin: .75rem 0; font-weight: 500; }
.picker-close { font-size: 1.2rem; text-decoration: none !important; color: var(--muted) !important; }
.picker-row { display: flex; gap: .5rem; }
.picker-row input { margin-top: 0 !important; }
.picker-results { list-style: none; padding: 0; margin: .5rem 0; max-height: 260px; overflow: auto; }
.picker-results li button { display: block; width: 100%; text-align: left; background: var(--surface); color: var(--fg); margin-bottom: .3rem; font-weight: 400; }
.picker-results li button:hover, .picker-results li button.selected { background: #eef4ff; color: var(--accent); }
.picker-results small { color: var(--muted); display: block; }
.picker-error { color: var(--danger); margin: .5rem 0 0; }
.attribution { margin-top: .75rem; }
.birth-place { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin: .5rem 0; }
.help-tip-wrap { position: relative; display: inline-block; }
button.help-tip { width: 1.55rem; height: 1.55rem; padding: 0; border-radius: 50%; font-size: .9rem; line-height: 1.3; }
.help-tip-text { display: none; position: absolute; z-index: 5; top: calc(100% + .4rem); left: 0; width: min(22rem, 80vw); padding: .6rem .75rem; border-radius: 6px; background: #17202f; color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.2); font-size: .85rem; font-weight: 400; }
.help-tip:hover + .help-tip-text, .help-tip:focus + .help-tip-text, .help-tip.is-open + .help-tip-text { display: block; }

@media print {
  .site-header, .site-footer, .tabs, .map { display: none; }
  .card { border: 0; padding: 0; }
}
