/* ==========================================================================
   Drama Online – Mobile UX layer
   Loaded AFTER app.css. Dark theme + RTL are preserved.
   Sections: 1 header/drawer/search · 2 promo banner · 3 filter bottom-sheet
             4 poster grid · 5 pagination · 6 floating buttons · 7 footer
   Desktop (≥992px) is untouched: every mobile-only control is hidden here.
   ========================================================================== */

/* ---- Mobile-only controls are hidden by default (desktop) ---------------- */
.do-search-toggle,
.do-drawer-head,
.do-drawer-actions,
.do-backdrop,
.do-filter-toggle,
.do-filter-backdrop,
.do-sheet-head,
.wp-pagenavi .disabled {
    display: none;
}

/* ==========================================================================
   1. HEADER · DRAWER · SEARCH  (below 992px, where the navbar collapses)
   ========================================================================== */
@media (max-width: 991.98px) {
    body.do-lock { overflow: hidden; touch-action: none; }

    /* backdrop-filter would trap the fixed drawer inside the header box */
    body .site-header {
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
        background-color: #0f1420 !important;
        padding-top: env(safe-area-inset-top, 0px) !important;
    }

    .site-header .navbar { padding: 0; }
    .site-header .navbar > .container {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        min-height: 56px;
        padding-top: 6px;
        padding-bottom: 6px;
    }

    /* Order (RTL: first = right edge): hamburger · logo · search */
    .site-header .do-menu-toggle { order: 1; }
    .site-header .navbar-brand   { order: 2; margin: 0 auto; padding: 0; }
    .site-header .do-search-toggle { order: 3; }

    .site-header .site-logo-img {
        height: 40px;
        width: auto;
        max-width: 140px;
        object-fit: contain;
    }

    .site-header .do-menu-toggle,
    .site-header .do-search-toggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        width: 44px;
        height: 44px;
        padding: 0;
        border: 0;
        border-radius: 12px;
        color: #f5c16c !important;
        background: rgba(255, 255, 255, .06) !important;
        -webkit-tap-highlight-color: transparent;
        transition: background .2s ease, transform .15s ease;
    }
    .site-header .do-menu-toggle:active,
    .site-header .do-search-toggle:active { transform: scale(.94); }
    body.do-search-open .site-header .do-search-toggle {
        background: rgba(245, 193, 108, .18) !important;
    }

    /* ---- Slide-out drawer ---- */
    .site-header #dramaNavbar.navbar-collapse {
        display: flex !important;
        flex-direction: column;
        flex-wrap: nowrap !important;
        align-items: stretch !important;
        position: fixed !important;
        top: 0;
        right: 0;
        bottom: 0;
        left: auto;
        width: min(320px, 86vw);
        height: 100vh;
        height: 100dvh;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        border-left: 1px solid rgba(255, 255, 255, .08) !important;
        border-radius: 0 !important;
        background: #121827 !important;
        box-shadow: -12px 0 40px rgba(0, 0, 0, .55);
        overflow-y: auto;
        overscroll-behavior: contain;
        z-index: 10001;
        transform: translateX(105%);
        visibility: hidden;
        transition: transform .3s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .3s;
    }
    body.do-drawer-open .site-header #dramaNavbar.navbar-collapse {
        transform: none;
        visibility: visible;
        transition-delay: 0s;
    }

    .do-drawer-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
        padding-top: max(12px, env(safe-area-inset-top, 0px));
        border-bottom: 1px solid rgba(255, 255, 255, .08);
        flex: 0 0 auto;
    }
    .do-drawer-title { color: #f5c16c; font-weight: 700; font-size: 1.05rem; }
    .do-drawer-close {
        display: inline-flex; align-items: center; justify-content: center;
        width: 44px; height: 44px; border: 0; border-radius: 12px;
        color: #e5e7eb; background: rgba(255, 255, 255, .06);
    }

    .site-header #dramaNavbar .navbar-nav {
        flex-direction: column;
        align-items: stretch !important;
        width: 100%;
        margin: 0 !important;
        padding: 10px 10px 0;
        gap: 2px;
    }
    .site-header #dramaNavbar .nav-item { width: 100%; }
    .site-header #dramaNavbar .nav-link,
    .site-header #dramaNavbar .dropdown-item {
        display: flex;
        align-items: center;
        gap: 8px;
        min-height: 48px;
        padding: 0 14px !important;
        border-radius: 10px;
        color: #e5e7eb !important;
        font-size: 1rem !important;
        white-space: normal;
    }
    .site-header #dramaNavbar .nav-link:hover,
    .site-header #dramaNavbar .nav-link:focus-visible,
    .site-header #dramaNavbar .dropdown-item:hover {
        background: rgba(245, 193, 108, .1);
        color: #f5c16c !important;
    }
    .site-header #dramaNavbar .nav-link svg { color: #f5c16c; flex: 0 0 auto; }
    .site-header #dramaNavbar .dropdown-toggle::after { margin-inline-start: auto; }
    .site-header #dramaNavbar .dropdown-menu {
        position: static !important;
        transform: none !important;
        float: none;
        width: auto;
        margin: 2px 14px 6px 0 !important;
        padding: 4px 0 !important;
        background: rgba(255, 255, 255, .04) !important;
        border: 0 !important;
        border-right: 2px solid rgba(245, 193, 108, .35) !important;
        border-radius: 8px !important;
        box-shadow: none !important;
    }

    .do-drawer-actions {
        display: flex;
        flex-direction: column;
        gap: 10px;
        margin-top: auto;
        padding: 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
        border-top: 1px solid rgba(255, 255, 255, .08);
    }
    .do-drawer-actions a {
        display: flex; align-items: center; justify-content: center;
        min-height: 48px; border-radius: 12px;
        font-weight: 700; font-size: .95rem; text-decoration: none;
    }
    .do-drawer-login { color: #4ade80 !important; border: 1px solid rgba(74, 222, 128, .35); }
    .do-drawer-sub {
        color: #fff !important;
        background: linear-gradient(135deg, #e94560, #c0392b);
        box-shadow: 0 3px 10px rgba(233, 69, 96, .3);
    }

    .do-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 9998;
        background: rgba(0, 0, 0, .6);
        opacity: 0;
        visibility: hidden;
        transition: opacity .25s ease, visibility 0s linear .25s;
    }
    body.do-drawer-open .do-backdrop { opacity: 1; visibility: visible; transition-delay: 0s; }

    /* ---- Search: icon in the bar, input expands beneath it ---- */
    .site-header .header-search {
        position: fixed;
        top: var(--do-header-h, 60px);
        right: 0;
        left: 0;
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding: 10px 12px !important;
        border: 0 !important;
        border-bottom: 1px solid rgba(255, 255, 255, .08) !important;
        background: #121827;
        box-shadow: 0 12px 24px rgba(0, 0, 0, .4);
        z-index: 10000;
        opacity: 0;
        visibility: hidden;
        transform: translateY(-8px);
        transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s;
    }
    body.do-search-open .site-header .header-search {
        opacity: 1;
        visibility: visible;
        transform: none;
        transition-delay: 0s;
    }
    .site-header .header-search .search_input { min-height: 46px; font-size: 16px; /* avoids iOS zoom */ }
    .site-header .header-search #datafetch.Result { max-height: 60vh; overflow-y: auto; }
}

/* ==========================================================================
   2. PROMO BANNER  (below 768px)
   ========================================================================== */
@media (max-width: 767.98px) {
    .header-promo-banner { padding: 10px 0 12px !important; }
    .header-promo-banner .promo-inner {
        flex-direction: column;
        align-items: stretch;
        row-gap: 8px;
    }
    .header-promo-banner .promo-text-area {
        flex-wrap: nowrap;
        justify-content: center;
        align-items: center;
        gap: 8px;
    }
    .header-promo-banner .promo-badge {
        padding: 3px 10px;
        font-size: 11px;
        animation: none;
    }
    .header-promo-banner .promo-main-text {
        font-size: 12px;
        line-height: 1.45;
        text-align: right;
        text-wrap: balance;
    }
    .header-promo-banner .promo-actions {
        display: flex;
        flex-wrap: nowrap;
        gap: 8px;
        width: 100%;
    }
    .header-promo-banner .promo-actions a {
        flex: 1 1 0;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 42px;
        padding: 0 8px !important;
        font-size: 13px !important;
        white-space: nowrap;
        text-align: center;
    }
}

/* ==========================================================================
   3. FILTER – toggle button + bottom sheet  (below 768px)
   ========================================================================== */
@media (max-width: 767.98px) {
    .do-list-heading {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
    }
    .do-list-heading .Title { margin: 0 !important; }

    .do-filter-toggle {
        position: relative;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        flex: 0 0 auto;
        min-height: 44px;
        padding: 0 16px;
        border-radius: 12px;
        border: 1px solid rgba(245, 193, 108, .4);
        background: #1e2029;
        color: #f5c16c;
        font-size: .9rem;
        font-weight: 700;
        -webkit-tap-highlight-color: transparent;
    }
    .do-filter-toggle.has-filters { background: rgba(245, 193, 108, .15); }
    .do-filter-count {
        display: inline-flex; align-items: center; justify-content: center;
        min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
        background: #f5c16c; color: #111; font-size: .72rem; font-style: normal; font-weight: 800;
    }
    .do-filter-count[hidden] { display: none; }

    .do-filter-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 10010;
        background: rgba(0, 0, 0, .6);
        opacity: 0;
        visibility: hidden;
        transition: opacity .25s ease, visibility 0s linear .25s;
    }
    body.do-filter-open .do-filter-backdrop { opacity: 1; visibility: visible; transition-delay: 0s; }

    .do-filter-sheet {
        position: fixed;
        right: 0;
        left: 0;
        bottom: 0;
        z-index: 10011;
        display: flex;
        flex-direction: column;
        max-height: 88vh;
        max-height: 88dvh;
        background: #1e2029;
        border-radius: 20px 20px 0 0;
        border-top: 1px solid rgba(255, 255, 255, .1);
        box-shadow: 0 -12px 40px rgba(0, 0, 0, .55);
        transform: translateY(105%);
        visibility: hidden;
        transition: transform .3s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .3s;
    }
    body.do-filter-open .do-filter-sheet { transform: none; visibility: visible; transition-delay: 0s; }

    .do-sheet-head { display: block; flex: 0 0 auto; padding: 8px 16px 0; }
    .do-sheet-grip {
        display: block; width: 44px; height: 4px; margin: 0 auto 6px;
        border-radius: 2px; background: rgba(255, 255, 255, .25);
    }
    .do-sheet-title {
        display: flex; align-items: center; justify-content: space-between;
        color: #f5c16c; font-weight: 700; font-size: 1.05rem;
        padding-bottom: 8px; border-bottom: 1px solid rgba(255, 255, 255, .06);
    }
    .do-sheet-close {
        display: inline-flex; align-items: center; justify-content: center;
        width: 44px; height: 44px; border: 0; border-radius: 12px;
        color: #e5e7eb; background: rgba(255, 255, 255, .06);
    }

    .do-filter-sheet .do-filter-form { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; margin: 0; }
    .do-filter-sheet .do-filter-container {
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
        margin: 0 !important;
        padding: 12px 16px 0 !important;
        background: transparent !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .do-filter-sheet .do-filter-header { display: none; }
    .do-filter-sheet .do-active-filters { margin-bottom: 10px; }
    .do-filter-sheet .do-filter-grid {
        display: flex !important;
        flex-direction: column;
        gap: 10px !important;
        margin-bottom: 12px !important;
    }
    .do-filter-sheet .do-dropdown-btn {
        width: 100%;
        min-height: 48px;
        transform: none !important;
    }
    .do-filter-sheet .do-dropdown-content {
        position: static !important;
        width: 100%;
        max-height: 240px;
        margin-top: 6px !important;
        overflow-y: auto;
        box-shadow: none !important;
        -webkit-overflow-scrolling: touch;
    }
    .do-filter-sheet .do-checkbox-list { list-style: none; margin: 0; padding: 0; }
    .do-filter-sheet .do-checkbox-list li { list-style: none; }
    .do-filter-sheet .do-checkbox-list li::marker { content: ''; }
    /* Icon fonts are not loaded on this page, so draw the chevron in CSS */
    .do-filter-sheet .do-dropdown-btn i { display: none; }
    .do-filter-sheet .do-dropdown-btn::after {
        content: '';
        flex: 0 0 auto;
        width: 8px; height: 8px;
        margin-inline-start: 12px;
        border-left: 2px solid #f5c16c;
        border-bottom: 2px solid #f5c16c;
        transform: rotate(-45deg) translateY(-2px);
    }
    .do-filter-sheet .do-checkbox-list li label { min-height: 44px; display: flex; align-items: center; }
    .do-filter-sheet .do-dropdown-search input { min-height: 44px; font-size: 16px; }

    .do-filter-sheet .do-filter-actions {
        position: sticky;
        bottom: 0;
        display: flex;
        gap: 10px;
        margin: 0 -16px;
        padding: 12px 16px;
        padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
        border-top: 1px solid rgba(255, 255, 255, .08);
        background: #1e2029;
    }
    .do-filter-sheet .do-filter-actions .do-btn {
        flex: 1 1 0;
        min-width: 0;
        min-height: 48px;
        margin: 0 !important;
        justify-content: center;
        align-items: center;
        gap: 8px;
    }
    /* "إفراغ" is always visible inside the sheet, next to "عرض النتائج" */
    .do-filter-sheet #filter-reset-btn { display: inline-flex !important; }
}

/* ==========================================================================
   4. POSTER GRID  (2 cols < 480px, 3 cols 480–767px)
   ========================================================================== */
@media (max-width: 767.98px) {
    #response .movie-grid {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 12px !important;
        margin-bottom: 1.25rem;
    }
    #response .movie-grid > .movie-card { min-width: 0; }
    #response .do-card-info { padding: 8px 8px 9px !important; }
    #response .movie-title {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        overflow: hidden;
        white-space: normal !important;
        text-overflow: ellipsis;
        padding: 0 !important;
        margin: 0 0 3px;
        font-size: .85rem !important;
        line-height: 1.35;
        overflow-wrap: anywhere;
    }
    #response .movie-year { font-size: .72rem; }
}
@media (max-width: 479.98px) {
    #response .movie-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
    }
}

/* ==========================================================================
   5. PAGINATION – compact:  ‹  صفحة 2 من 125  ›   (below 768px)
   ========================================================================== */
@media (max-width: 767.98px) {
    nav.wp-pagenavi {
        display: flex;
        align-items: center;
        gap: 8px;
        min-height: 0;
        margin: 1.25rem 0 1.5rem !important;
        font-size: 0;
    }
    nav.wp-pagenavi a.inactive,
    nav.wp-pagenavi .current,
    nav.wp-pagenavi .dots { display: none !important; }

    nav.wp-pagenavi .pages {
        order: 2;
        flex: 1 1 auto;
        margin: 0;
        padding: 0 8px;
        height: 44px;
        line-height: 44px;
        text-align: center;
        font-size: .9rem;
        background: transparent;
        white-space: nowrap;
    }
    nav.wp-pagenavi a.prev,
    nav.wp-pagenavi a.next,
    nav.wp-pagenavi .disabled {
        display: flex !important;
        align-items: center;
        justify-content: center;
        flex: 0 0 56px;
        min-width: 56px;
        height: 44px;
        margin: 0;
        padding: 0;
        line-height: 1;
        font-size: 1.6rem;
        border-radius: 10px;
        background: #22252d;
    }
    nav.wp-pagenavi .prev { order: 1; }
    nav.wp-pagenavi .next { order: 3; }
    nav.wp-pagenavi .disabled { opacity: .3; pointer-events: none; }
    nav.wp-pagenavi a.prev:active,
    nav.wp-pagenavi a.next:active { background: #f5c16c; color: #111; }
}

/* ==========================================================================
   6. FLOATING ELEMENTS  (below 768px)
   Guests: the floating "تسجيل الدخول" pill is hidden (login lives in the
   drawer + promo banner). Logged-in users: avatar button and back-to-top are
   stacked with a 16px margin from the screen edge.
   ========================================================================== */
@media (max-width: 767.98px) {
    #drama-profile-widget .dp-login-btn { display: none !important; }

    #drama-profile-widget {
        left: 16px !important;
        right: auto !important;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    }
    body .back-to-top {
        left: 16px !important;
        right: auto !important;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
        width: 44px !important;
        height: 44px !important;
    }
    body.logged-in .back-to-top {
        bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important;
    }
    body.do-lock #drama-profile-widget,
    body.do-lock .back-to-top { visibility: hidden !important; }
}

/* ==========================================================================
   7. FOOTER  (below 768px) – 2×2 grid, 44px tap targets
   ========================================================================== */
@media (max-width: 767.98px) {
    .ad-container:empty { display: none; }
    .site-footer { padding-left: 4px; padding-right: 4px; }
    .site-footer .footer-nav .footer-menu {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px !important;
        padding: 0;
        margin: 0;
    }
    .site-footer .footer-nav .footer-menu li { min-width: 0; }
    .site-footer .footer-nav .footer-menu li:last-child:nth-child(odd) { grid-column: 1 / -1; }
    .site-footer .footer-nav .footer-menu li a {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        min-height: 44px;
        padding: 0 10px;
        border: 1px solid rgba(156, 163, 175, .15);
        border-radius: 12px;
        background: rgba(255, 255, 255, .03);
        font-size: .9rem;
        text-align: center;
    }
    .site-footer .social-links { gap: 12px; }
    .site-footer .social-links a { width: 44px; height: 44px; }
    .site-footer .footer-disclaimer p { padding: 0 6px; }
}
