/* ===================================
   Unruly Movies - Responsive Styles
   Enhanced for Mobile Devices
   =================================== */

/* Base Mobile-First Reset */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Prevent iOS Safari zoom on input focus */
@media (max-width: 767px) {
    input, select, textarea {
        font-size: 16px !important;
    }
}

/* Safe area support for notched devices */
@supports (padding: env(safe-area-inset-top)) {
    .app-header {
        padding-top: env(safe-area-inset-top);
    }
    .app-footer {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Tablet Devices (768px and up) */
@media (min-width: 768px) {
    .d-md-block {
        display: block !important;
    }
    
    .d-md-none {
        display: none !important;
    }
    
    /* Hide mobile search on desktop */
    .search-btn,
    .mobile-search-form,
    #mobileSearchBtn {
        display: none !important;
    }
    
    /* Ensure header search is visible on desktop */
    .header-search {
        display: block !important;
    }
    
    .row-cols-md-4 > .col {
        width: 25%;
    }
    
    .row-cols-md-5 > .col {
        width: 20%;
    }
}

/* Large Devices (992px and up) */
@media (min-width: 992px) {
    .d-lg-block {
        display: block !important;
    }
    
    .d-lg-inline {
        display: inline !important;
    }
    
    .d-lg-none {
        display: none !important;
    }
}

/* Mobile Devices (max-width: 767px) */
@media (max-width: 767px) {
    /* Ensure smooth rendering */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        overflow-x: hidden;
    }
    
    /* Hide header search on mobile - only show mobile search */
    .header-search {
        display: none !important;
    }
    
    /* Show mobile search button */
    .search-btn,
    #mobileSearchBtn {
        display: block !important;
    }
    
    /* Mobile Search Form */
    .mobile-search-form {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        padding: 12px 15px;
        background: var(--background-dark);
        z-index: 10001;
        align-items: center;
        gap: 10px;
        box-shadow: 0 4px 20px rgba(0,0,0,0.5);
        animation: slideDown 0.3s ease;
    }
    
    .mobile-search-form.active {
        display: flex;
    }
    
    @keyframes slideDown {
        from {
            transform: translateY(-100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
    
    .mobile-search-input {
        flex: 1;
        padding: 12px 16px;
        border: 1px solid var(--border-color);
        border-radius: 25px;
        background: var(--background-light);
        color: var(--text-primary);
        font-size: 16px;
        outline: none;
    }
    
    .mobile-search-input:focus {
        border-color: var(--primary-color);
        box-shadow: 0 0 0 3px rgba(102, 187, 106, 0.2);
    }
    
    .mobile-search-input::placeholder {
        color: var(--text-secondary);
    }
    
    .mobile-search-submit,
    .mobile-search-close {
        width: 44px;
        height: 44px;
        border: none;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    .mobile-search-submit {
        background: var(--primary-color);
        color: #000;
    }
    
    .mobile-search-submit:hover,
    .mobile-search-submit:active {
        background: #9dff44;
        transform: scale(1.05);
    }
    
    .mobile-search-close {
        background: rgba(255,255,255,0.1);
        color: var(--text-primary);
    }
    
    .mobile-search-close:hover,
    .mobile-search-close:active {
        background: rgba(255,0,0,0.2);
        color: #ff4444;
    }
    
    /* Header */
    .navbar {
        padding: 10px 15px;
        position: sticky;
        top: 0;
        z-index: 1000;
    }
    
    .navbar-brand img {
        max-height: 35px;
        height: auto;
        width: auto;
        display: block;
    }
    
    /* Search button styling */
    .search-btn {
        padding: 8px;
        cursor: pointer;
        border-radius: 50%;
        transition: background 0.2s ease;
    }
    
    .search-btn:hover,
    .search-btn:active {
        background: rgba(124, 252, 0, 0.2);
    }
    
    /* Adjust navbar for mobile */
    .navbar-user {
        gap: 3px;
        margin-left: auto;
        display: flex;
        align-items: center;
    }
    
    /* Hide text labels on mobile, show icons */
    .navbar-user .nav-link span {
        display: none !important;
    }
    
    .navbar-user .nav-link {
        padding: 6px 8px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Keep login button visible and styled on mobile */
    .navbar-user .btn-login {
        padding: 8px 14px;
        font-size: 13px;
        min-width: auto;
    }
    
    /* User dropdown mobile styles */
    .user-dropdown {
        position: relative;
    }
    
    .user-avatar {
        width: 32px;
        height: 32px;
    }
    
    .user-btn {
        padding: 4px 8px !important;
    }
    
    .dropdown-menu {
        right: 0;
        left: auto;
        min-width: 150px;
        position: absolute;
        top: 100%;
        z-index: 9999;
    }
    
    /* Hide some nav items on very small screens */
    @media (max-width: 400px) {
        .navbar-user .nav-item:not(#loginBtn):not(#userMenu) {
            display: none;
        }
    }
    
    .header-search {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        max-width: 100%;
        background-color: var(--background-dark);
        padding: 15px;
        z-index: 10000;
        transform: translateY(-100%);
        transition: transform 0.3s ease;
    }
    
    .header-search.active {
        transform: translateY(0);
    }
    
    /* Sidebar */
    .app-aside {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        z-index: 9999;
        transition: left 0.3s ease;
        padding-top: 60px;
        background-color: var(--background-light);
    }
    
    .app-aside.show {
        left: 0;
    }
    
    .modal-close {
        position: absolute;
        top: 15px;
        right: 15px;
        background: transparent;
        border: none;
        color: var(--text-primary);
        cursor: pointer;
        z-index: 10;
    }
    
    /* Main Content */
    .app-container {
        padding: 15px;
        width: 100%;
    }
    
    /* Fix movie grid on mobile - 4 columns grid layout */
    .list-scrollable {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 8px !important;
        overflow-x: visible !important;
        flex-wrap: wrap !important;
        padding-bottom: 10px;
    }
    
    .list-scrollable::-webkit-scrollbar {
        display: none;
    }
    
    .list-scrollable > .col {
        flex: none !important;
        width: 100% !important;
        min-width: 0 !important;
    }
    
    /* Row cols override for mobile grid - 2 columns on mobile */
    .row-cols-2 {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    
    .row-cols-2 > .col {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
        padding: 0 !important;
    }
    
    /* Larger cards on mobile */
    .list-movie {
        min-height: 0;
    }
    
    .list-media {
        padding-bottom: 150%; /* 2:3 ratio */
    }
    
    /* Movie cards */
    .list-movie {
        width: 100%;
    }
    
    .list-media {
        display: block;
        position: relative;
        aspect-ratio: 2/3;
        border-radius: 8px;
        overflow: hidden;
    }
    
    .media-cover {
        width: 100%;
        height: 100%;
        background-size: cover;
        background-position: center;
    }
    
    /* Hero Slider */
    .slide {
        height: 350px;
    }
    
    .slide-caption {
        padding: 30px 20px;
    }
    
    .slide .title {
        font-size: 28px;
    }
    
    .slide .description {
        font-size: 14px;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    
    .carousel-control {
        padding: 0 10px;
    }
    
    .control-prev,
    .control-next {
        width: 40px;
        height: 40px;
    }
    
    /* Section Headings */
    .app-heading .text {
        font-size: 20px;
    }
    
    .app-heading .all {
        font-size: 12px;
        padding: 6px 15px;
    }
    
    /* Movie Cards - 4 column mobile grid */
    .list-scrollable > .col {
        width: 100% !important;
    }
    
    .list-title {
        font-size: 11px;
        line-height: 1.2;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    
    .list-category {
        font-size: 10px;
    }
    
    .list-caption {
        padding: 5px 2px;
    }
    
    /* Smaller quality badge and rating for mobile */
    .quality {
        font-size: 8px;
        padding: 2px 5px;
    }
    
    .imdb {
        transform: scale(0.7);
        transform-origin: top right;
    }
    
    .list-media-attr {
        top: 5px;
        left: 5px;
        right: 5px;
    }
    
    .play-btn {
        width: 35px;
        height: 35px;
    }
    
    .play-btn svg,
    .play-btn .icon {
        width: 16px;
        height: 16px;
    }
    
    /* Footer */
    .app-footer {
        padding: 30px 15px 20px;
    }
    
    .footer-nav .nav-head {
        font-size: 14px;
    }
    
    .footer-nav a {
        font-size: 13px;
    }
    
    /* Scroll to Top */
    .scroll-up {
        width: 45px;
        height: 45px;
        bottom: 20px;
        right: 20px;
    }
    
    .scroll-up svg {
        width: 20px;
        height: 20px;
    }
}

/* Small Mobile Devices (max-width: 480px) */
@media (max-width: 480px) {
    .slide {
        height: 300px;
    }
    
    .slide .title {
        font-size: 24px;
    }
    
    .slide-header {
        gap: 10px;
        font-size: 12px;
    }
    
    .list-scrollable > .col {
        width: 130px;
    }
    
    .app-section {
        margin-bottom: 35px;
    }
    
    .navbar-nav {
        gap: 8px;
    }
    
    .nav-link {
        padding: 6px 10px;
        font-size: 13px;
    }
}

/* Landscape Mobile Devices */
@media (max-width: 767px) and (orientation: landscape) {
    .slide {
        height: 280px;
    }
    
    .app-aside {
        width: 250px;
    }
}

/* Large Desktop (1400px and up) */
@media (min-width: 1400px) {
    .container {
        max-width: 1600px;
    }
    
    .slide {
        height: 550px;
    }
    
    .slide .title {
        font-size: 48px;
    }
    
    .list-scrollable > .col {
        width: 220px;
    }
}

/* Extra Large Desktop (1920px and up) */
@media (min-width: 1920px) {
    .container {
        max-width: 1800px;
    }
    
    .slide {
        height: 600px;
    }
    
    .app-heading .text {
        font-size: 28px;
    }
}

/* Print Styles */
@media print {
    .app-header,
    .app-aside,
    .app-footer,
    .scroll-up,
    .play-btn,
    .carousel-control,
    .carousel-indicators {
        display: none !important;
    }
    
    body {
        background: white;
        color: black;
    }
    
    .app-container {
        width: 100%;
        max-width: 100%;
    }
}

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

/* Dark Mode Support (if system prefers dark) */
@media (prefers-color-scheme: dark) {
    :root {
        --background-dark: #0a0a0a;
        --background-light: #1a1a1a;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --border-color: #ffffff;
        --text-secondary: #ffffff;
    }
    
    .list-media-attr,
    .play-btn {
        border: 2px solid var(--primary-color);
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .nav-link,
    .list-movie,
    .control-prev,
    .control-next {
        -webkit-tap-highlight-color: rgba(124, 252, 0, 0.2);
    }
    
    .play-btn {
        opacity: 1;
    }
    
    /* Increase touch targets */
    .nav-link {
        min-height: 44px;
    }
    
    .control-prev,
    .control-next {
        min-width: 44px;
        min-height: 44px;
    }
}
