/* ================================================================
   app.css — PenOC PWA styles
   Mobile-first. The app fills the full screen height with a fixed
   header at the top and a fixed nav bar at the bottom. The content
   area between them scrolls independently.
================================================================ */


/* ----------------------------------------------------------------
   DESIGN TOKENS
   Central place to update colours and fonts.
   Change a value here and it updates everywhere.
---------------------------------------------------------------- */
:root {
    --orange:      #ff6720;
    --dark-grey:   #616365;
    --grey:        #808285;
    --light-grey:  #bcbcc0;
    --white:       #ffffff;
    --font:        'Roboto', sans-serif;

    --header-height:  56px;
    --nav-height:     64px;
}


/* ----------------------------------------------------------------
   RESET & BASE
   Removes default browser margins/padding. Box-sizing: border-box
   means padding and borders are included in an element's width —
   avoids surprising overflow.
---------------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    font-weight: 300;
    background-color: var(--light-grey);
    color: #333;

    /* Prevent the page itself from scrolling — each screen scrolls internally */
    overflow: hidden;
    height: 100dvh;  /* dvh = dynamic viewport height, accounts for mobile browser chrome */
}


/* ----------------------------------------------------------------
   HEADER
   Fixed at the top. Shows the PenOC logo and current screen title.
---------------------------------------------------------------- */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: var(--dark-grey);
    color: var(--white);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.header-logo {
    height: 36px;
    width: 36px;
    border-radius: 6px;
}

.header-title {
    font-size: 1.1rem;
    font-weight: 500;
}


/* ----------------------------------------------------------------
   SCREENS
   Each screen is a full-height scrollable area that sits between
   the header and nav bar. Only one screen is visible at a time —
   app.js toggles the "active" class.
---------------------------------------------------------------- */
.screen {
    display: none;               /* hidden by default */
    position: fixed;
    top: var(--header-height);
    bottom: var(--nav-height);
    left: 0;
    right: 0;
    overflow-y: auto;            /* this area scrolls, not the page */
    padding: 16px;
    -webkit-overflow-scrolling: touch;  /* smooth momentum scrolling on iOS */
}

.screen.active {
    display: block;
}


/* ----------------------------------------------------------------
   BOTTOM NAVIGATION BAR
   Fixed at the bottom. Four tabs — icon above label.
   The active tab is highlighted in orange.
---------------------------------------------------------------- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background-color: var(--dark-grey);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.2);
}

.nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--light-grey);
    cursor: pointer;
    padding: 8px 0;
    transition: color 0.15s ease;
}

.nav-tab.active {
    color: var(--orange);
}

.nav-tab .material-symbols-outlined {
    font-size: 26px;
}

.nav-label {
    font-family: var(--font);
    font-size: 0.7rem;
    font-weight: 400;
}


/* ----------------------------------------------------------------
   HOME SCREEN — HERO
   Full-width branding section at the top of the home screen.
   Dark grey background with the white/orange club logo centred.
---------------------------------------------------------------- */
.hero {
    background-color: var(--dark-grey);
    border-radius: 12px;
    padding: 28px 16px 24px;
    text-align: center;
    margin-bottom: 16px;
}

.hero-title {
    color: var(--white);
    font-size: 1.8rem;
    font-weight: 500;
    margin-bottom: 4px;
}

.hero-tagline {
    color: var(--grey);
    font-size: 0.8rem;
    font-weight: 300;
}


/* ----------------------------------------------------------------
   HOME SCREEN — NEXT RACE CARD
   Prominent card for the next upcoming event.
   Orange left border distinguishes it from regular cards.
---------------------------------------------------------------- */
.next-race-card {
    background-color: var(--white);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 12px;
    border-left: 4px solid var(--orange);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.next-race-label {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--orange);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}

.next-race-name {
    font-size: 1.05rem;
    font-weight: 500;
    color: #222;
    margin-bottom: 4px;
}

.next-race-detail {
    font-size: 0.85rem;
    color: var(--grey);
    margin-bottom: 2px;
}

.entry-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 7px 14px;
    background-color: var(--orange);
    color: var(--white);
    border: none;
    border-radius: 20px;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
}

.entry-btn .material-symbols-outlined {
    font-size: 16px;
}


/* ----------------------------------------------------------------
   HOME SCREEN — QUICK LINKS
   Three equal-width buttons linking to the other main screens.
---------------------------------------------------------------- */
.quick-links {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.quick-link-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    background-color: var(--white);
    border: none;
    border-radius: 10px;
    padding: 14px 8px;
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--dark-grey);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    transition: background-color 0.15s ease;
}

.quick-link-btn .material-symbols-outlined {
    font-size: 28px;
    color: var(--orange);
}

.quick-link-btn:active {
    background-color: #f0f0f0;
}


/* ----------------------------------------------------------------
   CARDS
   Used for each race, event, and news item.
---------------------------------------------------------------- */
.card {
    background-color: var(--white);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    transition: box-shadow 0.15s ease;
}

.card:active {
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.card-title {
    font-size: 1rem;
    font-weight: 500;
    color: #222;
    margin-bottom: 4px;
}

.card-subtitle {
    font-size: 0.85rem;
    color: var(--grey);
}

.card-badge {
    display: inline-block;
    background-color: var(--orange);
    color: var(--white);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 12px;
    margin-top: 6px;
}


/* ----------------------------------------------------------------
   BACK BUTTON
   Shown on the results detail screen (course list within an event).
---------------------------------------------------------------- */
.back-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--orange);
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0 0 14px 0;
}


/* ----------------------------------------------------------------
   RESULTS TABLE
   Used on the course results screen.
---------------------------------------------------------------- */
.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.results-table th {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 2px solid var(--orange);
    font-weight: 500;
    color: var(--dark-grey);
}

.results-table td {
    padding: 8px;
    border-bottom: 1px solid var(--light-grey);
}

.results-table tr:last-child td {
    border-bottom: none;
}

.clickable-row {
    cursor: pointer;
}

.clickable-row:active {
    background-color: #f5f5f5;
}

.pos-cell {
    font-weight: 500;
    color: var(--orange);
    width: 36px;
}


/* ----------------------------------------------------------------
   NEWS ITEMS
   Tapping a news card opens the MailChimp archive URL in the
   device's browser (a new tab).
---------------------------------------------------------------- */
.news-date {
    font-size: 0.78rem;
    color: var(--grey);
    margin-top: 4px;
}


/* ----------------------------------------------------------------
   UTILITY
---------------------------------------------------------------- */
.loading-msg {
    color: var(--grey);
    text-align: center;
    margin-top: 32px;
    font-size: 0.95rem;
}

.error-msg {
    color: var(--orange);
    text-align: center;
    margin-top: 32px;
    font-size: 0.95rem;
}

.section-heading {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--grey);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
}


/* ----------------------------------------------------------------
   NOTIFICATION OPT-IN
   Shown on the home screen when the user hasn't yet granted
   notification permission. Hidden once they subscribe or deny.
---------------------------------------------------------------- */
.notify-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background-color: var(--white);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.notify-card .material-symbols-outlined {
    font-size: 28px;
    color: var(--orange);
    flex-shrink: 0;
}

.notify-card-text {
    flex: 1;
}

.notify-card-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: #222;
    margin-bottom: 2px;
}

.notify-card-subtitle {
    font-size: 0.78rem;
    color: var(--grey);
}

.notify-btn {
    background-color: var(--orange);
    color: var(--white);
    border: none;
    border-radius: 16px;
    padding: 6px 14px;
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    flex-shrink: 0;
}

.notify-denied {
    font-size: 0.8rem;
    color: var(--grey);
    text-align: center;
    margin-bottom: 16px;
}


/* ----------------------------------------------------------------
   INSTALL-TO-HOME-SCREEN BANNER
   Shown on the home screen when the app is running in a browser tab
   (not yet installed). Dismissible via the close button; reappears
   after the dismiss window expires (see INSTALL_DISMISS_DAYS).
---------------------------------------------------------------- */
.install-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    background-color: var(--white);
    border-radius: 10px;
    padding: 14px 16px;
    padding-right: 36px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.install-card .install-icon {
    font-size: 28px;
    color: var(--orange);
    flex-shrink: 0;
}

.install-card-text {
    flex: 1;
    min-width: 0;
}

.install-card-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: #222;
    margin-bottom: 2px;
}

.install-card-subtitle {
    font-size: 0.78rem;
    color: var(--grey);
}

.install-btn {
    background-color: var(--orange);
    color: var(--white);
    border: none;
    border-radius: 16px;
    padding: 6px 14px;
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    flex-shrink: 0;
}

.install-close {
    position: absolute;
    top: 4px;
    right: 4px;
    background: transparent;
    border: none;
    padding: 4px;
    color: var(--light-grey);
    cursor: pointer;
    line-height: 0;
}

.install-close .material-symbols-outlined {
    font-size: 18px;
}


/* ----------------------------------------------------------------
   RUNNER CARD
   Used in both the favourites section and search results.
   Flex row: runner info (left, tappable) + star button (right).
   The star uses font-variation-settings to switch between outline
   and filled states without needing a different icon name.
---------------------------------------------------------------- */
.runner-card {
    display: flex;
    align-items: center;
    background-color: var(--white);
    border-radius: 10px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    overflow: hidden;
}

.runner-card-info {
    flex: 1;
    padding: 14px 16px;
    cursor: pointer;
}

.star-btn {
    padding: 14px 12px;
    background: none;
    border: none;
    border-left: 1px solid var(--light-grey);
    cursor: pointer;
    color: var(--light-grey);
    display: flex;
    align-items: center;
}

.star-btn .material-symbols-outlined {
    font-size: 22px;
    font-variation-settings: 'FILL' 0;
}

.star-btn.starred {
    color: var(--orange);
}

.star-btn.starred .material-symbols-outlined {
    font-variation-settings: 'FILL' 1;
}


/* ----------------------------------------------------------------
   RUNNER SEARCH
   Search box fixed at the top of the My Results screen.
   The results list scrolls beneath it.
---------------------------------------------------------------- */
.search-box {
    position: sticky;
    top: 0;
    background-color: var(--light-grey);
    padding-bottom: 12px;
    z-index: 10;
}

.search-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--light-grey);
    border-radius: 24px;
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 300;
    background-color: var(--white);
    outline: none;
    transition: border-color 0.15s ease;
}

.search-input:focus {
    border-color: var(--orange);
}

.input-error {
    border-color: var(--orange) !important;
}

.app-version {
    text-align: center;
    font-size: 0.7rem;
    color: var(--grey);
    margin-top: 24px;
    margin-bottom: 8px;
}


/* ----------------------------------------------------------------
   VIRTUAL COURSES — course list + setup screens
---------------------------------------------------------------- */
.virtual-event-location {
    font-size: 0.78rem;
    color: var(--grey);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 4px 0 6px;
}

.virtual-links {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 16px;
}

.virtual-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--orange);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 6px 0;
}

.virtual-link .material-symbols-outlined {
    font-size: 18px;
}

.virtual-start-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 4px;
}

.virtual-name-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: #333;
}

.virtual-start-btn {
    justify-content: center;
    width: 100%;
    padding: 12px;
    font-size: 1rem;
}

.virtual-start-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.start-gps-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.9rem;
    background-color: #f5f5f5;
    color: var(--grey);
}

.start-gps-status .material-symbols-outlined {
    font-size: 20px;
}

.start-gps-status.searching {
    background-color: #fff8e1;
    color: #7a6000;
}

.start-gps-status.at-start {
    background-color: #e8f5e9;
    color: #2e7d32;
}

.start-gps-status.no-gps {
    background-color: #fce4ec;
    color: #c62828;
}


/* ----------------------------------------------------------------
   VIRTUAL RUN — active running screen
   The nav bar is hidden during a run, so this screen extends to
   the bottom of the viewport.
---------------------------------------------------------------- */
#screen-virtual-run.active {
    display: flex;
    flex-direction: column;
    padding: 0;
    bottom: 0;        /* override the default nav-height offset */
    overflow: hidden; /* children handle their own scrolling */
}

.run-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background-color: var(--dark-grey);
    color: var(--white);
    flex-shrink: 0;
}

.run-timer {
    font-size: 2.4rem;
    font-weight: 300;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.run-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hint-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: var(--orange);
    color: var(--white);
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
}

.hint-btn .material-symbols-outlined {
    font-size: 18px;
}

.run-hint-area {
    flex-shrink: 0;
}

.hint-box {
    margin: 8px 16px;
    padding: 10px 14px;
    background-color: #fff8e1;
    border-left: 3px solid #f9a825;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #333;
}

.run-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px;
    -webkit-overflow-scrolling: touch;
}

.run-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--light-grey);
}

.run-row:last-child {
    border-bottom: none;
}

.run-row.visited  { opacity: 1; }
.run-row.next     { opacity: 1; font-weight: 500; border-left: 3px solid var(--orange); padding-left: 10px; }
.run-row.pending  { opacity: 0.35; }

.run-icon {
    font-size: 22px;
    flex-shrink: 0;
    color: var(--light-grey);
}

.run-icon.done { color: #388e3c; }
.run-icon.next { color: var(--orange); }

.run-label {
    flex: 1;
    font-size: 1rem;
}

.run-split {
    font-size: 1rem;
    font-weight: 600;
    color: #388e3c;
    font-variant-numeric: tabular-nums;
    min-width: 58px;
    text-align: right;
}

.run-next-icon {
    font-size: 24px;
    color: var(--orange);
    min-width: 58px;
    text-align: right;
}

.run-time {
    font-size: 1rem;
    color: var(--grey);
    font-variant-numeric: tabular-nums;
    min-width: 58px;
    text-align: right;
}

.run-footer {
    flex-shrink: 0;
    padding: 12px 16px;
    border-top: 1px solid var(--light-grey);
    background-color: var(--white);
}

.run-end-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--light-grey);
    border-radius: 8px;
    font-family: var(--font);
    font-size: 0.9rem;
    color: var(--grey);
    cursor: pointer;
}

.run-end-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ----------------------------------------------------------------
   HOLD-TO-ACTIVATE BUTTONS
   Buttons with .hold-btn require a 1.5-second hold (duration is set
   in attachHoldBehavior's HOLD_MS) before the action fires. A fill
   animates across the button to show progress; it snaps back if the
   user releases early. No-tap semantics: pointerdown's preventDefault
   stops the synthetic click, so a quick tap does nothing.
---------------------------------------------------------------- */
.hold-btn {
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.hold-btn .hold-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    background-color: rgba(255, 103, 32, 0.25);
    pointer-events: none;
    transition: width 0.15s linear;
}

.hold-btn.holding .hold-fill {
    width: 100%;
    transition: width 1.5s linear;
}

.hold-btn .hold-label {
    position: relative;   /* stack above the fill */
    z-index: 1;
}


/* ----------------------------------------------------------------
   VIRTUAL MAP OVERLAY
   Full-screen PDF map shown when the runner taps the Map button in
   the run header. Browser's native PDF viewer handles pinch-zoom
   and pan. A single Back button at the top closes the overlay.
---------------------------------------------------------------- */
#virtual-map-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background-color: var(--white);
    display: none;
    flex-direction: column;
}

.map-back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 16px;
    background-color: var(--dark-grey);
    color: var(--white);
    border: none;
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    flex-shrink: 0;
}

.map-back-btn .material-symbols-outlined {
    font-size: 20px;
}

.map-frame {
    flex: 1;
    width: 100%;
    border: none;
    background-color: #333;
}

.resume-run-card {
    background-color: #fff8e1;
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 16px;
    border-left: 4px solid var(--orange);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.resume-run-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--dark-grey);
    margin-bottom: 4px;
}

.resume-run-detail {
    font-size: 0.85rem;
    color: var(--grey);
    margin-bottom: 10px;
}

.resume-run-btns {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.run-finish-card {
    flex-shrink: 0;
    background-color: #e8f5e9;
    margin: 16px 16px 0;
    padding: 24px 16px;
    border-radius: 12px;
    text-align: center;
    border-left: 4px solid #388e3c;
}

.run-finish-title {
    font-size: 1rem;
    font-weight: 500;
    color: #388e3c;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.run-finish-time {
    font-size: 3rem;
    font-weight: 300;
    color: #388e3c;
    font-variant-numeric: tabular-nums;
    margin-bottom: 4px;
}

.run-finish-name {
    font-size: 0.95rem;
    color: #555;
}
