/* ========================================================
   art of rally - MOBILE RESPONSIVE OVERRIDES
======================================================== */

/*
 * 1. PASKI BOCZNE (Rozdzielczości poniżej 1280px)
 * Zachowanie wysuwanych nakładek nad głównym ekranem (tablet & telefon)
 */
@media (max-width: 1279px) {
    .left-sidebar {
position: fixed; top: 0; bottom: 0; left: 0;
max-width: 85vw; background: rgba(70, 85, 88, 0.98) !important;
box-shadow: 10px 0 30px rgba(0,0,0,0.5);
border-radius: 0 12px 12px 0; border: 1px solid rgba(255,255,255,0.1);
z-index: 100;
}
.right-sidebar {
position: fixed; top: 0; bottom: 0; right: 0;
max-width: 85vw; background: rgba(70, 85, 88, 0.98) !important;
box-shadow: -10px 0 30px rgba(0,0,0,0.5);
border-radius: 12px 0 0 12px; border: 1px solid rgba(255,255,255,0.1);
z-index: 100;
}

    body.light-mode .left-sidebar, body.light-mode .right-sidebar {
        background: rgba(253, 240, 222, 0.98) !important;
        border-color: rgba(0,0,0,0.1);
    }
    body.light-mode .left-sidebar { box-shadow: 10px 0 30px rgba(0,0,0,0.15); }
    body.light-mode .right-sidebar { box-shadow: -10px 0 30px rgba(0,0,0,0.15); }

    .panel-hide-left { margin-left: 0 !important; transform: translateX(-100%); opacity: 0; }
    .panel-hide-right { margin-right: 0 !important; transform: translateX(100%); opacity: 0; }
}

/*
 * 2. GŁĘBOKA PRZEBUDOWA UKŁADU NA SMARTFONY (poniżej 768px)
 */
@media (max-width: 768px) {

    /* 2.1 Odblokowanie sztywnej szerokości kontenera z tabelą */
    #mainScrollArea > div {
        min-width: 0 !important;
    }

    /* 2.2 Zwijanie polaroidów na samej górze, by nie wychodziły poza krawędź */
    #topHeroContainer > div {
        flex-wrap: wrap;
        gap: 12px !important;
    }
    #topHeroContainer[style*="max-height: 350px"] {
        max-height: 1200px !important; /* Dopuszczalne zawinięcie kilku rzędów */
    }

    /* 2.3 Całkowite ukrycie paska z nagłówkami tabeli */
    .list-row.header-row {
        display: none !important;
    }

    /* 2.4 Zamiana Rzędów Tabeli w układ KART Grid */
    #tableBody {
        background: transparent !important;
        border: none !important;
        padding: 0 !important;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .list-row {
        display: grid !important;
        grid-template-columns: auto auto 1fr;
        grid-template-areas:
            "rank icon name"
            "time time time"
            "gap gap gap"
            "track track track"
            "car car car";
        gap: 4px 10px;
        background: rgba(0, 0, 0, 0.15);
        border: 1px solid rgba(255, 255, 255, 0.05) !important;
        border-radius: 12px;
        padding: 14px 16px !important;
        align-items: center;
    }

    body.light-mode .list-row {
        background: rgba(255, 255, 255, 0.5);
        border: 1px solid rgba(0, 0, 0, 0.1) !important;
        box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    }

    /* Alokacja komórek pod konkretne kwadraty grida */
    .list-row .col-rank { grid-area: rank; width: auto; text-align: left; font-size: 1.3rem; line-height: 1; }
    .list-row .col-icon { grid-area: icon; width: auto; display: flex; align-items: center; justify-content: center; }

    .list-row .col-name {
        grid-area: name;
        width: auto;
        text-align: left;
        padding: 0;
        font-size: 1.25rem;
        line-height: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .list-row .col-time {
        grid-area: time;
        width: 100%;
        justify-content: center;
        font-size: 1.7rem;
        line-height: 1;
        margin: 4px 0 2px 0;
        display: flex;
        align-items: center;
        z-index: 2;
    }

    /* Ikona YT, o ile występuje (teraz siedzi elegancko przed czasem) */
    .list-row .col-time .absolute {
        position: relative !important;
        left: auto !important; right: auto !important; top: auto !important; transform: none !important;
        margin-right: 10px;
        font-size: 1.4rem !important;
        display: flex;
        align-items: center;
    }

    .list-row .col-gap {
        grid-area: gap;
        width: 100%;
        justify-content: center;
        padding-left: 0;
        font-size: 1rem;
        opacity: 0.7;
        margin: -2px 0 2px 0;
        display: flex;
        align-items: center;
        z-index: 1;
    }

    .list-row .col-track {
        grid-area: track;
        width: auto;
        text-align: left;
        font-size: 0.9rem;
        opacity: 0.65;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding-top: 2px;
    }

    .list-row .col-car {
        grid-area: car;
        width: auto;
        text-align: left;
        font-size: 0.9rem;
        opacity: 0.65;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Puste miejsce usuniętych z widoku kolumn (filtrami z app.js) znika, by nie niszczyć Grida */
    .list-row .col-track[style*="display: none"],
    .list-row .col-car[style*="display: none"],
    .list-row .col-gap[style*="display: none"],
    .list-row .col-gap:empty {
        display: none !important;
    }

    /* 2.5 Reszta drobnych korekt UI (Header, Tytuły) */
    header {
        margin-bottom: 12px !important;
        padding-bottom: 8px !important;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }

    .header-controls-container {
        transition: gap 0.3s ease, margin-bottom 0.3s ease;
    }

    .mobile-hide-on-scroll {
        transition: all 0.3s ease !important;
        max-height: 150px;
        opacity: 1;
        transform: translateY(0);
        overflow: hidden;
    }

    body.mobile-scrolled .mobile-hide-on-scroll {
        max-height: 0 !important;
        opacity: 0 !important;
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        border-top-width: 0 !important;
        border-bottom-width: 0 !important;
        transform: translateY(-10px) !important;
        pointer-events: none;
    }

    body.mobile-scrolled .header-controls-container {
        gap: 0 !important;
        margin-bottom: 0 !important;
    }

    #tableTitle {
        font-size: 1.35rem !important;
        white-space: normal !important;
        word-wrap: break-word;
        line-height: 1.2;
    }

    [id$="ModalContent"] {
        width: 95vw !important;
        padding: 20px !important;
        max-height: 85vh !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        /* Nigdy nie animuj transformem kontenera, który scrolluje - to zrodlo migotania */
        transform: none !important;
        will-change: opacity;
    }

    #ytPlayerModalContent {
        padding: 0 !important;
        overflow: hidden !important;
        height: auto !important;
        max-height: none !important;
    }

    #notifDropdown {
        position: fixed !important;
        top: 70px !important;
        left: 50% !important;
        right: auto !important;
        width: calc(100vw - 32px) !important;
        max-width: 400px !important;
        --tw-translate-x: -50% !important;
    }
}

/*
 * 3. GLOBAL STATS (Wykresy i bloki na ekranach do 1024px)
 */
@media (max-width: 1024px) {
    #globalStatsContainer {
        display: flex;
        flex-direction: column;
    }
    #globalStatsContainer > div {
        min-height: 380px !important;
        height: auto !important;
        flex-shrink: 0;
    }
    /* 1 i 2 div to wykresy liniowe - zwiększona wysokość, by linie miały więcej miejsca w osi Y */
    #globalStatsContainer > div:nth-child(1),
    #globalStatsContainer > div:nth-child(2) {
        min-height: 450px !important;
    }
    /* Wykresy słupkowe są teraz przewijalne poziomo, nie muszą być bardzo wysokie */
    #globalStatsContainer > .lg\:col-span-2 {
        min-height: 380px !important;
    }
}
