/* Extracted from library-video.php; preserve page scope. */
/* =========================================================
   تحسينات خاصة بصفحة مكتبة الفيديو
   ========================================================= */

.video-page {
    position: relative;
}

/* البحث */

.video-page .search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: #fff;
    border: 2px solid #e2e8f0;
    border-radius: 50px;
    padding: 4px 4px 4px 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,.04);
    transition: border-color .2s, box-shadow .2s;
    margin-bottom: 20px;
}

.video-page .search-wrapper:focus-within {
    border-color: #4facfe;
    box-shadow: 0 4px 20px rgba(79,172,254,.15);
}

.video-page .search-icon {
    color: #94a3b8;
    font-size: 1.1rem;
    margin-inline-end: 8px;
    flex-shrink: 0;
}

.video-page .search-wrapper input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: none;
    background: transparent;
    padding: 10px 0;
    font-size: 1rem;
    color: #1e293b;
}

.video-page .search-wrapper .clear-btn {
    display: none;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 8px 12px;
}

.video-page .search-wrapper .search-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    background: #1e40af;
    color: #fff;
    border: none;
    border-radius: 50px;
    padding: 10px 24px;
    font-weight: 700;
    cursor: pointer;
}

/* شريط التصنيفات */

.video-categories-bar {
    position: relative;
    z-index: 50;
    width: 100%;
    overflow: visible;
}

.video-categories-scroll {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 2px;
    white-space: nowrap;
    scrollbar-width: thin;
    scrollbar-color: #4facfe #e2e8f0;
    -webkit-overflow-scrolling: touch;
}

.video-categories-scroll::-webkit-scrollbar {
    height: 6px;
}

.video-categories-scroll::-webkit-scrollbar-track {
    background: #e2e8f0;
    border-radius: 10px;
}

.video-categories-scroll::-webkit-scrollbar-thumb {
    background: #4facfe;
    border-radius: 10px;
}

.cat-bar-item {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}

.cat-bar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 20px;
    border-radius: 30px;
    border: 2px solid #e2e8f0;
    background: #f8fafc;
    color: #1e293b;
    cursor: pointer;
    font-weight: 700;
    font-size: 1rem;
    white-space: nowrap;
    transition: background .2s, color .2s, border-color .2s;
}

.cat-bar-btn:hover {
    background: #e2e8f0;
}

.cat-bar-btn.active {
    background: #1e40af;
    color: #fff;
    border-color: #1e40af;
}

.cat-bar-btn .cat-count,
.cat-bar-sub-btn .cat-count {
    font-size: .85rem;
    opacity: .75;
}

.cat-arrow {
    font-size: .75rem;
    transition: transform .2s;
}

.cat-bar-item.open .cat-arrow {
    transform: rotate(180deg);
}

/*
 * طبقة خلفية القائمة.
 * يتم وضعها مباشرة داخل body بواسطة JavaScript.
 */

.category-dropdown-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: transparent;
    display: none;
}

.category-dropdown-overlay.active {
    display: block;
}

/*
 * القائمة المنسدلة أصبحت مستقلة عن شريط التمرير.
 * لذلك لن يقصها overflow الخاص بشريط التصنيفات.
 */

.cat-bar-dropdown {
    position: fixed;
    display: none;
    z-index: 9999;
    min-width: 230px;
    max-width: min(340px, calc(100vw - 20px));
    max-height: min(420px, calc(100vh - 30px));
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    box-shadow: 0 10px 35px rgba(0,0,0,.18);
    padding: 7px 0;
    white-space: normal;
    direction: inherit;
}

.cat-bar-dropdown.visible {
    display: block;
    animation: categoryDropIn .16s ease-out;
}

@keyframes categoryDropIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cat-bar-sub-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 44px;
    padding: 11px 16px;
    text-align: start;
    background: #fff;
    border: 0;
    cursor: pointer;
    color: #1e293b;
    font-size: .95rem;
    font-weight: 600;
    white-space: normal;
}

.cat-bar-sub-btn:hover {
    background: #f1f5f9;
}

.cat-bar-sub-btn.active {
    background: #dbeafe;
    color: #1e40af;
    font-weight: 700;
}

/* خلفية الجوال */

.category-mobile-backdrop {
    display: none;
}

/* الشبكة */

.yt-grid-section {
    margin-top: 12px;
}

.yt-grid-section .ui-card-grid {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 22px 18px !important;
    width: 100%;
    align-items: start;
}

.yt-grid-section .ui-card-grid > .yt-card {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
}

.yt-card {
    cursor: pointer;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    border-radius: 12px;
    background: #fff;
    transition: transform .25s, box-shadow .25s;
}

.yt-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 22px rgba(0,0,0,.09);
}

.yt-card-thumb {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: #f1f5f9;
    flex-shrink: 0;
}

.yt-card-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .3s;
}

.yt-card:hover .yt-card-thumb img {
    transform: scale(1.04);
}

.video-duration {
    position: absolute;
    bottom: 8px;
    left: 8px;
    z-index: 2;
    background: rgba(0,0,0,.78);
    color: #fff;
    padding: 4px 9px;
    border-radius: 6px;
    font-size: .8rem;
    font-weight: 700;
}

.yt-card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 8px;
    padding: 12px 13px 14px;
    min-width: 0;
}

.yt-card-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    margin: 0;
    min-height: 3em;
    color: #1e40af;
    font-size: .95rem;
    line-height: 1.6;
    font-weight: 800;
}

.yt-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    color: #64748b;
    font-size: .8rem;
    font-weight: 600;
}

/* المودال */

.video-modal {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0,0,0,.85);
}

.video-modal.open {
    display: flex;
}

.video-modal .modal-content {
    position: relative;
    width: 100%;
    max-width: 900px;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 20px;
    background: #fff;
    direction: ltr;
}

.video-modal #closeModal {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: rgba(0,0,0,.65);
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
}

.video-modal .modal-video-wrap {
    position: relative;
    height: 0;
    padding-bottom: 56.25%;
    flex-shrink: 0;
    background: #000;
}

.video-modal #modalPlayer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.video-modal .modal-info {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    background: #fff;
    text-align: right;
}

.video-modal .modal-title {
    margin: 0 0 8px;
    color: #1e293b;
    font-size: 1.2rem;
    font-weight: 800;
    line-height: 1.5;
}

.video-modal .modal-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    color: #64748b;
    font-size: .9rem;
}

.video-modal .modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

.video-modal .modal-actions .ui-btn {
    flex: 1 1 auto;
    min-width: 120px;
    justify-content: center;
}

/* الاستجابة */

@media (max-width: 1200px) {
    .yt-grid-section .ui-card-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 20px 15px !important;
    }
}

@media (max-width: 900px) {
    .yt-grid-section .ui-card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 18px 14px !important;
    }
}

@media (max-width: 768px) {
    .video-page .search-wrapper {
        padding: 4px 4px 4px 10px;
    }

    .video-page .search-btn {
        padding: 10px 16px;
    }

    .video-page .search-btn span {
        display: none;
    }

    .cat-bar-btn {
        padding: 10px 16px;
        font-size: .95rem;
    }

    /*
     * القائمة على الجوال لا تعتمد على مكان الزر.
     * تظهر كلوحة سفلية مستقلة.
     */

    .cat-bar-dropdown.mobile-dropdown {
        position: fixed !important;
        top: auto !important;
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        max-height: 60vh !important;
        border: 0;
        border-radius: 18px 18px 0 0;
        padding: 12px 0 max(18px, env(safe-area-inset-bottom));
        box-shadow: 0 -8px 30px rgba(0,0,0,.22);
        z-index: 10003;
        direction: inherit;
    }

    .category-mobile-backdrop.active {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 10002;
        background: rgba(15,23,42,.42);
        backdrop-filter: blur(2px);
    }

    .cat-bar-dropdown.mobile-dropdown .cat-bar-sub-btn {
        min-height: 50px;
        padding: 13px 22px;
        font-size: 1rem;
    }

    .video-modal {
        padding: 0;
        align-items: flex-end;
    }

    .video-modal .modal-content {
        max-height: 95vh;
        border-radius: 18px 18px 0 0;
    }

    .video-modal .modal-actions .ui-btn {
        flex: 1 1 100%;
    }
}

@media (max-width: 600px) {
    .yt-grid-section .ui-card-grid {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 18px !important;
    }
}

@media (max-width: 480px) {
    .video-duration {
        font-size: .75rem;
    }
}

/* الطباعة */

@media print {
    .video-modal,
    .video-categories-bar,
    .search-wrapper {
        display: none !important;
    }

    .yt-grid-section .ui-card-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .yt-card {
        break-inside: avoid;
        box-shadow: none !important;
    }
}
