/* ========================================
   UX/UI IMPROVEMENTS - Enhanced Responsive Design
   All inline styles and event handlers moved to CSS
   ======================================== */

/* ========================================
   RESPONSIVE CONTAINER & LAYOUT
   ======================================== */
@media (max-width: 768px) {
    .container {
        max-width: 100%;
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
    
    .main-content {
        padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

@media (min-width: 769px) {
    .container {
        max-width: 1400px;
        margin: 0 auto;
    }
}

/* ========================================
   HEADER HEIGHT OPTIMIZATION (MOBILE)
   Reduced from 56px to 50px for more content
   ======================================== */
@media (max-width: 768px) {
    .top-nav {
        height: 50px !important;
    }
    
    .main-content {
        padding-top: 50px !important;
    }
    
    .mobile-menu {
        top: 50px !important;
    }
}

/* ========================================
   BOTTOM NAV OPTIMIZATION
   ======================================== */
@media (max-width: 768px) {
    .bottom-nav-bar {
        height: calc(56px + env(safe-area-inset-bottom, 0px)) !important;
    }
    
    .bottom-nav-item {
        height: 56px;
        font-size: 0.75rem;
        justify-content: center;
    }
    
    .bottom-nav-item i {
        font-size: 1.25rem;
        margin-bottom: 0.25rem;
    }
}

/* ========================================
   IMAGE OPTIMIZATION - PREVENT CLS
   ======================================== */

/* Aspect ratio container for images */
.poster-wrapper {
    position: relative;
    width: 100%;
    padding-bottom: 150%; /* 2:3 aspect ratio */
    overflow: hidden;
    border-radius: 6px;
    background-color: var(--bg-card);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}

.poster-wrapper img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease !important;
}

.poster-wrapper .no-poster {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-card), rgba(255,255,255,0.1));
    color: var(--text-secondary);
}

.poster-wrapper .trailer-badge {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    width: 48px;
    height: 48px;
    background: rgba(229, 9, 20, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* ========================================
   MOVIE CARD - ENHANCED
   ======================================== */

.movie-card {
    text-decoration: none;
    color: inherit;
    transition: transform 0.3s ease !important; /* Only transform, not all */
    display: block;
    height: 100%;
}

.movie-card:hover {
    transform: translateY(-8px);
}

@media (hover: hover) {
    .movie-card:hover .poster-wrapper {
        box-shadow: 0 12px 32px rgba(0, 0, 0, 0.8), 0 0 20px rgba(229, 9, 20, 0.15);
    }
    
    .movie-card:hover .poster-wrapper img {
        transform: scale(1.08);
    }
    
    .movie-card:hover .trailer-badge {
        opacity: 1;
    }
}

.movie-info {
    margin-top: 0.75rem;
}

.movie-title {
    margin: 0;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.movie-year {
    margin: 0.3rem 0 0 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.movie-rating {
    font-weight: 700;
    font-size: 0.85rem;
    color: #ffc107;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* ========================================
   RATING BADGE - ENHANCED
   ======================================== */

.rating-badge {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    padding: 0.5rem 0.8rem;
    background: rgba(0,0,0,0.8);
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.85rem;
    color: #ffc107;
    border: 1px solid rgba(255,193,7,0.5);
    z-index: 5;
    backdrop-filter: blur(4px);
}

/* ========================================
   FILTER CHIPS - MOBILE OPTIMIZED
   ======================================== */

.filter-chips-container {
    margin-bottom: 2rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.filter-chips-wrapper {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    min-width: min-content;
    padding: 0.5rem 0; /* Make scrollbar visible if needed */
}

@media (max-width: 600px) {
    .filter-chips-wrapper {
        padding-right: 1rem; /* Add space after last chip */
    }
}

.filter-chip {
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.3s ease;
    flex-shrink: 0;
    border-radius: 999px;
    cursor: pointer;
}

.filter-chip:hover,
.filter-chip:focus {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(229, 9, 20, 0.2);
}

.filter-chip:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.filter-chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.filter-chip--active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    font-weight: 600;
}

.filter-chip i {
    margin-right: 0.5rem;
}

/* ========================================
   PAGINATION - ENHANCED
   ======================================== */

.pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 2rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

.pagination-btn,
.pagination-link {
    padding: 0.6rem 1rem;
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-primary);
    transition: all 0.3s ease;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
}

.pagination-link:hover,
.pagination-link:focus {
    background: rgba(255,255,255,0.2);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
}

.pagination-link.active,
.pagination-current {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.pagination-link:focus,
.pagination-btn:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ========================================
   EMPTY STATE - IMPROVED
   ======================================== */

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    background: rgba(255,255,255,0.05);
    border-radius: 12px;
    border: 1px dashed var(--border-soft);
    margin: 2rem 0;
}

.empty-state-icon {
    font-size: 3rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    display: block;
}

.empty-state-title {
    color: var(--text-primary);
    margin: 0 0 0.5rem 0;
    font-size: 1.25rem;
}

.empty-state-text {
    color: var(--text-secondary);
    margin: 0;
    font-size: 0.95rem;
}

/* ========================================
   LOADING STATES - NEW
   ======================================== */

.skeleton-loader {
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-elevated) 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: skeletonLoading 1.5s infinite;
    border-radius: 6px;
}

@keyframes skeletonLoading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.poster-skeleton {
    position: relative;
    width: 100%;
    padding-bottom: 150%;
    border-radius: 6px;
    background: var(--bg-card);
}

.poster-skeleton::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width:100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    animation: shimmer 2s infinite;
    border-radius: 6px;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.title-skeleton {
    height: 1rem;
    background: var(--bg-card);
    border-radius: 4px;
    margin-top: 0.5rem;
    animation: skeletonLoading 1.5s infinite;
}

.meta-skeleton {
    height: 0.75rem;
    background: var(--bg-card);
    border-radius: 4px;
    margin-top: 0.5rem;
    width: 70%;
    animation: skeletonLoading 1.5s infinite;
}

/* Loading spinner */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 0.8s linear infinite;
    margin-right: 0.5rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   ERROR STATES - NEW
   ======================================== */

.error-container {
    padding: 1.5rem;
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(239, 68, 68, 0.05));
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    margin: 1rem 0;
    color: #feca57;
}

.error-title {
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.error-message {
    font-size: 0.9rem;
    margin: 0;
    color: var(--text-soft);
}

.error-retry-btn {
    padding: 0.6rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 1rem;
    transition: all 0.3s ease;
    font-weight: 600;
}

.error-retry-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

/* ========================================
   FOCUS STATES - ACCESSIBILITY
   ======================================== */

a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Remove default outline for mouse users only */
a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
    outline: none;
}

/* ========================================
   GRID RESPONSIVE - OPTIMIZED
   ======================================== */

.movies-grid {
    display: grid;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

@media (max-width: 500px) {
    .movies-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        gap: 1rem;
    }
}

@media (min-width: 501px) and (max-width: 768px) {
    .movies-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .movies-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

@media (min-width: 1025px) {
    .movies-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

/* ========================================
   IMPROVED BUTTONS
   ======================================== */

.btn {
    padding: 0.8rem 1.2rem;
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
}

.btn:hover,
.btn:focus {
    background: var(--bg-elevated);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--primary-hover);
    color: white;
    box-shadow: 0 6px 20px rgba(229, 9, 20, 0.3);
}

.btn-secondary {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
    border-color: var(--border-soft);
}

.btn-secondary:hover,
.btn-secondary:focus {
    background: rgba(255,255,255,0.2);
    border-color: var(--primary);
}

/* ========================================
   RESPONSIVE TEXT & IMAGES
   ======================================== */

@media (max-width: 500px) {
    h1 {
        font-size: 1.5rem !important;
    }
    
    h2 {
        font-size: 1.25rem !important;
    }
    
    p {
        font-size: 0.9rem;
    }
}

/* Lazy loading image support */
img[loading="lazy"] {
    background: var(--bg-card);
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.page-header {
    margin-bottom: 2rem;
}

.page-title {
    font-size: 2rem;
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
    font-weight: 800;
    letter-spacing: -0.5px;
}

.page-subtitle {
    color: var(--text-secondary);
    margin: 0;
    font-size: 0.95rem;
}

.page-meta {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0.5rem 0 0 0;
}

/* ========================================
   FILTER CONTAINER - LAYOUT & STYLING
   ======================================== */

.filter-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    align-items: center;
}

.filter-label {
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

/* ========================================
   PAGINATION CONTAINER - ENHANCED
   ======================================== */

.pagination-container {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 2rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.pagination-ellipsis {
    color: var(--text-secondary);
    padding: 0.6rem 0.3rem;
}

.text-muted {
    color: var(--text-secondary);
}

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border-width: 0;
}

/* ========================================
   ANIMATIONS - PERFORMANCE OPTIMIZED
   ======================================== */

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

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    .top-nav,
    .bottom-nav-bar,
    .nav-toggle,
    .skip-to-main {
        display: none !important;
    }
    
    .main-content {
        margin-top: 0;
        padding-bottom: 0;
    }
}

/* ========================================
   DESKTOP ONLY - ENHANCED
   ======================================== */

@media (min-width: 1025px) {
    .desktop-nav-links {
        display: flex !important;
    }
    
    .mobile-nav-toggle {
        display: none !important;
    }
    
    .bottom-nav-bar {
        display: none !important;
    }
    
    .main-content {
        margin-top: 0;
        padding-bottom: 0;
    }
}
