/* ===================================================
   MOBILE UI/UX PRO MAX REDESIGN (APP-LIKE EXPERIENCE)
=================================================== */

@media screen and (max-width: 768px) {
    /* 1. Base Container Scaling */
    html, body {
        overflow-x: hidden;
        width: 100%;
    }

    .dashboard-page {
        background-color: #020617; 
        -webkit-tap-highlight-color: transparent;
    }

    .studio-layout {
        display: block !important;
    }

    .sidebar {
        display: none !important;
    }

    .main-area {
        height: auto !important;
        min-height: 100vh;
        padding-bottom: 100px !important; /* Space for bottom nav */
    }

    .top-bar {
        padding: 12px 16px !important;
        background: rgba(2, 6, 23, 0.85) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        position: sticky;
        top: 0;
        z-index: 100;
        border-bottom: 1px solid rgba(255,255,255,0.05);
    }

    .page-title h1 {
        font-size: 18px !important;
        line-height: 1.2;
    }

    .content-wrapper {
        padding: 16px !important;
    }

    /* 2. Bento Grid -> Stack */
    .bento-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 16px !important;
        margin-bottom: 24px !important;
    }

    .bento-card {
        padding: 20px !important;
        border-radius: 20px !important;
    }

    /* 3. Premium Hero Card (Video Download Redesign) */
    .hero-card {
        padding: 28px 24px !important;
        background: linear-gradient(165deg, rgba(30, 41, 59, 0.5), rgba(15, 23, 42, 0.8)) !important;
        border: 1px solid rgba(255, 255, 255, 0.08) !important;
        box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4) !important;
        position: relative;
        overflow: hidden;
    }
    
    .hero-card::before {
        content: '';
        position: absolute;
        top: -50%;
        right: -50%;
        width: 150px;
        height: 150px;
        background: radial-gradient(circle, rgba(59, 130, 246, 0.15), transparent 70%);
        pointer-events: none;
    }

    .hero-card h2 {
        font-size: 24px !important;
        font-weight: 800 !important;
        letter-spacing: -0.02em !important;
        margin-bottom: 8px !important;
        background: linear-gradient(to right, #fff, #94a3b8);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }
    
    .hero-card p {
        font-size: 14px !important;
        color: #94a3b8 !important;
        margin-bottom: 24px !important;
    }

    .platform-cards {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 16px !important;
        margin-bottom: 24px !important;
    }

    .platform-card {
        padding: 20px 16px !important;
        background: rgba(255, 255, 255, 0.03) !important;
        border: 1px solid rgba(255, 255, 255, 0.08) !important;
        border-radius: 20px !important;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    .platform-card.active {
        background: rgba(59, 130, 246, 0.1) !important;
        border-color: var(--primary) !important;
        box-shadow: 0 0 20px rgba(59, 130, 246, 0.2) !important;
    }

    .platform-icon {
        width: 48px !important;
        height: 48px !important;
        margin-bottom: 12px !important;
        font-size: 24px !important;
        border-radius: 14px !important;
    }
    
    .platform-card span {
        font-weight: 600 !important;
        font-size: 14px !important;
    }

    .search-bar {
        display: flex !important;
        flex-direction: column !important;
        gap: 16px !important;
        background: transparent !important;
        padding: 0 !important;
        border: none !important;
    }

    .search-bar input {
        width: 100% !important;
        background: rgba(15, 23, 42, 0.6) !important;
        border: 1px solid rgba(255, 255, 255, 0.12) !important;
        padding: 18px 20px !important;
        border-radius: 18px !important;
        font-size: 15px !important;
        color: white !important;
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2) !important;
        transition: all 0.2s ease !important;
    }
    
    .search-bar input:focus {
        border-color: var(--primary) !important;
        background: rgba(15, 23, 42, 0.8) !important;
        outline: none !important;
    }

    .search-bar .btn-download-hero {
        width: 100% !important;
        padding: 18px !important;
        border-radius: 18px !important;
        font-size: 16px !important;
        font-weight: 700 !important;
        justify-content: center !important;
        background: linear-gradient(135deg, var(--primary), #2563eb) !important;
        box-shadow: 0 10px 20px rgba(37, 99, 235, 0.3) !important;
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }

    /* 4. Tools Grid */
    .tools-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    .pro-tool-card {
        padding: 16px !important;
        border-radius: 16px !important;
    }

    .pro-tool-card h4 {
        font-size: 15px !important;
    }

    /* 5. AI Studio Area */
    .command-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
        margin-bottom: 20px !important;
    }

    .header-titling h2 {
        font-size: 20px !important;
    }

    .input-hero-wrapper {
        flex-direction: column !important;
        padding: 8px !important;
        border-radius: 20px !important;
    }

    .input-icon {
        display: none !important;
    }

    .hero-input {
        width: 100% !important;
        padding: 12px 8px !important;
        background: transparent !important;
        border: none !important;
    }

    .btn-hero-action {
        align-self: flex-end !important;
        background: rgba(255,255,255,0.1) !important;
        padding: 8px 16px !important;
        border-radius: 12px !important;
        width: auto !important;
    }

    /* 6. Context Panel - Scrollable Enhancement */
    .context-panel {
        padding: 20px !important;
        background: rgba(15, 23, 42, 0.6) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        border-radius: 24px !important;
        border: 1px solid rgba(255, 255, 255, 0.08) !important;
        margin-top: 12px !important;
        max-height: 400px !important; /* Limit height */
        overflow-y: auto !important; /* Enable scrolling */
        scrollbar-width: thin;
    }

    .context-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }
    
    .context-group label {
        font-size: 13px !important;
        color: #94a3b8 !important;
        margin-bottom: 8px !important;
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
    }
    
    .context-group input {
        background: rgba(255, 255, 255, 0.04) !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        padding: 14px 16px !important;
        border-radius: 14px !important;
        font-size: 14px !important;
        color: white !important;
    }

    /* 7. Tool Dock - Premium Mobile App Experience */
    .tool-dock-container {
        flex-direction: column !important;
        gap: 16px !important;
        margin-bottom: 24px !important;
    }

    .tool-dock {
        display: flex !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        scroll-snap-type: x mandatory;
        gap: 12px !important;
        padding: 16px !important;
        background: rgba(15, 23, 42, 0.4) !important;
        filter: drop-shadow(0 10px 30px rgba(0,0,0,0.2));
        border: 1px solid rgba(255, 255, 255, 0.08) !important;
        border-radius: 20px !important;
        width: 100% !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    
    .tool-dock::-webkit-scrollbar {
        display: none;
    }

    .dock-item {
        flex: 0 0 auto !important; /* Allow content to define width */
        min-width: 120px !important; /* Force a minimum width to prevent overlap */
        max-width: 120px !important; /* Keep consistent width */
        scroll-snap-align: center; /* Center-snap for better mobile feel */
        padding: 18px 10px !important;
        background: rgba(255, 255, 255, 0.03) !important;
        border: 1px solid rgba(255, 255, 255, 0.05) !important;
        border-radius: 20px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: flex-start !important;
        min-height: 120px !important;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    .dock-item.active {
        background: rgba(59, 130, 246, 0.15) !important;
        border-color: rgba(59, 130, 246, 0.4) !important;
        transform: translateY(-4px) !important;
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3) !important;
    }

    .dock-item .icon-box {
        font-size: 26px !important;
        margin-bottom: 12px !important;
        width: 48px !important;
        height: 48px !important;
        background: rgba(255, 255, 255, 0.05) !important;
        border-radius: 14px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .dock-item.active .icon-box {
        background: var(--primary) !important;
        color: #fff !important;
    }

    .dock-item .label {
        font-size: 11px !important;
        font-weight: 600 !important;
        color: var(--text-muted) !important;
        white-space: normal !important;
        text-align: center !important;
        line-height: 1.3 !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
        height: 2.6em !important;
    }
    
    .dock-item.active .label {
        color: white !important;
    }

    .dock-divider {
        display: none !important;
    }

    .btn-execute-primary {
        width: 100% !important;
        height: 56px !important;
        border-radius: 16px !important;
        font-size: 16px !important;
        justify-content: center !important;
        margin: 0 !important;
    }

    /* 8. Results Area Mobile Refinement */
    .result-console-container {
        padding: 0 !important;
        margin-top: 24px !important;
    }

    .result-console {
        padding: 0 !important; /* Let cards handle padding */
        background: transparent !important;
        border: none !important;
    }
    
    .result-card, .analysis-result, .scripts-result {
        background: rgba(15, 23, 42, 0.6) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        border: 1px solid rgba(255, 255, 255, 0.08) !important;
        border-radius: 24px !important;
        padding: 20px 16px !important;
        margin-bottom: 20px !important;
    }

    /* Score Header Adjustments */
    .score-header-pro {
        flex-direction: column !important;
        gap: 20px !important;
        align-items: center !important;
    }
    
    .score-card-main {
        width: 100% !important;
        justify-content: center !important;
    }
    
    .critique-box {
        width: 100% !important;
        padding: 20px !important;
    }
    
    .critique-content {
        font-size: 14px !important;
        line-height: 1.6 !important;
    }

    /* Grid Adjustments */
    .layers-grid, .scripts-grid, .platform-optimization-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
    
    .layer-card {
        padding: 16px !important;
    }
    
    .section-divider {
        margin: 32px 0 16px 0 !important;
        font-size: 11px !important;
    }

    /* Transcript & Script Mobile Fixes */
    .transcript-container {
        max-height: 350px !important;
        padding: 40px 12px 16px !important;
    }
    
    .transcript-segment {
        gap: 12px !important;
        padding: 12px !important;
    }
    
    .transcript-segment div:last-child {
        font-size: 13px !important;
    }
    
    .script-card {
        padding: 16px !important;
    }
    
    .script-header {
        font-size: 12px !important;
    }
    
    .section-text {
        font-size: 14px !important;
    }

    /* Buttons Mobile Targets */
    .mega-actions, .script-footer {
        flex-direction: column !important;
        gap: 10px !important;
    }
    
    .btn-download-mega, .btn-hero-action, .btn-execute-primary, .btn-copy-script {
        height: 54px !important;
    }

    /* 9. Bottom Navigation Overlay FIX */
    .mobile-bottom-nav {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        background: rgba(15, 23, 42, 0.85) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        border-top: 1px solid rgba(255,255,255,0.08) !important;
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)) !important;
        justify-content: space-around !important;
        z-index: 1000 !important;
    }

    .mobile-nav-item {
        font-size: 10px !important;
        gap: 4px !important;
    }

    .mobile-nav-item i {
        font-size: 24px !important;
        margin-bottom: 2px !important;
    }

    /* 10. Modals - Mobile Bottom Sheet style */
    .script-modal {
        align-items: flex-end !important;
    }

    .script-modal-content {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: 90vh !important;
        border-radius: 24px 24px 0 0 !important;
        margin-top: auto !important;
        margin-bottom: 0 !important;
        padding: 30px 20px 40px !important;
        overflow-y: auto !important;
        background: linear-gradient(135deg, rgba(30,30,40,0.98), rgba(10,10,15,0.98)) !important;
        border: none !important;
        border-top: 1px solid rgba(255,255,255,0.1) !important;
    }
    
    .btn-close-modal {
        top: -46px !important;
        right: 16px !important;
        background: rgba(0,0,0,0.5) !important;
        backdrop-filter: blur(10px) !important;
        border-radius: 50% !important;
    }

    .script-types-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }
    
    .script-type-card {
        padding: 14px 8px !important;
    }
}
