/* Leaflet tile seams: the real cure is in JS — we monkey-patch
   L.DomUtil.setPosition (in live_map.html, before the map is built)
   to round transform offsets to integer pixels. Chrome's compositor
   alpha-blends each tile's edge with whatever's behind it when tiles
   land on fractional offsets, and that blend lightens the boundary
   into a hair-thin grid of vertical/horizontal lines. CSS-only
   tricks (outline, translateZ, image-rendering) all stopped short
   of fixing it in Chrome — some made it worse. We just paint a
   neutral background so any stray pixel doesn't reveal the dark page bg. */
.leaflet-container {
    background: #f3f2ed;
}

/* Map preloader */
.map-loader {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #1a1a2e;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.3s ease;
}

.map-loader.fade-out {
    opacity: 0;
    pointer-events: none;
}

.map-loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--cx3-orange);
    border-radius: 50%;
    animation: map-spin 0.8s linear infinite;
}

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

/* Map scroll guard overlay */
.map-scroll-guard {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 900;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.25s ease;
}
.map-scroll-guard .map-scroll-msg {
    background: rgba(26, 26, 46, 0.7);
    color: #eee;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(4px);
}
.map-scroll-guard:hover .map-scroll-msg,
.map-scroll-guard.show-msg .map-scroll-msg {
    opacity: 1;
}
.map-scroll-guard.active {
    pointer-events: none;
    opacity: 0;
}

:root {
    --cx3-red: #DC3F22;
    --cx3-orange: #F68316;
    --cx3-dark-orange: #EC711A;
    --cx3-gold: #F7AB0F;
    --cx3-dark: #1a1a2e;
    --cx3-darker: #0f0f1a;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: #f5f5f0;
    min-height: 100vh;
    color: #333;
}

/* Inside the native Capacitor shell: paint the html element the same
   navy as the navbar so overscroll-bounce above the navbar shows a
   branded band, never a white flash from the WebView's default
   background. */
html.capacitor {
    background: linear-gradient(135deg, var(--cx3-dark) 0%, #16213e 100%);
}
html.capacitor body {
    overscroll-behavior-y: contain;
}

/* iOS rubber-band: bouncing the document past its end drags the whole
   viewport, so the fixed navbar and the footer band visibly slide away
   from the screen edges and snap back. Containing the overscroll on the
   document itself stops the bounce (and with it the drift) while leaving
   inner scrollers — modals, DataTables' horizontal scroll — free to
   bounce as they should. Applied to every browser, not just the
   Capacitor shell: the check-in desk works from Safari on an iPad. */
html, body {
    overscroll-behavior-y: none;
}

main {
    min-height: calc(100vh - 62px - 80px);
}


/* Navbar */
.cx3-navbar {
    background: linear-gradient(135deg, var(--cx3-dark) 0%, #16213e 100%) !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
}


.cx3-navbar .nav-link {
    color: rgba(255, 255, 255, 0.85) !important;
    transition: color 0.2s;
}

.cx3-navbar .nav-link:hover {
    color: var(--cx3-orange) !important;
}

.cx3-btn-register {
    background: var(--cx3-red);
    border-radius: 20px !important;
    padding: 6px 18px !important;
    color: white !important;
    font-weight: 600;
}

.cx3-btn-register:hover {
    background: var(--cx3-dark-orange);
}

.cx3-badge-role {
    background: var(--cx3-orange);
    font-size: 0.7em;
    vertical-align: middle;
}

/* Hero section */
.cx3-hero {
    background: linear-gradient(135deg, var(--cx3-dark) 0%, #16213e 60%, var(--cx3-red) 100%);
    color: white;
    padding: 60px 0;
    margin: -1.5rem -12px 2rem -12px;
    border-radius: 0 0 20px 20px;
    text-align: center;
}

.cx3-hero h1 {
    font-size: 2.5rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.cx3-hero .lead {
    color: var(--cx3-gold);
    font-weight: 600;
}

/* Cards */
.cx3-card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s, box-shadow 0.2s;
    overflow: hidden;
}
.cx3-card:has(.dataTable) {
    overflow: visible;
}

.cx3-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

.cx3-card-header {
    background: linear-gradient(135deg, var(--cx3-red), var(--cx3-orange));
    color: white;
    font-weight: 700;
    padding: 15px 20px;
    border: none;
}
.cx3-card:has(.dataTable) .cx3-card-header {
    border-radius: 12px 12px 0 0;
}
.cx3-card:has(.dataTable) .card-body:last-child {
    border-radius: 0 0 12px 12px;
}

.cx3-card .card-body {
    padding: 20px;
}

/* Race cards */
.race-distance {
    font-size: 2rem;
    font-weight: 800;
    color: var(--cx3-red);
}

.race-elevation {
    color: var(--cx3-orange);
    font-weight: 600;
}

.race-spots {
    font-size: 0.85em;
    color: #666;
}

.race-spots .spots-count {
    font-weight: 700;
    color: var(--cx3-red);
}

/* Buttons */
.btn-cx3 {
    background: linear-gradient(135deg, var(--cx3-red), var(--cx3-dark-orange));
    border: none;
    color: white;
    font-weight: 600;
    border-radius: 8px;
    padding: 10px 24px;
    transition: all 0.2s;
}

.btn-cx3:hover {
    background: linear-gradient(135deg, var(--cx3-dark-orange), var(--cx3-orange));
    color: white;
    transform: translateY(-1px);
}

/* btn-sm modifier — see .btn-cx3-outline.btn-sm below for the same
   reason: stylesheet order otherwise lets cx3's padding override
   Bootstrap's compact .btn-sm padding. */
.btn-cx3.btn-sm {
    padding: 4px 12px;
    font-size: 0.85rem;
    /* btn-cx3 has no border, but btn-cx3-outline.btn-sm has border-width:1px
       — without a transparent border here the two render 2px taller/shorter
       than each other in the same row, which reads as "different radius". */
    border: 1px solid transparent;
}

.btn-cx3-outline {
    border: 2px solid var(--cx3-red);
    color: var(--cx3-red);
    background: transparent;
    font-weight: 600;
    border-radius: 8px;
    padding: 8px 22px;
    transition: all 0.2s;
}

.btn-cx3-outline:hover {
    background: var(--cx3-red);
    color: white;
}

/* btn-sm modifier — without this the cx3 outline class wins over
   Bootstrap's .btn-sm padding rule (later in stylesheet order) and
   .btn btn-sm btn-cx3-outline renders at the full cx3 height instead
   of the compact size next to .btn-sm btn-outline-danger etc. */
.btn-cx3-outline.btn-sm {
    padding: 4px 12px;
    font-size: 0.85rem;
    border-width: 1px;
}

/* Match the 8px radius of .btn-cx3-outline so Bootstrap's small
   danger/secondary outline buttons line up cleanly alongside the
   custom cx3 buttons in the same card/row. Without this the corners
   default to .25rem and look mismatched next to cx3-outline.btn-sm. */
.btn-outline-danger.btn-sm,
.btn-outline-secondary.btn-sm {
    border-radius: 8px;
}

/* Admin participants tables: the Tracking column (safety-manager only)
   carries a switch that's awkward to tap on small screens and not the
   key information when triaging the list — hide on mobile/tablet and
   keep it on desktop where there's room. DataTables data-priority
   gives the same hint but a CSS hide is deterministic and survives
   responsive recalculations. */
@media (max-width: 991.98px) {
    .cx3-table .col-tracking { display: none !important; }
    /* Actions column on the per-race participants table holds the
       status-change select + send-declaration button. Both are quite
       wide and would force horizontal overflow on phones; the same
       actions are reachable from the per-row edit page. */
    .cx3-table .col-actions { display: none !important; }
}

/* Tracking switch grey-out when the race is outside the live window
   (race_date−2h … race_date+5h). Visually communicates "you can't
   accidentally push a notification right now"; the actual disabled
   attribute on the checkbox is what blocks the click. */
.cx3-switch-disabled { opacity: 0.4; cursor: not-allowed; }
.cx3-switch-disabled .cx3-slider { background: #999; }

/* Declaration column on admin participants tables: badge + PDF
   button + audit-lock button all on one line on desktop. Mobile
   collapses the column into the DataTables child row anyway. */
@media (min-width: 992px) {
    .cx3-table .col-declaration { min-width: 200px; white-space: nowrap; }
}

/* Dashboard "My Races" header: on phones the buttons row wraps onto
   its own line below the heading via flex-wrap, and we want it to
   span the row so the two buttons can flex-fill to a clean 50/50.
   Stock Bootstrap doesn't ship responsive w-* utilities, hence this
   scoped rule. */
@media (max-width: 767.98px) {
    .my-races-actions { width: 100%; }
}

/* iPhone safe-area for centred modals. Bootstrap's default margins
   leave the dialog under the dynamic island at the top and behind the
   home indicator + rounded screen corners at the bottom. Pad
   aggressively inside the native shell — desktop is unaffected.
   !important so no later cascade (Bootstrap utilities, page-level
   styles) can win. */
html.capacitor .modal {
    padding-top: env(safe-area-inset-top, 0px) !important;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 2rem) !important;
    /* Side padding lives on .modal (not .modal-dialog) so the dialog
       can still use `margin: auto` to horizontally centre when the
       viewport is wider than its max-width. The previous rule fixed
       margin-left/right to 1rem, which left-aligned the dialog on any
       screen above ~500 px (tablets, landscape phones). */
    padding-left: 1rem !important;
    padding-right: 1rem !important;
}
html.capacitor .modal-dialog {
    margin-top: 0.5rem !important;
    margin-bottom: 0.5rem !important;
    margin-left: auto !important;
    margin-right: auto !important;
}
html.capacitor .modal-dialog-centered {
    min-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 3rem) !important;
}
html.capacitor .modal-content {
    max-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 4rem) !important;
}
html.capacitor .modal-dialog-scrollable .modal-content {
    max-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 4rem) !important;
}

/* Icon-only action buttons (tables, lists) */
.action-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border-width: 2px;
    font-size: 0.85rem;
}
@media (max-width: 575.98px) {
    .action-btn {
        width: 26px;
        height: 26px;
        border-width: 1px;
        border-radius: 6px;
        font-size: 0.75rem;
    }
}

/* Forms */
.cx3-form {
    max-width: 560px;
    margin: 0 auto;
}
.auth-wide .cx3-form {
    max-width: none;
}

.cx3-form .form-label {
    font-weight: 600;
    color: #444;
    font-size: 0.9rem;
}

.cx3-form .form-control:focus,
.cx3-form .form-select:focus {
    border-color: var(--cx3-orange);
    box-shadow: 0 0 0 0.2rem rgba(246, 131, 22, 0.25);
}

/* Stats */
.cx3-stat {
    text-align: center;
    padding: 20px;
}

.cx3-stat .stat-number {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--cx3-red);
}

.cx3-stat .stat-label {
    color: #666;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 1px;
}

/* Status badges */
.badge-confirmed {
    background-color: #28a745;
}

.badge-pending {
    background-color: var(--cx3-orange);
}

.badge-cancelled {
    background-color: #dc3545;
}

.badge-finished {
    background-color: var(--cx3-gold);
    color: #333;
}

.badge-pending_payment {
    background-color: var(--cx3-orange);
    color: white;
}

/* Table */
.cx3-table thead {
    background: linear-gradient(135deg, var(--cx3-dark), #16213e);
    color: white;
}

.cx3-table thead th {
    border: none;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

/* Responsive table wrapper */
.table-responsive-cx3 {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
div.dt-container > .row { flex-wrap: wrap !important; }

/* Footer */
.cx3-footer {
    background: var(--cx3-darker);
    color: rgba(255, 255, 255, 0.7);
}

/* Auth pages */
.auth-container {
    max-width: 480px;
    margin: 40px auto;
}
.auth-container.auth-wide {
    max-width: 1200px;
}

.auth-container .cx3-card-header {
    text-align: center;
    padding: 25px;
}

.auth-container .cx3-card-header img {
    max-width: 160px;
    margin-bottom: 10px;
}

/* Dashboard registration cards */
.reg-card {
    border-left: 4px solid var(--cx3-red);
}

.reg-card.cancelled {
    border-left-color: #dc3545;
    opacity: 0.7;
}

/* Language switcher */
.lang-switcher {
    display: flex;
    align-items: center;
    gap: 6px;
}

.lang-link {
    color: rgba(255, 255, 255, 0.5);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s;
}

.lang-link:hover {
    color: white;
}

.lang-link.active {
    color: white;
    background: var(--cx3-red);
}

/* ── Responsive ─────────────────────────────────────────────── */

/* Small phones */
@media (max-width: 575.98px) {
    /* Hero */
    .cx3-hero {
        padding: 30px 0;
        margin: -1.5rem 0 1.5rem 0;
        border-radius: 0;
    }

    .cx3-hero h1 {
        font-size: 1.4rem;
        letter-spacing: 1px;
    }

    .cx3-hero .lead {
        font-size: 0.85rem;
    }

    .cx3-hero img {
        max-width: 150px !important;
    }

    /* Container padding */
    main.container {
        padding-left: 12px;
        padding-right: 12px;
    }

    /* Page headers — stack vertically */
    .page-header-responsive {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .page-header-responsive .d-flex {
        width: 100%;
    }

    .page-header-responsive .btn {
        flex: 1;
        text-align: center;
    }

    /* Page title */
    h2 {
        font-size: 1.3rem;
    }

    /* Cards */
    .cx3-card:hover {
        transform: none;
    }

    .cx3-card .card-body {
        padding: 14px;
    }

    .cx3-card-header {
        padding: 12px 14px;
    }

    /* Race cards */
    .race-distance {
        font-size: 1.4rem;
    }

    /* Buttons — smaller on mobile */
    .btn-cx3 {
        padding: 8px 16px;
        font-size: 0.9rem;
    }

    .btn-cx3-outline {
        padding: 6px 14px;
        font-size: 0.85rem;
    }

    .btn-sm {
        font-size: 0.78rem;
        padding: 4px 10px;
    }

    /* Stats */
    .cx3-stat {
        padding: 14px 10px;
    }

    .cx3-stat .stat-number {
        font-size: 1.8rem;
    }

    .cx3-stat .stat-label {
        font-size: 0.7rem;
    }

    /* Invoice card */
    .card-body.d-flex.flex-wrap {
        flex-direction: column;
        align-items: flex-start !important;
    }

    .card-body.d-flex.flex-wrap .me-auto {
        margin-right: 0 !important;
        margin-bottom: 0.5rem;
    }

    /* Navbar */
    .cx3-navbar .navbar-brand img {
        height: 30px;
    }

    .cx3-navbar .navbar-brand span {
        font-size: 0.9rem;
    }

    /* Auth */
    .auth-container {
        margin: 20px auto;
    }

    /* Footer */
    .cx3-footer {
        font-size: 0.85rem;
    }

    .cx3-footer img {
        height: 22px !important;
    }
}

/* Tablets */
@media (max-width: 767.98px) {
    .cx3-hero h1 {
        font-size: 1.6rem;
    }

    .cx3-hero {
        padding: 40px 0;
        margin: -1.5rem 0 1.5rem 0;
        border-radius: 0;
    }

    .race-distance {
        font-size: 1.5rem;
    }

    .cx3-stat .stat-number {
        font-size: 1.8rem;
    }

    /* Disable hover lift on touch */
    .cx3-card:hover {
        transform: none;
    }

    /* Admin dashboard action grid */
    .col-md-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* Tables — horizontal scroll on small screens */
@media (max-width: 991.98px) {
    .card-body.p-0 {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .cx3-table:not(.cx3-table-responsive):not(.dataTable) {
        min-width: 700px;
    }

    .cx3-table:not(.cx3-table-responsive):not(.dataTable) td,
    .cx3-table:not(.cx3-table-responsive):not(.dataTable) th {
        white-space: nowrap;
    }

    .cx3-table td, .cx3-table th {
        font-size: 0.85rem;
        padding: 10px 12px;
    }
}

/* Medium screens */
@media (min-width: 576px) and (max-width: 991.98px) {
    .cx3-hero h1 {
        font-size: 2rem;
    }

    .cx3-hero img {
        max-width: 200px !important;
    }
}

/* DataTables overrides */
.dt-buttons .buttons-excel {
    padding: 0.3rem 0.6rem !important;
    font-size: 0.875rem !important;
    line-height: 1.5 !important;
}
@media (max-width: 575.98px) {
    .dt-buttons .buttons-excel span span {
        display: none;
    }
    .dt-buttons .buttons-excel {
        padding: 0.3rem 0.5rem !important;
    }
}
table.dataTable thead th {
    cursor: pointer;
}
table.dataTable thead th.sorting::after,
table.dataTable thead th.sorting_asc::after,
table.dataTable thead th.sorting_desc::after {
    opacity: 0.5;
}

/* PWA landscape blocker — only in standalone (installed) mode on mobile */
.pwa-landscape-block {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 99999;
    background: var(--cx3-dark);
    color: white;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    font-size: 1.1rem;
    font-weight: 600;
}
@media (display-mode: standalone) and (orientation: landscape) and (max-height: 500px) {
    .pwa-landscape-block {
        display: flex;
    }
}

/* iOS-style toggle switch — used in the profile's tracking section. */
.cx3-switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.cx3-switch input { opacity: 0; width: 0; height: 0; }
.cx3-slider { position: absolute; cursor: pointer; inset: 0; background: #ccc; transition: .25s; border-radius: 28px; }
.cx3-slider:before { position: absolute; content: ""; height: 22px; width: 22px; left: 3px; top: 3px; background: #fff; transition: .25s; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.cx3-switch input:checked + .cx3-slider { background: var(--cx3-red); }
.cx3-switch input:checked + .cx3-slider:before { transform: translateX(22px); }


/* iOS Capacitor WKWebView auto-zooms when an input with
   font-size < 16px is focused, and reliably FAILS to zoom back
   out after the keyboard dismisses. Forcing >= 16px on every
   text-like form control prevents the zoom-in in the first
   place. `max(16px, 1rem)` keeps the visual scale on viewports
   that already use a larger base. Non-text inputs (checkbox,
   radio, button, file, reset, submit) excluded — they don't
   trigger zoom and we don't want to inflate their hit areas. */
input:not([type=checkbox]):not([type=radio]):not([type=button]):not([type=submit]):not([type=file]):not([type=reset]):not([type=color]):not([type=range]),
select,
textarea {
    font-size: max(16px, 1rem);
}

