/* Modern Course List Page Styles - Dark/Light Mode Compatible */

.course-list-page {
    position: relative;
    min-height: 100vh;
    box-sizing: border-box;
}

/* Top area: title + list/map + filters (grid — mobile puts list/map + filters on one row) */
.course-list-top {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 1rem;
    align-items: start;
    margin-bottom: 1rem;
    position: relative;
    z-index: 101;
    transition: all 0.3s ease;
}

.course-list-top .page-header {
    grid-column: 1;
    grid-row: 1;
}

.course-list-top .view-toggle-container {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
}

.course-list-top .filters-section-collapsed {
    grid-column: 1 / -1;
    grid-row: 2;
}

/* When map is visible, overlay list/map + filters - no background */
body.map-view-active .course-list-top {
    position: fixed;
    top: 80px; /* Below header */
    left: auto;
    right: 2rem;
    padding: 0.75rem 0 0;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: none;
    z-index: 102;
    margin-bottom: 0;
    border: none;
    width: auto;
    max-width: min(360px, calc(100vw - 2rem));
    justify-items: end;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
}

body.map-view-active .course-list-top .page-header {
    display: none;
}

body.map-view-active .course-list-top .view-toggle-container {
    grid-column: 1;
    grid-row: 1;
    justify-self: end;
    width: 100%;
}

body.map-view-active .course-list-top .filters-section-collapsed {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    /* Stack inside fixed .course-list-top — do not use separate fixed positioning */
    position: static;
    top: auto;
    right: auto;
    left: auto;
    min-width: 0;
    max-width: none;
    margin-bottom: 0;
}

/* Page Header - Compact */
.page-header {
    flex: 1;
    min-width: 0;
    text-align: left;
    padding: 0.5rem 0;
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
    text-align: left;
}

.page-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0;
    text-align: left;
}

/* View Toggle Container - Compact */
.view-toggle-container {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex-shrink: 0;
}

/* In map view, ensure view toggle group has consistent width */
body.map-view-active .view-toggle-group {
    width: 240px; /* Increased to accommodate "List" and "Map" text */
    justify-content: center;
}

/* In map view, add background to view toggle only */
body.map-view-active .view-toggle-group {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

[data-theme="dark"] body.map-view-active .view-toggle-group {
    background: rgba(26, 26, 26, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.view-toggle-group {
    display: inline-flex;
    background-color: var(--bg-secondary);
    padding: 0.375rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px var(--shadow);
    position: relative;
}

.view-toggle-btn {
    padding: 0.875rem 1.5rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.25s ease;
    font-family: inherit;
    position: relative;
    z-index: 1;
    white-space: nowrap;
    flex: 1;
    text-align: center;
    min-width: 0;
}

.view-toggle-btn:hover:not(.active) {
    color: var(--text-primary);
}

.view-toggle-btn.active {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .view-toggle-btn.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Category filter buttons - inside filters panel, flow left-to-right and wrap onto multiple rows */
.category-filter-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.category-filter-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.5rem;
}

.category-filter-buttons-inline {
    margin-top: 0.25rem;
}

button.category-filter-more {
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    line-height: inherit;
}

.category-filter-more.expanded {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.category-filter-extra[hidden] {
    display: none !important;
}

/* Category / level filter groups span full width so buttons have room to flow in rows */
.filter-group-category,
.filter-group-level {
    grid-column: 1 / -1;
}

.category-filter-buttons .category-filter-btn {
    justify-self: stretch;
}

.category-filter-btn {
    display: inline-block;
    flex-shrink: 0;
    white-space: normal;
    text-align: center;
    padding: 0.5rem 1rem;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    text-decoration: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.category-filter-btn:hover {
    background-color: var(--bg-primary);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.category-filter-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.category-filter-btn.active:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
    color: white;
}

[data-theme="dark"] .category-filter-btn {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
}

[data-theme="dark"] .category-filter-btn.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

/* Collapsible Filters Section */
.filters-section-collapsed {
    margin-bottom: 1rem;
    position: relative;
    z-index: 101;
    transition: all 0.3s ease;
}

/* When map is visible, overlay filters on the right, aligned below view toggle */
body.map-view-active .filters-section-collapsed {
    position: fixed;
    top: 145px; /* Below view toggle (80px header + ~65px for toggle) */
    right: 2rem;
    left: auto;
    z-index: 102;
    margin-bottom: 0;
    width: 320px;
    min-width: 280px;
}

/* Make filter button same size as view toggle in map view */
body.map-view-active .filter-toggle-modern {
    width: 100%;
    min-width: 0;
    max-width: none;
    justify-content: center;
    padding: 0.875rem 1.75rem; /* Match view toggle button padding */
    box-sizing: border-box;
}

/* Filters content in map view - ensure full width and allow category names to wrap */
body.map-view-active .filters-content {
    min-width: 280px;
    width: 100%;
}

body.map-view-active .filters-content.active {
    max-height: 70vh;
    overflow-y: auto;
}

body.map-view-active .category-filter-buttons {
    grid-template-columns: 1fr;
    min-width: 0;
}

body.map-view-active .category-filter-btn {
    white-space: normal;
    word-break: break-word;
    text-align: left;
    min-height: 2.5rem;
}

body.map-view-active .filter-label,
body.map-view-active .filter-input,
body.map-view-active .filter-select {
    min-width: 0;
}

body.map-view-active .filter-group {
    min-width: 0;
}

.filter-toggle-modern {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    background: var(--bg-primary);
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    position: relative;
    overflow: hidden;
}

.filter-toggle-modern::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.filter-toggle-modern:hover::before {
    left: 100%;
}

.filter-toggle-modern:hover {
    border-color: var(--primary-color);
    background: var(--bg-secondary);
    box-shadow: 0 2px 8px rgba(0, 102, 204, 0.15);
    transform: translateY(-1px);
}

.filter-toggle-modern.active {
    border-color: var(--primary-color);
    background: var(--bg-secondary);
    box-shadow: 0 2px 8px rgba(0, 102, 204, 0.2);
}

[data-theme="dark"] .filter-toggle-modern {
    background: var(--bg-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .filter-toggle-modern:hover {
    background: var(--bg-secondary);
    border-color: var(--primary-color);
}

[data-theme="dark"] .filter-toggle-modern.active {
    background: var(--bg-secondary);
    border-color: var(--primary-color);
}

.filter-icon-modern {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    flex-shrink: 0;
    opacity: 0.8;
}

.filter-toggle-text {
    font-weight: 600;
    letter-spacing: 0.3px;
}

.filter-badge-modern {
    width: 6px;
    height: 6px;
    background: var(--primary-color);
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px var(--bg-primary);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

.filter-arrow {
    width: 14px;
    height: 14px;
    stroke: var(--text-secondary);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    opacity: 0.7;
}

.filter-toggle-modern.active .filter-arrow {
    transform: rotate(180deg);
    opacity: 1;
}

.filters-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, margin 0.3s ease;
    padding: 0;
    margin: 0;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-top: none;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .filters-content {
    background: rgba(26, 26, 26, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.filters-content.active {
    max-height: 1000px;
    padding: 1rem;
    margin-top: 0.5rem;
}

.filters-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.clear-filters-btn {
    padding: 0.625rem 1.25rem;
    background: transparent;
    color: var(--text-secondary);
    text-decoration: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s ease;
    display: inline-block;
}

.clear-filters-btn:hover {
    background-color: var(--bg-primary);
    color: var(--primary-color);
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

.filters-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    align-items: end;
}

@media (min-width: 768px) {
    .filters-form {
        grid-template-columns: 2fr 1fr 1fr 1fr auto;
        gap: 1rem;
    }
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-label {
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.filter-input,
.filter-select {
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    transition: all 0.2s ease;
    width: 100%;
}

.filter-input:focus,
.filter-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

[data-theme="dark"] .filter-input:focus,
[data-theme="dark"] .filter-select:focus {
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.2);
}

.filter-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.filter-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

[data-theme="dark"] .filter-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23b0b0b0' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
}

.filter-submit-btn {
    padding: 0.625rem 1.25rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    min-height: 40px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.filter-submit-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 102, 204, 0.3);
}

[data-theme="dark"] .filter-submit-btn:hover {
    box-shadow: 0 4px 12px rgba(74, 158, 255, 0.3);
}

/* Map Container */
.map-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100vh;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background-color: var(--bg-primary);
    z-index: 100;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Mobile: pull-up sheet lives inside .map-container; children cannot stack above .course-list-top (z-index ~101)
   without raising this layer — must be below site header (z-index 1200). */
@media (max-width: 1023px) {
    body.map-view-active.map-mobile-sheet-open .map-container {
        z-index: 900;
    }
}

/* Map layout: sidebar (left) + map (right) on desktop */
@media (min-width: 1024px) {
    .map-container {
        flex-direction: row;
    }

    .map-sidebar {
        display: flex;
        flex-direction: column;
        width: 360px;
        min-width: 320px;
        max-width: 420px;
        height: 100%;
        background: var(--bg-primary);
        border-right: 1px solid var(--border-color, rgba(0, 0, 0, 0.08));
        overflow: hidden;
        flex-shrink: 0;
    }

    .map-sidebar-header {
        padding: 1.25rem 1.25rem 0.75rem;
        border-bottom: 1px solid var(--border-color, rgba(0, 0, 0, 0.08));
        flex-shrink: 0;
    }

    .map-sidebar-title {
        font-size: 1.25rem;
        font-weight: 700;
        margin: 0 0 0.25rem;
        color: var(--text-primary);
    }

    .map-sidebar-count {
        font-size: 0.9rem;
        color: var(--text-secondary);
        margin: 0;
    }

    .map-sidebar-list {
        flex: 1;
        overflow-y: auto;
        padding: 0.65rem 0.75rem 1rem;
    }

    /* Map sidebar / mobile sheet: same course-card pattern as list view */
    .map-sidebar-list .map-sidebar-card.course-card {
        margin-bottom: 0.85rem;
    }

    .map-sidebar-list .map-sidebar-card.course-card:last-child {
        margin-bottom: 0;
    }

    .map-sidebar-list .map-sidebar-card.course-card {
        aspect-ratio: auto;
        min-height: 0;
    }

    .map-sidebar-list .map-sidebar-card .course-card-link {
        aspect-ratio: 16 / 10;
        min-height: 180px;
    }

    .map-sidebar-list .map-sidebar-card .course-title {
        font-size: 1rem;
        line-height: 1.3;
    }

    .map-sidebar-list .map-sidebar-card .course-short-desc {
        font-size: 0.82rem;
        line-height: 1.35;
    }

    .map-sidebar-list .map-sidebar-card .meta-item.map-sidebar-date {
        white-space: normal;
        line-height: 1.3;
    }

    .map-sidebar-card-actions {
        padding: 0 1rem 1rem;
        border-top: 1px solid var(--border-color, rgba(0, 0, 0, 0.08));
        margin-top: 0;
    }

    .map-sidebar-card-actions .map-sidebar-book-btn {
        display: block;
        width: 100%;
        text-align: center;
        box-sizing: border-box;
        padding: 0.55rem 1rem;
        font-size: 0.9rem;
        font-weight: 600;
        background: var(--primary-color);
        color: white;
        text-decoration: none;
        border-radius: 10px;
        border: none;
        cursor: pointer;
        transition: opacity 0.2s, transform 0.2s;
    }

    .map-sidebar-card-actions .map-sidebar-book-btn:hover {
        opacity: 0.92;
        transform: translateY(-1px);
    }

    .map-sidebar-card-actions .map-sidebar-book-btn.map-sidebar-book-disabled {
        background: #e5e7eb;
        color: #6b7280;
        cursor: not-allowed;
        transform: none;
    }

    .map-sidebar-card-actions .map-sidebar-book-btn.map-sidebar-book-disabled:hover {
        opacity: 1;
        transform: none;
    }

    .map-main {
        flex: 1;
        min-width: 0;
        height: 100%;
        position: relative;
    }
}

/* Mobile: full-width map + pull-up sheet (reuses .map-sidebar) */
@media (max-width: 1023px) {
    .map-sheet-backdrop {
        position: fixed;
        inset: 0;
        z-index: 1005;
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
        border: none;
        background: rgba(0, 0, 0, 0.4);
        cursor: pointer;
        appearance: none;
        -webkit-appearance: none;
    }

    .map-sheet-backdrop[hidden] {
        display: none !important;
    }

    /* Hit area is tall; grey pill is only ::after (padding + bg on one element painted a big grey block) */
    .map-sheet-handle {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        margin: 0;
        padding: 10px 0 8px;
        min-height: 28px;
        cursor: grab;
        touch-action: none;
        box-sizing: border-box;
        background: transparent;
    }

    .map-sheet-handle::after {
        content: '';
        width: 40px;
        height: 5px;
        border-radius: 3px;
        background: var(--border-color, rgba(0, 0, 0, 0.2));
        flex-shrink: 0;
    }

    .map-sheet-handle:active {
        cursor: grabbing;
    }

    .map-sidebar {
        display: flex;
        flex-direction: column;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: auto;
        /* Stay below sticky header; leave room so the sheet top does not sit under list/map + filters */
        max-height: min(82vh, calc(100dvh - 120px), calc(100vh - 120px));
        min-height: 0;
        z-index: 1010;
        border-right: none;
        border-top: 1px solid var(--border-color, rgba(0, 0, 0, 0.08));
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
        transform: translateY(100%);
        transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
        background: var(--bg-primary);
        pointer-events: none;
    }

    .map-sidebar.map-sheet--open {
        transform: translateY(0);
        pointer-events: auto;
    }

    .map-sheet-backdrop:not([hidden]) {
        display: block;
    }

    .map-sidebar-header {
        flex-shrink: 0;
        padding: 0.35rem 1rem 0.75rem;
    }

    .map-sidebar-list {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0.5rem 1rem 1.25rem;
    }

    .map-sidebar-list .map-sidebar-card.course-card {
        margin-bottom: 0.65rem;
    }

    .map-sidebar-list .map-sidebar-card.course-card {
        aspect-ratio: auto;
        min-height: 0;
    }

    .map-sidebar-list .map-sidebar-card .course-card-link {
        aspect-ratio: 16 / 10;
        min-height: 140px;
    }

    .map-main {
        width: 100%;
        height: 100%;
    }
}

@media (min-width: 1024px) {
    .map-sheet-backdrop {
        display: none !important;
    }

    .map-sheet-handle {
        display: none !important;
    }
}

[data-theme="dark"] .map-sidebar {
    background: var(--bg-primary);
    border-right-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .map-sidebar-header {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .map-sidebar-card-actions {
    border-top-color: rgba(255, 255, 255, 0.1);
}

/* Ensure filters content has proper background when overlaid */
body.map-view-active .filters-content {
    background: rgba(255, 255, 255, 0.98) !important;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] body.map-view-active .filters-content {
    background: rgba(26, 26, 26, 0.98) !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.map-container {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.4s, transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    transform: translateY(20px) scale(0.98);
}

.map-container:not(.hidden) {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.map-container.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(20px) scale(0.98);
}

#course-map {
    width: 100%;
    height: 100%;
    min-height: 100vh;
}

/* Custom marker styling */
.custom-marker {
    background: transparent !important;
    border: none !important;
}

.custom-marker img {
    pointer-events: none;
}

/* Marker pulse animation when selected */
.leaflet-marker-icon.marker-pulse {
    position: relative;
    overflow: visible !important;
}

.leaflet-marker-icon.marker-pulse::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid var(--primary-color, #0066cc);
    transform: translate(-50%, -50%) scale(1);
    animation: markerPulse 1.5s ease-out infinite;
    pointer-events: none;
}

@keyframes markerPulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.8;
    }
    100% {
        transform: translate(-50%, -50%) scale(2.5);
        opacity: 0;
    }
}

/* Course Grid */
.course-grid-container {
    display: block;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.4s, transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(0) scale(1);
    position: relative;
}

.course-grid-container.hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.98);
    pointer-events: none;
    position: absolute;
    width: 100%;
    top: 0;
    left: 0;
    z-index: 1;
}

.course-grid {
    display: block;
    margin-bottom: 1.5rem;
    width: 100%;
}

.course-grid .category-section {
    width: 100%;
}

/* Category sections - subheader + cards layout */
.category-section {
    margin-bottom: 2.5rem;
    display: block;
}

.category-section:last-child {
    margin-bottom: 0;
}

.category-section-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 1rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary-color);
}

/* Mobile: horizontal scroll within each category (negative margin matches .course-list-page padding) */
.category-courses {
    display: flex;
    flex-wrap: nowrap;
    gap: 1rem;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem;
    margin: 0 -1.25rem;
    padding-left: 1.25rem;
    padding-right: 1.25rem;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE / legacy Edge */
}

.category-courses::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
    width: 0;
    height: 0;
}

.category-section .course-card--overlay {
    flex: 0 0 260px;
    min-width: 260px;
    max-width: 260px;
    scroll-snap-align: start;
}

/* Desktop: category subheader + grid of cards below */
@media (min-width: 768px) {
    .category-section {
        margin-bottom: 3rem;
    }

    .category-section-title {
        font-size: 1.5rem;
        margin: 0 0 1.25rem 0;
        padding-bottom: 0.75rem;
    }

    .category-courses {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: 1.5rem;
        overflow-x: visible;
        overflow-y: visible;
        scroll-snap-type: none;
        margin: 0;
        padding: 0;
        width: 100%;
    }

    .category-section .course-card--overlay {
        flex: none;
        min-width: 0;
        max-width: none;
        scroll-snap-align: none;
    }
}

/* Course Cards — full-bleed image with overlay content */
.course-list-page .course-card--overlay {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    background-color: var(--bg-secondary);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.35s ease;
    aspect-ratio: 3 / 4;
    min-height: 300px;
    isolation: isolate;
}

[data-theme="dark"] .course-list-page .course-card--overlay {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

.course-list-page .course-card--overlay:hover {
    transform: translateY(-6px);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.14);
}

.course-list-page .course-card--overlay.course-card--has-video:hover {
    transform: none;
}

[data-theme="dark"] .course-list-page .course-card--overlay:hover {
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.course-list-page .course-card--overlay .course-card-link {
    display: block;
    position: relative;
    text-decoration: none;
    color: #fff;
    height: 100%;
    width: 100%;
    min-height: 100%;
}

.course-list-page .course-card--overlay .course-image-wrapper {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background-color: var(--bg-secondary);
}

.course-list-page .course-card--overlay .course-thumbnail,
.course-list-page .course-card--overlay .course-card-poster.course-placeholder {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.35s ease, transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.course-list-page .course-card--overlay .course-card-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border: 0;
    opacity: 0;
    z-index: 1;
    pointer-events: none;
    transition: opacity 0.35s ease, transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.course-list-page .course-card--overlay.is-video-active .course-card-video {
    opacity: 1;
}

.course-list-page .course-card--overlay.is-video-active .course-card-poster {
    opacity: 0;
}

.course-list-page .course-card--overlay:hover .course-thumbnail,
.course-list-page .course-card--overlay:hover .course-card-poster.course-placeholder {
    transform: scale(1.06);
}

.course-list-page .course-card--overlay.is-video-active:hover .course-card-video:not(.course-card-video--embed) {
    transform: scale(1.06);
}

.course-list-page .course-card--overlay.is-video-active:hover .course-thumbnail,
.course-list-page .course-card--overlay.is-video-active .course-thumbnail,
.course-list-page .course-card--overlay.is-video-active .course-card-poster.course-placeholder {
    transform: none;
}

.course-list-page .course-card--overlay .course-card-scrim {
    position: absolute;
    inset: 0;
    z-index: 2;
    background: linear-gradient(
        180deg,
        rgba(0, 0, 0, 0.15) 0%,
        rgba(0, 0, 0, 0.05) 35%,
        rgba(0, 0, 0, 0.45) 68%,
        rgba(0, 0, 0, 0.88) 100%
    );
    pointer-events: none;
}

.course-list-page .course-card--overlay .course-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.5rem;
    color: var(--text-secondary);
    background: linear-gradient(145deg, #2a2a2a 0%, #1a1a1a 100%);
}

.course-list-page .course-card--overlay .course-level-badge {
    position: absolute;
    top: 0.875rem;
    left: 0.875rem;
    z-index: 4;
    padding: 0.35rem 0.7rem;
    color: white;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Level-specific colors matching homepage (level-box-1, -2, -3, etc.) */
.course-list-page .course-card--overlay .course-level-badge[data-level="beginner"] {
    background: linear-gradient(135deg, #4caf50 0%, #66bb6a 100%);
    color: white;
}

.course-list-page .course-card--overlay .course-level-badge[data-level="intermediate"] {
    background: linear-gradient(135deg, #ff9800 0%, #ffb74d 100%);
    color: white;
}

.course-list-page .course-card--overlay .course-level-badge[data-level="advanced"] {
    background: linear-gradient(135deg, #9c27b0 0%, #ba68c8 100%);
    color: white;
}

.course-list-page .course-card--overlay .course-level-badge[data-level="masterclass"] {
    background: linear-gradient(135deg, #2196f3 0%, #64b5f6 100%);
    color: white;
}

.course-list-page .course-card--overlay .course-level-badge[data-level="various"] {
    background: linear-gradient(135deg, #c2185b 0%, #ec407a 100%);
    color: white;
}

.course-list-page .course-card--overlay .course-card-content {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4;
    padding: 1.125rem 1.125rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.course-list-page .course-card--overlay .course-header {
    margin: 0;
}

.course-list-page .course-card--overlay .course-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.25;
    color: #fff;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-shadow: 0 1px 12px rgba(0, 0, 0, 0.35);
}

.course-list-page .course-card--overlay .course-short-desc {
    color: rgba(255, 255, 255, 0.82);
    font-size: 0.82rem;
    line-height: 1.45;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.course-list-page .course-card--overlay .course-meta {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    padding: 0;
    border: none;
}

.course-list-page .course-card--overlay .meta-item {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.95);
    padding: 0.25rem 0.55rem;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    font-weight: 600;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Course Locations: flex column so "more" stays below chips (never overlaps rows) */
.course-list-page .course-card--overlay .course-locations {
    margin-top: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
}

.course-list-page .course-card--overlay .course-locations-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.88);
    line-height: 1.5;
    min-height: 0;
    /* Enough height for two full rows of chips + gap (flex-wrap; 3em clipped the second row) */
    max-height: 5.75em;
    overflow: hidden;
    position: relative;
    transition: max-height 0.3s ease;
}

.course-list-page .course-card--overlay .course-locations-list.expanded {
    max-height: 1000px; /* Large enough to show all */
}

.course-list-page .course-card--overlay .location-item {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 999px;
    white-space: nowrap;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.92);
    font-weight: 500;
}

.course-list-page .course-card--overlay .locations-more-btn {
    margin-top: 0;
    padding: 0.2rem 0.6rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
    font-family: inherit;
    position: relative;
    z-index: 4;
    align-self: flex-start;
    flex-shrink: 0;
}

.course-list-page .course-card--overlay .locations-more-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

.course-list-page .course-card--overlay .locations-more-btn .less-text {
    display: none;
}

.course-list-page .course-card--overlay .locations-more-btn.expanded .more-text {
    display: none;
}

.course-list-page .course-card--overlay .locations-more-btn.expanded .less-text {
    display: inline;
}

.course-list-page .course-card--overlay .course-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding-top: 0.35rem;
    margin-top: 0.15rem;
    border: none;
}

.course-list-page .course-card--overlay .course-price {
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
}

.course-list-page .course-card--overlay .btn-view {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    background: rgba(255, 255, 255, 0.95);
    color: #111;
    text-decoration: none;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.75rem;
    transition: transform 0.2s ease, background 0.2s ease;
    pointer-events: none;
    flex-shrink: 0;
    white-space: nowrap;
}

.course-list-page .course-card--overlay .btn-view::after {
    content: '→';
    font-size: 0.9em;
}

.course-list-page .course-card--overlay:hover .btn-view {
    background: #fff;
    transform: translateX(2px);
}

/* Infinite scroll */
.infinite-scroll-sentinel {
    height: 1px;
    visibility: hidden;
    pointer-events: none;
}

.infinite-scroll-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.infinite-scroll-loading.hidden {
    display: none;
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* No Results */
.no-results {
    text-align: center;
    padding: 4rem 2rem;
    background-color: var(--bg-secondary);
    border-radius: 16px;
    border: 2px dashed var(--border-color);
}


.no-results h3 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.no-results p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.btn-clear-search {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 10px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-clear-search:hover {
    background-color: var(--primary-hover);
}

/* Responsive Design */
@media (max-width: 768px) {
    .course-list-page {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }

    .course-list-top {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-rows: auto auto;
        gap: 0.5rem 0.65rem;
        margin-bottom: 0.75rem;
        align-items: center;
    }

    .course-list-top .page-header {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .course-list-top .view-toggle-container {
        grid-column: 1;
        grid-row: 2;
        justify-self: start;
        justify-content: flex-start;
        width: auto;
        max-width: 148px;
    }

    .course-list-top .filters-section-collapsed {
        grid-column: 2;
        grid-row: 2;
        justify-self: stretch;
        width: 100%;
        min-width: 0;
    }

    .view-toggle-group {
        padding: 0.2rem;
        border-radius: 9px;
        width: 100%;
        max-width: 148px;
        justify-content: center;
    }

    .view-toggle-btn {
        padding: 0.35rem 0.45rem;
        font-size: 0.72rem;
        border-radius: 6px;
        flex: 1;
        text-align: center;
        min-width: 0;
    }

    /* Map view: same compact List/Map + Filters on one row as list view (title hidden) */
    body.map-view-active .course-list-top {
        padding: 0.65rem 0 0;
        top: 70px;
        left: 1.25rem;
        right: 1.25rem;
        width: auto;
        max-width: none;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-rows: auto;
        justify-items: stretch;
        align-items: center;
        gap: 0.5rem 0.65rem;
    }

    body.map-view-active .course-list-top .view-toggle-container {
        grid-column: 1;
        grid-row: 1;
        max-width: 148px;
        justify-self: start;
        justify-content: flex-start;
        width: auto;
    }

    body.map-view-active .course-list-top .filters-section-collapsed {
        grid-column: 2;
        grid-row: 1;
        width: 100%;
        min-width: 0;
    }

    .page-header {
        width: 100%;
    }
    
    .page-header h1 {
        font-size: 2rem;
    }
    
    body.map-view-active .page-header h1 {
        font-size: 1.5rem;
    }
    
    .page-subtitle {
        font-size: 1rem;
    }
    
    body.map-view-active .page-subtitle {
        font-size: 0.85rem;
    }
    
    body.map-view-active .course-list-top .filters-section-collapsed {
        position: static;
        left: auto;
        right: auto;
        top: auto;
        width: 100%;
        max-width: none;
        min-width: 0;
    }
    
    body.map-view-active .view-toggle-group {
        width: 100%;
        max-width: 148px;
        padding: 0.2rem;
        border-radius: 9px;
    }

    body.map-view-active .view-toggle-btn {
        padding: 0.35rem 0.45rem;
        font-size: 0.72rem;
        border-radius: 6px;
    }

    body.map-view-active .filter-toggle-modern {
        padding: 0.4rem 0.65rem;
        font-size: 0.8rem;
    }

    /* Mobile: expanded filters — narrow grid column + min-width:280px (map) clips panel; full-width overlay */
    .course-list-top {
        overflow: visible;
    }

    .course-list-top .filters-section-collapsed {
        min-width: 0;
        max-width: 100%;
    }

    .filters-content {
        min-width: 0 !important;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }

    .course-list-top .filters-content.active {
        position: fixed;
        left: 1.25rem;
        right: 1.25rem;
        width: auto;
        min-width: 0 !important;
        max-width: none;
        margin-top: 0;
        overflow-y: auto;
        overflow-x: hidden;
        z-index: 200;
        border-radius: 12px;
        border-top: 1px solid rgba(255, 255, 255, 0.3);
    }

    /* Map: toolbar only (no title row) */
    body.map-view-active .course-list-top .filters-content.active {
        top: calc(70px + 0.65rem + 2.75rem);
        max-height: min(70vh, calc(100dvh - 9rem));
    }

    /* List: title + subtitle + list/map + filter button rows */
    body:not(.map-view-active) .course-list-top .filters-content.active {
        top: calc(70px + 9rem);
        max-height: min(62vh, calc(100dvh - 11rem));
    }

    [data-theme="dark"] .course-list-top .filters-content.active {
        border-top-color: rgba(255, 255, 255, 0.15);
    }

    .filters-section {
        padding: 1.5rem;
    }
    
    .filters-form {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .filter-toggle-modern {
        padding: 0.4rem 0.65rem;
        font-size: 0.8rem;
        width: 100%;
        justify-content: center;
    }

    .filter-icon-modern {
        width: 16px;
        height: 16px;
    }
    
    .filters-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .category-section-title {
        font-size: 1.1rem;
        margin: 0 0 0.75rem 0;
    }
    
    .course-card-link {
        cursor: pointer;
    }
}

/* Mobile list view: denser course cards (horizontal scroll < 768px) */
@media (max-width: 767px) {
    .course-list-page .page-header h1 {
        font-size: 1.5rem;
        margin-bottom: 0.15rem;
    }

    .course-list-page .page-subtitle {
        font-size: 0.85rem;
        line-height: 1.35;
    }

    .category-section {
        margin-bottom: 1.35rem;
    }

    .category-section-title {
        font-size: 1rem;
        margin: 0 0 0.5rem 0;
        padding-bottom: 0.35rem;
    }

    .category-courses {
        gap: 0.65rem;
        margin: 0 -1.25rem;
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }

    .category-section .course-card--overlay {
        flex: 0 0 240px;
        min-width: 240px;
        max-width: 240px;
        aspect-ratio: 3 / 4;
        min-height: 280px;
    }

    .course-list-page .course-card--overlay {
        border-radius: 14px;
    }

    .course-list-page .course-card--overlay:hover {
        transform: translateY(-4px);
    }

    .course-list-page .course-card--overlay.course-card--has-video:hover {
        transform: none;
    }

    .course-list-page .course-card--overlay .course-placeholder {
        font-size: 2.5rem;
    }

    .course-list-page .course-card--overlay .course-level-badge {
        top: 0.65rem;
        left: 0.65rem;
        padding: 0.22rem 0.5rem;
        font-size: 0.6rem;
    }

    .course-list-page .course-card--overlay .course-card-content {
        padding: 0.75rem 0.8rem 0.85rem;
        gap: 0.35rem;
    }

    .course-list-page .course-card--overlay .course-title {
        font-size: 0.98rem;
        line-height: 1.25;
    }

    .course-list-page .course-card--overlay .course-short-desc {
        font-size: 0.78rem;
        line-height: 1.35;
    }

    .course-list-page .course-card--overlay .course-meta {
        gap: 0.35rem;
        flex-wrap: nowrap;
    }

    .course-list-page .course-card--overlay .meta-item {
        font-size: 0.72rem;
        padding: 0.2rem 0.45rem;
        flex: 1 1 0;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .course-list-page .course-card--overlay .course-locations-list {
        font-size: 0.72rem;
        gap: 0.3rem;
        max-height: 5.5em;
    }

    .course-list-page .course-card--overlay .location-item {
        font-size: 0.72rem;
        padding: 0.15rem 0.35rem;
    }

    .course-list-page .course-card--overlay .locations-more-btn {
        padding: 0.15rem 0.5rem;
        font-size: 0.72rem;
    }

    .course-list-page .course-card--overlay .course-price {
        font-size: 1rem;
        line-height: 1.2;
    }

    .course-list-page .course-card--overlay .btn-view {
        padding: 0.32rem 0.6rem;
        font-size: 0.68rem;
    }
}

@media (min-width: 1200px) {
    .category-section .course-card--overlay {
        aspect-ratio: 4 / 5;
    }
}
