/* ============================================================
   LernHub Mobile UI — Native App Experience
   All rules scoped to max-width: 768px
   ============================================================ */

@media (max-width: 768px) {
    /* === CSS VARIABLES === */
    :root {
        --mobile-nav-height: 60px;
        --safe-area-top: env(safe-area-inset-top, 0px);
        --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    }

    html {
        overflow-x: hidden;
        -webkit-text-size-adjust: 100%;
    }

    body {
        font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, Roboto, sans-serif;
        font-size: 16px;
        padding-bottom: calc(var(--mobile-nav-height) + var(--safe-area-bottom) + 16px);
        overflow-x: hidden;
    }

    /* === HEADER & NAVIGATION === */
    .header { 
        display: block !important; 
        padding: 0.5rem 0.75rem;
        background: var(--bg-primary);
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        z-index: 1000;
    }
    .header-actions .create-btn, 
    /* .header-actions .user-info, */
    .header-actions #settingsBtn, 
    .header-actions #logoutBtn,
    .header-actions #mobileMenuBtn { 
        display: none !important; 
    }
    
    .header-container {
        justify-content: space-between;
    }
    
    .header .user-info {
        display: flex !important;
        flex-direction: row-reverse !important;
        align-items: center;
        gap: 8px;
    }
    
    .header .user-id {
        font-size: 0.85rem;
        font-weight: 600;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--text-primary);
    }
    
    .header .user-status {
        font-size: 0.7rem;
        padding: 2px 8px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.02em;
    }

    /* === HERO === */
    .hero { padding: 2rem 1rem 1.5rem; }

    .mobile-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        z-index: 1000;
        background: rgba(10, 15, 26, 0.92);
        backdrop-filter: blur(20px);
        border-top: 1px solid var(--border-color);
        padding-bottom: var(--safe-area-bottom);
        height: calc(var(--mobile-nav-height) + var(--safe-area-bottom));
    }

    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.2rem;
        text-decoration: none;
        color: var(--text-muted);
        font-size: 0.7rem;
    }

    .mobile-nav-item.active { color: var(--accent-blue); }
    .mobile-nav-item.mobile-nav-disabled { opacity: 0.3; pointer-events: none; }

    /* === HERO === */
    .hero { padding: 1.5rem 1rem 1rem; }
    .hero-container { grid-template-columns: 1fr; text-align: center; }
    .hero-visual, .hero-illustration { display: none; }
    .hero-title { font-size: 1.75rem; }

    /* === SEARCH === */
    .search-section {
        padding: 0.75rem 1rem;
        position: sticky; top: 0;
        z-index: 1010;
        background: rgba(17, 24, 39, 0.95);
        backdrop-filter: blur(12px);
    }

    /* === CARDS === */
    .pdf-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
        padding: 1rem;
    }

    .pdf-card {
        border-radius: 16px;
        padding: 1.25rem;
    }

    /* === MODALS & VIEWER === */
    .modal-overlay { align-items: flex-end; }
    .modal-content {
        width: 100% !important;
        margin: 0 !important;
        border-radius: 20px 20px 0 0 !important;
        padding-bottom: var(--safe-area-bottom);
        transform: translateY(100%);
        transition: transform 0.3s ease;
    }
    .modal-overlay.active .modal-content { transform: translateY(0); }

    /* PDF Viewer Specific */
    .modal-large {
        height: 100% !important;
        max-height: 100vh !important;
        width: 100% !important;
        border-radius: 0 !important;
    }

    .viewer-body {
        padding: 0 !important;
        margin: 0 !important;
    }

    .viewer-header {
        padding: 0.5rem 0.75rem !important;
        background: var(--bg-primary) !important;
        min-height: auto !important;
    }

    .viewer-title {
        display: flex !important;
        flex-direction: column !important; /* Back to column, but subject is hidden */
        justify-content: center !important;
        flex: 1 !important;
        overflow: hidden;
    }

    .viewer-title > div {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
    }

    .viewer-title h2 {
        font-size: 0.9rem !important;
        max-width: 50vw !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin: 0 !important;
    }

    #videoIndicator {
        display: none;
        align-items: center;
        justify-content: center;
        background: rgba(59, 130, 246, 0.15);
        padding: 2px 6px;
        border-radius: 4px;
        color: var(--accent-blue, #3b82f6);
        flex-shrink: 0;
    }

    .viewer-subject {
        display: none !important; /* Hide subject on mobile */
    }

    /* Compact podcast player on mobile */
    .podcast-player {
        padding: 0.3rem 0.75rem !important;
        border-bottom: 1px solid var(--border-color);
    }
    .podcast-player-inner {
        gap: 0.5rem !important;
    }
    .podcast-label {
        display: none !important;
    }
    .podcast-time {
        font-size: 0.7rem !important;
        min-width: 70px;
    }

    .viewer-actions {
        gap: 0.2rem !important;
        flex-shrink: 0;
    }

    /* Hide redundant buttons in header on mobile, they move to FAB */
    .viewer-actions .quiz-btn-wrap,
    .viewer-actions .chat-btn,
    .viewer-actions .download-btn,
    .viewer-actions .share-btn {
        display: none !important;
    }

    /* Make Night Mode and Search smaller/icon-only in header */
    .viewer-actions button {
        padding: 0.4rem !important;
        min-width: 36px !important;
        height: 36px !important;
    }

    .pdf-navigation {
        position: fixed !important;
        bottom: 4px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 98% !important;
        max-width: 380px !important;
        padding: 0.4rem 0.6rem !important;
        background: rgba(17, 24, 39, 0.98) !important;
        backdrop-filter: blur(20px) !important;
        border-radius: 12px !important; /* Slightly less rounded for more space */
        border: 1px solid rgba(255,255,255,0.1) !important;
        box-shadow: 0 4px 20px rgba(0,0,0,0.6) !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 0.4rem !important;
        z-index: 2100 !important;
    }

    .zoom-controls {
        display: flex !important;
        align-items: center !important;
        gap: 0.4rem !important;
    }

    .zoom-controls #zoomIn,
    .zoom-controls #zoomOut {
        display: none !important;
    }

    .zoom-level {
        display: block !important;
        font-size: 0.75rem !important;
        font-weight: 600 !important;
        color: var(--text-muted) !important;
        min-width: 35px;
    }

    .zoom-btn {
        width: auto !important;
        height: 34px !important;
        padding: 0 0.6rem !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: rgba(255,255,255,0.08) !important;
        border-radius: 6px !important;
        border: 1px solid rgba(255,255,255,0.1) !important;
        font-size: 0.7rem !important; /* Show text again */
        font-weight: 600 !important;
        text-transform: uppercase;
        color: white !important;
    }
    
    /* Icons already in HTML text content, no ::before needed */

    .nav-btn {
        width: 34px !important;
        height: 34px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: rgba(255,255,255,0.08) !important;
        border-radius: 6px !important;
        border: 1px solid rgba(255,255,255,0.1) !important;
    }

    .page-info {
        font-size: 0.75rem !important;
        font-weight: 600 !important;
        min-width: 65px;
        text-align: center;
        color: white !important;
    }

    /* PDF Canvas container touch handling */
    .pdf-canvas-container {
        touch-action: pan-x pan-y;
        overflow: scroll !important;
        background: #000 !important;
        height: calc(100vh - 44px) !important;
        padding: 0 !important;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        display: block !important;
    }

    .keyboard-shortcuts-hint {
        display: none !important;
    }

    .pdf-page-wrapper,
    canvas#pdfCanvas {
        margin: 0 auto !important;
        box-shadow: none !important;
        display: block;
    }

    /* === FAB === */
    .mobile-fab-container {
        display: none; /* Controlled by JS */
        position: fixed;
        bottom: 85px !important;
        right: 20px !important;
        z-index: 2200 !important;
        flex-direction: column-reverse;
        align-items: center;
        gap: 12px;
    }

    .mobile-fab-toggle {
        width: 56px !important;
        height: 56px !important;
        border-radius: 50% !important;
        background: var(--accent-blue, #3b82f6) !important;
        color: white !important;
        box-shadow: 0 4px 15px rgba(0,0,0,0.4);
        border: none !important;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .mobile-fab-toggle.open {
        transform: rotate(45deg);
        background: var(--surface2, #1f2937) !important;
        animation: none !important;
        box-shadow: 0 4px 15px rgba(0,0,0,0.4) !important;
    }

    .mobile-fab-toggle.has-video {
        animation: fab-pulse-advanced 2s infinite;
    }

    @keyframes fab-pulse-advanced {
        0% { 
            box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.6);
            transform: scale(1);
        }
        50% {
            transform: scale(1.05);
        }
        70% { 
            box-shadow: 0 0 0 15px rgba(59, 130, 246, 0);
            transform: scale(1);
        }
        100% { 
            box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
            transform: scale(1);
        }
    }

    .mobile-fab-actions {
        display: none;
        flex-direction: column-reverse;
        gap: 12px;
        margin-bottom: 8px;
    }

    .mobile-fab-actions.open {
        display: flex !important;
    }

    .mobile-fab-action {
        width: 48px !important;
        height: 48px !important;
        border-radius: 50% !important;
        background: var(--surface2, #1f2937) !important;
        color: white !important;
        border: 1px solid var(--border-color) !important;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 10px rgba(0,0,0,0.3) !important;
    }

    /* === INPUTS === */
    input, select, textarea { font-size: 16px !important; }

    /* === SKELETON === */
    .skeleton {
        background: linear-gradient(90deg, var(--bg-card) 25%, var(--border-color) 50%, var(--bg-card) 75%);
        background-size: 200% 100%;
        animation: skeleton-loading 1.5s infinite;
    }
    @keyframes skeleton-loading {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
}

/* === DESKTOP FIXES === */
@media (min-width: 769px) {
    .mobile-bottom-nav,
    .mobile-fab-container,
    .pull-to-refresh {
        display: none !important;
    }
}
