/* ============================================================
   Timetrack Live — Styles
   ============================================================ */

/* --- CSS Variables --- */
:root {
    --color-primary: #f97316;
    --color-primary-hover: #ea580c;
    --color-primary-light: #fff7ed;
    --color-primary-ring: rgba(249, 115, 22, 0.3);

    --color-text-heading: #111827;
    --color-text-primary: #1f2937;
    --color-text-secondary: #6b7280;
    --color-text-muted: #9ca3af;

    --color-bg: #ffffff;
    --color-bg-muted: #f9fafb;
    --color-border: #e5e7eb;
    --color-border-light: #f3f4f6;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

    --header-border-width: 3px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-tabs: 0 2px 4px rgba(0, 0, 0, 0.05);

    /* tsRankings widget overrides */
    --split-selected-color: var(--color-primary);
    --light-background: #f3f3f3;
    --dark-background: #888;
    --web-background: #fff;
    --font-size: 12px;
    --icon-size: 30px;
    --navigation-padding: 20px;
    --detail-item-font-size: 20px;
    --detail-item-title-font-size: 16px;
    --detail-subtitle-font-size: 14px;
    --detail-table-font-size: 14px;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    color: var(--color-text-primary);
    background-color: var(--color-bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

button {
    cursor: pointer;
    font-family: inherit;
    border: none;
    background: none;
    padding: 0;
}

.hidden {
    display: none !important;
}

/* ============================================================
   HEADER
   ============================================================ */
#live-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background-color: var(--color-bg);
    border-top: var(--header-border-width) solid var(--color-primary);
    box-shadow: var(--shadow-md);
    transition: all 0.3s ease-in-out;
}

/* --- Mobile Header --- */
.header-mobile {
    display: block;
    padding: 0.75rem 1rem;
}

.header-mobile-inner {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.logo-img-sm {
    height: 2.5rem;
    width: 2.5rem;
    flex-shrink: 0;
    border-radius: 0.375rem;
}

.header-mobile-info {
    flex: 1;
    min-width: 0;
}

.header-brand-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.125rem;
}

.header-brand-label {
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.event-title-mobile {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text-heading);
    line-height: 1.3;
    margin-bottom: 0.25rem;
}

.event-meta {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* --- Desktop Header --- */
.header-desktop {
    display: none;
    padding: 1rem 1.5rem;
}

.header-desktop-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 80rem;
    margin: 0 auto;
}

.logo-img-full {
    height: 3rem;
    width: auto;
}

.header-desktop-info {
    text-align: right;
}

.header-desktop-title-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
}

.event-title-desktop {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text-heading);
    letter-spacing: -0.02em;
}

.event-subtitle-desktop {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

/* --- Compact header on scroll (mobile) --- */
#live-header.compact .header-mobile {
    padding: 0.5rem 1rem;
}

#live-header.compact .logo-img-sm {
    height: 1.75rem;
    width: 1.75rem;
}

#live-header.compact .event-title-mobile {
    font-size: 0.875rem;
}

#live-header.compact .event-meta {
    display: none;
}

#live-header.compact {
    border-top-width: 2px;
    box-shadow: var(--shadow-sm);
}

/* --- Status Badge --- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.625rem;
    font-weight: 700;
    white-space: nowrap;
}

.status-badge--lg {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

.status-badge--live {
    background-color: var(--color-primary-light);
    color: var(--color-primary-hover);
    border: 1px solid var(--color-primary-ring);
}

.status-badge--upcoming {
    background-color: #eff6ff;
    color: #1d4ed8;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.status-badge--finished {
    background-color: #f3f4f6;
    color: #6b7280;
    border: 1px solid #e5e7eb;
}

.status-badge-dot {
    position: relative;
    display: inline-flex;
    height: 0.375rem;
    width: 0.375rem;
}

.status-badge-dot-ping {
    position: absolute;
    display: inline-flex;
    height: 100%;
    width: 100%;
    border-radius: 9999px;
    background-color: var(--color-primary);
    opacity: 0.75;
    animation: ping 1.5s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.status-badge-dot-solid {
    position: relative;
    display: inline-flex;
    border-radius: 9999px;
    height: 0.375rem;
    width: 0.375rem;
    background-color: var(--color-primary);
}

@keyframes ping {
    75%, 100% {
        transform: scale(2);
        opacity: 0;
    }
}

/* ============================================================
   TABS
   ============================================================ */
.sticky-tabs {
    position: sticky;
    z-index: 30;
    background-color: var(--color-bg);
    box-shadow: var(--shadow-tabs);
}

.tab-nav-wrapper {
    position: relative;
    border-bottom: 1px solid var(--color-border);
}

.tab-nav-wrapper::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 2rem;
    background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s;
    z-index: 1;
}

.tab-nav-wrapper.scrolled-end::after {
    opacity: 0;
}

.tab-nav {
    display: flex;
    gap: 0;
    padding: 0 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.tab-nav::-webkit-scrollbar {
    display: none;
}

.tab-button {
    position: relative;
    padding: 0.875rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    background: none;
}

.tab-button:hover {
    color: var(--color-text-primary);
    border-bottom-color: var(--color-border);
}

.tab-button:active {
    transform: scale(0.97);
    transition: transform 0.1s;
}

.tab-button.active {
    color: var(--color-primary-hover);
    border-bottom-color: var(--color-primary);
    font-weight: 600;
}

.tab-button.active:hover {
    border-bottom-color: var(--color-primary);
    color: var(--color-primary-hover);
}

/* ============================================================
   CONTENT PANELS
   ============================================================ */
.tab-content-area {
    padding: 0 1rem 5rem;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* --- Preloader --- */
.preloader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    min-height: 200px;
}

.spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid var(--color-border-light);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.preloader-text {
    margin-top: 1.25rem;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    font-weight: 500;
}

.tab-panel.content-loaded .preloader-container {
    display: none !important;
}

/* ============================================================
   404 PAGE (inline)
   ============================================================ */
.not-found {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
    text-align: center;
    background-color: var(--color-bg-muted);
}

.not-found-inner {
    max-width: 28rem;
}

.not-found-code {
    font-size: 5rem;
    font-weight: 800;
    color: var(--color-border);
    line-height: 1;
    letter-spacing: -0.04em;
}

.not-found h1 {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--color-text-heading);
    margin: 0.75rem 0 0.5rem;
}

.not-found p {
    color: var(--color-text-secondary);
    margin-bottom: 1.75rem;
    line-height: 1.6;
    font-size: 0.9375rem;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background-color: var(--color-primary);
    color: white;
    text-decoration: none;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background-color: var(--color-primary-hover);
}

.btn-primary svg {
    width: 1rem;
    height: 1rem;
}

/* ============================================================
   HOME — Event Listing
   ============================================================ */
.home {
    min-height: 100vh;
    background-color: var(--color-bg-muted);
    padding: 2rem 1rem 4rem;
}

.home-inner {
    max-width: 40rem;
    margin: 0 auto;
}

.home-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.home-logo-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.home-logo {
    height: 2rem;
    width: 2rem;
    border-radius: 0.375rem;
}

.home-brand {
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.home-title {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--color-text-heading);
    letter-spacing: -0.02em;
    margin-bottom: 0.375rem;
}

.home-subtitle {
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
}

.home-events-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.home-event-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 0.75rem;
    padding: 1.25rem;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.home-event-card:hover {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-ring), var(--shadow-md);
    transform: translateY(-1px);
}

.home-event-card:active {
    transform: translateY(0);
}

.home-event-card-body {
    flex: 1;
    min-width: 0;
}

.home-event-card-header {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.home-event-name {
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--color-text-heading);
    line-height: 1.3;
}

.home-event-detail {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    margin-bottom: 0.25rem;
}

.home-event-detail svg {
    flex-shrink: 0;
    color: var(--color-text-muted);
}

.home-race-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: 0.625rem;
}

.home-race-tag {
    display: inline-block;
    padding: 0.1875rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--color-primary-hover);
    background-color: var(--color-primary-light);
    border-radius: 9999px;
    letter-spacing: 0.02em;
}

.home-event-card-arrow {
    flex-shrink: 0;
    color: var(--color-text-muted);
    transition: color 0.2s, transform 0.2s;
}

.home-event-card:hover .home-event-card-arrow {
    color: var(--color-primary);
    transform: translateX(2px);
}

.home-event-card--finished {
    opacity: 0.65;
}

.home-event-card--finished:hover {
    opacity: 1;
}

.home-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
    font-size: 0.9375rem;
}

@media (min-width: 768px) {
    .home {
        padding: 4rem 1.5rem 6rem;
    }

    .home-title {
        font-size: 2.25rem;
    }

    .home-event-card {
        padding: 1.5rem;
    }

    .home-event-name {
        font-size: 1.1875rem;
    }
}

/* ============================================================
   tsRankings WIDGET OVERRIDES
   ============================================================ */
[id^="ranking-container-"] button.MuiButton-root,
[id^="ranking-container-"] .MuiButton-root {
    -webkit-appearance: revert !important;
    appearance: revert !important;
}

[id^="ranking-container-"] button.MuiButton-root.MuiButton-colorPrimary,
[id^="ranking-container-"] .MuiButton-root.MuiButton-colorPrimary,
[id^="ranking-container-"] .MuiButton-colorPrimary.MuiButton-variantSolid {
    background-color: var(--color-primary) !important;
    background-image: none !important;
}

[id^="ranking-container-"] .MuiButton-colorPrimary:hover {
    background-color: var(--color-primary-hover) !important;
}

[id^="ranking-container-"] .MuiButton-root:not(.MuiButton-colorPrimary) {
    background-color: revert !important;
    background-image: revert !important;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Mobile-only sticky tabs offset */
@media (max-width: 767px) {
    .sticky-tabs {
        top: 77px;
    }

    #live-header.compact ~ main .sticky-tabs {
        top: 52px;
    }

    .tab-button {
        min-height: 2.75rem;
    }
}

/* Desktop breakpoint */
@media (min-width: 768px) {
    .header-mobile {
        display: none;
    }

    .header-desktop {
        display: block;
    }

    .sticky-tabs {
        top: 83px;
    }

    .tab-nav {
        padding: 0 1.5rem;
        gap: 0.5rem;
    }

    .tab-button {
        padding: 1rem 1rem;
        font-size: 0.875rem;
    }

    .tab-content-area {
        padding: 0 1.5rem 5rem;
    }

    .preloader-container {
        padding: 4rem 2rem;
        min-height: 400px;
    }
}

@media (min-width: 1280px) {
    .tab-content-area {
        max-width: 80rem;
        margin: 0 auto;
    }
}
