/* ═══════════════════════════════════════════════
   MOBILE FIXES v2 — à coller à la fin de style.css
═══════════════════════════════════════════════ */

@media (max-width: 639px) {

    /* ── 1. BOTTOM NAV : toujours visible ── */
    .bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: var(--nav-h);
        background: rgba(14,14,14,.98);
        border-top: 1px solid var(--border);
        backdrop-filter: blur(20px);
        z-index: 600;
        justify-content: space-around;
        align-items: center;
    }

    /* ── 2. APP : hauteur = 100dvh - bottom nav ── */
    .app {
        height: calc(100dvh - var(--nav-h)) !important;
        grid-template-columns: 1fr !important;
        grid-template-rows: 1fr 90px;
        padding: 0;
        gap: 0;
    }

    /* ── 3. SIDEBAR OVERLAY ── */
    .sidebar {
        display: none !important;
    }

    .sidebar.mobile-open {
        display: flex !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: calc(90px + var(--nav-h)) !important;
        width: 100% !important;
        z-index: 700 !important;
        background: var(--bg-surface) !important;
        border-radius: 0 !important;
        flex-direction: column;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        animation: slideUp .2s ease both;
    }

    @keyframes slideUp {
        from { opacity: 0; transform: translateY(12px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    /* Tout afficher dans l'overlay */
    .sidebar.mobile-open .logo span             { display: inline !important; }
    .sidebar.mobile-open .logo                  { justify-content: flex-start !important; padding: 14px 16px 12px !important; border-bottom: 1px solid var(--border); }
    .sidebar.mobile-open .nav-item span         { display: inline !important; }
    .sidebar.mobile-open .nav-item              { justify-content: flex-start !important; padding: 10px 16px !important; }
    .sidebar.mobile-open .lib-filters           { display: flex !important; }
    .sidebar.mobile-open .library-header span   { display: flex !important; }
    .sidebar.mobile-open .lib-item              { justify-content: flex-start !important; padding: 8px 16px !important; }
    .sidebar.mobile-open .lib-item-thumb        { width: 52px !important; height: 52px !important; }
    .sidebar.mobile-open .lib-item-info         { display: flex !important; }
    .sidebar.mobile-open .lib-item-more         { display: flex !important; }
    
    .sidebar.mobile-open .sidebar-top           { flex-shrink: 0; }
    .sidebar.mobile-open .sidebar-library       { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
    .sidebar.mobile-open .lib-list              { flex: 1; overflow-y: auto; }

    /* ── 4. Bouton déconnexion visible dans l'overlay ── */
    .sidebar.mobile-open .sidebar-nav button {
        display: flex !important;
        align-items: center;
        width: 100%;
        padding: 10px 16px;
        font-size: .83rem;
        font-weight: 600;
        color: var(--text-sub);
        text-align: left;
    }

    /* ── 5. QUEUE et MAIN ── */
    .queue-panel { display: none !important; }

    .main-content {
        grid-column: 1;
        grid-row: 1;
        border-radius: 0;
        border: none;
        overflow-y: auto;
    }

    /* ── 6. TOPBAR ── */
    .topbar {
        flex-wrap: wrap;
        padding: 8px 10px;
        gap: 8px;
        background: rgba(0,0,0,.92);
    }
    .topbar-nav, .topbar-right { display: none !important; }
    .search-wrap {
        max-width: 100%;
        width: 100%;
        flex: unset;
        order: 1;
    }

    /* ── 7. PLAYER BAR ── */
    .player-bar {
        grid-column: 1;
        grid-row: 2;
        flex-direction: column;
        justify-content: center;
        height: 90px;
        padding: 6px 16px 4px;
        gap: 4px;
    }
    .player-left         { max-width: 100%; width: 100%; flex: 0 0 auto; }
    .player-thumb        { width: 36px; height: 36px; }
    .player-track-title  { font-size: .8rem; }
    .player-track-artist { font-size: .68rem; }
    .player-center       { width: 100%; max-width: 100%; flex: 0 0 auto; gap: 2px; }
    #btn-shuffle,
    #btn-repeat          { display: none !important; }
    .player-right        { display: none !important; }

    /* ── 8. GRILLE RÉSULTATS : 3 colonnes ── */
    .music-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    .track-card        { padding: 7px; }
    .track-card h4     { font-size: .72rem; margin-bottom: 2px; }
    .track-card p      { font-size: .65rem; }
    .card-play-btn     { width: 32px; height: 32px; bottom: 6px; right: 6px; }
    .card-options-btn  { width: 22px; height: 22px; font-size: .7rem; top: 6px; right: 6px; }
    .section-pad       { padding: 8px 8px 16px; }

    /* ── 9. TOAST au-dessus de la nav ── */
    .toast { bottom: calc(var(--nav-h) + 100px); }

    /* ── 10. PLAYLIST VIEW ── */
    .pl-hero              { flex-direction: column; align-items: center; padding: 24px 16px 16px; min-height: auto; gap: 16px; }
    .pl-hero-art          { width: 140px; height: 140px; }
    .pl-hero-info         { text-align: center; }
    .pl-hero-name         { font-size: 1.5rem; }
    .pl-tr-artist-col     { display: none; }
    .pl-track-header      { display: none; }
    .pl-track-row         { grid-template-columns: 36px 1fr 56px; padding: 6px 10px; }

    /* ── 11. MODAL ── */
    .modal-box { width: 95vw; padding: 22px 18px; }
}

/* Très petits écrans */
@media (max-width: 400px) {
    .music-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
}

/* ═══════════════════════════════════════════════
   LANDSCAPE FIX — téléphone & tablette en paysage
═══════════════════════════════════════════════ */

/* ── Téléphone en paysage (hauteur ≤ 500px) ── */
@media (orientation: landscape) and (max-height: 500px) {

    /* Cacher la bottom-nav, on a de la place en largeur */
    .bottom-nav { display: none !important; }

    /* Grid 2 colonnes + player compact */
    .app {
        height: 100dvh !important;
        grid-template-columns: 72px 1fr !important;
        grid-template-rows: 1fr 60px !important;
        padding: 4px !important;
        gap: 4px !important;
    }

    /* Sidebar icônes seulement */
    .sidebar {
        display: flex !important;
        position: static !important;
        width: 72px !important;
    }
    .sidebar .lib-item-info,
    .sidebar .lib-item-more,
    .sidebar .logo span,
    .sidebar .nav-item span,
    .sidebar .library-header span,
    .sidebar .lib-filters,
    .sidebar .lib-empty        { display: none !important; }
    .sidebar .lib-item         { justify-content: center; padding: 10px; }
    .sidebar .lib-item-thumb   { width: 40px; height: 40px; }
    .sidebar .logo             { justify-content: center; padding: 6px 0 12px; }
    .sidebar .nav-item         { justify-content: center; padding: 10px; }

    /* Player bar horizontal compact */
    .player-bar {
        grid-column: 1 / -1 !important;
        flex-direction: row !important;
        height: 60px !important;
        padding: 0 14px !important;
        gap: 10px !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    .player-left {
        flex: 1 !important;
        max-width: 33% !important;
        width: auto !important;
        gap: 8px !important;
    }
    .player-thumb        { width: 36px !important; height: 36px !important; }
    .player-track-title  { font-size: .78rem !important; }
    .player-track-artist { font-size: .66rem !important; }

    .player-center {
        flex: 0 0 36% !important;
        max-width: 36% !important;
        width: auto !important;
        gap: 2px !important;
    }
    #btn-shuffle,
    #btn-repeat { display: flex !important; }

    .player-right {
        display: flex !important;
        flex: 1 !important;
        max-width: 31% !important;
        justify-content: flex-end !important;
    }

    /* Topbar & contenu compacts */
    .topbar      { padding: 6px 10px !important; }
    .section-pad { padding: 6px 10px 16px !important; }

    /* Grille résultats : 4 colonnes en paysage */
    .music-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 8px !important;
    }

    /* Toast au-dessus du player */
    .toast { bottom: 68px !important; }
}

/* ── Tablette en paysage (501–1023px de hauteur) ── */
@media (orientation: landscape) and (min-height: 501px) and (max-width: 1023px) {

    .bottom-nav { display: none !important; }

    .app {
        height: 100dvh !important;
        grid-template-columns: 72px 1fr !important;
        grid-template-rows: 1fr var(--player-h) !important;
        padding: var(--gap) !important;
        gap: var(--gap) !important;
    }

    .sidebar     { display: flex !important; position: static !important; }
    .queue-panel { display: none !important; }

    .player-bar {
        grid-column: 1 / -1 !important;
        flex-direction: row !important;
        height: var(--player-h) !important;
        padding: 0 20px !important;
        justify-content: space-between !important;
        align-items: center !important;
    }
    .player-left   { flex: 1 !important; max-width: 30% !important; width: auto !important; }
    .player-center { flex: 0 0 40% !important; max-width: 40% !important; width: auto !important; }
    .player-right  { display: flex !important; flex: 1 !important; max-width: 30% !important; }
    #btn-shuffle,
    #btn-repeat    { display: flex !important; }

    .music-grid { grid-template-columns: repeat(4, 1fr) !important; }
    .toast      { bottom: 100px !important; }
}
@media (max-width: 639px) {

    /* ── 2 colonnes compactes ── */
    .music-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    .track-card {
        padding: 8px !important;
    }

    /* Vignette moins haute */
    .track-card img,
    .card-img-wrap {
        aspect-ratio: 16 / 9 !important;
    }

    .card-img-wrap {
        margin-bottom: 8px !important;
    }

    .track-card h4 {
        font-size: .72rem !important;
        margin-bottom: 2px !important;
    }

    .track-card p {
        font-size: .65rem !important;
    }

    .card-play-btn {
        width: 30px !important;
        height: 30px !important;
        bottom: 6px !important;
        right: 6px !important;
    }
}
/* ── Bottom sheet mobile ── */
@media (max-width: 639px) {
    #connect-popup.connect-popup-mobile {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        border-radius: 16px 16px 0 0;
        min-width: unset;
        padding-bottom: calc(env(safe-area-inset-bottom) + 10px);
        animation: connectSlideUp .22s cubic-bezier(.34,1.56,.64,1) both;
    }

    @keyframes connectSlideUp {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }

    .connect-handle {
        width: 36px;
        height: 4px;
        background: rgba(255,255,255,.2);
        border-radius: 2px;
        margin: 10px auto 4px;
    }

    .connect-device-btn {
        padding: 14px 20px; /* plus grand pour les doigts */
    }

    .connect-device-icon svg {
        width: 22px;
        height: 22px;
    }
}
