/**
 * IPTV App - Mobile & Tablet Responsive Styles
 * Phone: ≤480px | Tablet: 481-1024px | Desktop: >1024px (unchanged)
 */

/* === Disable double-tap zoom on all interactive elements === */
button, a, input, select, textarea,
[data-focusable], .sidebar-item, .channel-card,
.bottom-nav-item, .osd-touch-btn, .osd-control-item,
.player-ch-item, .player-cat-tab, .vod-card,
.category-tab, .vod-cat-tab, .group-tab {
    touch-action: manipulation;
}

/* === Hamburger Button (hidden on desktop) === */
.hamburger-btn {
    display: none;
}

/* === Bottom Nav (hidden on desktop) === */
.bottom-nav {
    display: none;
}

/* === Sidebar Backdrop (hidden on desktop) === */
.sidebar-backdrop {
    display: none;
}

/* ============================================
   MOBILE + TABLET (≤1024px)
   ============================================ */
@media (max-width: 1024px) {

    /* --- Sidebar: Fixed Overlay Drawer --- */
    #sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        inset-inline-start: 0;
        width: 280px;
        z-index: 1000;
        transform: translateX(-280px);
        pointer-events: none;
        transition: transform 0.3s ease, opacity 0.3s ease;
        opacity: 0;
    }

    [dir="rtl"] #sidebar {
        transform: translateX(280px);
    }

    #sidebar.mobile-open {
        transform: translateX(0) !important;
        opacity: 1;
        pointer-events: auto;
    }

    /* Override desktop hidden class on mobile */
    #sidebar.hidden {
        transform: translateX(-280px);
    }

    [dir="rtl"] #sidebar.hidden {
        transform: translateX(280px);
    }

    /* Show labels in mobile drawer */
    #sidebar .sidebar-label {
        opacity: 1;
    }
    #sidebar .sidebar-item {
        justify-content: flex-start;
        padding: 12px 16px;
    }
    #sidebar .sidebar-keymap {
        display: block;
    }

    /* --- Backdrop --- */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        -webkit-tap-highlight-color: transparent;
    }

    .sidebar-backdrop.visible {
        display: block;
    }

    /* --- Hamburger Button --- */
    .hamburger-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 10px;
        inset-inline-start: 10px;
        width: 44px;
        height: 44px;
        background: var(--bg-secondary);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        cursor: pointer;
        z-index: 998;
        color: var(--text-primary);
        -webkit-tap-highlight-color: transparent;
    }

    .hamburger-btn:active {
        background: var(--bg-hover);
    }

    .hamburger-btn svg {
        width: 22px;
        height: 22px;
    }

    /* --- Search Icon Button (mobile) --- */
    .search-btn-mobile {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 10px;
        inset-inline-end: 10px;
        width: 44px;
        height: 44px;
        background: var(--bg-secondary);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        cursor: pointer;
        z-index: 998;
        color: var(--text-primary);
        -webkit-tap-highlight-color: transparent;
    }

    .search-btn-mobile:active {
        background: var(--bg-hover);
    }

    .search-btn-mobile svg {
        width: 22px;
        height: 22px;
    }

    /* Hide desktop search bar on mobile */
    .global-search-bar {
        display: none !important;
    }

    /* --- Main Content: Full Width --- */
    .app-layout {
        flex-direction: column;
    }

    #main-content {
        width: 100%;
        padding-top: 60px;
        padding-bottom: 62px;
    }

    /* --- Hide bottom nav & hamburger when player is active --- */
    body:has(#player-container.active) .bottom-nav,
    body:has(#player-container.active) .hamburger-btn {
        display: none !important;
    }

    /* --- Bottom Navigation --- */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 52px;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border);
        z-index: 997;
        justify-content: space-around;
        align-items: center;
        padding: 0 2px;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1px;
        padding: 4px 2px;
        color: var(--text-muted);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        font-size: 9px;
        text-decoration: none;
        min-width: 44px;
        transition: color var(--transition);
    }

    .bottom-nav-item.active {
        color: var(--accent);
    }

    .bottom-nav-icon {
        width: 20px;
        height: 20px;
    }

    .bottom-nav-icon svg {
        width: 100%;
        height: 100%;
    }

    .bottom-nav-label {
        font-weight: 500;
        white-space: nowrap;
    }

    /* --- EPG Browser: Stack Vertically --- */
    .epg-browser-layout {
        flex-direction: column;
    }

    .epg-channel-sidebar {
        width: 100%;
        max-height: 180px;
        border-bottom: 1px solid var(--border);
        border-inline-end: none;
    }

    .epg-day-tabs {
        overflow-x: auto;
        width: 100%;
        justify-content: flex-start;
    }

    /* --- Toast: Above Bottom Nav --- */
    .toast {
        bottom: 64px;
    }

    /* --- Player OSD: Fullscreen overlay on mobile --- */
    #player-osd.visible {
        background: rgba(0, 0, 0, 0.75);
    }

    .osd-top-bar {
        position: relative;
        padding: 12px 16px;
        padding-top: max(12px, env(safe-area-inset-top, 12px));
        background: rgba(0, 0, 0, 0.4);
    }

    .osd-bottom-bar {
        position: relative;
        padding: 12px 16px 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
        background: rgba(0, 0, 0, 0.4);
        overflow-y: auto;
        max-height: 50vh;
    }

    /* Stack OSD as flex column so bottom bar is always visible */
    #player-osd {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    .osd-center-controls {
        position: relative;
        top: auto;
        left: auto;
        transform: none;
        justify-content: center;
        flex-shrink: 0;
        padding: 12px 0;
    }

    .osd-control-item {
        min-height: 44px;
        min-width: 44px;
        justify-content: center;
    }

    .osd-progress-bar-wrap {
        height: 6px;
        max-width: 100%;
    }

    /* Timeshift seek bar: larger touch target */
    .osd-ts-track {
        height: 8px;
        padding: 8px 0;
        background-clip: content-box;
    }

    .osd-ts-thumb {
        width: 18px;
        height: 18px;
    }

    .player-channel-list {
        width: 100%;
        max-width: 100%;
    }

    .player-ch-item {
        padding: 10px 14px;
        min-height: 48px;
    }

    /* --- VOD Catalog Tabs: Scroll --- */
    .vod-catalog-tabs,
    .vod-season-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    /* --- Welcome: Fit Mobile --- */
    .welcome-form {
        max-width: 100%;
    }

    .welcome-input {
        min-width: 0;
        width: 100%;
    }

    /* --- Settings: Full Width Inputs --- */
    .settings-input {
        min-width: 0;
        width: 100%;
    }

    .settings-row {
        flex-wrap: wrap;
    }
}

/* === Hide Scrollbars on Touch Devices === */
@media (hover: none) and (max-width: 1024px) {
    ::-webkit-scrollbar {
        display: none;
    }

    * {
        scrollbar-width: none;
    }
}

/* ============================================
   PHONE ONLY (≤480px)
   ============================================ */
@media (max-width: 480px) {

    :root {
        --sidebar-width: 280px;
    }

    html {
        font-size: 14px;
    }

    #main-content {
        padding: 8px;
        padding-top: 52px;
        padding-bottom: 56px;
    }

    .view-title {
        font-size: 18px;
        margin-bottom: 6px;
    }

    /* --- Channel View: Prevent Overflow --- */
    .channel-view {
        overflow: hidden;
    }

    .category-tabs {
        gap: 6px;
        padding-bottom: 8px;
        margin-bottom: 8px;
    }

    .category-tab {
        padding: 5px 12px;
        font-size: 12px;
    }

    /* --- Channel Grid: 2 Columns --- */
    .channel-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .channel-card {
        padding: 6px 8px;
        gap: 6px;
    }

    .channel-logo-wrap {
        width: 32px;
        height: 32px;
    }

    .channel-name {
        font-size: 11px;
    }

    .channel-num {
        font-size: 10px;
        min-width: 14px;
    }

    .channel-header-row {
        gap: 4px;
    }

    .epg-now {
        font-size: 10px;
    }

    /* --- VOD/Catalog: Compact --- */
    .vod-catalog {
        padding: 0;
    }

    .vod-catalog-header {
        margin-bottom: 8px;
        gap: 8px;
    }

    .vod-catalog-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .vod-show-info {
        padding: 6px 8px;
    }

    .vod-show-title {
        font-size: 11px;
    }

    .vod-show-cat,
    .vod-show-desc {
        font-size: 10px;
    }

    .vod-show-desc {
        display: none;
    }

    .vod-catalog-tabs {
        gap: 4px;
        margin-bottom: 8px;
    }

    .vod-cat-tab {
        padding: 4px 10px;
        font-size: 11px;
    }

    .vod-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    /* --- Category Tabs: Compact --- */
    .group-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .group-tab {
        padding: 6px 12px;
        font-size: 12px;
        white-space: nowrap;
    }

    /* --- Search --- */
    .search-input,
    .vod-search-input {
        padding: 8px 12px;
        font-size: 14px;
    }

    /* --- Welcome --- */
    .welcome-screen h1 {
        font-size: 22px;
    }

    .welcome-screen p {
        font-size: 13px;
    }

    .welcome-input {
        padding: 10px 14px;
        font-size: 14px;
    }

    .welcome-btn {
        padding: 10px 20px;
        font-size: 14px;
    }

    /* --- VOD Detail: Compact --- */
    .vod-detail-header {
        gap: 10px;
        margin-bottom: 8px;
    }

    .vod-detail-title {
        font-size: 16px;
    }

    .vod-detail-desc {
        font-size: 12px;
        margin-bottom: 8px;
    }

    .vod-detail-meta {
        gap: 8px;
        margin-bottom: 12px;
        font-size: 12px;
    }

    .vod-ep-group {
        margin-bottom: 12px;
    }

    .vod-ep-item {
        flex-wrap: wrap;
        gap: 6px;
        padding: 8px 10px;
    }

    .vod-ep-time {
        min-width: auto;
        font-size: 12px;
    }

    .vod-ep-title {
        font-size: 13px;
    }

    .vod-back-btn {
        padding: 6px 12px;
        font-size: 13px;
    }

    /* --- Player OSD: Compact --- */
    .osd-program-desc,
    .osd-program-next {
        display: none;
    }

    .osd-ch-number {
        font-size: 18px;
        min-width: 36px;
    }

    .osd-channel-name {
        font-size: 13px;
    }

    .osd-logo {
        width: 36px;
        height: 36px;
    }

    .osd-top-left {
        gap: 8px;
    }

    .osd-time {
        font-size: 15px;
    }

    .osd-group {
        font-size: 11px;
    }

    .osd-center-controls {
        gap: 24px;
    }

    .osd-touch-btn {
        width: 46px;
        height: 46px;
    }

    .osd-touch-btn svg {
        width: 20px;
        height: 20px;
    }

    .osd-touch-btn-main {
        width: 56px;
        height: 56px;
    }

    .osd-touch-btn-main svg {
        width: 26px;
        height: 26px;
    }

    .osd-controls {
        gap: 8px;
        justify-content: center;
    }

    .osd-ctrl-label {
        display: none;
    }

    .osd-ctrl-icon {
        font-size: 20px;
    }

    .osd-now-badge {
        font-size: 10px;
        padding: 2px 6px;
    }

    .osd-program-title {
        font-size: 14px;
    }

    .osd-program-time {
        font-size: 11px;
    }

    /* Channel list compact */
    .player-ch-header {
        padding: 10px 14px;
        font-size: 14px;
    }

    .player-ch-logo,
    .player-ch-logo-ph {
        width: 28px;
        height: 28px;
    }

    .player-ch-name {
        font-size: 12px;
    }

    .player-ch-epg {
        font-size: 10px;
    }

    .player-ch-categories {
        gap: 4px;
        padding: 6px 14px;
    }

    .player-cat-tab {
        padding: 3px 8px;
        font-size: 11px;
    }

    /* OSD nav arrows compact */
    .osd-nav-arrow {
        width: 36px;
        height: 36px;
    }

    .osd-nav-arrow svg {
        width: 18px;
        height: 18px;
    }

    .osd-catchup-btn {
        font-size: 12px;
        padding: 5px 12px;
    }

    .osd-catchup-badge {
        font-size: 10px;
        padding: 2px 8px;
        margin-inline-start: 8px;
    }

    .osd-catchup-program-title {
        max-width: 120px;
    }

    .osd-snap-now {
        font-size: 10px;
        padding: 2px 8px;
    }

    /* EPG info compact on phone */
    .osd-epg-info {
        margin-bottom: 8px;
    }

    .osd-program-browse-info {
        min-width: 0;
    }

    .osd-program-header {
        flex-wrap: wrap;
        gap: 6px;
    }

    /* --- Sidebar: Compact Items --- */
    .sidebar-item {
        padding: 12px 14px;
        gap: 10px;
    }

    .sidebar-label {
        font-size: 14px;
    }

    .sidebar-logo {
        font-size: 22px;
    }

    /* --- Settings --- */
    .settings-section {
        padding: 14px;
    }
}

/* ============================================
   TABLET (481px - 1024px)
   ============================================ */
@media (min-width: 481px) and (max-width: 1024px) {

    :root {
        --sidebar-width: 300px;
    }

    #main-content {
        padding: 14px;
        padding-top: 58px;
        padding-bottom: 60px;
    }

    .view-title {
        font-size: 20px;
        margin-bottom: 10px;
    }

    /* --- Channel Grid: 3 Columns --- */
    .channel-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .channel-card {
        padding: 8px 10px;
        gap: 8px;
    }

    /* --- VOD/Catalog Grid: 3-4 Columns --- */
    .vod-grid,
    .vod-catalog-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 10px;
    }

    .vod-catalog {
        padding: 8px;
    }

    /* --- EPG Panel --- */
    .epg-panel-header {
        flex-wrap: wrap;
        gap: 10px;
    }

    /* --- TV-Style OSD: Compact for small screens --- */
    .osd-zap-digits {
        font-size: 48px;
        letter-spacing: 3px;
    }
    .osd-zap-overlay {
        padding: 10px 24px;
    }
    .osd-transition-num {
        font-size: 48px;
    }
    .osd-banner {
        padding: 12px 16px 16px;
        gap: 12px;
        flex-wrap: wrap;
    }
    .osd-banner-num {
        font-size: 28px;
        min-width: 40px;
    }
    .osd-banner-logo {
        width: 36px;
        height: 36px;
    }
    .osd-banner-name {
        font-size: 14px;
    }
    .osd-banner-info {
        max-width: 140px;
    }
    .osd-banner-divider {
        display: none;
    }
    .osd-banner-title {
        font-size: 13px;
    }
    .osd-banner-next {
        display: none;
    }
    .osd-banner-clock {
        font-size: 16px;
    }
    .osd-no-signal-text {
        font-size: 18px;
    }

    /* --- Home Screen Mobile/Tablet --- */
    .home-hero {
        height: 38vh;
        min-height: 260px;
        max-height: 400px;
    }
    .home-hero__content {
        padding: 0 20px 24px;
        max-width: 100%;
    }
    .home-hero__title {
        font-size: 26px;
    }
    .home-hero__badge {
        font-size: 10px;
        padding: 3px 10px;
        margin-bottom: 10px;
    }
    .home-hero__program-text {
        font-size: 13px;
    }
    .home-hero__btn {
        padding: 10px 20px;
        font-size: 13px;
    }
    .home-hero__logo-wrap {
        display: none;
    }
    .home-hero__dots {
        margin-top: 4px;
    }
    .home-rows {
        margin-top: -16px;
    }
    .home-row {
        margin-bottom: 24px;
    }
    .home-row__header {
        padding: 0 16px 8px;
    }
    .home-row__title {
        font-size: 16px;
    }
    .home-row__scroll {
        padding: 6px 16px 14px;
        gap: 8px;
        scroll-padding-inline-start: 16px;
    }
    .home-card {
        flex: 0 0 145px;
    }
    .home-card__body {
        padding: 8px 10px 10px;
    }
    .home-card__name {
        font-size: 12px;
    }
    .home-card__epg-text {
        font-size: 10px;
    }
}

/* --- Home Screen Tablet Override --- */
@media (min-width: 481px) and (max-width: 1024px) {
    .home-hero {
        height: 42vh;
        min-height: 300px;
    }
    .home-hero__content {
        padding: 0 32px 32px;
    }
    .home-hero__title {
        font-size: 32px;
    }
    .home-row__header {
        padding: 0 28px 10px;
    }
    .home-row__scroll {
        padding: 6px 28px 16px;
        gap: 10px;
        scroll-padding-inline-start: 28px;
    }
    .home-card {
        flex: 0 0 165px;
    }
}
