/* =============================================
   MOBILE OVERRIDE (V9 - FINAL ZOOM ENABLED)
   Auteur : Horror Control Panel System
   ============================================= */

@media (max-width: 768px) {
    /* 1. RÉGLAGES DE BASE & LOCK */
    * { 
        box-sizing: border-box !important; 
        -webkit-tap-highlight-color: transparent;
    }

    body { 
        overflow: hidden !important; 
        height: 100% !important;
        position: fixed; 
        width: 100%;
        margin: 0;
        padding: 0;
        background-color: #050508;
        display: flex;
        flex-direction: column;
        touch-action: none; 
    }

    /* 2. HEADER HUD */
    .app-header { 
        position: relative !important;
        width: 100% !important; 
        height: 90px !important; 
        padding-top: 30px !important; 
        display: flex !important; 
        align-items: center !important;
        justify-content: center !important; 
        z-index: 9000; 
        background: #000 !important;
        border-bottom: 2px solid var(--accent);
    }
    
    .header-titles { text-align: center; width: 100%; }
    
    h1 { 
        font-size: 1em !important; 
        letter-spacing: 1px !important; 
        width: 100% !important;
        margin: 0 !important;
        white-space: nowrap !important;
    }
    
    .status-bar { font-size: 0.55em !important; margin-top: 3px !important; }

    #mobile-menu-btn, #mobile-logs-btn {
        position: absolute !important;
        top: 60% !important;
        transform: translateY(-50%) !important;
        padding: 8px 10px !important;
        font-size: 0.6em !important;
        font-family: inherit;
        z-index: 9001;
    }
    #mobile-menu-btn { left: 5px; }
    #mobile-logs-btn { right: 5px; }

    /* 3. LOGIN PAGE (Correction Bouton et Boot Loader) */
    #section-login { 
        position: absolute; top: 0; left: 0; width: 100%; height: 100vh;
        display: flex; flex-direction: column; 
        justify-content: flex-start !important;
        padding-top: 15vh !important; 
        align-items: center; 
        z-index: 10;
        background: transparent !important;
    }

    #login-btn { 
        width: 290px !important; height: 70px !important; 
        margin-top: 20px !important; 
        font-size: 0.85em !important; 
        letter-spacing: 0.5px !important;
        white-space: nowrap !important;
        border: 2px solid var(--terminal-green);
        background: rgba(0, 20, 0, 0.5);
        display: flex; align-items: center; justify-content: center;
        z-index: 20;
    }

    /* Correction positionnement chargeur sous le bouton */
    #boot-loader {
        margin: 30px auto 0 auto !important; 
        width: 280px !important;
        display: none; /* Reste géré par le JS pour l'apparition */
    }
    .boot-text {
        margin-top: 10px !important;
        font-size: 0.6em !important;
        text-align: center;
        width: 100%;
    }

    .blood-hand { 
        display: block !important;
        position: fixed !important; 
        width: 130px !important; 
        top: 55% !important; 
        right: 0 !important; 
        opacity: 0.3 !important; 
        z-index: 5 !important;
        pointer-events: none;
    }
    
    .twitch-container { 
        display: flex; /* Retrait du !important pour permettre le masquage via JS */
        position: fixed !important; 
        z-index: 15 !important; 
        bottom: 30px !important; 
        left: 20px !important; 
        transform: scale(0.65) !important; 
        transform-origin: left bottom;
    }
    .blood-gif { display: block !important; width: 110px !important; }

    /* 4. VOLETS NAVIGATION */
    .sidebar, .history-panel {
        position: fixed !important; 
        top: 90px !important; 
        bottom: 0 !important; 
        height: calc(100vh - 90px) !important; 
        max-height: none !important; /* NEUTRALISE LA LIMITE DU DESKTOP (100vh - 170px) */
        width: 85% !important; 
        max-width: 280px !important;
        z-index: 10000 !important; 
        background: #050508 !important; 
        padding: 0 !important; 
        margin: 0 !important; 
        box-sizing: border-box !important; /* Force le respect strict des dimensions */
        box-shadow: 0 0 50px #000;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        padding-bottom: env(safe-area-inset-bottom) !important; 
    }

    .sidebar { left: 0 !important; transform: translateX(-105%); border-right: 1px solid #333 !important; }
    
    .history-panel { 
        right: 0 !important; 
        transform: translateX(105%); 
        border-left: 1px solid #333 !important;
    }

    /* Repositionnement du titre "SYSTEM_ACTIVITY_LOG" pour mobile */
    .history-panel::after {
        top: 5px !important; /* Redescendu à l'intérieur du panneau */
        left: 10px !important;
        font-size: 0.6em !important;
        z-index: 10 !important;
        background: #050508 !important; /* Fond opaque pour ne pas voir les logs dessous */
    }

    /* On s'assure que la liste de logs prend l'espace dispo et scrolle */
    .history-list {
        flex: 1 !important;
        overflow-y: auto !important;
        padding: 30px 15px 15px 15px !important; /* Padding ajusté pour le titre */
        border-bottom: 1px solid #222 !important;
    }

    /* Le manager de traffic (Section Basse) */
    .download-manager {
        flex-shrink: 0 !important;
        height: 160px !important; 
        background: #050508 !important; /* Même fond que le reste */
        display: flex !important;
        flex-direction: column !important;
    }

    /* Correction du titre de section Network Traffic pour éviter la morsure */
    .download-manager .monitor-header {
        background: #0a0a0a !important; /* Plus sombre et opaque */
        color: var(--terminal-green) !important;
        padding: 8px !important;
        font-size: 0.5em !important;
        border-top: 1px solid #301010 !important;
        flex-shrink: 0 !important;
    }

    .download-body {
        padding: 10px !important;
        overflow-y: auto !important;
        flex: 1 !important;
    }
    .sidebar.mobile-open, .history-panel.mobile-open { transform: translateX(0) !important; }

    /* =============================================
       GESTION DES VUES CENTRALES (SONS / ARCHIVES / VIDEOS)
       ============================================= */

    /* 1. VUES STANDARDS (SONS ET ARCHIVES) */
    #view-sounds, #view-archives {
        position: absolute !important; 
        top: 90px !important; 
        left: 0 !important; 
        right: 0 !important; 
        bottom: 0 !important;
        padding: 0 10px 20px 10px !important;
        overflow-y: auto !important;
        background: transparent !important;
        touch-action: pan-y !important;
        z-index: 10 !important;
    }

    /* 2. VUE VIDÉO (FOND NOIR ET CENTRAGE) */
    #view-videos {
        position: fixed !important;
        top: 90px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        background: #000 !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        z-index: 500 !important;
    }

    /* 3. LOGIQUE D'AFFICHAGE (ÉVITE LES CONFLITS !IMPORTANT) */
    
    /* Si la vue n'est pas cachée, on active le bon mode de display */
    #view-sounds:not(.hidden), #view-archives:not(.hidden) {
        display: block !important;
    }

    #view-videos:not(.hidden) {
        display: flex !important;
    }

    /* Sécurité absolue : si .hidden est présent, on fait tout disparaître */
    #view-sounds.hidden, #view-archives.hidden, #view-videos.hidden {
        display: none !important;
    }

    /* RE-CALIBRAGE DU HUD ET DES CONTROLEURS VIDÉO */
    .video-player-container {
        width: 100% !important;
        max-width: 100vw !important;
        aspect-ratio: 16 / 9 !important;
        border-top: 1px solid #222 !important;
        border-bottom: 1px solid #222 !important;
        background: #050505 !important;
        position: relative !important;
    }

    .video-hud-top {
        padding: 5px 10px !important;
        font-size: 0.42em !important; 
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        top: 5px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .video-player-container {
        width: 100% !important;
        max-width: 100vw !important;
        aspect-ratio: 16 / 9 !important;
        border-left: none !important;
        border-right: none !important;
        border-top: 1px solid #222 !important;
        border-bottom: 1px solid #222 !important;
        background: #050505 !important;
        position: relative !important;
    }

    /* RE-CALIBRAGE DU HUD (TEXTES TRÈS PETITS) */
    .video-hud-top {
        padding: 5px 10px !important;
        font-size: 0.42em !important; 
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        top: 5px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    #video-filename {
        position: static !important;
        transform: none !important;
        text-align: center !important;
        max-width: 40% !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .video-stats-group {
        display: flex !important;
        gap: 8px !important;
    }

    #video-signal { display: none !important; }

    .video-hud-bottom {
        bottom: 5px !important;
        right: 10px !important;
        font-size: 0.5em !important;
    }

    .video-player-container {
        width: 100% !important;
        max-width: 100vw !important;
        aspect-ratio: 16 / 9 !important;
        border-left: none !important;
        border-right: none !important;
        border-top: 1px solid #222 !important;
        border-bottom: 1px solid #222 !important;
        background: #050505 !important;
    }

    /* RE-CALIBRAGE DU HUD (TEXTES TRÈS PETITS) */
    .video-hud-top {
        padding: 5px 10px !important;
        font-size: 0.45em !important; /* Texte minuscule type "OSD" */
        display: grid !important;
        grid-template-columns: 1fr 1fr 1fr !important;
        align-items: center !important;
        top: 5px !important;
    }

    #video-filename {
        position: static !important;
        transform: none !important;
        text-align: center !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .video-stats-group {
        justify-content: flex-end !important;
        gap: 8px !important;
    }

    #video-signal { display: none !important; } /* On cache le signal sur mobile pour gagner de la place */

    .video-hud-bottom {
        bottom: 5px !important;
        right: 10px !important;
        font-size: 0.5em !important;
    }

    /* PLACEHOLDER & MIRE */
    .video-placeholder, .test-pattern {
        background-size: 200% 200% !important;
    }

    .glitch-text { font-size: 0.8em !important; letter-spacing: 2px !important; }
    .sub-text { font-size: 0.5em !important; }

    /* COMMANDES DE PILOTAGE MOBILE (V6 - UI ÉCLATÉE) */
    .video-controls {
        position: absolute !important; /* Flotte indépendamment du lecteur */
        top: 100% !important; /* S'attache exactement sous la bordure de la vidéo */
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        background: transparent !important; /* On retire le fond noir pour un look plus incrusté */
        padding: 15px 15px !important; /* Rapproché de la vidéo */
        display: grid !important;
        grid-template-columns: 1fr 1fr !important; 
        grid-template-rows: auto auto !important;
        gap: 12px !important;
        border: none !important;
        box-sizing: border-box !important;
        z-index: 10 !important;
    }

    .video-progress-bar {
        grid-column: 1 / span 2 !important;
        grid-row: 1 !important;
        height: 12px !important; /* Ligne de progression très tactile */
        margin-bottom: 0 !important; 
        background: rgba(255,255,255,0.1) !important;
        border-radius: 2px !important;
    }

    .btn-video {
        height: 45px !important;
        font-size: 0.6em !important;
        background: rgba(255, 255, 255, 0.02) !important;
        border: 1px solid #222 !important;
        color: #666 !important;
        width: 100% !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        text-transform: uppercase;
        letter-spacing: 1px;
    }

    /* ABORT (ROUGE DISCRET) - SOUS LA VIDÉO, GAUCHE */
    .video-controls button:nth-child(1) {
        grid-column: 1 !important;
        grid-row: 2 !important;
        border-color: #301010 !important;
        color: #833 !important;
    }

    /* PLAY/PAUSE - SOUS LA VIDÉO, DROITE */
    #play-pause-btn {
        grid-column: 2 !important;
        grid-row: 2 !important;
        border-color: #222 !important;
        color: #666 !important;
    }

    /* RE-SYNC - EXTRAIT ET PLACÉ AU-DESSUS DE LA VIDÉO */
    .video-controls button:nth-child(3) {
        display: flex !important; 
        position: absolute !important;
        /* Calcul magique: 100% (sa propre pos) + 56.25vw (hauteur exacte du 16:9 sur mobile) + 20px (marge) */
        bottom: calc(100% + 56.25vw + 20px) !important; 
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: auto !important;
        min-width: 140px !important;
        height: 35px !important; /* Légèrement plus fin */
        background: rgba(0, 15, 0, 0.8) !important; /* Teinte verte très sombre */
        border: 1px solid var(--terminal-green) !important;
        color: var(--terminal-green) !important;
        box-shadow: 0 0 15px rgba(21, 255, 0, 0.1) !important;
    }

    /* ANTI-ROTATION MANUELLE (BLOQUE L'INTERFACE EN PAYSAGE) */
    @media screen and (max-width: 768px) and (orientation: landscape) {
        body::after {
            content: "SYSTEM_ERROR: LANDSCAPE_MODE_NOT_SUPPORTED. PLEASE_ROTATE_DEVICE_TO_PORTRAIT_MODE.";
            position: fixed;
            top: 0; left: 0; right: 0; bottom: 0;
            background: #050508;
            color: #ff4646;
            z-index: 9999999 !important;
            display: flex;
            justify-content: center;
            align-items: center;
            text-align: center;
            font-family: 'Courier New', monospace;
            font-size: 1.2em;
            padding: 20px;
            letter-spacing: 2px;
            pointer-events: all !important;
        }
    }

    /* Effet au clic (feedback tactile) */
    .btn-video:active {
        background: rgba(255, 255, 255, 0.1) !important;
        color: #fff !important;
    }

    /* FEEDBACK VISUEL (PLAY/PAUSE) AU CENTRE */
    .video-status-feedback {
        font-size: 1em !important;
        padding: 10px 20px !important;
        letter-spacing: 2px !important;
    }

    .search-container { 
        width: 100% !important; 
        padding: 15px 0 !important; 
        background: #050508;
        margin: 0 !important;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    /* Aligne le bloc Label + Boutons Grid/List sur 80% comme l'input */
    .search-container > div {
        width: 80% !important;
        max-width: none !important;
        margin-bottom: 5px !important;
    }

    .search-input { width: 80% !important; height: 45px !important; font-size: 0.9em !important; }

    .view-selector { margin-bottom: 10px !important; }
    .view-option { font-size: 0.75em !important; padding: 5px; }
    
    /* RE-CALIBRAGE DU MODE LISTE MOBILE (V12 - STRUCTURE CROQUIS) */
    .grid.list-mode {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important; 
        width: 100% !important;
        padding: 0 10px !important;
        box-sizing: border-box !important;
    }

    .list-mode .card { 
        display: flex !important;
        flex-direction: row !important;
        width: 100% !important;
        height: 80px !important; /* Augmenté pour permettre le stacking vertical */
        background: #000 !important;
        border: 1px solid #251010 !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }
    
    /* 1. ZONE GAUCHE : ID Vertical */
    .list-mode .card-header { 
        width: 30px !important;
        flex-shrink: 0 !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        background: rgba(255, 70, 70, 0.03) !important;
        border-right: 1px solid #301515 !important;
        padding: 0 !important;
    }

    .list-mode .file-id {
        font-size: 0.35em !important;
        color: #444 !important;
        transform: rotate(-90deg);
        white-space: nowrap;
        text-transform: uppercase;
        letter-spacing: 1px;
    }
    .list-mode .card-header span:last-child { display: none !important; }

    /* 2. ZONE CENTRALE : Titre et Prix empilés */
    .list-mode .card-body { 
        flex: 1 !important;
        display: grid !important;
        /* Colonne 1: Textes (Titre/Prix) | Colonne 2: Boutons */
        grid-template-columns: 1fr 100px !important;
        grid-template-rows: 1fr 1fr !important;
        padding: 8px 12px !important;
        min-width: 0;
        align-items: center !important;
    }

    /* Titre en haut à gauche */
    .list-mode h3 { 
        grid-column: 1 !important;
        grid-row: 1 !important;
        font-size: 0.75em !important; 
        margin: 0 !important;
        color: #eee !important;
        align-self: end !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Prix en bas à gauche */
    .list-mode .price { 
        grid-column: 1 !important;
        grid-row: 2 !important;
        font-size: 0.7em !important; 
        margin: 0 !important;
        color: var(--terminal-green) !important;
        align-self: start !important;
        padding-top: 4px;
    }
    .list-mode .price::before { content: "> " !important; opacity: 0.5; }

    /* 3. ZONE DROITE : Boutons avec textes (V14 - COMPACT) */
    .list-mode .btn span { 
        display: block !important; 
        font-size: 0.42em !important; /* Augmenté de 0.32em à 0.42em */
        letter-spacing: 0.5px !important;
        font-weight: bold;
        opacity: 0.8;
        margin-top: 3px !important;
        line-height: 1 !important;
    }

    .list-mode .card-body { 
        flex: 1 !important;
        display: grid !important;
        /* Légère augmentation de la zone boutons à 105px */
        grid-template-columns: 1fr 105px !important;
        grid-template-rows: 1fr 1fr !important;
        padding: 8px 10px !important;
        min-width: 0;
        align-items: center !important;
    }

    .list-mode .btn-group {
        grid-column: 2 !important;
        grid-row: 1 / span 2 !important;
        display: flex !important;
        flex-direction: row !important;
        gap: 5px !important; /* Espace entre les boutons légèrement augmenté */
        justify-content: flex-end !important;
        align-items: center !important;
    }

    .list-mode .btn {
        width: 50px !important; /* Augmenté de 46px à 50px */
        height: 48px !important; /* Augmenté de 42px à 48px */
        padding: 0 !important;
        display: flex !important;
        flex-direction: column !important; 
        justify-content: center !important;
        align-items: center !important;
        background: rgba(255,255,255,0.03) !important;
        border: 1px solid #333 !important;
        flex-shrink: 0 !important;
    }

    .list-mode .btn-launch { border-color: var(--accent) !important; }
    .list-mode .btn-launch span { color: var(--accent) !important; opacity: 1 !important; }
    
    .list-mode .icon-preview, 
    .list-mode .icon-execute { 
        width: 18px !important; /* Augmenté de 15px à 18px */
        height: 18px !important;
        margin-bottom: 1px !important;
    }

    .list-mode .btn-launch .icon-execute { filter: drop-shadow(0 0 5px var(--accent)); }

    .list-mode .btn-launch span { color: var(--accent) !important; }
    
    .list-mode .icon-preview, 
    .list-mode .icon-execute { 
        width: 14px !important; 
        height: 14px !important;
        opacity: 0.8;
    }

    .list-mode .btn-launch .icon-execute { opacity: 1; filter: drop-shadow(0 0 5px var(--accent)); }

    .list-mode .btn-launch .icon-execute { opacity: 1; filter: drop-shadow(0 0 5px var(--accent)); }

    .list-mode .btn-launch { border-color: var(--accent) !important; }
    
    .list-mode .icon-preview, 
    .list-mode .icon-execute { 
        width: 16px !important; 
        height: 16px !important;
        opacity: 0.7;
    }

    .list-mode .btn-launch .icon-execute { opacity: 1; }

    /* Barre de chargement en mode liste */
    .list-mode .loading-container {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 2px;
    }

    .grid { 
        grid-template-columns: 1fr 1fr !important; 
        gap: 8px !important; 
        width: 100% !important; 
    }
    .card { background: rgba(10, 10, 15, 0.9) !important; border: 1px solid #1a1a25 !important; }
    .card-body { padding: 8px !important; }
    h3 { font-size: 0.6em !important; height: 32px; overflow: hidden; margin-bottom: 5px !important; line-height: 1.1; }
    .price { font-size: 0.65em !important; margin: 8px 0 !important; }
    
    .btn-group { flex-direction: column !important; gap: 5px !important; }
    .btn { font-size: 0.5em !important; padding: 10px 2px !important; justify-content: center !important; }
    
    .icon-preview, .icon-execute { 
        width: 12px !important; height: 12px !important; 
        background-image: url('../preview_icon.png') !important; 
    }
    .btn-launch .icon-execute { background-image: url('../execute_icon.png') !important; }

    .sub-tab.active::before { content: ">" !important; color: var(--terminal-green) !important; }
    .sub-sub-tab.active::before { content: ">>" !important; color: var(--terminal-green) !important; }

    /* 6. ARCHIVES : SYSTÈME DE ZOOM TACTILE */
    #view-archives { 
        position: absolute !important; top: 90px !important; left: 0; right: 0; bottom: 0; 
    }
    
    #archive-display-area { 
        height: 65vh !important; 
        margin: 10px 0 !important; 
        /* Rendu transparent pour le logo mobile */
        background-color: transparent !important;
        touch-action: none !important; 
        overflow: hidden !important; 
    }

    .paper-container {
        width: 100% !important; height: 100% !important;
        display: flex; justify-content: center; align-items: center;
        touch-action: none !important;
        transform-origin: center center;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* LE BOUTON FLOTTANT */
    #mobile-zoom-btn {
        display: block; /* Active le bouton sur mobile (écrase le masquage du PC) */
        margin-top: 15px;
        padding: 12px 25px;
        background: rgba(21, 255, 0, 0.1);
        border: 1px solid var(--terminal-green);
        color: var(--terminal-green);
        font-family: inherit;
        font-size: 0.8em;
        font-weight: bold;
        text-transform: uppercase;
        letter-spacing: 2px;
        z-index: 9999;
        box-shadow: 0 0 15px rgba(21, 255, 0, 0.2);
    }

    /* La classe .hidden garde la priorité absolue pour masquer le bouton via le JavaScript */
    #mobile-zoom-btn.hidden {
        display: none !important;
    }
    
    #mobile-zoom-btn.active {
        background: var(--terminal-green);
        color: #000;
        box-shadow: 0 0 25px var(--terminal-green);
    }

    .report-page { 
        background: #000 !important; /* Retour du fond noir pour l'effet Tunnel */
        width: 90% !important; 
        padding: 5px !important;
        position: relative !important;
        pointer-events: none; 
        box-shadow: 0 30px 60px rgba(0,0,0,0.8) !important;
    }
    
    /* RÉACTIVATION DES EFFETS LORE SUR MOBILE */
    .report-page::after {
        display: block !important;
        content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 100%;
        background: radial-gradient(
            circle at var(--light-x) var(--light-y), 
            rgba(255,255,255,0.85) 0%, 
            rgba(255,255,255,0.2) 30%,
            rgba(0,0,0,0.95) 85%
        ) !important;
        mix-blend-mode: hard-light !important;
        z-index: 10;
    }

    .silhouette-shadow { 
        display: block !important; 
        opacity: 0.6 !important; 
        z-index: 20 !important;
    }

    .dust-overlay { 
        display: block !important; 
        opacity: 0.4 !important; 
        z-index: 15 !important;
    }

    .report-page img {
        filter: brightness(0.8) contrast(1.4) grayscale(0.2) !important;
    }
}