/* === 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;
}



/* 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;
}



.msc-course-container {
    max-width: 1400px;
    /* Container width for 6 columns */
    margin: 0 auto 1% auto;
    /* Removed top margin */
    padding: 0 40px;
    /* Side margins */
    padding-top: 0 !important;
    /* Force remove top padding */
}

/* --- 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: 15px;
    flex-wrap: wrap;
    /* Allow wrapping */
    align-items: flex-start;
    /* Align to top */
    flex-grow: 1;
}

.msc-form-group {
    flex-grow: 1;
    min-width: 150px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.msc-form-group label {
    font-weight: 700;
    font-size: 0.9rem;
    color: #444;
}

.msc-desktop-filter-title {
    display: block !important;
    width: 100%;
    margin-bottom: 15px;
    font-weight: bold;
    font-size: 1.2rem;
}

.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: #5A4917;
    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;
}



/* === 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 #5A4917;
    /* 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: #5A4917;
    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 span.icon-clock::before {
    content: "⏰";
}

.card-meta span.icon-info::before {
    content: "ℹ️";
}

.card-meta .location-detail {
    margin-top: -3px;
    padding-left: 18px;
    font-size: 0.7rem;
    color: #888;
}

/* Dual Button Layout */
.card-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: auto;
}

.msc-explore-btn,
.msc-schedule-btn {
    display: block;
    width: 100%;
    background-color: #5A4917;
    color: #fff;
    text-align: center;
    padding: 10px 0;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 3px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: background-color 0.3s ease;
}

.msc-explore-btn:hover,
.msc-schedule-btn:hover {
    background-color: #4A3817;
}

/* Legacy button styling (kept for backward compatibility) */
.msc-register-btn {
    display: block;
    width: 100%;
    margin-top: auto;
    background-color: #5A4917;
    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;
    font-family: inherit;
}

.msc-register-btn:hover {
    background-color: #5A4917;
}

.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 --- */
/* ================================
   VIEW TOGGLE BUTTON (GRID / LIST)
   ================================ */

/* Toggle wrapper */
.msc-view-toggle-wrapper {
    display: flex;
    align-items: center;
}

/* Toggle container */
.msc-toggle-switch {
    position: relative;
    display: flex;
    background-color: #e6e6e6;
    /* light grey */
    border-radius: 50px;
    padding: 4px;
    border: 1px solid #dcdcdc;
    cursor: pointer;
    overflow: hidden;
    user-select: none;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Sliding pill */
.msc-toggle-slider {
    position: absolute;
    top: 4px;
    left: 4px;
    bottom: 4px;
    width: calc(50% - 4px);
    background-color: #5A4917;
    /* dark blue */
    border-radius: 50px;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    z-index: 1;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* When List View is active */
.msc-toggle-switch.list-view-active .msc-toggle-slider {
    transform: translateX(100%);
}

/* Toggle options (Grid / List text) */
.msc-toggle-option {
    position: relative;
    z-index: 2;
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px 25px;
    font-size: 0.95rem;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.3s ease;
    text-align: center;
    font-family: inherit;
    outline: none;
    min-width: 100px;
}

/* Active option text */
.msc-toggle-option.active {
    color: #fff;
}

/* Hover (inactive only) */
.msc-toggle-option:hover:not(.active) {
    color: #333;
}

/* === RTL Support for Toggle Button === */
[dir="rtl"] .msc-toggle-switch {
    direction: ltr;
    /* Keep toggle behavior consistent */
}

[dir="rtl"] .msc-toggle-slider {
    /* Slider behavior remains same */
}

[dir="rtl"] .msc-toggle-option {
    /* Text color and active states work the same */
    color: #666;
}

[dir="rtl"] .msc-toggle-option.active {
    color: #fff;
    /* Active text white in both RTL and LTR */
}

[dir="rtl"] .msc-toggle-option:hover:not(.active) {
    color: #333;
    /* Hover effect same in both directions */
}


/* --- 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: flex;
    flex-direction: column;
    align-items: center;
    /* Center everything */
    gap: 20px;
    /* More space between title and buttons */
    flex-grow: 1;
}

.msc-course-grid.list-view .card-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: #2c3e50;
    line-height: 1.4;
    word-break: break-word;
    white-space: normal;
    overflow-wrap: break-word;
    text-align: center;
    /* Center the title */
    width: 100%;
}

.msc-course-grid.list-view .card-meta {
    display: none;
    /* Hide meta in list view since we removed it */
}


.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 */
}

/* List View: Buttons in single horizontal line */
.msc-course-grid.list-view .card-buttons {
    flex-direction: row;
    gap: 10px;
    margin-top: 0;
    /* Remove extra margin since we have gap in parent */
    justify-content: center;
    /* Center the buttons */
    max-width: 400px;
    /* Limit button container width */
}

.msc-course-grid.list-view .msc-explore-btn,
.msc-course-grid.list-view .msc-schedule-btn {
    flex: 1;
    /* Equal width */
    min-width: 150px;
    /* Minimum button width */
}

/* 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 #5A4917;
        color: #5A4917;
        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) */



    /* --- 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: #5A4917;
        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 AND Fix Layout */
@media (min-width: 769px) {

    .msc-mobile-filter-trigger,
    .msc-mobile-modal-header,
    .msc-mobile-apply-btn {
        display: none;
    }

    /* Force the modal content wrapper to behave like a horizontal row on desktop */
    .msc-modal-content {
        display: flex !important;
        flex-direction: row !important;
        background: transparent !important;
        box-shadow: none !important;
        width: 100% !important;
        max-width: none !important;
        gap: 10px;
        align-items: center;
        padding: 0 !important;
        overflow: visible !important;
        max-height: none !important;
        border-radius: 0 !important;
    }

    /* Ensure form groups don't fill 100% like on mobile */
    .msc-form-group {
        width: auto !important;
        margin-bottom: 0 !important;
        padding: 0 !important;
    }

    .msc-clear-btn {
        margin: 0 !important;
        width: auto !important;
    }
}

/* Language Toggle Styles */
.msc-lang-toggle {
    display: inline-flex;
    background: #eef1f6;
    border-radius: 8px;
    padding: 3px;
    margin-right: 15px;
    /* Spacing between lang toggle and view toggle */
}

.msc-lang-btn {
    background: transparent;
    border: none;
    padding: 6px 14px;
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    color: #64748b;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.msc-lang-btn:hover {
    color: #1e293b;
}

.msc-lang-btn.active {
    background: #ffffff;
    color: #0f172a;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    font-weight: 600;
}

/* RTL Adjustments for Toggle Wrapper */
.msc-course-container[dir='rtl'] .msc-lang-toggle {
    margin-right: 0;
    margin-left: 15px;
}

/* =========================================
   REGISTRATION MODAL STYLES
   ========================================= */

.msc-reg-modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

.msc-reg-modal-content {
    background: #fff;
    width: 100%;
    max-width: 1200px;
    /* Increased from 800px to accommodate new columns */
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.msc-reg-header {
    background: #5A4917;
    color: #fff;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.msc-reg-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #fff;
}

.msc-close-reg-modal {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.msc-reg-body {
    padding: 20px;
    overflow-y: auto;
}

.msc-readonly-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.msc-form-row {
    display: flex;
    flex-direction: column;
}

.msc-form-row.full-width {
    grid-column: 1 / -1;
}

.msc-form-row label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 5px;
}

.msc-form-row input {
    background: #f9f9f9;
    border: 1px solid #ddd;
    padding: 8px 10px;
    border-radius: 4px;
    color: #333;
    font-weight: 500;
    font-size: 0.95rem;
}

.msc-reg-table-wrapper {
    border: 1px solid #eee;
    border-radius: 4px;
    overflow: hidden;
    overflow-x: auto;
    /* Enable horizontal scrolling for wide tables */
}

.msc-reg-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.msc-reg-table th {
    background: #f1f2f3;
    text-align: left;
    padding: 10px 15px;
    font-weight: 600;
    color: #444;
    border-bottom: 2px solid #ddd;
}

.msc-reg-table td {
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    color: #555;
    vertical-align: middle;
    cursor: pointer;
    white-space: nowrap;
    /* Prevent text wrapping */
    font-size: 0.85rem;
    /* Slightly smaller for more columns */
}

/* Radio Button Cell */
.msc-radio-cell {
    width: 40px;
    text-align: center;
}

.msc-reg-table tr:hover {
    background-color: #fcfcfc;
}

.msc-reg-table tr.selected-row {
    background-color: #f0f7ff;
}

.msc-reg-table tr.selected-row td {
    color: #333;
    font-weight: 500;
}

/* Footer & Buttons */
.msc-reg-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 15px;
    background: #fbfbfb;
}

.msc-reg-warning {
    color: #d32f2f;
    font-size: 0.9rem;
    font-weight: 500;
    display: none;
}

.msc-btn-cancel {
    background: #fff;
    border: 1px solid #ddd;
    padding: 8px 16px;
    border-radius: 4px;
    color: #555;
    cursor: pointer;
    font-weight: 500;
}

.msc-btn-confirm {
    background: #5A4917;
    border: none;
    padding: 8px 24px;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: opacity 0.2s;
}

.msc-btn-confirm:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.7;
}

/* RTL Support for Modal */
[dir="rtl"] .msc-reg-table th {
    text-align: right;
}

[dir="rtl"] .msc-close-reg-modal {
    float: left;
}