/* =========================================================================
   Races group: race calendars, sports calendar, race + sports event singles.
   Loaded only on those templates (jrl_template_assets map). Mobile first.
   Builds on main.css components (.race-card, .tile, .facts, .chip, .register-cta …).
   ========================================================================= */

/* ---------- Calendar filters ---------- */
.cal-filters { display: grid; gap: var(--sp-3); margin: 0 0 var(--sp-5); padding: var(--sp-4); border-radius: var(--radius-lg); background: var(--c-bg-soft); }
.cal-filters__row { display: grid; gap: var(--sp-2); min-width: 0; }
.cal-filters__label { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--c-muted); }
.cal-filters__nav { min-width: 0; }
.cal-filters__chips { margin: 0; }
.cal-filters__chips .chip { min-height: var(--tap); white-space: nowrap; }
.cal-filters__chips .chip .flag { height: 1em; margin-right: .1em; }
.cal-filters__chips .chip .icon { margin-right: .1em; }
.cal-filters__state { grid-template-columns: minmax(0, 1fr); }
.cal-filters__state select { min-height: var(--tap); width: 100%; max-width: 360px; }
.js .cal-filters__submit { display: none; }
.cal-filters__clear { margin: 0; font-size: var(--fs-sm); font-weight: 600; }
.cal-filters__clear a { display: inline-flex; align-items: center; gap: .35em; min-height: var(--tap); }
@media (min-width: 768px) {
	.cal-filters__row { grid-template-columns: 96px minmax(0, 1fr); align-items: center; }
	.cal-filters__state { grid-template-columns: 96px minmax(0, 360px) auto; }
	.cal-filters__chips { flex-wrap: wrap; overflow: visible; mask-image: none; }
	.cal-filters__chips .chip { min-height: 36px; }
}

/* Compact calendar switcher (country / trail / triathlon calendars): one control, list in a popover. */
.cal-filters__row--switch { align-items: center; }
.cal-switch { position: relative; min-width: 0; }
.cal-switch__summary { display: inline-flex; align-items: center; gap: var(--sp-3); min-height: var(--tap); max-width: 100%; padding: 6px 8px 6px 14px; border: 1px solid var(--c-line-strong); border-radius: var(--radius-pill); background: #fff; color: var(--c-ink); font-weight: 700; cursor: pointer; list-style: none; }
.cal-switch__summary::-webkit-details-marker { display: none; }
.cal-switch__summary:hover { border-color: var(--c-ink); }
.cal-switch__summary:focus-visible { outline: 3px solid var(--c-focus); outline-offset: 2px; }
.cal-switch__current { display: inline-flex; align-items: center; gap: .45em; min-width: 0; }
.cal-switch__current .flag, .cal-switch__current .icon { flex: none; width: 1.25em; height: 1.25em; margin: 0; vertical-align: 0; }
.cal-switch__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-switch__change { display: inline-flex; align-items: center; gap: .25em; padding: 4px 10px; border-radius: var(--radius-pill); background: var(--c-bg-soft); color: var(--c-muted); font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; }
.cal-switch__chev { transition: transform .15s; }
.cal-switch[open] .cal-switch__chev { transform: rotate(180deg); }
.cal-switch__panel { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; width: min(320px, calc(100vw - 32px)); max-height: min(60vh, 440px); overflow-y: auto; padding: var(--sp-2); border: 1px solid var(--c-line-strong); border-radius: var(--radius); background: #fff; box-shadow: 0 12px 32px rgba(0,0,0,.16); }
.cal-switch__list { margin: 0; padding: 0; list-style: none; }
.cal-switch__link { display: flex; align-items: center; gap: .6em; min-height: var(--tap); padding: 6px 10px; border-radius: var(--radius-sm); color: var(--c-ink); font-weight: 600; text-decoration: none; }
.cal-switch__link:hover { background: var(--c-bg-soft); }
.cal-switch__link:focus-visible { outline: 3px solid var(--c-focus); outline-offset: -3px; }
.cal-switch__link .flag, .cal-switch__link > .icon { flex: none; width: 20px; height: 20px; margin: 0; vertical-align: 0; }
.cal-switch__link.is-current { background: var(--c-bg-muted); }
.cal-switch__check { margin-left: auto; color: var(--c-ink); }
/* Flag button in front of the calendar H1 (owner, 28 Nov 2026): flag + chevron, opens the list of
   calendars. It replaces both the plain flag in the H1 and the "Calendar" row of the filter card. */
.page-header__titlerow { display: flex; align-items: flex-start; gap: var(--sp-3); min-width: 0; }
.page-header__titlerow > .page-title { flex: 1 1 auto; min-width: 0; margin: 0; }
.cal-switch--flag { flex: none; margin-top: .2em; }
/* Since 29 Nov 2026 the flag button sits in the header actions, right of the H1, beside "Add a race":
   same height, centred on one line; its list opens towards the page (right-aligned) from 768px. */
.page-header__actions { align-items: center; }
.page-header__actions .cal-switch--flag { margin-top: 0; }
.page-header__actions .cal-switch--flag .cal-switch__summary { min-height: 44px; }
.page-header__actions .cal-add-race { min-height: 44px; }
@media (min-width: 768px) {
	.page-header__actions .cal-switch__panel { left: auto; right: 0; }
}
.cal-switch--flag .cal-switch__summary { gap: 4px; min-width: var(--tap); padding: 6px 8px 6px 10px; }
.cal-switch--flag .cal-switch__current .flag, .cal-switch--flag .cal-switch__current .icon { width: 28px; height: 28px; }
.cal-switch--flag .cal-switch__chev { color: var(--c-muted); }
/* Owner, 29 Nov 2026: flag + Add a race line up with the top of the H1 (not its last line), and the
   flag chip is black, so flags with white in them (Singapore, Japan, Indonesia) keep their edge. */
.page-header:has(> .page-header__actions .cal-switch--flag) { align-items: flex-start; }
.page-header__actions:has(.cal-switch--flag) { margin-top: var(--jrl-head-actions-top, 4px); }
/* Chip = the outlined "Add a race" button (white, 2px ink border, button corners); the flag gets its
   own hairline so white flags (Singapore, Japan, Indonesia) keep their edge (black chip was too heavy). */
.page-header__actions .cal-switch--flag .cal-switch__summary { border: 2px solid var(--c-ink); border-radius: var(--btn-radius); background: #fff; }
.page-header__actions .cal-switch--flag .cal-switch__summary:hover { background: var(--c-bg-soft); }
.page-header__actions .cal-switch--flag .cal-switch__chev { color: var(--c-ink); }
@media print { .cal-switch { display: none; } }

/* ---------- Featured tiles ---------- */
.cal-featured { margin: 0 0 var(--sp-6); }
.cal-featured__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--sp-2) var(--sp-4); padding-bottom: var(--sp-2); border-bottom: 1px solid var(--jrl-gold-border, #e0b84f); }
.cal-featured__title { display: flex; align-items: center; gap: .4em; margin: 0; font-size: var(--fs-xl); }
.cal-featured__title .icon { color: var(--jrl-gold-accent, #b8860b); }
.cal-featured__intro { margin: var(--sp-2) 0 0; color: var(--c-muted); font-size: var(--fs-sm); }
.cal-featured__carousel { margin-top: var(--sp-4); }
.cal-featured .tile__title { font-size: var(--fs-base); }
@media (min-width: 600px) and (max-width: 1023.98px) { .cal-featured__carousel .scroller { grid-auto-columns: 31%; } }

/* ---------- Sections + lists ---------- */
.cal-section { margin: 0 0 var(--sp-6); }
.cal-section__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2) var(--sp-4); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); background: var(--c-ink); color: #fff; }
.cal-section__title { display: flex; align-items: center; gap: .5em; margin: 0; font-size: var(--fs-lg); color: #fff; }
.cal-section__title .icon { flex: none; color: var(--jrl-gold-border, #e0b84f); } /* gold on ink: never red on calendars (R1) */
.cal-section__page { margin: 0; font-size: var(--fs-sm); color: #ddd; }
.cal-section__intro { margin: var(--sp-3) 0 0; color: var(--c-muted); font-size: var(--fs-sm); }
.cal-section--past .cal-section__head { background: var(--c-bg-muted); color: var(--c-ink); }
.cal-section--past .cal-section__title { color: var(--c-ink); }
.cal-section--past .cal-section__title .icon { color: var(--c-subtle); }
.cal-list__month { margin-top: var(--sp-4); }
/* One <section class="month-group"> per month (calendar-list parts, pass 5): a sticky .month-head
   (main.css) is contained by its section, so the next month's heading pushes it out instead of
   stacking on top of it. */
.month-group { display: block; }
.month-group > .cal-list__rows { margin-bottom: 0; }
.cal-list--past .cal-list__month { background: var(--c-bg-muted); color: var(--c-ink); }
.cal-list__rows { margin-bottom: 0; }
.race-list > li.race-list__ad { padding: var(--sp-3) 0; }
.cal-section .pagination { margin-top: var(--sp-5); }
.cal-section .empty-state { margin-top: var(--sp-4); }

/* ---------- Footer links ---------- */
.cal-more { margin: var(--sp-6) 0 0; }
.cal-more__title { margin: 0 0 var(--sp-3); font-size: var(--fs-md); text-transform: uppercase; letter-spacing: .06em; }
.cal-more__list { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--c-line); }
.cal-more__list a { display: flex; align-items: center; gap: var(--sp-2); min-height: var(--tap); padding: var(--sp-2) 0; border-bottom: 1px solid var(--c-line); font-weight: 600; text-decoration: none; }
.cal-more__list a:hover span { text-decoration: underline; }
.cal-more__chev { margin-left: auto; color: var(--c-subtle); }
@media (min-width: 768px) { .cal-more__list { grid-template-columns: 1fr 1fr; column-gap: var(--sp-6); } }

/* Sports calendar + single: templates/sports.css (loaded after this file on those pages). */

/* ---------- Event singles ----------
   Header (identity row, facts strip, CTA) and the sticky section nav: main.css "Event header"
   (shared with virtual-run singles). */
.event-body > .content-section,
.event-body > .gallery-block,
.event-body > .share-block { margin: var(--sp-6) 0 0; }
.event-body > :first-child { margin-top: 0; }
.event-body .content-section > h2,
.event-body .gallery-block__title { margin: 0 0 var(--sp-3); padding-bottom: var(--sp-2); border-bottom: 1px solid var(--c-line); font-size: var(--fs-xl); }
.event-body .content-section h3, .event-body .gallery-block h3 { margin: var(--sp-5) 0 var(--sp-3); font-size: var(--fs-lg); }
.event-body .content-section .gallery-block__title { padding-bottom: 0; border-bottom: 0; margin: var(--sp-5) 0 var(--sp-3); font-size: var(--fs-lg); } /* a gallery inside a section is a sub-heading: no second hairline */
.event-body .content-section > h2 + :is(h3, .gallery-block) > .gallery-block__title, .event-body .content-section > h2 + h3 { margin-top: var(--sp-3); }
.event-body .gallery-block { margin-bottom: 0; }
.event-text { overflow-wrap: anywhere; }
.event-text img { max-width: 100%; height: auto; }
.event-text table { display: block; max-width: 100%; overflow-x: auto; }
.event-text > :last-child { margin-bottom: 0; }
.event-muted { color: var(--c-muted); font-size: var(--fs-sm); }
.event-ecert { display: flex; align-items: center; gap: .5em; font-weight: 700; }
.event-body .register-cta { margin-top: var(--sp-4); }
.event-body .register-cta .btn { text-decoration: none; }
.event-body .btn-row .btn { text-decoration: none; }
.event-credits { margin: var(--sp-5) 0 0; color: var(--c-muted); font-size: var(--fs-sm); }

.related-races { margin: var(--sp-7) 0 0; }
.related-races__list { margin-bottom: 0; }

.event-disclaimer { margin: var(--sp-6) 0 0; padding-top: var(--sp-4); border-top: 1px solid var(--c-line); color: var(--c-subtle); font-size: var(--fs-xs); line-height: 1.5; }
.event-disclaimer__title { margin: 0 0 var(--sp-1); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.event-disclaimer ul { margin: 0; padding-left: 1.1em; }
.event-disclaimer li + li { margin-top: var(--sp-1); }

@media print {
	.cal-filters, .cal-featured, .cal-more { display: none !important; }
}

/* ---------- Fixes found in review (mirror of vrun.css / home.css; see FOUNDATION_REQUESTS) ---------- */

/* Featured tiles carry .race-card AND .tile (template-parts/cards/race.php). The later .race-card grid
   rule in main.css (64px | 1fr | auto) beat .tile and squeezed the desktop tiles into a 14px-wide text
   column (titles rendered one letter per line at 1280px). Restore the tile layout. */
.race-card.tile { display: flex; flex-direction: column; gap: var(--sp-2); padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; opacity: 1; }
.race-card.tile:hover, .race-card.tile:focus-within { background: none; }
@media (min-width: 768px) { .race-card.tile { grid-template-columns: none; gap: var(--sp-2); } }
.race-card.tile .tile__chip { white-space: nowrap; text-overflow: ellipsis; line-height: 1.25; } /* one line; a long distance list ends in "…", the full list is the chip's title (owner, 1 Dec 2026) */

/* Row meta lines (icon + text nowrap): moved to main.css next to .race-card__place / __dist. */

/* Tap targets. */
.event-text a.lb-link { display: inline-block; max-width: 100%; }

/* ---------- Recently held rows (calendar rules: muted rows, reviews link; no "Past race" chip, pass 6) ----------
   The reviews link sits in normal flow under the card (no negative margin: it overlapped the row). */
.cal-past__meta { margin: 0; padding: 0 var(--sp-2) var(--sp-2) calc(1px + var(--sp-3) + 64px + var(--sp-3)); font-size: var(--fs-sm); font-weight: 600; }
.cal-past__meta a { display: inline-flex; align-items: center; min-height: var(--tap); }
@media (min-width: 768px) { .cal-past__meta { padding-left: calc(1px + var(--sp-3) + 76px + var(--sp-4)); } }
/* One quiet link after a past list ("Search older races in the race database →"). */
.cal-list__more { margin: var(--sp-3) 0 0; font-size: var(--fs-sm); font-weight: 600; }
.cal-list__more a { display: inline-flex; align-items: center; gap: .35em; min-height: var(--tap); }

/* ---------- Distance landing pages (pass 5 pilot: /calendar-of-running-events-singapore/{full-marathon|half-marathon|10k}/) ----------
   inc/groups/races-distance.php + template-parts/races/distance-*.php. Full hairlines only (R2), gold /
   ink accents, never red outside CTAs (R1). */
.dist-summary { margin: 0 0 var(--sp-5); padding: var(--sp-2) var(--sp-4); border: 1px solid var(--c-line); border-radius: var(--radius); background: var(--c-bg-soft); }
.dist-summary__facts { margin: 0; border-top: 0; }
.dist-summary__facts .facts__row:last-child { border-bottom: 0; }
.dist-summary__note { color: var(--c-muted); font-size: var(--fs-sm); }
@media (min-width: 768px) { .dist-summary__facts { grid-template-columns: 1fr 1fr; column-gap: var(--sp-5); } }
.dist-intro { margin: 0 0 var(--sp-5); max-width: 72ch; }

.dist-faq { margin: 0 0 var(--sp-6); }
.dist-faq__title, .dist-training__title { margin: 0 0 var(--sp-3); font-size: var(--fs-xl); }
.dist-faq__item { padding: var(--sp-3) 0; border-top: 1px solid var(--c-line); }
.dist-faq__item:last-child { border-bottom: 1px solid var(--c-line); }
.dist-faq__q { margin: 0 0 var(--sp-1); font-size: var(--fs-md); }
.dist-faq__a { margin: 0; color: var(--c-text); max-width: 72ch; }

.dist-past__grid { margin-top: var(--sp-4); }
.dist-past__media img { object-fit: contain; background: #fff; }
.dist-past .tile__title { font-size: var(--fs-sm); }
.dist-past__more { margin: var(--sp-3) 0 0; }

.dist-training { margin: 0 0 var(--sp-6); }
.dist-training__list { display: grid; gap: var(--sp-3); margin: 0 0 var(--sp-3); padding: 0; list-style: none; }
@media (min-width: 768px) { .dist-training__list { grid-template-columns: 1fr 1fr; column-gap: var(--sp-5); } }
.dist-training__more { margin: 0; }
.dist-add { margin-top: var(--sp-5); }
