/* === General Reset and Global Styles === */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif, 'Arial', 'Helvetica';
    line-height: 1.4;
    background-color: #f4f6f9;
    /* Light grey background like reference */
}

/* === Bilingual Support (Arabic + English) === */
* {
    /* Handle mixed RTL/LTR content properly */
    unicode-bidi: plaintext;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Ensure proper text rendering for Arabic */
.msc-course-container,
.msc-course-card,
.card-title,
.card-meta,
.msc-select,
.msc-register-btn {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* RTL Support for Arabic Content */
[dir="rtl"] .card-meta span::before {
    margin-right: 0;
    margin-left: 6px;
}

[dir="rtl"] .card-meta .location-detail {
    padding-left: 0;
    padding-right: 18px;
}

[dir="rtl"] .msc-select {
    text-align: right;
    padding-right: 10px;
    padding-left: 30px;
}

[dir="rtl"] .msc-download-btn {
    margin-left: 0;
    margin-right: 10px;
}

/* LTR Support for English Content */
[dir="ltr"] .card-meta span::before {
    margin-right: 6px;
    margin-left: 0;
}

[dir="ltr"] .card-meta .location-detail {
    padding-left: 18px;
    padding-right: 0;
}

[dir="ltr"] .msc-select {
    text-align: left;
}

[dir="ltr"] .msc-download-btn {
    margin-left: 10px;
    margin-right: 0;
}

.msc-course-container {
    max-width: 1400px;
    /* Container width for 6 columns */
    margin: 20px auto;
    padding: 0 40px;
    /* Side margins */
}

/* --- FILTER BAR --- */
.msc-filter-row {
    background-color: #fff;
    padding: 10px 15px;
    margin-bottom: 25px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #ddd;
    /* White bar with border */
}

.msc-filter-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    flex-grow: 1;
}

.msc-form-group {
    flex-grow: 0;
    min-width: 100px;
}

.msc-select {
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #fff;
    font-size: 0.85rem;
    color: #555;
    cursor: pointer;
    height: 34px;
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msc-select[type="text"] {
    cursor: text;
    white-space: normal;
}

.msc-select[type="text"]::placeholder {
    color: #999;
}

.msc-select:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    background-color: #eee;
}

.msc-clear-btn {
    padding: 6px 15px;
    background: #202F3E;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    height: 34px;
    white-space: nowrap;
}

.msc-clear-btn:hover {
    background-color: #1a252f;
}

.msc-download-btn {
    padding: 6px 15px;
    background-color: #202F3E;
    color: #fff;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.85rem;
    white-space: nowrap;
    margin-left: 10px;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.msc-download-btn:hover {
    background-color: #5d3b74;
}

/* === Course Cards Grid === */
.msc-course-grid {
    display: grid;
    /* Fixed 6 columns per row */
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    /* Spacing between cards */
}

/* --- COURSE CARD STYLING --- */
.msc-course-grid:not(.list-view) .msc-course-card {
    background: #fff;
    border: 1px solid #202F3E;
    /* Dark blue border per reference */
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s;
    height: 100%;
}

.msc-course-grid:not(.list-view) .msc-course-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.msc-course-grid:not(.list-view) .card-image {
    height: 140px;
    /* Reduced height */
    background-size: cover;
    background-position: center;
    background-color: #eee;
    position: relative;
    border-bottom: 1px solid #eee;
}

.status-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    color: #d32f2f;
    padding: 5px 10px;
    border-radius: 3px;
    font-weight: bold;
    font-size: 0.8rem;
    white-space: nowrap;
}

.plus-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: #202F3E;
    color: #fff;
    padding: 4px 8px;
    font-size: 0.7rem;
    font-weight: bold;
    border-radius: 2px;
}

.card-content {
    padding: 12px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.card-title {
    font-size: 0.95rem;
    /* Smaller title */
    font-weight: 700;
    color: #333;
    margin: 0 0 10px 0;
    line-height: 1.4;
    min-height: 2.8em;
    /* Ensure 2 lines check */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
    /* Handle long Arabic/English words */
    white-space: normal;
}

.card-meta {
    flex-grow: 1;
    margin-bottom: 10px;
}

.card-meta p {
    margin: 4px 0;
    font-size: 0.75rem;
    /* Compact text */
    color: #666;
    display: flex;
    align-items: center;
    word-break: break-word;
    /* Handle mixed languages */
    white-space: normal;
    line-height: 1.5;
}

.card-meta span::before {
    margin-right: 6px;
    font-size: 0.85rem;
    color: #e67e22;
    /* Orange icons like reference */
}

/* Icons */
.card-meta span.icon-calendar::before {
    content: "📅";
}

.card-meta span.icon-flag::before {
    content: "🏳️";
}

.card-meta span.icon-location::before {
    content: "🎓";
}

.card-meta span.icon-city::before {
    content: "📍";
}

.card-meta .location-detail {
    margin-top: -3px;
    padding-left: 18px;
    font-size: 0.7rem;
    color: #888;
}

.msc-register-btn {
    display: block;
    width: 100%;
    margin-top: auto;
    /* Push to bottom */
    background-color: #202F3E;
    /* Dark blue */
    color: #fff;
    text-align: center;
    padding: 8px 0;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 3px;
    border: none;
    cursor: default;
    /* No pointer since it's disabled */
    font-family: inherit;
}

.msc-register-btn:hover {
    background-color: #202F3E;
    /* No hover effect since disabled */
}

.msc-no-courses-found {
    grid-column: 1/-1;
    text-align: center;
    padding: 50px;
    background: #f8f8f8;
    border-radius: 6px;
    border: 1px dashed #ccc;
    font-size: 1.2rem;
    color: #555;
}

/* --- Tablet Responsiveness --- */
@media (max-width: 992px) and (min-width: 769px) {
    .msc-filter-row {
        flex-direction: column;
        align-items: stretch;
        padding: 15px;
    }

    .msc-filter-form {
        gap: 10px;
        margin-bottom: 15px;
        justify-content: space-between;
    }

    .msc-form-group {
        flex: 1 1 45%;
        min-width: 140px;
    }
}

/* =========================================
   NEW SLIDING TOGGLE & LIST VIEW STYLES
   ========================================= */

/* --- Header Row --- */
.msc-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 15px;
}

.msc-title {
    font-size: 1.75rem;
    color: #d7dce0;
    margin: 0;
    font-weight: 700;
}

/* --- Sliding Toggle Container --- */
.msc-view-toggle-wrapper {
    display: flex;
    align-items: center;
}

.msc-toggle-switch {
    display: flex;
    position: relative;
    background-color: #e6e6e6;
    /* Initial Grey */
    border-radius: 50px;
    padding: 4px;
    border: 1px solid #dcdcdc;
    overflow: hidden;
    cursor: pointer;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    user-select: none;
}

/* The Sliding Blue Pill */
.msc-toggle-slider {
    position: absolute;
    top: 4px;
    left: 4px;
    bottom: 4px;
    width: calc(50% - 4px);
    /* Roughly half width */
    background-color: #202F3E;
    /* Updated color */
    border-radius: 50px;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    z-index: 1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    pointer-events: none;
    /* Let clicks pass to container/buttons */
}

/* Move slider to the right when List is active */
.msc-toggle-switch.list-view-active .msc-toggle-slider {
    transform: translateX(100%);
}

/* The Option Text/Buttons */
.msc-toggle-option {
    position: relative;
    z-index: 2;
    /* Sit ABOVE the slider */
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 25px;
    font-size: 0.95rem;
    font-family: inherit;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    transition: color 0.3s;
    outline: none;
    white-space: nowrap;
    text-align: center;
    min-width: 100px;
}

.msc-toggle-option.active {
    color: #fff;
    /* White text when active for better contrast */
}

.msc-toggle-option:hover:not(.active) {
    color: #333;
}


/* --- List View Logic --- */

.msc-course-grid.list-view {
    grid-template-columns: 100%;
}

.msc-course-grid.list-view .msc-course-card {
    display: flex;
    /* 🔴 THIS WAS MISSING */
    flex-direction: row;
    /* image left, text right */
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 15px;
    overflow: hidden;
}

.msc-course-grid.list-view .card-image {
    width: 250px;
    min-height: 160px;
    background-size: cover;
    background-position: center;
    border-right: 1px solid #eee;
    flex-shrink: 0;
    /* image squeeze na ho */
}

.msc-course-grid.list-view .card-content {
    padding: 15px 20px;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "title button"
        "meta button";
    gap: 10px 20px;
    flex-grow: 1;
}

.msc-course-grid.list-view .card-title {
    grid-area: title;
    font-size: 1.2rem;
    font-weight: 700;
    color: #2c3e50;
    line-height: 1.4;
    word-break: break-word;
    /* Handle mixed Arabic/English */
    white-space: normal;
    overflow-wrap: break-word;
}

.msc-course-grid.list-view .card-meta {
    grid-area: meta;
    display: grid;
    /* 🔴 flex ki jagah grid */
    grid-template-columns: 1fr 1fr;
    /* 2 items per row */
    gap: 8px 20px;
}


.msc-course-grid.list-view .msc-register-btn {
    grid-area: button;
    min-width: 150px;
    padding: 10px 20px;
    white-space: nowrap;
    align-self: center;
    /* 🔴 vertical center */
    justify-self: center;
    /* 🔴 horizontal neat */
}


/* Mobile Responsiveness */
@media (max-width: 768px) {

    /* Main Layout */
    .msc-course-container {
        padding: 0 15px;
    }

    /* Grid view: 2 columns with gap */
    .msc-course-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }

    /* --- FILTER LAYOUT --- */
    .msc-filter-row {
        padding: 0 0 20px 0;
        /* Remove padding */
        border: none;
        background: transparent;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        flex-wrap: nowrap;
        /* Keep them in one line */
    }

    /* Toggle Button (Visible on Mobile) */
    .msc-mobile-filter-trigger {
        display: flex;
        align-items: center;
        justify-content: space-between;
        background: #fff;
        border: 1px solid #202F3E;
        color: #202F3E;
        padding: 8px 15px;
        border-radius: 4px;
        font-weight: 600;
        cursor: pointer;
        flex: 1;
        /* Take half space */
        height: 42px;
        font-size: 0.95rem;
    }

    .msc-mobile-filter-trigger:hover {
        background: #f4f6f9;
    }

    /* Download Button (Visible on Mobile) */
    .msc-download-btn {
        flex: 1;
        /* Take half space */
        margin: 0 !important;
        text-align: center;
        height: 42px;
        padding: 8px 5px;
        white-space: nowrap;
        font-size: 0.9rem;
        display: flex;
        /* Centering */
        align-items: center;
        justify-content: center;
        width: auto !important;
        /* Override desktop width */
    }

    /* --- MODAL STYLES (Hide Form Initially) --- */
    .msc-filter-form {
        display: none;
        /* Hidden by default */
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        /* Dark Overlay */
        z-index: 9999;
        justify-content: center;
        align-items: center;
        /* Vertically enter */
        padding: 0 15px;
        /* Side padding so box has margins */
        box-sizing: border-box;
    }

    .msc-filter-form.open {
        display: flex;
        /* Show flex to center content */
    }

    /* New Content Wrapper - The White Box */
    .msc-modal-content {
        background: #fff;
        width: 100%;
        max-width: 380px;
        /* Nice popup width */
        border-radius: 12px;
        /* Rounded corners */
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
        overflow: hidden;
        display: flex;
        flex-direction: column;
        max-height: 85vh;
        overflow-y: auto;
    }

    /* Remove white bg from form itself since wrapper has it */
    .msc-filter-form.open {
        background: rgba(0, 0, 0, 0.5);
    }

    /* Inside Modal Layout */
    .msc-filter-form.open>* {
        width: 100%;
    }

    /* Modal Header */
    .msc-mobile-modal-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 15px 20px;
        background: #fff;
        border-bottom: 1px solid #eee;
        margin-bottom: 15px;
        flex: 0 0 auto;
    }

    .msc-mobile-modal-header h3 {
        margin: 0;
        font-size: 1.1rem;
        color: #333;
        font-weight: 700;
    }

    .msc-close-modal {
        background: none;
        border: none;
        font-size: 2rem;
        color: #999;
        cursor: pointer;
        line-height: 0.8;
        padding: 0;
        margin-top: -5px;
    }

    /* Filter Inputs in Modal */
    .msc-form-group {
        padding: 0 20px;
        margin-bottom: 15px;
        flex: 0 0 auto;
        /* Stop resizing */
        width: 100% !important;
        box-sizing: border-box;
    }

    .msc-search-group {
        margin-bottom: 20px;
    }

    .msc-select {
        height: 45px;
        /* Larger touch targets */
        font-size: 1rem;
        width: 100%;
    }

    /* Clear Button */
    .msc-clear-btn {
        width: calc(100% - 40px);
        margin: 0 20px 10px 20px;
        background: transparent;
        color: #666;
        border: 1px solid #ccc;
        height: 45px;
    }

    /* Apply Filter Button */
    .msc-mobile-apply-btn {
        display: block;
        width: calc(100% - 40px);
        margin: 10px 20px 20px 20px;
        background: #202F3E;
        color: #fff;
        border: none;
        border-radius: 4px;
        height: 48px;
        font-size: 1.1rem;
        font-weight: 600;
        cursor: pointer;
    }


    /* List view adjustments */
    .msc-course-grid.list-view .msc-course-card {
        flex-direction: column;
        height: auto;
    }

    .msc-course-grid.list-view .card-image {
        width: 100%;
        height: 180px;
        border-right: none;
        border-bottom: 1px solid #d1d1d1;
    }

    .msc-course-grid.list-view .card-content {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .msc-course-grid.list-view .card-meta {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .msc-course-grid.list-view .msc-register-btn {
        width: 100%;
        margin-left: 0;
    }

    .msc-header-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .msc-view-toggle-wrapper {
        margin-left: auto;
        /* Keep toggle visible but compact if needed */
        margin-top: 10px;
    }
}

/* Hide Mobile Elements on Desktop */
@media (min-width: 769px) {

    .msc-mobile-filter-trigger,
    .msc-mobile-modal-header,
    .msc-mobile-apply-btn {
        display: none;
    }
}