/* =====================================================
   Aura Vision Studio — Mobile layout (2026-07-07)
   Every rule is gated behind BOTH @media (max-width:900px)
   AND body.av-mobile (added by js/mobile.js), so desktop
   rendering is completely untouched.
   ===================================================== */

/* Injected mobile-only elements stay hidden outside mobile mode */
.av-drawer-btn { display: none; }
#av-scrim { display: none; }
.av-drawer-close { display: none; }

@media (max-width: 900px) {

    /* ---------- Page-level: never overflow horizontally ---------- */
    html.av-mobile-root,
    html.av-mobile-root body.av-mobile {
        overflow-x: hidden;
        width: 100%;
    }
    body.av-mobile .app-container {
        width: 100%;
        max-width: 100vw;
    }

    /* ---------- Top navigation: wraps into rows, nothing cut off ---------- */
    body.av-mobile .app-nav {
        flex-wrap: wrap;
        height: auto;
        min-height: 52px;
        padding: 0.35rem 0.5rem;
        gap: 0.3rem;
        row-gap: 0.3rem;
        align-items: center;
    }
    body.av-mobile .nav-left {
        gap: 0.4rem;
        min-width: 0;
        flex: 1 1 auto;
    }
    body.av-mobile .nav-brand h1 { display: none; } /* icon-only brand */
    body.av-mobile .nav-brand i { font-size: 1.4rem; }
    body.av-mobile .nav-controls { gap: 0.25rem; }

    /* Compact icon-over-label buttons, >=44px touch targets */
    body.av-mobile .nav-btn,
    body.av-mobile .ai-quick-btn {
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-width: 44px;
        min-height: 44px;
        padding: 4px 6px;
        font-size: 0.5rem;
        line-height: 1.1;
        white-space: nowrap;
    }
    body.av-mobile .nav-btn i,
    body.av-mobile .ai-quick-btn i {
        font-size: 0.95rem;
        margin: 0;
    }
    body.av-mobile .nav-right {
        gap: 0.35rem;
        flex-wrap: nowrap;
    }
    body.av-mobile .ai-quick-controls { gap: 0.25rem; }
    body.av-mobile .btn-signin {
        min-height: 44px;
        padding: 0.3rem 0.6rem;
        font-size: 0.7rem;
        white-space: nowrap;
    }

    /* Transport + time row: full-width second row, scrollable as fallback */
    body.av-mobile .nav-center {
        display: flex;            /* overrides the base 900px display:none */
        order: 3;
        width: 100%;
        justify-content: flex-start;
        gap: 0.6rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0.15rem 0.1rem 0.3rem;
        scrollbar-width: thin;
    }
    body.av-mobile .transport-controls { gap: 0.2rem; flex-shrink: 0; }
    body.av-mobile .transport-btn {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 0.9rem;
    }
    body.av-mobile .timeline-controls {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        flex-shrink: 0;
    }
    body.av-mobile .timeline-controls select { min-height: 40px; }
    body.av-mobile .time-display { white-space: nowrap; font-size: 0.7rem; }

    /* Drawer toggle buttons (injected by js/mobile.js) */
    body.av-mobile .av-drawer-btn {
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-width: 44px;
        min-height: 44px;
        padding: 4px 6px;
        background: rgba(139, 92, 246, 0.12);
        border: 1px solid rgba(139, 92, 246, 0.35);
        color: var(--accent-color, #a78bfa);
        border-radius: 6px;
        font-size: 0.5rem;
        cursor: pointer;
        flex-shrink: 0;
    }
    body.av-mobile .av-drawer-btn i { font-size: 0.95rem; }

    /* ---------- Sidebars become slide-in drawers ---------- */
    body.av-mobile .left-sidebar,
    body.av-mobile .right-sidebar {
        display: flex;            /* overrides base display:none */
        flex-direction: column;
        position: fixed;
        top: 0;
        bottom: 0;
        width: 86vw;
        max-width: 340px;
        z-index: 1200;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        transition: transform 0.25s ease;
        background: #0f172a;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
        border: none;
    }
    body.av-mobile .left-sidebar {
        left: 0;
        transform: translateX(-105%);
    }
    body.av-mobile .right-sidebar {
        right: 0;
        left: auto;
        transform: translateX(105%);
    }
    body.av-mobile.av-drawer-left .left-sidebar { transform: translateX(0); }
    body.av-mobile.av-drawer-right .right-sidebar { transform: translateX(0); }

    body.av-mobile .av-drawer-close {
        position: sticky;
        top: 0;
        z-index: 5;
        width: 100%;
        min-height: 44px;
        background: rgba(15, 23, 42, 0.98);
        border: none;
        border-bottom: 1px solid rgba(139, 92, 246, 0.25);
        color: var(--text-light, #e2e8f0);
        font-size: 0.85rem;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        cursor: pointer;
    }

    #av-scrim { display: none; }
    body.av-mobile #av-scrim {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.55);
        z-index: 1100;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }
    body.av-mobile.av-drawer-left #av-scrim,
    body.av-mobile.av-drawer-right #av-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    /* Bigger touch targets inside drawers */
    body.av-mobile .import-option { min-height: 44px; }
    body.av-mobile .sidebar .btn,
    body.av-mobile .sidebar button { min-height: 40px; }

    /* ---------- Program monitor ---------- */
    body.av-mobile .preview-monitor { min-height: 150px; }
    body.av-mobile .preview-container { min-height: 110px; }
    body.av-mobile .preview-btn {
        min-width: 40px;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 3px;
    }
    body.av-mobile .preview-header {
        padding: 0.3rem 0.5rem;
        gap: 0.3rem;
        flex-wrap: wrap;
    }
    body.av-mobile .video-placeholder i { font-size: 2rem; margin-bottom: 0.5rem; }
    body.av-mobile .video-placeholder p { font-size: 0.75rem; padding: 0 1rem; }

    /* ---------- Timeline: horizontally scrollable ---------- */
    body.av-mobile .timeline-area {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        height: 232px;
    }
    body.av-mobile .timeline-header,
    body.av-mobile .timeline-tracks {
        min-width: var(--av-tl-width, 800px);
    }
    /* keep track name/controls column pinned while clips scroll */
    body.av-mobile .track-headers,
    body.av-mobile .track-controls {
        position: sticky;
        left: 0;
        z-index: 3;
        background: #0f172a;
    }
    body.av-mobile .track { height: 46px; }
    body.av-mobile .track-header { height: 46px; }
    body.av-mobile .track-mute,
    body.av-mobile .track-lock,
    body.av-mobile .track-solo {
        min-width: 34px;
        min-height: 34px;
        font-size: 0.75rem;
    }
    body.av-mobile .video-clip,
    body.av-mobile .audio-clip,
    body.av-mobile .title-clip,
    body.av-mobile .effect-clip {
        top: 5px;
        height: 36px;
    }
    body.av-mobile .clip-handle { width: 14px; } /* easier to grab on touch */

    /* ---------- Footer ---------- */
    body.av-mobile .app-footer {
        flex-wrap: wrap;
        gap: 0.4rem;
        padding: 0.4rem 0.5rem;
    }
    body.av-mobile .footer-left {
        width: 100%;
        justify-content: flex-start;
        gap: 0.5rem;
        flex-wrap: wrap;
    }
    body.av-mobile .record-btn {
        min-height: 44px;
        padding: 0.3rem 0.7rem;
    }
    body.av-mobile .input-sources select {
        min-height: 44px;
        max-width: 34vw;
    }
    body.av-mobile .footer-center {
        display: flex;            /* overrides base display:none */
        order: 3;
        width: 100%;
    }
    body.av-mobile .ai-generation { width: 100%; }
    body.av-mobile .ai-gen-controls {
        display: flex;
        flex-wrap: wrap;
        gap: 0.35rem;
    }
    body.av-mobile .ai-gen-controls input[type="text"] {
        flex: 1 1 100%;
        min-height: 44px;
    }
    body.av-mobile .ai-gen-controls select {
        flex: 1 1 40%;
        min-height: 44px;
        min-width: 0;
    }
    body.av-mobile .ai-gen-controls .btn { min-height: 44px; }
    body.av-mobile .footer-right { display: none; } /* decorative stats */

    /* ---------- Modals fit the phone screen ---------- */
    body.av-mobile .modal-content {
        width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
        max-height: 88vh;
        overflow-y: auto;
    }
    body.av-mobile .modal .btn { min-height: 44px; }

    /* ---------- Notifications above everything, readable ---------- */
    body.av-mobile .notification {
        max-width: calc(100vw - 24px);
        z-index: 99999;
    }
}
