/* ====================================================================
   RidesMap – light theme
   Tokens: paper #FBFAF7 / surface #FFFFFF / ink #22272B / muted #5C646C
           hairline #E6E3DC / route red #D7263D / strava orange #FC4C02
   Type:   Archivo (slightly narrow) for everything; weight does the work.
   ==================================================================== */

/* The HTML `hidden` attribute means "not displayed", but any element with an
   explicit `display` rule (.field uses display:grid, .seg display:flex, …)
   overrides it, so toggling el.hidden=true would have no visible effect.
   This global rule makes `hidden` authoritative again everywhere. */
[hidden] { display: none !important; }

:root {
  --paper: #FBFAF7;
  --surface: #FFFFFF;
  --ink: #22272B;
  --muted: #5C646C;
  --hairline: #E6E3DC;
  --route: #D7263D;
  --strava: #FC4C02;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(34, 39, 43, .06), 0 8px 24px rgba(34, 39, 43, .09);
  --font: 'Archivo', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  color: var(--ink);
  background: var(--paper);
}

/* ------------------------------ auth state -------------------------- */

body:not(.authenticated) .auth-only { display: none !important; }
body.authenticated .anon-only { display: none !important; }
/* when we show cached data but the live connection is gone, keep the map and
   controls visible (authenticated) but also surface the Connect button and
   hide actions that need a live connection */
body.authenticated.disconnected .anon-only { display: revert !important; }
body.authenticated.disconnected .needs-connection { display: none !important; }

/* ------------------------------- topbar ----------------------------- */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--hairline);
  z-index: 1100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.brand-mark { width: 24px; height: 24px; color: var(--route); }

.brand-name {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .02em;
}

.searchbox {
  position: relative;
  flex: 0 1 340px;
  display: flex;
  align-items: center;
}

.searchbox input {
  width: 100%;
  height: 34px;
  padding: 0 64px 0 12px;
  border: 1px solid var(--hairline);
  border-radius: 17px;
  background: var(--paper);
  font: inherit;
  color: var(--ink);
}

.searchbox input:focus {
  outline: 2px solid var(--route);
  outline-offset: -1px;
  background: var(--surface);
}

.searchbox .count {
  position: absolute;
  right: 12px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  margin-right: 4px;
  white-space: nowrap;
}

.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3E7C59;
}

.status.busy .dot {
  background: var(--strava);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .status.busy .dot { animation: none; } .travel-activities { transition: none; } }

/* ------------------------------ buttons ----------------------------- */

.btn {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  font-size: 13.5px;
  padding: 0 14px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.btn:hover { border-color: var(--ink); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #000; }

.mini {
  appearance: none;
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  padding: 0 2px;
}
.mini:hover { color: var(--ink); }

.link-button {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  font-size: 12.5px;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}
.link-button:hover { color: var(--ink); }

.connect-button img { height: 40px; display: block; }

/* ------------------------------- stage ------------------------------ */

.stage { position: fixed; inset: 56px 0 0 0; }
#map { position: absolute; inset: 0; background: var(--paper); }

.powered-by {
  position: absolute;
  left: 12px;
  bottom: 10px;
  height: 26px;
  z-index: 1000;
  opacity: .9;
}

/* ----------------------------- welcome card ------------------------- */

.welcome {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, calc(100% - 32px));
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 30px;
  text-align: center;
  z-index: 1000;
}

.welcome h1 {
  margin: 0 0 10px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.01em;
}

.welcome p { color: var(--muted); line-height: 1.5; margin: 0 0 18px; }
.welcome .connect-button { display: inline-block; }
.welcome-note { font-size: 12.5px; margin-top: 16px; }

/* ------------------------------- panel ------------------------------ */

.panel {
  position: absolute;
  top: 14px;
  left: 12px;
  width: 252px;
  max-height: calc(100% - 70px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1000;
}

.panel details { border-bottom: 1px solid var(--hairline); }
.panel details:last-of-type { border-bottom: none; }

.panel summary {
  list-style: none;
  cursor: pointer;
  padding: 11px 14px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  user-select: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel summary::-webkit-details-marker { display: none; }
.panel summary::after { content: '+'; margin-left: auto; color: var(--hairline); }
.panel details[open] summary::after { content: '\2013'; }
/* when a reset button sits in the summary it takes the right slot, and the
   toggle marker follows it with a small gap */
.panel summary .summary-reset { margin-left: auto; }
.panel summary:has(.summary-reset)::after { margin-left: 10px; }

.panel-section { padding: 2px 14px 14px; display: grid; gap: 12px; }

.panel-footer {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--hairline);
}

/* ------------------------------- fields ----------------------------- */

.field { display: grid; gap: 5px; font-size: 13.5px; }
.field > span { color: var(--muted); display: flex; justify-content: space-between; }
.field em { font-style: normal; color: var(--ink); font-variant-numeric: tabular-nums; }
.field.inline { grid-template-columns: auto 1fr; align-items: center; gap: 10px; margin-bottom: 8px; }

.field select,
.field input[type="text"],
.field input[type="email"],
.field textarea {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--hairline);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
}

.field input[type="color"] {
  width: 44px;
  height: 30px;
  border: 1px solid var(--hairline);
  border-radius: 7px;
  background: var(--surface);
  padding: 2px;
  cursor: pointer;
}

.field-block { display: grid; gap: 8px; }
.field-title {
  font-size: 13.5px;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.field-title em { font-style: normal; color: var(--ink); margin-left: auto; font-variant-numeric: tabular-nums; }

/* range inputs */
input[type="range"] {
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--hairline);
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  margin-top: -6.5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--route);
}
input[type="range"]::-moz-range-track {
  height: 3px;
  background: var(--hairline);
  border-radius: 2px;
}
input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--route);
}

/* dual year slider: two stacked range inputs */
.dual-slider { position: relative; height: 22px; }
.dual-slider input {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.dual-slider input::-webkit-slider-thumb { pointer-events: auto; }
.dual-slider input::-moz-range-thumb { pointer-events: auto; }
.dual-slider input:nth-child(2)::-webkit-slider-runnable-track { background: transparent; }
.dual-slider input:nth-child(2)::-moz-range-track { background: transparent; }

/* type filter */
.type-filter { display: grid; gap: 2px; max-height: 220px; overflow-y: auto; }

.type-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  padding: 3px 2px;
  cursor: pointer;
  border-radius: 6px;
}
.type-check:hover { background: var(--paper); }
.type-check input { accent-color: var(--route); }

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
  display: inline-block;
}

.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }

/* ------------------------------ dialogs ----------------------------- */

dialog {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px 24px;
  width: min(480px, calc(100% - 32px));
  background: var(--surface);
  color: var(--ink);
}

dialog.wide { width: min(820px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(34, 39, 43, .35); }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.dialog-head h2 { margin: 0; font-size: 19px; font-weight: 700; }

.dialog-close {
  appearance: none;
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
}
.dialog-close:hover { color: var(--ink); }

dialog p { line-height: 1.55; color: var(--ink); }
dialog hr { border: none; border-top: 1px solid var(--hairline); margin: 18px 0; }
dialog h3 { font-size: 15px; margin: 0 0 10px; }
.fine-print { font-size: 12px; color: var(--muted); }

/* tabs */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 14px;
}

.tab-button {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab-button.active { color: var(--ink); border-bottom-color: var(--route); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.chart-holder { position: relative; height: 380px; }

/* summary table */
.summary-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.summary-table th, .summary-table td { padding: 7px 10px; text-align: right; }
.summary-table th:first-child, .summary-table td:first-child { text-align: left; }
.summary-table thead th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 1px solid var(--hairline);
}
.summary-table tbody tr { border-bottom: 1px solid var(--paper); }
.summary-table tr.total { font-weight: 600; border-top: 2px solid var(--hairline); }

/* contact */
.hp { position: absolute; left: -9999px; }
.form-row { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.contact-messages { font-size: 13px; }
.contact-messages.ok { color: #3E7C59; }
.contact-messages.fail { color: var(--route); }

/* ----------------------------- leaflet bits ------------------------- */

.leaflet-container { font-family: var(--font); }

.activity-tooltip {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--ink);
  padding: 9px 11px;
  font-family: var(--font);
}
.activity-tooltip::before { display: none; }

.tt-title { font-weight: 600; font-size: 13.5px; max-width: 240px; white-space: normal; }
.tt-type { color: var(--muted); font-size: 12px; margin: 1px 0 5px; }
.tt-table { font-size: 12px; border-spacing: 0; }
.tt-table td { padding: 1px 0; }
.tt-table td:first-child { color: var(--muted); padding-right: 12px; }
.tt-table td:last-child { font-variant-numeric: tabular-nums; }
.tt-hint { margin-top: 5px; font-size: 11px; color: var(--strava); }

/* ----------------------------- responsive --------------------------- */

@media (max-width: 760px) {
  .topbar { gap: 8px; flex-wrap: nowrap; }
  .brand { display: none; }
  .status { display: none; }
  .searchbox { flex: 1 1 auto; }
  .panel { width: 230px; top: 10px; left: 8px; }
  dialog.wide { width: calc(100% - 16px); padding: 16px; }
  .chart-holder { height: 300px; }
}

/* small phones: hide the search bar and the Draw-route button to free header space */
@media (max-width: 560px) {
  .searchbox { display: none !important; }
  #btn-draw { display: none !important; }
}

:focus-visible { outline: 2px solid var(--route); outline-offset: 2px; }

/* ---------------------------- load overlay -------------------------- */

.load-overlay {
  position: absolute;
  inset: 0;
  z-index: 1050;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(251, 250, 247, .45);
  backdrop-filter: blur(4px) grayscale(.7);
  -webkit-backdrop-filter: blur(4px) grayscale(.7);
}

.load-overlay[hidden] { display: none; }

.load-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 36px;
  text-align: center;
  min-width: 240px;
}

.load-card .spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 3px solid var(--hairline);
  border-top-color: var(--route);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .load-card .spinner { animation-duration: 2.5s; }
}

#load-text { font-weight: 600; font-size: 15px; }
.load-sub {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------ panel note --------------------------- */

.panel-note {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

/* ----------------------------- tab filters --------------------------- */

.tab-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;        /* controls sit on a common baseline */
  gap: 10px 16px;               /* row-gap smaller than column-gap */
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--hairline); /* separates filters from chart */
}

/* each labelled control: stack label above control, capped width so nothing
   stretches arbitrarily wide and everything aligns into a calm grid */
.tab-filters .field.inline {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  margin-bottom: 0;
  min-width: 0;
  flex: 0 1 auto;
}
.tab-filters .field.inline > span {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
/* selects + text inputs get a hard width cap (variable-length content) */
.tab-filters .field.inline select,
.tab-filters .field.inline input[type="text"] {
  width: 100%;
  max-width: 180px;
}
/* segmented controls keep their natural width (fixed, known options) but
   never wrap their buttons onto a second line */
.tab-filters .seg { flex-wrap: nowrap; }
.tab-filters .cum-year-field { width: 200px; max-width: 200px; }
.tab-filters .cum-slider { width: 100%; }

/* checkbox fields stay inline (label beside the box) */
.tab-filters .field.inline.checkbox {
  flex-direction: row;
  align-items: center;
}

/* push the action buttons block (Show on map, Reset) to the far right.
   Whichever action button comes first gets the auto margin; a Reset that
   follows a Show-on-map sits right next to it. */
.tab-filters .map-apply,
.tab-filters .filter-reset { align-self: flex-end; }
.tab-filters .map-apply { margin-left: auto; }
.tab-filters .filter-reset { margin-left: 0; }
.tab-filters .filter-reset:not(.map-apply ~ .filter-reset) { margin-left: auto; }

/* tablet / small: 2 controls per row, selects fill their cell */
@media (max-width: 720px) {
  .tab-filters { gap: 10px 12px; }
  .tab-filters .field.inline {
    flex: 1 1 calc(50% - 12px);
    max-width: none;
  }
  .tab-filters .field.inline select,
  .tab-filters .field.inline input[type="text"] { max-width: none; }
  /* segments fill the field width and split it evenly between their buttons
     (2 options -> 50/50, 3 -> 33/33/33) instead of leaving blank space */
  .tab-filters .seg { display: flex; width: 100%; flex-wrap: nowrap; }
  .tab-filters .seg .seg-btn { flex: 1 1 0; padding-left: 4px; padding-right: 4px; text-align: center; }
  .tab-filters .cum-year-field { flex: 1 1 100%; width: auto; max-width: none; }
  /* action buttons share a full-width row, side by side */
  .tab-filters .map-apply,
  .tab-filters .filter-reset { flex: 1 1 auto; margin-left: 0; }
  .tab-filters .map-apply { margin-left: 0; }
  .tab-filters .filter-reset:not(.map-apply ~ .filter-reset) { margin-left: 0; }
}

/* phones: one control per row for maximum legibility */
@media (max-width: 460px) {
  .tab-filters .field.inline { flex: 1 1 100%; }
  .tab-filters .map-apply,
  .tab-filters .filter-reset { flex: 1 1 100%; }
}

/* ------------------------------ calendar ----------------------------- */

.calendar-holder { padding: 6px 0 2px; }

.cal-total {
  font-size: 13.5px;
  color: var(--muted);
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}

svg.calendar .cal-label {
  font-size: 9px;
  fill: var(--muted);
  font-family: var(--font);
}

svg.calendar rect:hover { stroke: var(--ink); stroke-width: 1; }

/* ------------------------------ eddington ---------------------------- */

.eddington-hero {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin: 6px 0 2px;
}

.eddington-number {
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  color: var(--route);
  font-variant-numeric: tabular-nums;
}

.eddington-caption { font-size: 14px; color: var(--muted); }

.eddington-next {
  font-size: 13px;
  color: var(--muted);
  margin: 6px 0 14px;
}

.eddington-table { max-width: 360px; }

/* ------------------------------- records ----------------------------- */

.records-table .record-link {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  padding: 0;
  cursor: pointer;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--hairline);
  text-underline-offset: 2px;
}

.records-table .record-link:hover { text-decoration-color: var(--route); }

/* ----------------------------- player bar ---------------------------- */

.player-bar {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1010;
  width: min(620px, calc(100% - 24px));
}

.player-bar[hidden] { display: none; }

.player-bar select {
  font: inherit;
  font-size: 13px;
  padding: 5px 7px;
  border: 1px solid var(--hairline);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
}

.player-bar .btn { padding: 6px 12px; min-width: 64px; }
.player-bar .dialog-close { margin-left: auto; }

#player-scrub { flex: 1; }

.player-date {
  font-size: 13px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 92px;
  text-align: center;
}

@media (max-width: 760px) {
  .player-bar { flex-wrap: wrap; bottom: 8px; }
  #player-scrub { flex-basis: 100%; order: 5; }
}

/* ------------------------- panel sub-sections ------------------------ */

.panel details.sub {
  border: 1px solid var(--hairline);
  border-radius: 8px;
}

.panel details.sub summary {
  padding: 8px 10px;
  font-size: 12.5px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  color: var(--ink);
}

.panel details.sub .sub-body { padding: 0 10px 10px; }

.panel details.sub .sub-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 6px;
}

/* ----------------------------- stat cards ---------------------------- */

.stat-cards {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin: 6px 0 16px;
}

.stat-card {
  flex: 1 1 150px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  gap: 4px;
}

.stat-number {
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
  color: var(--route);
  font-variant-numeric: tabular-nums;
}

.stat-caption { font-size: 12.5px; color: var(--muted); line-height: 1.4; }

.streak-table { max-width: 380px; }

/* ----------------------------- comparison ---------------------------- */

.cmp-info {
  font-size: 13.5px;
  margin: 2px 0 10px;
  color: var(--muted);
}

.cmp-info strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.cmp-info .pos { color: #3E7C59; }
.cmp-info .neg { color: var(--route); }

/* ---------------------------- month matrix --------------------------- */

.months-holder { overflow-x: auto; }

.month-matrix {
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  width: 100%;
}

.month-matrix th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 5px 6px;
  text-align: right;
}

.month-matrix tbody th { text-align: left; }

.month-matrix td {
  padding: 5px 6px;
  text-align: right;
  border: 1px solid var(--surface);
  min-width: 42px;
}

.month-matrix .matrix-total {
  font-weight: 600;
  background: var(--paper);
}

/* -------------------------------- gear ------------------------------- */

.gear-table td:first-child { text-align: left; }
.gear-none td { color: var(--muted); }

/* tabs stay on one line; see fixed-size dialog block at the end */

/* ---------------------------- detail panel --------------------------- */

.detail-panel {
  position: absolute;
  top: 14px;
  right: 12px;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  z-index: 1020;
}

.detail-panel[hidden] { display: none; }

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.detail-name {
  font-weight: 600;
  font-size: 14.5px;
  line-height: 1.3;
  word-break: break-word;
}

.detail-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.detail-table { width: 100%; font-size: 13px; }
.detail-table td { padding: 2.5px 0; }
.detail-table td:first-child { color: var(--muted); padding-right: 14px; }
.detail-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.detail-actions .btn { flex: 1; text-align: center; font-size: 12.5px; padding: 7px 8px; }

@media (max-width: 760px) {
  .detail-panel { left: 8px; right: 8px; width: auto; top: auto; bottom: 8px; }
}

/* --------------------------- search suggest -------------------------- */

.search-suggest {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 420px;
  overflow-y: auto;
  z-index: 1200;
  padding: 4px;
}

.search-suggest[hidden] { display: none; }

.suggest-item {
  appearance: none;
  border: none;
  background: none;
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  padding: 7px 10px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--ink);
}

.suggest-item:hover,
.suggest-item.active { background: var(--paper); }

.suggest-name {
  display: block;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggest-meta {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 1px;
}

.suggest-hint {
  padding: 8px 10px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: default;
  user-select: none;
}

/* ----------------- fixed-size statistics dialog ---------------------- */

/* Wider and with a constant height: switching tabs never resizes the
   dialog. The pane area scrolls; head and tab row stay put. */
dialog.wide {
  width: min(1240px, calc(100vw - 32px));
  height: min(720px, calc(100vh - 64px));
}

dialog.wide[open] {
  display: flex;
  flex-direction: column;
}

dialog.wide .dialog-head,
dialog.wide .tabs { flex: none; }

dialog.wide .tab-pane { display: none; }

dialog.wide .tab-pane.active {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

/* One row of tabs, horizontally scrollable when space runs out */
dialog.wide .tabs {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
}

dialog.wide .tab-button {
  white-space: nowrap;
  flex: none;
  font-size: 13px;
  padding: 8px 9px;
}

/* Charts keep their previous size and aspect ratio: the holder is capped
   at the old inner width (820 px dialog minus padding) and centered. */
dialog.wide .chart-holder {
  max-width: 772px;
  margin-left: auto;
  margin-right: auto;
}
/* the scatter chart fills its grid column, not the centred 772px box */
dialog.wide .scatter-chart-holder { max-width: none; margin: 0; }

@media (max-width: 760px) {
  dialog.wide { height: calc(100vh - 24px); }
}

/* --------------------------- weekday matrix -------------------------- */

.week-matrix td { min-width: 26px; padding: 4px 4px; }
.week-matrix th { padding: 4px 4px; }

/* ---------------------------- confirm dialog ------------------------- */

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* --------------------------- bar chart filter ------------------------ */

.field.inline.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.field.inline.checkbox span { color: var(--muted); }
.field.inline.checkbox input { accent-color: var(--route); margin: 0; }

/* ---------------------------- month view ----------------------------- */

.monthcal-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.mc-nav {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.mc-nav:hover { border-color: var(--ink); }

.mc-label {
  font-size: 17px;
  font-weight: 600;
  min-width: 168px;
  text-align: center;
}

.mc-year, .mc-type-field select {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.mc-type-field { margin-bottom: 0; margin-left: auto; }

.cal-grid-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.cal-grid-head div {
  text-align: center;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 1fr;
  gap: 6px;
  /* Fill the available dialog height so a whole month fits without
     scrolling. Dialog body minus nav, filters and weekday header leaves
     room for up to 6 week rows; the rows share the height equally. */
  height: calc(min(720px, 100vh - 64px) - 250px);
  min-height: 300px;
}

.cal-cell {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--surface);
  border-radius: 9px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  font: inherit;
  color: var(--ink);
  text-align: left;
  cursor: default;
  position: relative;
  overflow: visible;
  min-height: 0;
}
/* inner wrapper clips text overflow so the cell itself can let the trip frame
   overlay extend across the grid gap */
.cal-inner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.cal-cell.empty { border: none; background: transparent; }
.cal-cell.has { cursor: pointer; }
.cal-cell.has:hover { border-color: var(--ink); }
.cal-cell.dark { color: #fff; }
/* today/selected use outline (not box-shadow) so the trip frame's inset
   box-shadow below can coexist on the same cell without conflict */
.cal-cell.today { outline: 2px solid var(--ink); outline-offset: -2px; }
.cal-cell.selected { outline: 2px solid #FFD500; outline-offset: -2px; }

/* ---- trip frame: a fine black band drawn OUTSIDE the cells with a small gap.
   top + bottom are always drawn; the left/right edge is closed only at the band
   ends (trip-l / trip-r). The uniform 3px outside offset (= half the 6px grid
   gap) makes the top/bottom lines of adjacent trip days meet, so a trip reads as
   one connected band per week row. */
.cal-cell.trip::before {
  content: '';
  position: absolute;
  top: -3px; bottom: -3px; left: -3px; right: -3px;
  pointer-events: none;
  border: 0 solid #111;
  border-top-width: 1.5px;
  border-bottom-width: 1.5px;
}
.cal-cell.trip-l::before {
  border-left-width: 1.5px;
  border-top-left-radius: 11px; border-bottom-left-radius: 11px;
}
.cal-cell.trip-r::before {
  border-right-width: 1.5px;
  border-top-right-radius: 11px; border-bottom-right-radius: 11px;
}

.cal-day { font-size: 13px; font-weight: 600; }
.cal-km {
  font-size: 13px;
  font-weight: 600;
  margin-top: auto;
  font-variant-numeric: tabular-nums;
}
.cal-n { font-size: 10.5px; opacity: .8; }

.monthcal-daylist {
  margin-top: 16px;
  border-top: 1px solid var(--hairline);
  padding-top: 12px;
}

.daylist-head {
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 8px;
}

.daylist-item {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--surface);
  border-radius: 8px;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  display: block;
  font: inherit;
  color: var(--ink);
}
.daylist-item:hover { border-color: var(--route); }

.daylist-name { display: block; font-weight: 500; font-size: 13.5px; }
.daylist-meta {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 760px) {
  .cal-cell { padding: 4px 5px; border-radius: 7px; }
  .cal-day { font-size: 11px; }
  .cal-km { font-size: 11px; }
  .cal-n { display: none; }
  .cal-extra { display: none; }
  .mc-type-field { margin-left: 0; }
  /* on phones the grid can use a bit less height; tiles stay legible */
  .cal-grid { height: calc(100vh - 280px); min-height: 260px; gap: 4px; }
}

/* ----------------------- cumulative year slider ---------------------- */

.cum-year-field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  min-width: 200px;
}
.cum-year-field > span {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13.5px;
}
.cum-year-field em { font-style: normal; color: var(--ink); font-variant-numeric: tabular-nums; }
.cum-slider { width: 100%; }

/* Bar tab: reserve room for the extra "Rest of year" legend row so
   toggling YTD never shifts the chart. */
.tab-pane[data-tab="bar"] .chart-holder { height: 420px; }

/* ----------------------------- GPS locate FAB ------------------------ */

.map-fabs {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-fab {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.map-fab:hover { color: var(--route); }
.map-fab.busy { opacity: .6; pointer-events: none; }
.map-fab.busy svg { animation: spin 0.9s linear infinite; }

/* ----------------------------- info button --------------------------- */

.info-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.info-btn:hover { color: var(--ink); border-color: var(--ink); }

/* --------------------------- filter reset btn ------------------------ */

.filter-reset {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-left: auto;
  align-self: center;
  flex: none;
}
.filter-reset:hover { color: var(--ink); border-color: var(--ink); }

/* --------------------- heatmap multi-year layout --------------------- */

.calendar-holder.scroll { max-height: 540px; overflow-y: auto; padding-right: 6px; }
.cal-year { margin-bottom: 18px; }
.cal-year-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 4px;
}
.cal-year-num { font-size: 16px; font-weight: 700; }
.cal-year-head .cal-total { font-size: 12.5px; color: var(--muted); margin: 0; }

/* ----------------- calendar tile extra (desktop only) ---------------- */

.cal-extra {
  font-size: 10.5px;
  opacity: .75;
  font-variant-numeric: tabular-nums;
}

/* ------------------- day-list extra (desktop only) ------------------- */

/* shown by default (desktop); hidden on small screens below */

/* ----------------------- sortable table headers ---------------------- */

table.sortable th[data-sort] {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 16px;
}
table.sortable th[data-sort]:hover { color: var(--ink); }
table.sortable th.sort-asc::after { content: '\2191'; position: absolute; right: 4px; }
table.sortable th.sort-desc::after { content: '\2193'; position: absolute; right: 4px; }

/* --------------------------- new-ground chart ------------------------ */

.ng-chart { height: 260px; margin: 8px 0 14px; }

/* ------------------------------- mobile ------------------------------ */

@media (max-width: 760px) {
  /* day-list: distance only */
  .daylist-extra { display: none; }
  /* calendar tile: km only, drop elevation/time and the count line */
  .cal-extra, .cal-n { display: none; }
  /* GPS FAB a little higher to clear the bottom controls */
  .map-fabs { top: 8px; right: 8px; }
}

/* desktop: ensure the extras are visible */
@media (min-width: 761px) {
  .daylist-extra { display: inline; }
}

/* --------------------- new-ground top contributors ------------------- */

.ng-top-bar { margin-top: 18px; }

.linklike {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--hairline);
  text-underline-offset: 2px;
  cursor: pointer;
  padding: 0;
  text-align: left;
}
.linklike:hover { text-decoration-color: var(--route); }

/* ----------------------- prominent connect prompt -------------------- */

.connect-prompt {
  font-size: 13px;
  font-weight: 600;
  color: var(--strava);
  margin-right: 2px;
  white-space: nowrap;
}

.connect-button.prominent {
  border-radius: 6px;
  box-shadow: 0 0 0 0 rgba(252, 76, 2, 0.5);
  animation: connectPulse 2s ease-out infinite;
}
.connect-button.prominent img { display: block; height: 36px; }

@keyframes connectPulse {
  0%   { box-shadow: 0 0 0 0 rgba(252, 76, 2, 0.5); }
  70%  { box-shadow: 0 0 0 10px rgba(252, 76, 2, 0); }
  100% { box-shadow: 0 0 0 0 rgba(252, 76, 2, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .connect-button.prominent { animation: none; }
}

/* ----------------------- new-ground year bar ------------------------- */

.ng-bar-label {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
#ng-bar .player-date { min-width: 56px; }
#ng-bar-scrub { flex: 1; }

@media (max-width: 760px) {
  .connect-prompt { display: none; }
}

/* ----------------------------- tab groups ---------------------------- */

.tab-groups {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  flex: none;
}

.tab-group {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 8px;
  cursor: pointer;
}
.tab-group:hover { color: var(--ink); }
.tab-group.active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* only tabs of the active group are shown */
dialog.wide .tab-button { display: none; }
dialog.wide .tab-button.in-group { display: inline-block; }

/* ----------------------- heatmap fits without scroll ----------------- */
/* (year-range slider lets the user narrow the set; full scroll remains) */

/* ------------------------------- mobile ------------------------------ */

@media (max-width: 760px) {
  .tab-groups { flex-wrap: wrap; }
  .tab-group { padding: 5px 12px; font-size: 12.5px; }
}

/* ----------------------- map view switch (bottom) -------------------- */

.view-switch {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 11px;
  box-shadow: var(--shadow);
}

.view-btn {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.view-btn:hover { color: var(--ink); }
.view-btn.active { background: var(--ink); color: #fff; }

@media (max-width: 760px) {
  .view-switch { bottom: 12px; gap: 1px; padding: 2px; }
  .view-btn { padding: 6px 10px; font-size: 12px; }
  /* Travels map mode needs the stats UI to set zones; hide it on small screens */
  .view-btn[data-view="travels"] { display: none; }
}

/* Mobile PORTRAIT: dock the map-view switcher as a bottom bar and end the map
   above it. The Leaflet zoom / layer controls then live inside the shortened
   map and can no longer be overlapped — solved by construction, not z-index. */
@media (max-width: 760px) and (orientation: portrait) {
  :root { --vs-h: 46px; }
  #map { bottom: calc(var(--vs-h) + env(safe-area-inset-bottom, 0px)); }
  .view-switch {
    left: 0; right: 0; bottom: 0; transform: none;
    height: var(--vs-h); box-sizing: content-box;
    padding: 0 8px; padding-bottom: env(safe-area-inset-bottom, 0px);
    gap: 1px;
    border: 0; border-top: 1px solid var(--hairline); border-radius: 0;
    background: var(--surface); box-shadow: 0 -1px 4px rgba(0, 0, 0, .06);
    justify-content: center; align-items: center;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  .view-btn { flex: 0 0 auto; }
}

/* --------------------------- header style menu ----------------------- */

.menu-wrap { position: relative; display: inline-flex; align-items: center; }
.btn-caret { gap: 5px; white-space: nowrap; }
.btn-caret .caret { font-size: 0.8em; line-height: 1; opacity: 0.7; }

.header-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 1200;
  width: 230px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 11px;
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* never exceed the space between the header and the bottom of the screen;
     scroll inside if the content (e.g. a long colour legend) is taller.
     Topbar is 56px high; leave a small margin below. */
  max-height: calc(100vh - 56px - 20px);
  max-height: calc(100dvh - 56px - 20px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.header-menu[hidden] { display: none; }
.header-menu .field { margin: 0; }

/* reset button inside the Filter <summary>: normal-case, non-bold, so it
   doesn't read like part of the uppercase section title */
.summary-reset {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}

@media (max-width: 760px) {
  .header-menu {
    /* centre in the viewport instead of anchoring to the button, so a
       near-full-width menu can't run off the left edge */
    position: fixed;
    top: 56px;                 /* just below the fixed 56px topbar */
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(340px, calc(100vw - 24px));
    max-height: calc(100dvh - 56px - 20px);
  }
}

/* GPS button active (location shown) */
.map-fab.active { color: #1B6CA8; border-color: #1B6CA8; }

/* --------------------- gear / device clickable rows ------------------ */

.pickable tbody tr.group-row { cursor: pointer; }
.pickable tbody tr.group-row:hover td { background: var(--paper-2, #F3F1EB); }
.pickable tbody tr.group-row.selected td {
  background: rgba(215, 38, 61, 0.07);
  box-shadow: inset 2px 0 0 var(--route);
}

.group-activities { margin-top: 14px; }
.group-activities:empty { display: none; }

.group-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.group-pager .mini[disabled] { opacity: .4; cursor: default; }

/* ---------------------------- scatter axes --------------------------- */

/* two-column scatter layout: controls left, chart + legend right */
.scatter-layout {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 16px;
  margin-top: 8px;
  align-items: start;
}
/* the side column matches the chart height; drop zones + hint stay fixed
   at the top and only the field palette scrolls inside it */
.scatter-side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  height: calc(min(760px, 100vh - 80px) - 300px);
  min-height: 280px;
}
.scatter-main { min-width: 0; }

.scatter-side .axis-drop,
.scatter-side .scatter-hint { flex: none; }

/* chart sized to fill the remaining modal height without scrolling */
.scatter-chart-holder { height: calc(min(760px, 100vh - 80px) - 300px); min-height: 280px; }
.scatter-info { margin-top: 10px; }

.axis-drop {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 12px;
  border: 1.5px dashed var(--hairline);
  border-radius: 9px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.axis-drop.over,
.axis-drop.awaiting { border-color: var(--route); background: rgba(215, 38, 61, 0.04); }

.axis-label {
  font-weight: 700;
  font-size: 13px;
  color: var(--muted);
  width: 14px;
  flex: none;
}
.axis-chip {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scatter-hint { margin: 4px 0 6px; }

/* palette as a vertical, scrollable list filling the rest of the column */
.scatter-palette {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  padding-right: 4px;
}

.var-chip {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  padding: 7px 11px;
  border-radius: 9px;
  cursor: grab;
  user-select: none;
  text-align: left;
}
.var-chip:hover { border-color: var(--ink); }
.var-chip.dragging { opacity: .5; }
.var-chip.picked { background: var(--ink); color: #fff; border-color: var(--ink); }

/* stack the columns on narrow screens */
@media (max-width: 760px) {
  .scatter-layout { grid-template-columns: 1fr; }
  .scatter-side { height: auto; min-height: 0; }
  .scatter-palette { flex-direction: row; flex-wrap: wrap; overflow: visible; flex: none; }
  .scatter-chart-holder { height: 320px; }
}

/* -------------------- scatter numeric colour legend ------------------ */

.scatter-legend {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.scatter-legend-bar {
  display: inline-block;
  width: 120px;
  height: 10px;
  border-radius: 5px;
  border: 1px solid var(--hairline);
}
.scatter-legend-label { font-weight: 600; color: var(--ink); margin-left: 4px; }

/* scatter categorical legend (single-dataset chart -> custom legend) */
.scatter-cat-legend {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
}
.scatter-cat-item {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
}
.scatter-cat-item:hover { background: rgba(0, 0, 0, 0.04); }
.scatter-cat-item.off { opacity: .35; text-decoration: line-through; }
.scatter-cat-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* clickable weekday/hour cells */
.week-matrix td.wm-cell { cursor: pointer; }
.week-matrix td.wm-cell:hover { outline: 2px solid var(--ink); outline-offset: -2px; }
.week-matrix td.wm-cell.selected { outline: 2px solid #FFD500; outline-offset: -2px; }

/* ------------------------------ timeline ----------------------------- */

.timeline-scroll { overflow-x: auto; overflow-y: hidden; }
.timeline-svg { display: block; min-width: 680px; }

.tl-grid { stroke: #EEECE6; stroke-width: 1; }
.tl-year { fill: var(--muted); font-size: 11px; font-weight: 600; }
.tl-label { fill: var(--ink); font-size: 12px; dominant-baseline: middle; }
.tl-label-sm { font-size: 10px; }
.tl-count { fill: var(--muted); font-size: 11px; dominant-baseline: middle; }

.tl-bar { fill: var(--route); }
.tl-span { fill: rgba(215, 38, 61, 0.22); }
.tl-ridge { fill: rgba(215, 38, 61, 0.55); stroke: var(--route); stroke-width: 1; stroke-linejoin: round; }

.tl-row:hover .tl-label { fill: var(--route); }
.tl-row:hover rect:first-of-type { fill: rgba(0, 0, 0, 0.03); }
.tl-row.selected rect:first-of-type { fill: rgba(255, 213, 0, 0.16); }
.tl-row.selected .tl-label { font-weight: 700; }

/* ----------------------- segmented (grouped) buttons ----------------- */

.seg {
  display: inline-flex;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.seg-btn {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--hairline); }
.seg-btn:hover { color: var(--ink); }
.seg-btn.active { background: var(--ink); color: #fff; }

/* ----------------------- activity mix: small multiples --------------- */

.mm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.mm-card {
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 10px 12px 4px;
  background: var(--surface);
}
.mm-card:hover { border-color: var(--ink); }
.mm-card.selected { border-color: #FFD500; box-shadow: 0 0 0 1px #FFD500; }
.mm-head { display: flex; align-items: center; gap: 7px; margin-bottom: 2px; }
.mm-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.mm-title { font-size: 13px; font-weight: 600; color: var(--ink); }
.mm-total { margin-left: auto; font-size: 12px; color: var(--muted); }
.mm-axis { stroke: var(--hairline); stroke-width: 1; }
.mm-xlabel { fill: var(--muted); font-size: 9px; }
.mm-ylabel { fill: var(--muted); font-size: 9px; }

/* ------------------------- timeline window nav ----------------------- */

.win-nav { display: inline-flex; align-items: center; gap: 8px; }
.win-arrow {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--surface);
  border-radius: 6px;
  width: 28px; height: 28px;
  font-size: 16px; line-height: 1;
  color: var(--ink);
  cursor: pointer;
}
.win-arrow:hover:not(:disabled) { border-color: var(--ink); }
.win-arrow:disabled { opacity: 0.35; cursor: default; }
.win-label { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 76px; text-align: center; }

/* mix small-multiples by-year legend */
.mm-legend {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  margin-bottom: 12px; font-size: 12px; color: var(--ink);
}
.mm-leg { display: inline-flex; align-items: center; gap: 6px; }

/* inline checkbox field (e.g. scatter "hide outliers") */
.checkbox-field { flex-direction: row; align-items: center; gap: 6px; }
.checkbox-field input { margin: 0; cursor: pointer; }
.checkbox-field span { cursor: pointer; }

/* ----------------------------- geography ----------------------------- */

.muni-share { display: flex; align-items: center; gap: 28px; padding: 20px 4px; }
.muni-share-pct { font-size: 30px; font-weight: 700; fill: var(--ink); }
.muni-share-sub { font-size: 12px; fill: var(--muted); }
.muni-share-nums { font-size: 16px; line-height: 1.6; }
.muni-share-nums strong { font-size: 22px; color: var(--route); }

.muni-table { width: 100%; border-collapse: collapse; }
.muni-table th, .muni-table td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--hairline); }
.muni-table th:last-child, .muni-table td:last-child,
.muni-table th:first-child, .muni-table td:first-child { text-align: right; width: 1%; white-space: nowrap; }
.muni-table th:nth-child(2), .muni-table td:nth-child(2) { text-align: left; width: auto; }
.muni-rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.muni-count { font-variant-numeric: tabular-nums; font-weight: 600; }
.muni-row:hover td { background: rgba(0,0,0,0.03); }
.muni-row.selected td { background: rgba(255,213,0,0.16); }

/* --------------------- commune search & detail ---------------------- */

.muni-search-field input { min-width: 280px; }
.muni-search-results { margin: 4px 0 14px; display: flex; flex-direction: column; gap: 2px; max-width: 480px; }
.muni-search-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 8px 12px; background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 8px; cursor: pointer; font-size: 14px; text-align: left;
}
.muni-search-item:hover { border-color: var(--route); background: rgba(215,38,61,0.04); }
.msi-name { font-weight: 600; color: var(--ink); }
.msi-count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.muni-detail h3 { margin: 0 0 14px; font-size: 20px; }
.muni-tiles { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.muni-tile {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 10px; min-width: 96px;
}
.mt-num { font-size: 18px; font-weight: 700; color: var(--ink); }
.mt-lab { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.muni-year-chart { margin-bottom: 16px; }

/* commune detail: tiles + mini locator map side by side */
.muni-detail-top { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 18px; }
.muni-detail-left { flex: 1 1 320px; }
.muni-detail-left .muni-tiles { margin-bottom: 0; }
.muni-detail-map { flex: 0 0 auto; }
.muni-minimap {
  border: 1px solid var(--hairline); border-radius: 10px; background: var(--surface);
  display: block;
}

/* municipalities tab: canton breakdown + frequency distribution */
.muni-section { margin-top: 26px; }
.muni-section h4 { margin: 0 0 12px; font-size: 15px; font-weight: 700; }

.kt-list { display: flex; flex-direction: column; gap: 5px; max-width: 560px; }
.kt-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.kt-code { width: 26px; font-weight: 700; color: var(--ink); flex: 0 0 auto; }
.kt-bar-wrap { flex: 1 1 auto; height: 10px; background: #EEECE6; border-radius: 5px; overflow: hidden; }
.kt-bar { display: block; height: 100%; background: #D7263D; border-radius: 5px; }
.kt-val { flex: 0 0 auto; width: 54px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.kt-pct { flex: 0 0 auto; width: 34px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.freq-chart { display: flex; align-items: flex-end; gap: 10px; height: 120px; padding-top: 16px; max-width: 480px; }
.freq-col { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; }
.freq-num { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.freq-bar { width: 100%; max-width: 36px; background: #D7263D; border-radius: 3px 3px 0 0; min-height: 2px; }
.freq-lab { font-size: 11px; color: var(--muted); }

/* municipalities: top-20 mini-map matrix */
.muni-mini-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px; max-width: 860px;
}
.muni-mini-card {
  display: flex; flex-direction: column; padding: 0; cursor: pointer;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 10px;
  overflow: hidden; text-align: left;
}
.muni-mini-card:hover { border-color: var(--route); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.mmc-map { width: 100%; display: flex; justify-content: center; background: var(--paper); }
.mmc-map .muni-minimap { border: none; border-radius: 0; width: 100%; height: auto; }
.mmc-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 10px; }
.mmc-name { font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mmc-count { font-size: 12px; font-weight: 700; color: var(--route); flex: 0 0 auto; }

/* canton row: show full name in its own tab */
.kt-name { flex: 0 0 160px; font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* municipality loading/progress bar */
.muni-progress-box { max-width: 420px; margin: 30px auto; text-align: center; }
.muni-progress-label { font-size: 14px; color: var(--ink); margin-bottom: 10px; }
.muni-progress-track { height: 10px; background: #EEECE6; border-radius: 5px; overflow: hidden; }
.muni-progress-fill { height: 100%; background: #D7263D; border-radius: 5px; transition: width 0.2s ease; }
.muni-progress-pct { font-size: 12px; color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums; }

/* canton tab: list left, map right */
.kt-layout { display: flex; gap: 28px; align-items: flex-start; flex-wrap: wrap; }
.kt-layout .kt-list { flex: 1 1 380px; }
.kt-mapside { flex: 0 0 auto; min-width: 200px; }
.kt-mapside h4 { margin: 0 0 8px; font-size: 16px; }
.kt-row.selected { background: rgba(255,213,0,0.16); border-radius: 6px; }
.kt-row { padding: 2px 4px; }
.canton-minimap { border: 1px solid var(--hairline); border-radius: 10px; background: var(--surface); display: block; }

/* canton map hover + lists */
.ktm-commune { transition: fill 0.1s; }
.ktm-commune:hover { fill: rgba(255,213,0,0.45) !important; cursor: default; }
.ktl-controls { margin: 14px 0 8px; font-size: 13px; color: var(--muted); }
.ktl-sort {
  margin-left: 6px; padding: 3px 10px; font-size: 12px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 6px; color: var(--ink);
}
.ktl-sort.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.ktl-sort:disabled { opacity: 0.5; cursor: default; }
.ktl-lists { display: flex; gap: 24px; flex-wrap: wrap; }
.ktl-block { flex: 1 1 220px; min-width: 200px; }
.ktl-block h5 { margin: 0 0 6px; font-size: 13px; font-weight: 700; }
.ktl-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ktl-table th { text-align: left; font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.03em; padding: 3px 6px; border-bottom: 1px solid var(--hairline); }
.ktl-table td { padding: 3px 6px; border-bottom: 1px solid var(--hairline); }
.ktl-table .ktl-d { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ktl-unvisited h5 { color: var(--muted); }
.ktl-visited td:first-child { color: var(--ink); }

/* choropleth control bar */
.choro-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); cursor: pointer; white-space: nowrap; }
.choro-toggle input { cursor: pointer; }

/* cluster planner */
.cluster-list { display: flex; flex-direction: column; gap: 6px; max-width: 720px; }
.cluster-row { display: flex; align-items: center; gap: 14px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 10px; cursor: pointer; }
.cluster-row:hover { border-color: var(--route); }
.cl-rank { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.cl-mapwrap { flex: 0 0 auto; width: 120px; height: 90px; background: var(--paper);
  border: 1px solid var(--hairline); border-radius: 8px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.cl-map { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.cl-map .cluster-minimap { width: 100%; height: auto; display: block; }
.cl-main { flex: 1 1 auto; min-width: 0; }
.cl-size { font-size: 14px; font-weight: 700; color: var(--ink); }
.cl-cantons { font-size: 12px; font-weight: 600; color: var(--route); margin-top: 1px; }
.cl-names { font-size: 12px; color: var(--muted); margin-top: 2px; }
.cl-right { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.cl-dist { text-align: right; font-size: 14px; font-weight: 700; color: var(--route);
  font-variant-numeric: tabular-nums; }
.cl-dist-lab { display: block; font-size: 10px; font-weight: 400; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.cl-zoom { padding: 4px 10px; font-size: 12px; cursor: pointer; white-space: nowrap;
  background: var(--ink); color: #fff; border: none; border-radius: 6px; }
.cl-zoom:hover { background: var(--route); }

/* GPX route editor */
.gpx-drawing { cursor: crosshair; }
.gpx-pt-icon { background: none; border: none; }
.gpx-pt-icon span {
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: #1763D7; color: #fff; font-size: 11px; font-weight: 700;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  cursor: grab;
}
.gpx-pt-icon span:active { cursor: grabbing; }
.btn-mini {
  padding: 5px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--hairline); border-radius: 6px;
}
.btn-mini:hover { border-color: var(--ink); }
.btn-mini:disabled { opacity: 0.45; cursor: default; }
.btn-mini-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-mini-primary:hover:not(:disabled) { background: #1763D7; border-color: #1763D7; }

/* "Show on map" button in stats tab filter bars */
.map-apply {
  padding: 5px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
  background: var(--route); color: #fff;
  border: 1px solid var(--route); border-radius: 6px;
}
.map-apply:hover { background: #b91f33; border-color: #b91f33; }

/* country report */
.country-list { display: flex; flex-direction: column; gap: 4px; max-width: 640px; }
.country-row { display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 8px; }
.country-flag { flex: 0 0 auto; width: 26px; height: 19px; line-height: 0;
  display: inline-flex; align-items: center; justify-content: center; overflow: hidden;
  border-radius: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,0.08); background: var(--paper); }
.country-flag svg { width: 100%; height: 100%; display: block; }
.country-flag:empty { box-shadow: none; background: none; }
.cty-actlist-flag { width: 22px; height: 16px; vertical-align: middle; }
.country-name { flex: 0 0 150px; text-align: left; background: none; border: none; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--ink); padding: 2px 0; }
.country-name:hover { color: var(--route); text-decoration: underline; }
.country-bar-wrap { flex: 1 1 auto; height: 8px; background: var(--paper);
  border-radius: 4px; overflow: hidden; }
.country-bar { display: block; height: 100%; background: var(--route); border-radius: 4px; }
.country-count { flex: 0 0 auto; min-width: 40px; text-align: right; background: none; border: none;
  cursor: pointer; font: inherit; font-weight: 700; color: var(--route); font-variant-numeric: tabular-nums; }
.country-count:hover { text-decoration: underline; }

.cty-actlist { margin-top: 14px; max-width: 640px; border: 1px solid var(--hairline);
  border-radius: 10px; overflow: hidden; }
.cty-actlist-head { display: flex; align-items: center; gap: 6px; padding: 8px 12px;
  background: var(--paper); font-weight: 700; border-bottom: 1px solid var(--hairline); }
.cty-actlist-close { margin-left: auto; background: none; border: none; font-size: 18px;
  cursor: pointer; color: var(--muted); line-height: 1; }
.cty-actlist-body { max-height: 320px; overflow-y: auto; }
.cty-act { display: flex; align-items: center; gap: 12px; width: 100%; padding: 7px 12px;
  background: none; border: none; border-bottom: 1px solid var(--hairline); cursor: pointer;
  font: inherit; text-align: left; }
.cty-act:hover { background: var(--paper); }
.cty-act-date { flex: 0 0 90px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.cty-act-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cty-act-dist { flex: 0 0 auto; color: var(--route); font-weight: 600; font-variant-numeric: tabular-nums; }

/* PWA update banner */
.update-banner {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  z-index: 2000; display: flex; align-items: center; gap: 12px;
  max-width: calc(100vw - 24px);
  padding: 10px 14px; border-radius: 12px;
  background: var(--ink); color: #fff;
  box-shadow: 0 6px 24px rgba(0,0,0,0.28);
  font-size: 14px;
}
.update-banner[hidden] { display: none; }
.update-banner-text { flex: 1 1 auto; }
.update-banner-btn {
  flex: 0 0 auto; padding: 6px 14px; border: none; border-radius: 7px;
  background: var(--route); color: #fff; font: inherit; font-weight: 700; cursor: pointer;
}
.update-banner-btn:hover:not(:disabled) { background: #b91f33; }
.update-banner-btn:disabled { opacity: 0.6; cursor: default; }
.update-banner-dismiss {
  flex: 0 0 auto; padding: 6px 8px; border: none; background: none;
  color: rgba(255,255,255,0.7); font: inherit; cursor: pointer; text-decoration: underline;
}
.update-banner-dismiss:hover { color: #fff; }

/* ---------------------------- custom dropdowns ---------------------------- */
.cs-root { position: relative; display: inline-block; }
/* hide the native select but keep it in the layout flow for the wrapper sizing;
   it stays in the DOM so .value and change events keep working */
.cs-native {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  /* keep the native control completely untouchable so iOS never shows its own
     picker wheel on top of the custom panel */
  pointer-events: none;
}
.cs-button {
  display: inline-flex; align-items: center; gap: 8px; width: 100%;
  font: inherit; padding: 7px 10px;
  border: 1px solid var(--hairline); border-radius: 7px;
  background: var(--surface); color: var(--ink);
  cursor: pointer; text-align: left;
}
.cs-button:hover { border-color: var(--muted); }
.cs-root.cs-open .cs-button { border-color: var(--route); }
.cs-root.cs-disabled .cs-button { opacity: 0.5; cursor: default; }
.cs-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-caret { flex: 0 0 auto; font-size: 10px; color: var(--muted); transition: transform 0.12s ease; }
.cs-root.cs-open .cs-caret { transform: rotate(180deg); }

.cs-panel {
  position: absolute; z-index: 1500; top: calc(100% + 4px); left: 0;
  min-width: 100%; max-width: 280px; max-height: 280px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 9px; box-shadow: var(--shadow); padding: 4px;
  overscroll-behavior: contain;
}
.cs-option {
  padding: 7px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap;
  font-size: 14px; color: var(--ink);
}
.cs-option:hover { background: var(--paper); }
.cs-option.cs-selected { background: var(--ink); color: #fff; font-weight: 600; }
.cs-option.cs-selected:hover { background: var(--ink); }
.cs-option-disabled { opacity: 0.4; cursor: default; }
.cs-option-disabled:hover { background: none; }

/* in filter bars the custom select should fill the capped field width */
.tab-filters .cs-root { width: 100%; max-width: 180px; }
.tab-filters .field.inline .cs-root { max-width: 180px; }

/* on phones, dropdown panels can use a bit more width */
@media (max-width: 460px) {
  .cs-panel { max-width: calc(100vw - 32px); }
  .tab-filters .cs-root { max-width: none; }
}

/* multi-select options (checkbox style) */
.cs-option.cs-multi { display: flex; align-items: center; gap: 8px; }
.cs-option.cs-multi .cs-check {
  flex: 0 0 auto; width: 15px; height: 15px; border-radius: 4px;
  border: 1.5px solid var(--muted); background: var(--surface); position: relative;
}
.cs-option.cs-multi.cs-selected { background: none; color: var(--ink); font-weight: 600; }
.cs-option.cs-multi.cs-selected:hover { background: var(--paper); }
.cs-option.cs-multi.cs-selected .cs-check {
  background: var(--route); border-color: var(--route);
}
.cs-option.cs-multi.cs-selected .cs-check::after {
  content: ''; position: absolute; left: 4px; top: 1px;
  width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* reset footer inside a multi-select panel */
.cs-reset-row { border-top: 1px solid var(--hairline); margin-top: 4px; padding-top: 4px; display: flex; justify-content: flex-end; }
.cs-reset {
  background: none; border: none; font: inherit; font-size: 13px; cursor: pointer;
  color: var(--route); padding: 5px 8px; border-radius: 6px;
}
.cs-reset:hover { background: var(--paper); text-decoration: underline; }

/* account menu items */
.header-menu .menu-item {
  display: block; width: 100%; text-align: left; font: inherit; font-size: 14px;
  padding: 9px 10px; border: none; background: none; border-radius: 7px;
  color: var(--ink); cursor: pointer;
}
.header-menu .menu-item:hover { background: var(--paper); }

/* ----------------------------- travels ------------------------------ */
.travels-settings {
  border: 1px solid var(--hairline); border-radius: 12px;
  padding: 18px 20px; margin-bottom: 18px; background: var(--paper);
}
.travels-set-head { margin-bottom: 16px; }
.travels-set-head strong { font-size: 15px; margin-right: 8px; }
.travels-hint { color: var(--muted); font-size: 13px; }
.travels-zones { margin-bottom: 14px; }
.travels-zone {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 12px 0; border-top: 1px solid var(--hairline);
}
.travels-zone-main { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.travels-zone-aux { display: flex; align-items: center; gap: 14px; }
.travels-zone-aux .field.inline { gap: 8px; }
.travels-zone-aux input[type="number"] { width: 5em; }
.travels-status { font-size: 14px; color: var(--ink); }
.btn-primary {
  background: var(--route); border-color: var(--route); color: #fff;
}
.btn-primary:hover { background: #c01f34; border-color: #c01f34; }
.btn-ghost {
  appearance: none; background: none; border: 1px solid var(--hairline);
  color: var(--muted); font: inherit; font-size: 13px; font-weight: 500;
  padding: 6px 12px; border-radius: 8px; cursor: pointer; line-height: 1;
}
.btn-ghost:hover { color: var(--route); border-color: var(--route); }
.travels-summary { color: var(--muted); font-size: 14px; margin: 10px 0 14px; }
.travels-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px; align-items: start;
}
.travel-card {
  border: 1px solid var(--hairline); border-radius: 10px; overflow: hidden;
  background: var(--surface); transition: box-shadow .15s, transform .15s;
}
.travel-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.travel-mini {
  height: 140px; background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--hairline); cursor: pointer;
}
.travel-mini svg { display: block; }
.travel-nomap { color: var(--muted); font-size: 13px; }
.travel-meta { padding: 10px 12px; cursor: pointer; }
.travel-title { font-weight: 600; font-size: 15px; color: var(--ink); margin-bottom: 2px; }
.travel-sub { font-size: 13px; color: var(--ink); }
.travel-stats { font-size: 12px; color: var(--muted); margin-top: 4px; }
.travel-stats2 { font-size: 11.5px; color: var(--muted); margin-top: 2px; opacity: 0.85; }
.travel-activities {
  display: grid; grid-template-rows: 0fr;
  transition: grid-template-rows .28s ease;
  background: var(--paper);
}
.travel-card.expanded .travel-activities {
  grid-template-rows: 1fr; border-top: 1px solid var(--hairline);
}
.trv-act-inner { overflow: hidden; min-height: 0; }
.trv-act-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; font-size: 12px; color: var(--muted);
  border-bottom: 1px solid var(--hairline);
}
.trv-act-close {
  appearance: none; border: none; background: none; cursor: pointer;
  font-size: 18px; line-height: 1; color: var(--muted); padding: 0 2px;
}
.trv-act-close:hover { color: var(--route); }
.trv-act-list { list-style: none; margin: 0; padding: 4px 0; }
.trv-act {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 5px 12px; font-size: 13px; cursor: pointer;
}
.trv-act:hover { background: var(--surface); }
.trv-act:focus-visible { outline: 2px solid var(--route); outline-offset: -2px; }
.trv-act-name { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trv-act-meta { color: var(--muted); font-size: 12px; white-space: nowrap; flex: none; }
.app-toast {
  position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 14px; z-index: 3000; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; box-shadow: var(--shadow);
}
.app-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* travels: year window control */
.year-window { display: inline-flex; align-items: center; gap: 8px; }
.yw-btn {
  appearance: none; border: 1px solid var(--hairline); background: var(--surface);
  color: var(--ink); width: 28px; height: 28px; border-radius: 7px; cursor: pointer;
  font-size: 16px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.yw-btn:hover:not(:disabled) { border-color: var(--route); color: var(--route); }
.yw-btn:disabled { opacity: 0.35; cursor: default; }
.yw-label { min-width: 3.5em; text-align: center; font-weight: 600; font-size: 14px; }

/* ---- Insights carousel ---- */
.insights-stage {
  display: flex;
  align-items: stretch;
  gap: 12px;
  width: 100%;
  max-width: 560px;
}
.ins-nav {
  flex: 0 0 auto;
  width: 40px;
  border: none;
  background: none;
  font-size: 28px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, transform .1s;
}
.ins-nav:hover { color: var(--ink); }
.ins-nav:active { transform: scale(0.88); }
.ins-card {
  flex: 1 1 auto;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 28px 32px;
  border: 1px solid var(--hairline);
  border-radius: 16px;
  background:
    radial-gradient(120% 140% at 50% 0%, rgba(31,157,85,0.06), transparent 60%),
    var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}
.ins-tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--trip, #1F9D55);
  padding: 4px 10px;
  border: 1px solid color-mix(in srgb, var(--trip, #1F9D55) 35%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--trip, #1F9D55) 8%, transparent);
}
.ins-text {
  font-size: 26px;
  line-height: 1.3;
  font-weight: 600;
  max-width: 36ch;
  transition: opacity .18s ease;
}
.ins-card.fade .ins-text { opacity: 0; }
.ins-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 12px;
  justify-content: center;
}
.ins-count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ins-status { font-size: 12px; color: var(--muted); font-style: italic; }
@media (max-width: 640px) {
  .ins-text { font-size: 20px; }
  .ins-card { min-height: 170px; padding: 22px 18px; }
  .ins-nav { width: 38px; font-size: 24px; }
}

/* center the whole carousel in the middle of the stats modal */
dialog.wide .tab-pane[data-tab="insights"].active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

/* hover tooltip over trip days in the month calendar */
.cal-tip {
  position: fixed;
  z-index: 4000;
  pointer-events: none;
  max-width: 260px;
  background: var(--ink);
  color: #fff;
  padding: 8px 11px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.45;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transition: opacity .12s ease;
}
.cal-tip.show { opacity: 1; }
.cal-tip .t { display: block; font-weight: 700; margin-bottom: 2px; }
.cal-tip .s { display: block; opacity: 0.82; }
.cal-tip .ds { margin-bottom: 3px; }

/* ---- background toast (post-sync trip work) ----
   sits ABOVE the map view-switch (bottom:18px) so the grouped map buttons stay
   visible, and is click-through so they stay clickable. */
.bg-toast {
  position: fixed; left: 50%; bottom: 118px; transform: translateX(-50%) translateY(10px);
  background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 999px;
  font-size: 13px; z-index: 1600; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; box-shadow: var(--shadow);
  display: inline-flex; align-items: center; gap: 9px; max-width: 80vw;
}
.bg-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.bg-toast .bg-msg { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bg-spin {
  width: 13px; height: 13px; flex: none; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.35); border-top-color: #fff;
  animation: bg-spin 0.7s linear infinite;
}
@keyframes bg-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .bg-spin { animation: none; } }

/* ---- country flag SVGs in trip titles (cards + calendar tooltip) ----
   SVG from data/flags, NOT emoji (Windows renders flag emoji as plain letters). */
.trip-flag {
  display: inline-flex; align-items: center;
  vertical-align: -0.15em; margin-right: 6px; line-height: 1;
}
.trip-flag svg, .trip-flag img {
  height: 0.95em; width: auto; display: block; border-radius: 2px;
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, .25);
}
.travel-flags, .cal-flags { display: inline; }
.cal-tip .cal-flags .trip-flag { vertical-align: -0.12em; }

/* ---- gentle PayPal donation hint (max once/month, not first 10 usage days) ----
   anchored bottom-left so it never overlaps the centered view-switch/toasts. */
.donate-card {
  position: fixed; left: 16px; bottom: 80px;
  width: min(360px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--hairline); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 16px 14px;
  z-index: 1700; opacity: 0; transform: translateY(16px);
  transition: opacity .25s, transform .25s;
}
.donate-card.show { opacity: 1; transform: translateY(0); }
.donate-x {
  position: absolute; top: 6px; right: 9px; border: none; background: none;
  font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px;
}
.donate-x:hover { color: var(--ink); }
.donate-row { display: flex; gap: 12px; align-items: flex-start; padding-right: 16px; }
.donate-heart { color: var(--route); flex: none; margin-top: 1px; }
.donate-text { display: flex; flex-direction: column; gap: 4px; }
.donate-text strong { font-size: 15px; }
.donate-text span { font-size: 13px; color: var(--muted); line-height: 1.45; }
.donate-actions { display: flex; align-items: center; gap: 14px; margin-top: 14px; }
.donate-go { text-decoration: none; }
.donate-later { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 6px 2px; }
.donate-later:hover { color: var(--ink); }
@media (prefers-reduced-motion: reduce) { .donate-card { transition: opacity .25s; transform: none; } }

/* ============================ Pattern tab ============================ */
.pat-intro {
  display: flex; gap: 16px; align-items: flex-start; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.pat-intro-text { display: flex; flex-direction: column; gap: 5px; max-width: 720px; }
.pat-intro-text strong { font-size: 15px; }
.pat-intro-text span { font-size: 13px; color: var(--muted); line-height: 1.5; }
.pat-intro #pat-run { flex: none; }

/* progress pills */
.pat-progress { display: block; padding: 2px 0 8px; margin-bottom: 12px; max-height: 190px; overflow-y: auto; scroll-behavior: smooth; }
.pat-progress.pat-hide { display: none; }
.pat-pill {
  display: flex; align-items: center; gap: 9px; width: fit-content;
  max-width: 100%; padding: 6px 12px; margin: 0 0 6px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--hairline);
  font-size: 12.5px; color: var(--ink);
  opacity: 0; transform: translateY(6px); transition: opacity .25s, transform .25s;
}
.pat-pill.show { opacity: 1; transform: translateY(0); }
.pat-pill .pat-pill-t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pat-pill-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.pat-pill.pat-stage { font-weight: 600; }
.pat-pill.pat-stage .pat-pill-dot { background: var(--ink); }
.pat-pill.pat-hypo .pat-pill-dot { background: #E8A33D; }
.pat-pill.pat-find .pat-pill-dot { background: var(--trip, #1F9D55); }

/* result cards */
.pat-section {
  font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); margin: 18px 2px 10px;
}
.pat-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.pat-section { grid-column: 1 / -1; }
.pat-card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.pat-card-note { grid-column: span 1; }
.pat-mini { height: 150px; width: 100%; background: var(--paper); }
.pat-mini .leaflet-control-container { display: none; }
.pat-card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 5px; }
.pat-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pat-kind { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.pat-card-title { font-size: 16px; font-weight: 600; color: var(--ink); }
.pat-card-detail { font-size: 13px; color: var(--muted); line-height: 1.45; }
.pat-conf { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.pat-conf-high { background: rgba(31,157,85,.14); color: #1F7A45; }
.pat-conf-medium { background: rgba(232,163,61,.16); color: #A86A12; }
.pat-conf-low { background: rgba(92,100,108,.12); color: var(--muted); }
.pat-empty { color: var(--muted); font-size: 14px; padding: 20px 2px; }
@media (max-width: 560px) { .pat-intro { flex-direction: column; } .pat-intro #pat-run { align-self: stretch; } }

/* pattern tab: privacy notice + footer */
.pat-privacy {
  font-size: 12.5px; color: var(--ink);
  background: rgba(31,157,85,.08); border: 1px solid rgba(31,157,85,.25);
  border-radius: 8px; padding: 8px 10px; margin-top: 4px; line-height: 1.45;
}
.pat-foot {
  grid-column: 1 / -1; margin-top: 18px; padding: 12px 14px;
  font-size: 12.5px; color: var(--muted); line-height: 1.5;
  border-top: 1px solid var(--hairline);
}

.pat-log-toggle { display:inline-block; margin: 0 0 12px; font-size:12px; color:var(--muted); background:none; border:none; cursor:pointer; text-decoration:underline; }
.pat-log-toggle:hover{ color:var(--ink); }

.pat-card-years { font-size: 12px; color: var(--muted); margin-top: 2px; }

.pat-adopt-btn { display: inline-block; margin: 0 0 14px; }

/* exclude-zone editing */
.zone-edit-handle {
  width: 20px; height: 20px; border-radius: 50%;
  background: #1763D7; border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: grab;
}
.zone-edit-handle:active { cursor: grabbing; }
.zone-edit-bar {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 2000; display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; border-radius: 12px;
  background: var(--surface, #fff); border: 1px solid var(--hairline, #e3e3e3);
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
}
.zone-edit-bar .zone-edit-title { font-weight: 600; }
.zone-edit-bar .field.inline { margin: 0; }
.zone-edit-bar input[type="number"] { width: 72px; }
.travels-zone-name { margin: 0 0 4px; }
.travels-zone-name input { min-width: 160px; }

/* trips table tab */
.trips-table-holder { overflow-x: auto; }
.trips-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.trips-table th, .trips-table td { padding: 8px 10px; border-bottom: 1px solid var(--hairline); text-align: left; }
.trips-table th { font-weight: 600; color: var(--muted); position: sticky; top: 0; background: var(--surface); }
.trips-table .tt-num { text-align: right; white-space: nowrap; }
.trips-table tbody tr { cursor: pointer; }
.trips-table tbody tr:hover { background: rgba(0,0,0,.04); }
.trips-table .tt-title { font-weight: 500; }
.trips-table .tt-flags { display: inline-flex; gap: 3px; margin-right: 6px; vertical-align: middle; }
.trips-table .tt-flags .trip-flag svg { height: .85em; border-radius: 1px; }
.trips-table .tt-period { color: var(--muted); white-space: nowrap; }

/* removable map pin (Pattern tab) */
.map-pin-wrap { pointer-events: none; }
.map-pin { pointer-events: auto; position: absolute; transform: translate(-50%, -130%);
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface, #fff); color: var(--ink, #1a1a1a);
  border: 1px solid var(--hairline, #ddd); border-radius: 999px;
  padding: 5px 10px; box-shadow: 0 3px 12px rgba(0,0,0,.28); white-space: nowrap; font-size: 13px; }
.map-pin::after { content: ''; position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
  border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 7px solid var(--surface, #fff); }
.map-pin-dot { width: 9px; height: 9px; border-radius: 50%; background: #D7263D; flex: none; }
.map-pin-label { font-weight: 600; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.map-pin-close { border: none; background: none; cursor: pointer; font-size: 16px; line-height: 1;
  color: var(--muted, #888); padding: 0 0 0 2px; }
.map-pin-close:hover { color: var(--ink, #000); }
.pat-card-click { cursor: pointer; }
.pat-card-click:hover { border-color: var(--accent, #D7263D); }

/* pattern origin-destination table */
.pat-od-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 4px 0 14px; }
.pat-od-table th, .pat-od-table td { padding: 7px 9px; border-bottom: 1px solid var(--hairline); text-align: left; }
.pat-od-table th { font-weight: 600; color: var(--muted); }
.pat-od-table .pat-od-num { text-align: right; white-space: nowrap; }
.pat-od-row { cursor: pointer; }
.pat-od-row:hover { background: rgba(0,0,0,.04); }

/* OD year-window control */
.pat-od-ctrl { display: flex; align-items: center; gap: 10px; margin: 6px 0 8px; }
.pat-od-ctrl .pat-od-window { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 92px; text-align: center; }
.pat-od-empty { color: var(--muted); text-align: center; padding: 12px; }
.pat-od-cap { color: var(--muted); font-size: 12px; margin: -4px 0 8px; grid-column: 1 / -1; }
/* stepper + toggle + table/matrix share one full-width block so they stack
   vertically instead of each becoming a separate (side-by-side) grid item. */
.pat-od-box { grid-column: 1 / -1; }

/* OD view toggle + matrix heatmap */
.pat-od-toggle { display: flex; width: 100%; max-width: 240px; border: 1px solid var(--hairline); border-radius: 8px; overflow: hidden; margin: 6px 0 10px; }
.pat-od-toggle .pat-od-tab { flex: 1 1 0; min-width: 0; padding: 6px 14px; font-size: 13px; background: transparent; border: none; cursor: pointer; color: var(--muted); text-align: center; }
.pat-od-toggle .pat-od-tab + .pat-od-tab { border-left: 1px solid var(--hairline); }
.pat-od-toggle .pat-od-tab.is-active { background: var(--accent, #2d8c78); color: #fff; }
.pat-od-mwrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.pat-od-matrix { border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.pat-od-matrix th, .pat-od-matrix td { border: 1px solid var(--hairline); padding: 5px 8px; text-align: center; }
.pat-od-matrix .pat-od-corner { font-size: 11px; color: var(--muted); font-weight: 600; white-space: nowrap; vertical-align: bottom; }
.pat-od-matrix .pat-od-colhdr { width: 104px; min-width: 104px; max-width: 104px; vertical-align: bottom; font-weight: 500; font-size: 11px; line-height: 1.25; white-space: normal; word-break: break-word; }
.pat-od-matrix .pat-od-colhdr span { display: block; }
.pat-od-matrix .pat-od-rowhdr { text-align: left; white-space: normal; word-break: break-word; font-weight: 500; min-width: 120px; max-width: 200px; }
.pat-od-matrix .pat-od-cell { min-width: 30px; color: var(--text); }
.pat-od-matrix .pat-od-cell.has-val { cursor: pointer; }
.pat-od-matrix .pat-od-cell.is-diag { outline: 1px dashed var(--hairline); outline-offset: -2px; }

/* hidden Pac-Man easter egg overlay (entry: "Q" key) */
.pac-overlay { position: fixed; inset: 0; z-index: 4000; touch-action: none; cursor: pointer; }
.pac-overlay canvas { display: block; }

/* filter-panel summary: a single horizontal bar split by the active color-by
   dimension, above the distance + count values. Scoped to viewport ("Visible")
   or the whole filtered set ("All"). */
.filter-statsblock { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--hairline); }
.filter-bar { display: flex; width: 100%; height: 20px; border-radius: 5px; overflow: hidden; background: var(--hairline); margin-bottom: 10px; }
.filter-bar .fbar-seg { height: 100%; min-width: 0; transition: width .45s ease; }
.filter-bar .fbar-seg:hover { filter: brightness(1.08); }
/* styled tooltip for the bar (shares the map tooltip's look) */
.fbar-tip {
  position: fixed; z-index: 6000; pointer-events: none;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 8px; box-shadow: var(--shadow); color: var(--ink);
  padding: 9px 11px; font-family: var(--font);
  opacity: 0; transform: translateY(2px);
  transition: opacity .12s ease, transform .12s ease;
}
.fbar-tip.is-visible { opacity: 1; transform: translateY(0); }
.filter-stats { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; }
.filter-stats .fstat { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.filter-stats .fstat-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.filter-stats .fstat-val { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.filter-stats .fstat-toggle { display: flex; margin-left: auto; flex: none; border: 1px solid var(--hairline); border-radius: 8px; overflow: hidden; }
.filter-stats .fstat-tab { display: flex; align-items: center; justify-content: center; padding: 6px 9px; background: transparent; border: none; cursor: pointer; color: var(--muted); }
.filter-stats .fstat-tab svg { width: 16px; height: 16px; display: block; }
.filter-stats .fstat-tab + .fstat-tab { border-left: 1px solid var(--hairline); }
.filter-stats .fstat-tab.is-active { background: var(--ink, #22272B); color: #fff; }
