/* ============================================================================
   LUMO TV — Mobile-First Adaptive CSS Override
   Covers: iPhone SE (320) → iPad Pro 12.9 (1180)
   Safe areas, fluid typography, responsive grids, touch targets
   ============================================================================ */

/* === VIEWPORT & SAFE AREA === */
:root {
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --nav-h: 60px;
    --top-h: 52px;
}

/* Fix iOS Safari 100vh bug */
@supports (height: 100dvh) {
    .page.active, #loginPage.active, .player-container.active {
        height: 100dvh !important;
    }
}

/* === GLOBAL TOUCH OPTIMIZATION === */
* { -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}
input, button, select, textarea { font-size: 16px !important; } /* Prevent iOS zoom on focus */

/* === FLUID TYPOGRAPHY === */
.hero-title { font-size: clamp(18px, 5vw, 42px) !important; }
.grid-title { font-size: clamp(18px, 4vw, 28px) !important; }
.content-row-title { font-size: clamp(14px, 3.5vw, 20px) !important; }
.card-title { font-size: clamp(10px, 2.8vw, 14px) !important; }
.detail-title { font-size: clamp(16px, 4.5vw, 28px) !important; }

/* === RESPONSIVE CARDS — GRID WITH MINMAX === */
.grid-container {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)) !important;
    gap: 12px 10px !important;
    padding-bottom: calc(var(--nav-h) + var(--sab) + 20px) !important;
}
.grid-container .content-card,
.grid-container .grid-item {
    flex: none !important;
    max-width: none !important;
    width: 100% !important;
}
.content-card img, .grid-item img {
    aspect-ratio: 2/3;
    object-fit: cover;
    width: 100%;
    border-radius: 6px;
}
/* Landscape grid (live channels) */
.grid-container.grid-landscape {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
}
.grid-container.grid-landscape .content-card img,
.grid-container.grid-landscape .grid-item img {
    aspect-ratio: 16/9;
}

/* === CAROUSEL SCROLL SNAP === */
.content-row {
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scroll-padding: 0 16px;
    scrollbar-width: none;
}
.content-row::-webkit-scrollbar { display: none; }
.content-row .content-card,
.content-row .carousel-item {
    scroll-snap-align: start;
}

/* === BOTTOM NAV — SAFE AREA + TOUCH TARGETS === */
@media (max-width: 768px) {
    .mobile-bottom-nav {
        height: calc(var(--nav-h) + var(--sab)) !important;
        padding-bottom: var(--sab) !important;
        gap: 0 !important;
        justify-content: space-evenly !important;
        background: rgba(9, 9, 11, 0.97) !important;
        border-top: 1px solid rgba(255,255,255,0.06) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
    }
    .mobile-nav-item {
        min-width: 48px !important;
        min-height: 44px !important;
        padding: 4px 6px !important;
        font-size: 9px !important;
        gap: 2px !important;
    }
    .mobile-nav-item i { font-size: 22px !important; }

    /* Padding bottom for content above nav */
    .page.active,
    #homePage, #livePage, #moviesPage, #seriesPage, #searchPage, #kidsPage, #profilePage {
        padding-bottom: calc(var(--nav-h) + var(--sab) + 16px) !important;
    }
}

/* === TOP BAR — SAFE AREA === */
@media (max-width: 768px) {
    .mobile-top-bar {
        padding-top: calc(8px + var(--sat)) !important;
        height: calc(var(--top-h) + var(--sat)) !important;
    }
    /* Push content below top bar */
    .hero-wrapper { margin-top: 0 !important; }
}

/* === LOGIN PAGE === */
@media (max-width: 768px) {
    #loginPage.active {
        padding: 20px 16px !important;
        padding-top: calc(20px + var(--sat)) !important;
    }
    .login-container {
        max-width: 100% !important;
        padding: 32px 24px !important;
        margin: 0 !important;
        border-radius: 16px !important;
    }
    .login-logo { font-size: 20px !important; letter-spacing: 3px !important; }
    .form-group input {
        padding: 14px 16px !important;
        font-size: 18px !important;
        border-radius: 10px !important;
    }
    .login-btn {
        padding: 14px !important;
        font-size: 16px !important;
        border-radius: 10px !important;
        min-height: 48px !important;
    }
}

/* === HERO SECTION === */
@media (max-width: 768px) {
    .hero-wrapper { height: 50vh !important; min-height: 280px !important; }
    .hero-content {
        left: 16px !important; right: 16px !important;
        bottom: 24px !important;
        max-width: calc(100% - 32px) !important;
    }
    .hero-description { display: none !important; }
    .hero-buttons { gap: 8px !important; flex-wrap: wrap !important; }
    .hero-btn {
        padding: 10px 20px !important;
        font-size: 13px !important;
        min-height: 44px !important;
        border-radius: 8px !important;
    }
}

/* === CONTENT AREA + SECTIONS === */
@media (max-width: 768px) {
    .content-container, .content-area {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
    .content-section { margin-bottom: 20px !important; }
    .content-row {
        gap: 8px !important;
        padding: 0 12px !important;
        margin: 0 -12px !important;
    }
    .content-card {
        flex: 0 0 120px !important;
        max-width: 120px !important;
    }
    .channel-card {
        flex: 0 0 150px !important;
        max-width: 150px !important;
    }
}

/* === GRID PAGES (Live, Movies, Series) === */
@media (max-width: 768px) {
    .grid-page-header {
        padding: 12px 12px 0 12px !important;
    }
    .grid-container, .search-results, .kids-grid {
        padding: 0 12px !important;
        padding-bottom: calc(var(--nav-h) + var(--sab) + 20px) !important;
    }
    .categories-wrapper {
        padding: 0 !important;
        margin: 8px 0 !important;
    }
    .grid-categories {
        gap: 6px !important;
        padding: 0 4px !important;
    }
    .cat-tab {
        padding: 6px 14px !important;
        font-size: 12px !important;
        border-radius: 20px !important;
        white-space: nowrap !important;
        min-height: 36px !important;
    }
    .cat-arrow { display: none !important; }
}

/* === DETAIL MODAL — BOTTOM SHEET ON MOBILE === */
@media (max-width: 768px) {
    .modal-backdrop {
        align-items: flex-end !important;
    }
    .detail-modal {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 90vh !important;
        border-radius: 16px 16px 0 0 !important;
        margin: 0 !important;
        animation: slideUp 0.3s ease-out !important;
    }
    @keyframes slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    .modal-close {
        position: sticky !important;
        top: 0 !important;
        z-index: 10 !important;
        background: rgba(17,17,19,0.95) !important;
        width: 100% !important;
        height: 40px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 16px 16px 0 0 !important;
    }
    /* Drag handle */
    .modal-close::before {
        content: '';
        width: 36px; height: 4px;
        background: rgba(255,255,255,0.3);
        border-radius: 2px;
        position: absolute; top: 8px;
    }
    .detail-hero {
        flex-direction: row !important;
        gap: 14px !important;
        padding: 12px 16px !important;
    }
    .detail-poster-wrap {
        width: 100px !important;
        min-width: 100px !important;
        height: 150px !important;
    }
    .detail-buttons { flex-wrap: wrap !important; gap: 8px !important; }
    .detail-btn {
        min-height: 44px !important;
        padding: 10px 18px !important;
        font-size: 13px !important;
        border-radius: 8px !important;
    }
    .detail-extra { padding: 0 16px 24px 16px !important; }

    /* Episodes */
    .episode-card {
        padding: 10px !important;
        gap: 10px !important;
    }
    .episode-image { width: 90px !important; height: 50px !important; border-radius: 6px !important; }
}

/* === SEARCH PAGE === */
@media (max-width: 768px) {
    .search-page-header {
        padding: 12px !important;
        padding-top: calc(var(--top-h) + var(--sat) + 8px) !important;
    }
    .search-input {
        padding: 12px 16px !important;
        font-size: 16px !important;
        border-radius: 10px !important;
        min-height: 48px !important;
    }
}

/* === PLAYER === */
@media (max-width: 768px) {
    .player-container.active {
        position: fixed !important;
        inset: 0 !important;
        z-index: 9999 !important;
        background: #000 !important;
    }
    /* Remove forced rotation — use Fullscreen API instead */
    .player-landscape-forced .player-container.active {
        width: 100% !important;
        height: 100% !important;
        transform: none !important;
        margin-left: 0 !important;
    }
    .player-controls {
        padding: 0 12px !important;
        padding-bottom: calc(12px + var(--sab)) !important;
    }
    .player-btn {
        min-width: 44px !important;
        min-height: 44px !important;
        font-size: 18px !important;
    }
    .player-top {
        padding: 12px 16px !important;
        padding-top: calc(12px + var(--sat)) !important;
    }
    .player-title { font-size: 14px !important; max-width: 55vw !important; }
}

/* === PROFILE PAGE === */
@media (max-width: 768px) {
    .profile-container {
        padding: 16px 12px !important;
        padding-top: calc(var(--top-h) + var(--sat) + 8px) !important;
    }
    .profile-header { font-size: 22px !important; margin-bottom: 16px !important; }
    .profile-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    .profile-card {
        padding: 16px !important;
        border-radius: 12px !important;
    }
    .profile-card-title { font-size: 14px !important; }
    .profile-download-card {
        margin-top: 12px !important;
        padding: 16px !important;
        border-radius: 12px !important;
        min-height: 48px !important;
    }
}

/* === MOBILE DRAWER === */
@media (max-width: 768px) {
    .mobile-drawer-backdrop.active {
        background: rgba(0,0,0,0.6) !important;
        backdrop-filter: blur(4px) !important;
        -webkit-backdrop-filter: blur(4px) !important;
    }
    .mobile-drawer {
        width: min(300px, 80vw) !important;
        padding-top: calc(20px + var(--sat)) !important;
        padding-bottom: calc(20px + var(--sab)) !important;
    }
    .mobile-drawer-item {
        min-height: 48px !important;
        padding: 12px 20px !important;
        font-size: 15px !important;
    }
}

/* === KIDS PAGE === */
@media (max-width: 768px) {
    .kids-header { padding: 12px !important; }
    .kids-title { font-size: clamp(20px, 5vw, 28px) !important; }
    .kids-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) !important;
        gap: 10px 8px !important;
        padding: 0 12px !important;
    }
}

/* === SKELETON LOADING SHIMMER === */
.skeleton-card {
    background: linear-gradient(90deg,
        rgba(255,255,255,0.03) 0%,
        rgba(255,255,255,0.08) 50%,
        rgba(255,255,255,0.03) 100%) !important;
    background-size: 200% 100% !important;
    animation: shimmer 1.5s ease-in-out infinite !important;
    border-radius: 8px !important;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* === HELP/SUPPORT SECTION (injected in profile) === */
.help-card {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 16px;
    margin-top: 12px;
}
.help-card-title {
    font-size: 15px; font-weight: 600; color: #fafafa;
    margin-bottom: 14px; display: flex; align-items: center; gap: 8px;
}
.help-btn {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 12px 14px; margin-bottom: 8px;
    background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px; color: #e4e4e7; font-size: 14px;
    cursor: pointer; transition: background 0.2s; min-height: 48px;
    text-align: left;
}
.help-btn:active { background: rgba(0,168,225,0.15); }
.help-btn i { font-size: 18px; color: rgba(255,255,255,0.4); min-width: 24px; text-align: center; }
.help-btn-danger { border-color: rgba(239,68,68,0.3); }
.help-btn-danger:active { background: rgba(239,68,68,0.15); }
.help-btn-danger i { color: rgba(239,68,68,0.6); }

/* FAQ Accordion */
.faq-item { border-bottom: 1px solid rgba(255,255,255,0.06); }
.faq-q {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 0; cursor: pointer; color: #e4e4e7; font-size: 14px;
    min-height: 44px;
}
.faq-q::after { content: '+'; font-size: 18px; color: rgba(255,255,255,0.3); transition: transform 0.2s; }
.faq-q.open::after { content: '-'; }
.faq-a {
    max-height: 0; overflow: hidden; transition: max-height 0.3s ease;
    color: rgba(255,255,255,0.5); font-size: 13px; line-height: 1.5;
}
.faq-a.open { max-height: 200px; padding-bottom: 14px; }

/* About card */
.about-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0; font-size: 13px;
}
.about-label { color: rgba(255,255,255,0.4); }
.about-value { color: #e4e4e7; font-family: monospace; }
.copy-info-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; padding: 12px; margin-top: 12px;
    background: rgba(0,168,225,0.1); border: 1px solid rgba(0,168,225,0.2);
    border-radius: 10px; color: #00A8E1; font-size: 13px; font-weight: 500;
    cursor: pointer; min-height: 44px;
}
.copy-info-btn:active { background: rgba(0,168,225,0.2); }

/* Network status banner */
.network-banner {
    position: fixed; top: 0; left: 0; right: 0; z-index: 10000;
    padding: 6px 16px; padding-top: calc(6px + var(--sat));
    text-align: center; font-size: 12px; font-weight: 600;
    transition: transform 0.3s ease;
    pointer-events: none;
}
.network-banner.offline { background: #ef4444; color: white; transform: translateY(0); }
.network-banner.online { background: #22c55e; color: white; transform: translateY(0); }
.network-banner.hidden { transform: translateY(-100%); }

/* Quality selector */
.quality-select {
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px; padding: 10px 14px; color: #e4e4e7;
    font-size: 14px; width: 100%; min-height: 44px;
    appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23999' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}

/* === EXTRA SMALL (320px — iPhone SE, Galaxy Fold) === */
@media (max-width: 359px) {
    .content-card { flex: 0 0 100px !important; max-width: 100px !important; }
    .mobile-nav-item { font-size: 8px !important; min-width: 42px !important; }
    .mobile-nav-item i { font-size: 18px !important; }
    .hero-wrapper { height: 45vh !important; min-height: 240px !important; }
    .login-container { padding: 24px 16px !important; }
    .grid-container { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)) !important; }
    .cat-tab { padding: 5px 10px !important; font-size: 11px !important; }
}

/* === SMALL PHONES (360-389px — Galaxy S, most Android) === */
@media (min-width: 360px) and (max-width: 389px) {
    .content-card { flex: 0 0 110px !important; max-width: 110px !important; }
    .grid-container { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) !important; }
}

/* === STANDARD PHONES (390-427px — iPhone 12-14) === */
@media (min-width: 390px) and (max-width: 427px) {
    .content-card { flex: 0 0 125px !important; max-width: 125px !important; }
    .grid-container { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)) !important; }
}

/* === LARGE PHONES (428-479px — iPhone Pro Max, Pixel XL) === */
@media (min-width: 428px) and (max-width: 479px) {
    .content-card { flex: 0 0 135px !important; max-width: 135px !important; }
    .grid-container { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important; }
}

/* === PHONE LANDSCAPE (480-599px) === */
@media (min-width: 480px) and (max-width: 599px) {
    .grid-container { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important; }
    .content-card { flex: 0 0 140px !important; max-width: 140px !important; }
    .hero-wrapper { height: 60vh !important; }
}

/* === SMALL TABLETS (600-767px) === */
@media (min-width: 600px) and (max-width: 767px) {
    .mobile-bottom-nav { height: calc(64px + var(--sab)) !important; }
    .mobile-nav-item { font-size: 11px !important; }
    .mobile-nav-item i { font-size: 24px !important; }
    .grid-container { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important; }
    .content-card { flex: 0 0 155px !important; max-width: 155px !important; }
    .content-container, .content-area { padding-left: 24px !important; padding-right: 24px !important; }
    .detail-modal { width: 90% !important; max-width: 500px !important; }
    .profile-grid { grid-template-columns: 1fr 1fr !important; }
}

/* === TABLETS (768-1023px — iPad Mini, iPad, iPad Air) === */
@media (min-width: 769px) and (max-width: 1023px) {
    .mobile-bottom-nav { display: none !important; }
    .grid-container { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important; gap: 16px 12px !important; }
    .content-card { flex: 0 0 170px !important; max-width: 170px !important; }
    .detail-modal { width: 80% !important; max-width: 600px !important; border-radius: 16px !important; }
    .profile-grid { grid-template-columns: 1fr 1fr !important; }
}

/* === LARGE TABLETS / LANDSCAPE (1024px+) === */
@media (min-width: 1024px) {
    .grid-container { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)) !important; gap: 18px 14px !important; }
}

/* === PRINT (hide irrelevant) === */
@media print {
    .mobile-bottom-nav, .mobile-top-bar, .sidebar, .player-container, .modal-backdrop { display: none !important; }
}
