/* Map Tracking — the public pages.
 *
 * These pages do NOT load src/tool-page.css (they are session-free and never include
 * tools/tool-header.php), so this file carries its own reset. Everything is .mt- prefixed anyway,
 * for the same reason derbybrackets/src/derby.css is: if either page ever ends up beside another
 * stylesheet, nothing here may leak.
 *
 * MOBILE IS THE DEFAULT CASE, NOT A BREAKPOINT. Almost everyone watching a race is standing at the
 * side of a road holding a phone, so the phone layout is what the plain rules describe and the
 * desktop layout is the media query. The map gets the whole screen and the racer list is a sheet
 * that comes up over it. */

:root {
    --mt-ink: #12303f;
    --mt-ink-soft: #5b7383;
    --mt-line: #dde5ea;
    --mt-bg: #f4f7f9;
    --mt-panel: #ffffff;
    --mt-accent: #1d6fa5;
    --mt-live: #1f8a54;
    --mt-warn: #8a5a12;
    --mt-bad: #a8423c;
    --mt-fav: #d68910;
    /* Safe-area insets, so the sheet clears the home indicator and the top bar clears a notch. */
    --mt-safe-b: env(safe-area-inset-bottom, 0px);
    --mt-safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--mt-ink);
    background: var(--mt-bg);
    -webkit-text-size-adjust: 100%;
}

/* ============================ the event list ============================= */

.mt-list-body { min-height: 100vh; }

.mt-list-head {
    padding: calc(1.25rem + var(--mt-safe-t)) 1rem 1rem;
    background: #11212b;
    color: #fff;
}
.mt-list-head h1 { margin: 0; font-size: 1.35rem; letter-spacing: 0.01em; }
.mt-list-sub { margin: 0.35rem 0 0; font-size: 0.9rem; color: #a9bcc7; }

.mt-list-main { padding: 1rem; max-width: 640px; margin: 0 auto; }

.mt-events { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }

.mt-ev-link {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.7rem;
    background: var(--mt-panel);
    border: 1px solid var(--mt-line);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    /* 44px is the smallest reliable touch target; the icon alone already clears it. */
    min-height: 56px;
}
.mt-ev-link:active { background: #eef3f6; }

.mt-ev-icon {
    width: 48px; height: 48px;
    flex: 0 0 48px;
    border-radius: 10px;
    object-fit: cover;
    background: #dfe7ec;
}
.mt-ev-initials {
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: 0.02em;
}

.mt-ev-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mt-ev-name {
    font-weight: 600; font-size: 1rem; line-height: 1.25;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mt-ev-date { font-size: 0.82rem; color: var(--mt-ink-soft); }

.mt-badge {
    flex: 0 0 auto;
    font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
    padding: 3px 8px; border-radius: 10px; white-space: nowrap;
    background: #eceff1; color: #4a5c66;
}
.mt-badge-live { background: #d8f0e3; color: var(--mt-live); }
.mt-badge-upcoming { background: #e2ecf5; color: var(--mt-accent); }
.mt-badge-finished { background: #ececec; color: #6b6b6b; }

.mt-empty, .mt-list-error {
    padding: 1.25rem 0.25rem; color: var(--mt-ink-soft); font-size: 0.92rem; text-align: center;
}
.mt-list-error { color: var(--mt-bad); }

/* ============================== the map page ============================== */

.mt-body { overflow: hidden; }

.mt-fatal { padding: 3rem 1.5rem; text-align: center; }
.mt-fatal h1 { font-size: 1.25rem; }
.mt-fatal a { color: var(--mt-accent); }

.mt-app {
    position: fixed;
    inset: 0;
    /* 100dvh, with a vh fallback: on mobile Safari 100vh is taller than the visible viewport and
       puts the bottom of the sheet under the browser chrome. */
    height: 100vh;
    height: 100dvh;
}

.mt-map { position: absolute; inset: 0; }

/* ---- top bar ---- */

.mt-top {
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: calc(0.5rem + var(--mt-safe-t)) 0.6rem 0.5rem;
    background: linear-gradient(#11212beb, #11212bcc 70%, #11212b00);
    color: #fff;
}

.mt-back {
    flex: 0 0 auto;
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; text-decoration: none; font-size: 1.3rem; line-height: 1;
    border-radius: 8px;
}
.mt-back:active { background: #ffffff22; }

.mt-top-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mt-top-name {
    font-weight: 600; font-size: 1rem; line-height: 1.2;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mt-top-sub { font-size: 0.75rem; color: #a9bcc7; }

.mt-fav-toggle {
    flex: 0 0 auto;
    width: 44px; height: 44px;
    border: 1px solid #ffffff33;
    background: #ffffff14;
    color: #ffffffcc;
    border-radius: 10px;
    font-size: 1.2rem;
    cursor: pointer;
}
.mt-fav-toggle.on { background: var(--mt-fav); border-color: var(--mt-fav); color: #fff; }

.mt-banner {
    position: absolute;
    top: calc(3.6rem + var(--mt-safe-t));
    left: 0.6rem; right: 0.6rem;
    z-index: 3;
    margin: 0;
    padding: 0.5rem 0.7rem;
    border-radius: 8px;
    font-size: 0.82rem;
    background: #fff5e0;
    color: var(--mt-warn);
    border: 1px solid #f0dcb4;
}
.mt-banner-bad { background: #fdecea; color: var(--mt-bad); border-color: #f3c9c5; }

/* ---- the bottom sheet ---- */

.mt-sheet {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    z-index: 4;
    background: var(--mt-panel);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.16);
    display: flex;
    flex-direction: column;
    /* Collapsed: just the grip and the counts. Opening is a height change rather than a
       transform, so the list inside keeps its own scroll position. */
    max-height: 72vh;
    max-height: 72dvh;
    transition: max-height 0.22s ease;
}
body:not(.mt-sheet-open) .mt-sheet { max-height: calc(3.6rem + var(--mt-safe-b)); }

.mt-sheet-grip {
    flex: 0 0 auto;
    width: 100%;
    border: 0;
    background: none;
    padding: 0.5rem 1rem 0.4rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    font: inherit;
    color: var(--mt-ink-soft);
}
.mt-grip-bar {
    width: 40px; height: 4px; border-radius: 2px; background: #c8d3da;
}
.mt-counts { font-size: 0.8rem; }

.mt-sheet-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 0.75rem calc(0.75rem + var(--mt-safe-b));
}

.mt-search-row { position: sticky; top: 0; background: var(--mt-panel); padding: 0.25rem 0 0.5rem; }
.mt-search {
    width: 100%;
    padding: 0.6rem 0.7rem;
    font-size: 16px;            /* under 16px and iOS zooms the whole page on focus */
    border: 1px solid var(--mt-line);
    border-radius: 10px;
    background: #fbfdfe;
    color: inherit;
}

.mt-sec-head {
    margin: 0.6rem 0 0.35rem;
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--mt-ink-soft); font-weight: 700;
}
.mt-sec-n { font-weight: 600; }

.mt-rows { list-style: none; margin: 0; padding: 0; }

.mt-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.25rem;
    border-bottom: 1px solid #eef2f5;
    min-height: 44px;
    cursor: pointer;
}
.mt-row-fav { background: #fffaf0; }
.mt-row-flash { animation: mt-flash 1.4s ease; }
@keyframes mt-flash { from { background: #fff0c2; } to { background: transparent; } }

.mt-star {
    flex: 0 0 auto;
    width: 36px; height: 36px;
    border: 0; background: none; cursor: pointer;
    color: #c3ced5; font-size: 1.15rem; line-height: 1;
    border-radius: 8px;
}
.mt-star.on { color: var(--mt-fav); }

.mt-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mt-row-1 {
    font-size: 0.95rem; font-weight: 600; line-height: 1.25;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mt-row-2 {
    font-size: 0.78rem; color: var(--mt-ink-soft);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mt-row-note {
    flex: 0 0 auto;
    font-size: 0.72rem; color: var(--mt-ink-soft); text-align: right; max-width: 45%;
}

/* ---- desktop ---- */

@media (min-width: 820px) {
    /* The sheet becomes a side panel; the map keeps the rest. Nothing overlaps, so the sheet is
       always open and the grip is only a header. */
    .mt-sheet {
        top: 0; bottom: 0; right: 0; left: auto;
        width: 360px;
        max-height: none;
        border-radius: 0;
        box-shadow: -2px 0 14px rgba(0, 0, 0, 0.1);
    }
    body:not(.mt-sheet-open) .mt-sheet { max-height: none; }
    .mt-map { right: 360px; }
    .mt-top { right: 360px; }
    .mt-banner { right: calc(360px + 0.6rem); }
    .mt-grip-bar { display: none; }
    .mt-sheet-grip { cursor: default; padding-top: 0.9rem; }
    .mt-row:hover { background: #f2f7fa; }
}

@media (prefers-reduced-motion: reduce) {
    .mt-sheet { transition: none; }
    .mt-row-flash { animation: none; }
}
