/* ============================================
   TyLearn Mobile Course List Styles
   Udemy-inspired mobile list view
   ============================================ */

/* ============================================
   CRITICAL: Desktop Protection Rules
   Ensure desktop layout is NEVER affected
   ============================================ */
@media (min-width: 992px) {
    /* Force hide all mobile-specific elements on desktop */
    .tylearn-mobile-course-list,
    .tylearn-mobile-course-item,
    .mobile-course-img,
    .mobile-course-content,
    .mobile-course-title,
    .mobile-course-instructor,
    .mobile-course-rating,
    .mobile-course-meta,
    #mobileFiltersOffcanvas,
    #mobileSortModal {
        display: none !important;
    }

    /* Ensure desktop filter sidebar shows */
    .d-none.d-lg-block {
        display: block !important;
    }

    /* Preserve desktop course list layout */
    .courses-list-item {
        display: block !important;
    }

    .course-list-contents {
        display: block !important;
    }

    /* Ensure desktop topbar shows */
    .header-topbar {
        display: block !important;
    }

    /* Desktop header-two class styling preserved */
    .header-two {
        display: block !important;
    }
}

/* ===========================================
   MOBILE LIST VIEW LAYOUT
   Only applies below 992px
   =========================================== */
@media (max-width: 991px) {
    /* Main Section Adjustments */
    .course-section {
        padding: 30px 0;
    }

    .breadcrumb-bar {
        padding: 20px 0;
    }

    .breadcrumb-title {
        font-size: 24px;
        margin-bottom: 8px;
    }

    /* Container adjustments */
    .container {
        padding-left: 16px;
        padding-right: 16px;
    }

    /* ===========================================
       MOBILE COURSE LIST ITEMS
       =========================================== */
    .tylearn-mobile-course-list {
        padding: 0;
        margin: 0;
    }

    .tylearn-mobile-course-item {
        margin-bottom: 0;
    }

    .tylearn-mobile-course-item a {
        display: flex !important;
        text-decoration: none;
        color: inherit;
        padding: 16px 0;
        border-bottom: 1px solid #d1d7dc;
        transition: background-color 0.2s ease;
    }

    .tylearn-mobile-course-item a:hover,
    .tylearn-mobile-course-item a:active {
        background-color: rgba(0, 0, 0, 0.02);
    }

    .tylearn-mobile-course-item:last-child a {
        border-bottom: none;
    }

    /* Course Thumbnail */
    .mobile-course-img {
        width: 100px;
        min-width: 100px;
        height: 75px;
        overflow: hidden;
        border-radius: 4px;
        background-color: #f7f9fa;
        margin-right: 12px;
    }

    .mobile-course-img img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
    }

    /* Course Content */
    .mobile-course-content {
        min-width: 0;
        flex: 1;
    }

    /* Course Title */
    .mobile-course-title {
        font-size: 14px;
        font-weight: 700;
        line-height: 1.4;
        color: #1c1d1f;
        margin-bottom: 8px;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Instructor Name */
    .mobile-course-instructor {
        font-size: 12px;
        color: #6a6f73;
        margin-bottom: 4px;
        font-weight: 400;
    }

    /* Rating Section */
    .mobile-course-rating {
        font-size: 14px;
        font-weight: 700;
        color: #b4690e;
        line-height: 1.2;
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .mobile-rating-stars {
        font-size: 12px;
        line-height: 1;
        display: inline-flex;
        align-items: center;
        color: #b4690e;
    }

    .mobile-rating-stars i {
        margin-right: 1px;
        font-size: 11px;
    }

    .mobile-course-reviews {
        font-size: 12px;
        color: #6a6f73;
        font-weight: 400;
    }

    /* Course Meta (duration, lectures, level) */
    .mobile-course-meta {
        font-size: 12px;
        color: #6a6f73;
        margin-top: 4px;
        line-height: 1.3;
    }

    /* ===========================================
       FILTER & SORT BUTTONS
       =========================================== */
    .btn-outline-dark {
        padding: 12px 16px;
        font-weight: 500;
        font-size: 14px;
        border-color: #1c1d1f;
        color: #1c1d1f;
        border-radius: 8px;
        transition: all 0.2s ease;
        min-height: 48px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        white-space: nowrap;
    }

    .btn-outline-dark.btn-icon-only {
        padding: 12px;
        min-width: 48px;
    }

    .btn-outline-dark:hover,
    .btn-outline-dark:focus {
        background-color: #1c1d1f;
        border-color: #1c1d1f;
        color: #fff;
    }

    .btn-outline-dark i {
        font-size: 16px;
        line-height: 1;
    }

    .btn-outline-dark .me-1 {
        margin-right: 6px;
    }

    /* ===========================================
       SEARCH BAR
       =========================================== */
    .search-group {
        position: relative;
        width: 100%;
    }

    .search-group i {
        position: absolute;
        right: 15px;
        top: 50%;
        transform: translateY(-50%);
        color: #6a6f73;
        font-size: 18px;
        z-index: 2;
        pointer-events: none;
    }

    .search-group .form-control {
        padding-left: 15px;
        padding-right: 45px;
        height: 48px;
        border-radius: 8px;
        border: 1px solid #d1d7dc;
        font-size: 14px;
        background-color: #fff;
        transition: border-color 0.2s ease;
    }

    .search-group .form-control:focus {
        border-color: var(--secondary, #10b981);
        box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
        outline: none;
    }

    .search-group .form-control::placeholder {
        color: #6a6f73;
    }

    /* ===========================================
       MOBILE FILTERS OFFCANVAS (SIDE PANEL - RIGHT)
       =========================================== */
    .tylearn-mobile-filters.offcanvas,
    .tylearn-mobile-filters.offcanvas-end,
    #mobileFiltersOffcanvas.offcanvas,
    #mobileFiltersOffcanvas.offcanvas-end {
        width: 80vw !important;
        max-width: 80vw !important;
        min-width: 80vw !important;
        height: 100vh !important;
        box-shadow: -2px 0 20px rgba(0, 0, 0, 0.15);
        z-index: 9999 !important;
        background-color: #fff;
    }

    /* Only apply max-width on larger mobile screens */
    @media (min-width: 500px) {
        .tylearn-mobile-filters.offcanvas,
        .tylearn-mobile-filters.offcanvas-end,
        #mobileFiltersOffcanvas.offcanvas,
        #mobileFiltersOffcanvas.offcanvas-end {
            max-width: 400px !important;
            min-width: 400px !important;
            width: 400px !important;
        }
    }

    .tylearn-mobile-filters .offcanvas-header {
        padding: 16px 15px;
        background-color: #fff;
        border-bottom: 1px solid #e4e8eb;
        display: block;
        position: relative;
        min-height: auto;
    }

    .tylearn-mobile-filters .offcanvas-header .btn-close {
        position: absolute;
        left: 15px;
        top: 50%;
        transform: translateY(-50%);
        width: 40px;
        height: 40px;
        padding: 0;
        margin: 0;
        background-color: #fff;
        border: 1px solid #d1d7dc;
        border-radius: 50%;
        background-size: 14px;
        flex-shrink: 0;
        opacity: 1;
        z-index: 10;
    }

    .tylearn-mobile-filters .offcanvas-header .btn-close:hover {
        background-color: #f7f9fa;
        border-color: #b4b8bb;
    }

    .tylearn-mobile-filters .offcanvas-header .header-content {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-left: 52px;
        min-height: 40px;
    }

    .tylearn-mobile-filters .offcanvas-title {
        font-size: 16px;
        font-weight: 400;
        color: #2d2f31;
        margin: 0;
        line-height: 1.4;
    }

    .clear-filters-link {
        font-size: 14px;
        font-weight: 600;
        color: #5624d0;
        text-decoration: none;
        white-space: nowrap;
        line-height: 1.4;
    }

    .clear-filters-link:hover {
        color: #401b9c;
        text-decoration: underline;
    }

    .tylearn-mobile-filters .offcanvas-body {
        padding: 0 15px !important;
        overflow-y: auto;
        background-color: #fff;
        height: calc(100vh - 140px) !important;
        max-height: calc(100vh - 140px) !important;
    }

    /* Accordion Styling for Side Panel */
    .tylearn-filter-accordion {
        background-color: #fff;
        margin: 0;
        padding: 0;
    }

    .tylearn-filter-accordion .accordion-item {
        background: #fff;
        border: none;
        border-radius: 0;
        margin: 0;
    }

    .tylearn-filter-accordion .accordion-item:not(:last-child) {
        border-bottom: 1px solid #e4e8eb;
    }

    .tylearn-filter-accordion .accordion-button {
        padding: 12px 15px 16px 15px;
        background: #fff;
        border: none;
        font-weight: 700;
        font-size: 16px;
        color: #2d2f31;
        box-shadow: none !important;
        line-height: 1.4;
    }

    .tylearn-filter-accordion .accordion-button:not(.collapsed) {
        color: #2d2f31;
        background-color: #fff;
    }

    .tylearn-filter-accordion .accordion-button:hover {
        background-color: #f7f9fa;
    }

    .tylearn-filter-accordion .accordion-button::after {
        width: 20px;
        height: 20px;
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%232d2f31'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
        background-size: 14px;
        transition: transform 0.2s ease;
    }

    .tylearn-filter-accordion .accordion-button:not(.collapsed)::after {
        transform: rotate(-180deg);
    }

    .tylearn-filter-accordion .accordion-collapse {
        background-color: #fff;
    }

    .tylearn-filter-accordion .accordion-body {
        padding: 0 15px 20px 15px !important;
        background-color: #fff;
    }

    /* Filter Options */
    .filter-option-item {
        margin-bottom: 12px;
    }

    .filter-option-item:last-of-type {
        margin-bottom: 12px;
    }

    .filter-option-item .custom_check {
        display: flex;
        align-items: flex-start;
        cursor: pointer;
        font-size: 14px;
        color: #2d2f31;
        line-height: 1.4;
        margin-bottom: 0;
        padding: 2px 0;
    }

    .filter-option-item .custom_check:hover .filter-name {
        color: #5624d0;
    }

    .filter-option-item .custom_check input[type="checkbox"] {
        position: absolute;
        opacity: 0;
        cursor: pointer;
        height: 0;
        width: 0;
    }

    .filter-option-item .checkmark {
        position: relative;
        width: 18px;
        height: 18px;
        min-width: 18px;
        margin-right: 10px;
        margin-top: 1px;
        border: 2px solid #1c1d1f;
        border-radius: 2px;
        background-color: #fff;
        transition: all 0.2s ease;
    }

    .filter-option-item .custom_check:hover .checkmark {
        border-color: #5624d0;
    }

    .filter-option-item .checkmark::after {
        content: "";
        position: absolute;
        display: none;
        left: 5px;
        top: 1px;
        width: 4px;
        height: 9px;
        border: solid white;
        border-width: 0 2px 2px 0;
        transform: rotate(45deg);
    }

    .filter-option-item .custom_check input:checked ~ .checkmark {
        background-color: #1c1d1f;
        border-color: #1c1d1f;
    }

    .filter-option-item .custom_check input:checked ~ .checkmark::after {
        display: block;
    }

    .filter-label {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        flex: 1;
        line-height: 1.4;
    }

    .filter-name {
        font-weight: 400;
        color: #2d2f31;
        transition: color 0.2s ease;
        line-height: 1.4;
    }

    .filter-count {
        font-size: 14px;
        color: #6a6f73;
        margin-left: 8px;
        white-space: nowrap;
        line-height: 1.4;
    }

    .show-more-link {
        display: inline-block;
        font-size: 14px;
        font-weight: 600;
        color: #5624d0;
        text-decoration: none;
        padding: 4px 0;
        cursor: pointer;
        margin-top: 4px;
        line-height: 1.4;
    }

    .show-more-link:hover {
        color: #401b9c;
        text-decoration: underline;
    }

    /* Offcanvas Footer */
    .offcanvas-footer {
        background-color: #fff;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        padding: 16px;
        border-top: 1px solid #e4e8eb;
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 10;
    }

    .offcanvas-footer .btn {
        height: 48px;
        font-weight: 600;
        border-radius: 8px;
    }

    /* Backdrop overlay */
    .offcanvas-backdrop {
        z-index: 9998 !important;
        background-color: rgba(0, 0, 0, 0.5);
    }

    /* Ensure offcanvas appears above everything */
    .offcanvas.show {
        z-index: 9999 !important;
    }

    /* Remove any default Bootstrap padding/margins */
    .tylearn-mobile-filters .accordion {
        margin: 0;
    }

    .tylearn-mobile-filters .accordion-flush .accordion-item {
        border-radius: 0;
    }

    .tylearn-mobile-filters .accordion-flush .accordion-collapse {
        border-width: 0;
    }

    /* ===========================================
       MOBILE SORT MODAL
       =========================================== */
    .modal-dialog-bottom {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        margin: 0;
        max-width: 100%;
        transform: translateY(0) !important;
    }

    .modal-dialog-bottom .modal-content {
        border-radius: 20px 20px 0 0;
        border: none;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }

    .modal-dialog-bottom .modal-header {
        padding: 20px;
        border-bottom: 1px solid #d1d7dc;
    }

    .modal-dialog-bottom .modal-title {
        font-size: 18px;
        font-weight: 700;
        color: #1c1d1f;
    }

    .modal-dialog-bottom .modal-body {
        padding: 0;
        max-height: 60vh;
        overflow-y: auto;
    }

    /* List Group Items */
    .list-group-item {
        padding: 16px 20px;
        border-left: 0;
        border-right: 0;
        cursor: pointer;
        transition: background-color 0.2s ease;
        font-size: 15px;
        color: #1c1d1f;
    }

    .list-group-item:hover,
    .list-group-item:active {
        background-color: rgba(0, 0, 0, 0.02);
    }

    .list-group-item:first-child {
        border-top: none;
    }

    .list-group-item .form-check-input {
        width: 20px;
        height: 20px;
        margin-top: 0;
        cursor: pointer;
    }

    .list-group-item .form-check-input:checked {
        background-color: var(--secondary, #10b981);
        border-color: var(--secondary, #10b981);
    }

    /* ===========================================
       PAGINATION MOBILE
       =========================================== */
    .pagination-text {
        font-size: 14px;
        color: #6a6f73;
    }

    .pagination.lms-page .page-link {
        min-width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
    }

    /* ===========================================
       RESULTS COUNT
       =========================================== */
    .show-result h6,
    .tylearn-mobile-course-list ~ div h6 {
        font-size: 14px;
        font-weight: 400;
        color: #6a6f73;
    }

    /* ===========================================
       UTILITY CLASSES
       =========================================== */
    .gx-2 {
        --bs-gutter-x: 0.5rem;
    }

    /* Remove margin from last mobile course item */
    .tylearn-mobile-course-list .tylearn-mobile-course-item:last-child {
        margin-bottom: 0;
    }

    /* Ensure proper spacing */
    .d-lg-none.mb-3 {
        margin-bottom: 1rem !important;
    }
}