/**
 * 📱 Drama Online - Mobile Enhancements
 * تحسينات الموبايل
 * Version: 2.0.0
 */

/* ============================================
   📱 Base Mobile Styles
   ============================================ */
@media (max-width: 768px) {
    /* Better touch targets */
    a, button, .clickable {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Remove hover effects on mobile */
    * {
        -webkit-tap-highlight-color: transparent;
    }
    
    body {
        -webkit-text-size-adjust: 100%;
        font-size: 15px;
    }
}

/* ============================================
   🍔 Mobile Menu
   ============================================ */
.mobile-menu-toggle {
    display: none;
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    cursor: pointer;
    position: relative;
    z-index: 1001;
}

@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 5px;
    }
}

.mobile-menu-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: #efab2d;
    border-radius: 2px;
    transition: all 0.3s ease;
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* Mobile Navigation Drawer */
.mobile-nav {
    position: fixed;
    top: 0;
    right: -100%;
    width: 85%;
    max-width: 320px;
    height: 100vh;
    background: #12161f;
    z-index: 1000;
    transition: right 0.3s ease;
    overflow-y: auto;
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.5);
}

.mobile-nav.open {
    right: 0;
}

.mobile-nav-header {
    padding: 20px;
    background: linear-gradient(135deg, #efab2d, #d4941f);
    color: #12161f;
}

.mobile-nav-header .logo {
    max-width: 150px;
}

.mobile-nav-close {
    position: absolute;
    top: 15px;
    left: 15px;
    background: none;
    border: none;
    color: #12161f;
    font-size: 24px;
    cursor: pointer;
}

.mobile-nav-links {
    padding: 15px;
}

.mobile-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px;
    color: #adb3bf;
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.2s ease;
}

.mobile-nav-link:hover,
.mobile-nav-link.active {
    background: rgba(239, 171, 45, 0.1);
    color: #efab2d;
}

.mobile-nav-link svg {
    width: 22px;
    height: 22px;
}

.mobile-nav-link.active {
    background: rgba(239, 171, 45, 0.15);
    border-right: 3px solid #efab2d;
}

/* Mobile Nav Overlay */
.mobile-nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.mobile-nav-overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   🔍 Mobile Search
   ============================================ */
.mobile-search-btn {
    display: none;
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    color: #efab2d;
    cursor: pointer;
}

@media (max-width: 768px) {
    .mobile-search-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .desktop-search {
        display: none;
    }
}

.mobile-search-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(18, 22, 31, 0.98);
    z-index: 1100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.mobile-search-modal.open {
    opacity: 1;
    visibility: visible;
}

.mobile-search-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.mobile-search-back {
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    color: #adb3bf;
    font-size: 24px;
    cursor: pointer;
}

.mobile-search-input {
    flex: 1;
    background: #1b1e25;
    border: 1px solid rgba(239, 171, 45, 0.2);
    border-radius: 25px;
    padding: 12px 20px;
    color: #fff;
    font-size: 16px;
    font-family: 'Cairo', sans-serif;
}

.mobile-search-input:focus {
    border-color: #efab2d;
    outline: none;
}

.mobile-search-results {
    flex: 1;
    overflow-y: auto;
}

/* ============================================
   🎴 Mobile Cards Grid
   ============================================ */
@media (max-width: 768px) {
    .cards-grid,
    .movies-grid,
    .series-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        padding: 10px;
    }
    
    .card,
    .movie-card,
    .series-card {
        border-radius: 8px;
    }
    
    .card-poster,
    .movie-poster {
        aspect-ratio: 2/3;
        border-radius: 8px;
    }
    
    .card-title,
    .movie-title {
        font-size: 12px;
        line-height: 1.3;
        padding: 8px 5px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .card-info,
    .movie-meta {
        font-size: 10px;
        padding: 0 5px 8px;
    }
    
    /* Hide extra info on mobile */
    .card-description,
    .movie-description {
        display: none;
    }
}

@media (max-width: 480px) {
    .cards-grid,
    .movies-grid,
    .series-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
}

/* ============================================
   📺 Mobile Episode List
   ============================================ */
@media (max-width: 768px) {
    .episodes-list {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        padding: 10px;
    }
    
    .episode-item-compact {
        aspect-ratio: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #1b1e25;
        border-radius: 8px;
        color: #adb3bf;
        font-weight: 600;
        font-size: 14px;
        transition: all 0.2s ease;
    }
    
    .episode-item-compact:hover,
    .episode-item-compact.active {
        background: linear-gradient(135deg, #efab2d, #d4941f);
        color: #12161f;
    }
    
    .episode-item-compact.watched {
        opacity: 0.6;
    }
    
    .episode-item-compact.watched::after {
        content: '✓';
        position: absolute;
        top: 3px;
        left: 3px;
        font-size: 10px;
        color: #4caf50;
    }
}

/* ============================================
   📄 Mobile Single Page
   ============================================ */
@media (max-width: 768px) {
    .single-movie,
    .single-series {
        padding-top: 0;
    }
    
    .backdrop-image {
        height: 200px;
    }
    
    .movie-info-container {
        padding: 15px;
        margin-top: -50px;
        position: relative;
        z-index: 10;
    }
    
    .movie-poster-single {
        width: 120px;
        margin: 0 auto -30px;
        border-radius: 10px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    }
    
    .movie-title-single {
        font-size: 20px;
        text-align: center;
        margin-top: 40px;
    }
    
    .movie-meta-single {
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        gap: 10px;
        font-size: 12px;
    }
    
    .movie-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        margin: 15px 0;
    }
    
    .action-btn {
        padding: 12px;
        font-size: 13px;
    }
    
    .action-btn svg {
        width: 18px;
        height: 18px;
    }
    
    .movie-description-single {
        font-size: 14px;
        line-height: 1.7;
    }
}

/* ============================================
   🍿 Mobile Bottom Navigation
   ============================================ */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #12161f;
    border-top: 1px solid rgba(239, 171, 45, 0.1);
    padding: 8px 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 1000;
}

@media (max-width: 768px) {
    .bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }
    
    body {
        padding-bottom: calc(60px + env(safe-area-inset-bottom));
    }
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: #adb3bf;
    text-decoration: none;
    font-size: 11px;
    padding: 5px 15px;
    transition: all 0.2s ease;
}

.bottom-nav-item svg {
    width: 24px;
    height: 24px;
}

.bottom-nav-item.active {
    color: #efab2d;
}

.bottom-nav-item.active svg {
    transform: scale(1.1);
}

/* ============================================
   📜 Mobile Scroll Improvements
   ============================================ */
@media (max-width: 768px) {
    /* Horizontal scroll for carousels */
    .carousel-container {
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    .carousel-container::-webkit-scrollbar {
        display: none;
    }
    
    .carousel-item {
        scroll-snap-align: start;
        flex-shrink: 0;
    }
    
    /* Pull to refresh indicator */
    .pull-refresh-indicator {
        position: fixed;
        top: 0;
        left: 50%;
        transform: translateX(-50%) translateY(-100%);
        background: #1b1e25;
        padding: 10px 20px;
        border-radius: 0 0 10px 10px;
        color: #efab2d;
        font-size: 13px;
        z-index: 1000;
        transition: transform 0.3s ease;
    }
    
    .pull-refresh-indicator.visible {
        transform: translateX(-50%) translateY(0);
    }
}

/* ============================================
   📏 Mobile Spacing
   ============================================ */
@media (max-width: 768px) {
    .section {
        padding: 20px 10px;
    }
    
    .section-title {
        font-size: 18px;
        padding: 0 10px;
        margin-bottom: 15px;
    }
    
    .container {
        padding: 0 10px;
    }
    
    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }
}

/* ============================================
   🎯 Mobile Touch Gestures Area
   ============================================ */
@media (max-width: 768px) {
    /* Double tap to like */
    .double-tap-heart {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) scale(0);
        font-size: 80px;
        color: #ef4444;
        pointer-events: none;
        opacity: 0;
        z-index: 100;
    }
    
    .double-tap-heart.animate {
        animation: doubleTapHeart 1s ease forwards;
    }
    
    @keyframes doubleTapHeart {
        0% {
            transform: translate(-50%, -50%) scale(0);
            opacity: 1;
        }
        50% {
            transform: translate(-50%, -50%) scale(1.2);
            opacity: 1;
        }
        100% {
            transform: translate(-50%, -50%) scale(1);
            opacity: 0;
        }
    }
    
    /* Swipe to go back */
    .swipe-back-indicator {
        position: fixed;
        top: 50%;
        right: 0;
        transform: translateY(-50%) translateX(100%);
        width: 50px;
        height: 100px;
        background: linear-gradient(to right, transparent, rgba(239, 171, 45, 0.2));
        border-radius: 25px 0 0 25px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #efab2d;
        font-size: 24px;
        transition: transform 0.3s ease;
    }
    
    .swipe-back-indicator.visible {
        transform: translateY(-50%) translateX(0);
    }
}

/* ============================================
   💬 Mobile Comments
   ============================================ */
@media (max-width: 768px) {
    .comments-section {
        padding: 15px;
    }
    
    .comment-item {
        padding: 12px;
    }
    
    .comment-avatar {
        width: 36px;
        height: 36px;
    }
    
    .comment-content {
        font-size: 14px;
    }
    
    .comment-reply {
        margin-right: 25px;
    }
    
    .comment-form textarea {
        min-height: 80px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* ============================================
   🔔 Mobile Notifications
   ============================================ */
@media (max-width: 768px) {
    .notification-toast {
        left: 10px;
        right: 10px;
        bottom: calc(70px + env(safe-area-inset-bottom));
        max-width: none;
    }
    
    .notification-dropdown {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
        max-height: none;
    }
}

/* ============================================
   ⚡ Performance: Reduce Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   📲 iOS Specific Fixes
   ============================================ */
@supports (-webkit-touch-callout: none) {
    /* iOS specific styles */
    body {
        -webkit-touch-callout: none;
    }
    
    input, textarea {
        font-size: 16px; /* Prevent zoom */
    }
    
    /* iOS momentum scrolling */
    .scroll-container {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Fix iOS 100vh issue */
    .full-height {
        height: 100vh;
        height: -webkit-fill-available;
    }
}

/* ============================================
   🤖 Android Specific Fixes
   ============================================ */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* Chrome on Android */
    select, input, textarea {
        font-size: 16px;
    }
}

/* ============================================
   🖼️ Mobile Image Optimizations
   ============================================ */
@media (max-width: 768px) {
    img {
        content-visibility: auto;
    }
    
    .lazy-image {
        background: linear-gradient(90deg, #1b1e25 25%, #263238 50%, #1b1e25 75%);
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
    }
    
    @keyframes shimmer {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
    
    .lazy-image.loaded {
        animation: none;
        background: none;
    }
}

/* ============================================
   🔲 Safe Area Handling
   ============================================ */
@supports (padding: max(0px)) {
    .header {
        padding-top: max(15px, env(safe-area-inset-top));
    }
    
    .bottom-nav {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
    
    .mobile-nav {
        padding-top: env(safe-area-inset-top);
    }
}

/* ============================================
   🌙 Mobile Dark Mode Enhancements
   ============================================ */
@media (max-width: 768px) and (prefers-color-scheme: dark) {
    /* Extra dark adjustments for mobile OLED screens */
    body {
        background: #0a0c10;
    }
    
    .card,
    .movie-card {
        background: #12161f;
    }
}

/* ============================================
   📍 Landscape Mode
   ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
    .bottom-nav {
        display: none;
    }
    
    body {
        padding-bottom: 0;
    }
    
    .cards-grid,
    .movies-grid {
        grid-template-columns: repeat(5, 1fr);
    }
    
    .player-container {
        height: 100vh;
        border-radius: 0;
    }
}
