/* tbp — single stylesheet, mobile-first, iOS-flavored.
   Targets recent iOS Safari, Android Chrome/Firefox, desktop browsers.
   No vendor prefixes for properties widely supported since ~2022. */

:root {
    --color-bg: #d7d3c8;            /* Taunus Bikepacking brand */
    --color-surface: #efece5;        /* slight tonal step up from bg */
    --color-border: rgba(40, 30, 20, 0.18);
    --color-text: #1c1c1e;
    --color-text-secondary: #6c6c70;
    --color-tint: #007aff;
    --color-tint-inactive: #8e8e93;
    --color-tabbar-bg: rgba(215, 211, 200, 0.88);
    --color-status: #6c6c70;

    --tab-bar-h: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #000000;
        --color-surface: #1c1c1e;
        --color-border: rgba(120, 120, 128, 0.32);
        --color-text: #f2f2f7;
        --color-text-secondary: #98989f;
        --color-tabbar-bg: rgba(28, 28, 30, 0.85);
        --color-status: #98989f;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: contain;
}

a { color: var(--color-tint); text-decoration: none; }
a:hover { text-decoration: underline; }

/* App frame: full viewport on mobile, capped + centered on desktop. */
.app-frame {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    width: 100%;
    max-width: 768px;
    margin: 0 auto;
    background: var(--color-bg);
    position: relative;
}

/* Content area scrolls; bottom space accounts for the fixed tab bar. */
.content {
    flex: 1 1 auto;
    padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px
             calc(var(--tab-bar-h) + var(--safe-bottom) + 24px) 16px;
}

.view-header {
    padding: 8px 0 12px 0;
}

.view-header h1 {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.view-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.meta-count {
    font-size: 14px;
    color: var(--color-text-secondary);
}

.status-line {
    margin: 4px 0 0 0;
    font-size: 13px;
    color: var(--color-status);
}

.btn-refresh {
    margin-left: auto;
    appearance: none;
    background: transparent;
    border: 0;
    color: var(--color-tint);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    line-height: 0;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-refresh:hover { background: rgba(0, 122, 255, 0.08); }
.btn-refresh:disabled { color: var(--color-tint-inactive); cursor: progress; }
.btn-refresh.is-spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Riders list: simple iOS-style grouped row look. */
.riders-list {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--color-surface);
    border-radius: 12px;
    overflow: hidden;
}

.riders-group + .riders-group { margin-top: 20px; }

.riders-group-title {
    margin: 0 8px 6px 8px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-secondary);
}
.riders-group-count {
    margin-left: 4px;
    font-weight: 400;
    opacity: 0.7;
}

.rider-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid var(--color-border);
    min-height: 44px;
}
.rider-row:first-child { border-top: 0; }

/* Start number badge — leftmost column */
.rider-num {
    flex: 0 0 auto;
    min-width: 36px;
    padding: 2px 6px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.06);
    font-family: ui-monospace, SFMono-Regular, Menlo, "Roboto Mono", monospace;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    color: var(--color-text);
}
.rider-num:empty {
    background: transparent;
}
@media (prefers-color-scheme: dark) {
    .rider-num { background: rgba(255, 255, 255, 0.08); }
}

.rider-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 16px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rider-meta {
    flex: 0 0 auto;
    font-size: 13px;
    color: var(--color-text-secondary);
}

/* Country flag — populated lazily by JS after the main paint */
.rider-flag {
    flex: 0 0 24px;
    width: 24px;
    height: 18px;
    border-radius: 2px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.04);
}
.rider-flag img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
@media (prefers-color-scheme: dark) {
    .rider-flag { background: rgba(255, 255, 255, 0.06); }
}

/* Overall position — leading column, blue tabular-nums so the digits
   right-align cleanly across single, double, and triple-digit ranks. */
.rider-pos {
    flex: 0 0 32px;
    min-width: 32px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 16px;
    color: var(--color-tint);
}
.rider-pos:empty { color: transparent; }

.rider-row.is-scratched .rider-name,
.rider-row.is-scratched .rider-num,
.rider-row.is-scratched .rider-pos {
    color: var(--color-text-secondary);
}
.rider-row.is-scratched .rider-name {
    text-decoration: line-through;
}

.empty-list {
    margin: 24px 0;
    text-align: center;
    color: var(--color-text-secondary);
    font-size: 14px;
}

/* Info view */
.info-body {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 16px;
    margin-top: 8px;
}
.info-body p { margin: 0 0 12px 0; }
.info-grid {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 8px 16px;
    margin: 16px 0;
    font-size: 14px;
}
.info-grid dt { color: var(--color-text-secondary); }
.info-grid dd { margin: 0; word-break: break-all; }
.info-foot { margin-top: 16px !important; font-size: 13px; color: var(--color-text-secondary); }

/* Empty / "coming soon" state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 48px 16px;
    color: var(--color-text-secondary);
}
.empty-state svg { color: var(--color-tint-inactive); margin-bottom: 16px; }
.empty-state h2 { margin: 0 0 4px 0; font-size: 22px; color: var(--color-text); }
.empty-state p { margin: 0; font-size: 14px; }

/* ====== Bottom Tab Bar ====== */
.tab-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    height: calc(var(--tab-bar-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--color-tabbar-bg);
    border-top: 1px solid var(--color-border);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    z-index: 100;
}

/* On desktop the tab bar tracks the centered frame width. */
@media (min-width: 600px) {
    .tab-bar {
        left: 50%;
        right: auto;
        width: 100%;
        max-width: 768px;
        transform: translateX(-50%);
        border-left: 1px solid var(--color-border);
        border-right: 1px solid var(--color-border);
    }
}

.tab {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--color-tint-inactive);
    font-size: 10px;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}
.tab:hover { text-decoration: none; }
.tab[aria-selected="true"] { color: var(--color-tint); }
.tab-label {
    font-size: 10px;
    line-height: 1;
    font-weight: 500;
}

/* Hide views by default fallback; JS switches `hidden`. */
.view[hidden] { display: none; }

/* ====== Map view ====== */
/* The map view is special: it fills the viewport between the top safe
   area and the bottom tab bar, ignoring the default .content padding. */
.view-map {
    position: fixed;
    inset: 0 0 calc(var(--tab-bar-h) + var(--safe-bottom)) 0;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
    z-index: 1;
}
@media (min-width: 600px) {
    .view-map {
        left: 50%;
        right: auto;
        width: 100%;
        max-width: 768px;
        transform: translateX(-50%);
    }
}
.view-header--compact {
    padding: calc(var(--safe-top) + 8px) 16px 8px 16px;
    background: var(--color-bg);
}
.view-header--compact h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
}
.map-canvas {
    flex: 1 1 auto;
    width: 100%;
    background: var(--color-surface);
}
.map-fab {
    position: absolute;
    right: 16px;
    bottom: 16px;
    width: 48px;
    height: 48px;
    border: 0;
    border-radius: 50%;
    background: var(--color-surface);
    color: var(--color-tint);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;     /* above Leaflet panes */
}
.map-fab:hover { background: rgba(0, 122, 255, 0.08); }
.map-fab:active { transform: scale(0.96); }

/* Leaflet's attribution control sits over the map; on dark mode the
   default white background looks fine. */
.leaflet-container {
    font-family: var(--font);
    background: var(--color-surface);
}
.leaflet-popup-content {
    margin: 10px 12px;
    font-size: 13px;
    line-height: 1.4;
}
