/* ============================================= */
/* mobile.css — Mobile UX: Accordion, Bottom Nav, Tab Sidebar */
/* ============================================= */

/* ============================================= */
/* Feature 1: Accordion Semesters (≤1280px)       */
/* ============================================= */

@media (max-width: 1280px) {

    /* Make header clickable */
    .semester-header {
        cursor: pointer;
        user-select: none;
        position: relative;
        padding-left: 40px; /* space for chevron (RTL: left side) */
        transition: background-color 0.2s;
    }

    .semester-header:hover {
        background-color: #f0f2f5;
    }

    .semester-header:active {
        background-color: #e8eaed;
    }

    /* Chevron indicator */
    .semester-header::after {
        content: '';
        position: absolute;
        left: 20px;
        top: 50%;
        transform: translateY(-50%);
        width: 10px;
        height: 10px;
        border-left: 2.5px solid var(--text-secondary);
        border-bottom: 2.5px solid var(--text-secondary);
        transform: translateY(-50%) rotate(-45deg);
        transition: transform 0.3s ease;
    }

    /* Expanded state chevron (pointing down) */
    .semester-container.semester-expanded .semester-header::after {
        transform: translateY(-70%) rotate(-225deg);
    }

    /* Collapsed state: hide content */
    .semester-container:not(.semester-expanded) .mobile-courses-list,
    .semester-container:not(.semester-expanded) .table-wrapper,
    .semester-container:not(.semester-expanded) .semester-footer {
        display: none !important;
    }

    /* Expanded state visual distinction */
    .semester-container.semester-expanded {
        box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
        border: 1px solid var(--primary-color);
    }

    .semester-container.semester-expanded .semester-header {
        background-color: #f0f6ff;
        border-bottom: 2px solid var(--primary-color);
    }

    /* Collapsed semester: reduce visual weight */
    .semester-container:not(.semester-expanded) {
        margin-bottom: 12px;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
    }

    .semester-container:not(.semester-expanded) .semester-header {
        border-bottom: none;
    }

    /* Smooth slide animation for content */
    .semester-container .mobile-courses-list,
    .semester-container .table-wrapper,
    .semester-container .semester-footer {
        animation: accordionSlideDown 0.3s ease-out;
    }

    @keyframes accordionSlideDown {
        from {
            opacity: 0;
            transform: translateY(-8px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}

/* ============================================= */
/* Bigger delete button on mobile cards           */
/* ============================================= */

@media (max-width: 1280px) {

    /* Make card-actions area bigger and more tappable */
    .course-card .card-actions {
        padding: 12px 16px;
        gap: 12px;
    }

        .course-card .card-actions .delete-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        height: 42px;
        padding: 0 16px;
        border-radius: 10px;
        background: #fef2f2;
        border: 1px solid #fecaca;
        transition: all 0.2s;
        font-family: var(--font-family);
        font-size: 13px;
        font-weight: 700;
        color: var(--text-danger);
    }

    .course-card .card-actions .delete-btn .delete-btn-text {
        display: inline;
    }

    .course-card .card-actions .delete-btn:active {
        background: #fee2e2;
        transform: scale(0.95);
    }

        .course-card .card-actions .delete-btn svg {
        width: 18px;
        height: 18px;
        color: var(--text-danger);
        flex-shrink: 0;
    }
}
/* ============================================= */
/* Course Selector Modal — Mobile Redesign        */
/* ============================================= */

@media (max-width: 768px) {

    /* Full screen modal */
    #course-selector-overlay .modal-content {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    /* Compact header */
    #course-selector-overlay .modal-header {
        padding: 14px 16px;
        flex-shrink: 0;
    }

    #course-selector-overlay .modal-header h2 {
        font-size: 17px;
    }

    /* --- Filters: collapsible --- */
    #course-selector-overlay .controls-container {
        padding: 12px 16px;
        flex-shrink: 0;
        max-height: none;
        overflow: visible;
    }

    /* Search input stays visible */
    #course-selector-overlay .search-input {
        height: 44px;
        font-size: 15px;
        border-radius: 10px;
    }

    /* Filters area — hidden by default */
    #course-selector-overlay .selector-filters-row {
        display: none;
        flex-direction: column;
        gap: 12px;
        padding-top: 12px;
        border-top: 1px solid var(--border-color);
        margin-top: 12px;
    }

    /* When filters are open */
    #course-selector-overlay .selector-filters-row.filters-open {
        display: flex;
    }

    /* Filter toggle button */
    .mobile-filter-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        width: 100%;
        padding: 10px;
        margin-top: 10px;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: var(--bg-main);
        color: var(--text-secondary);
        font-family: var(--font-family);
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
    }

    .mobile-filter-toggle:active {
        background: #e9ecef;
    }

    .mobile-filter-toggle.has-filters {
        border-color: var(--primary-color);
        color: var(--primary-color);
        background: #f0f6ff;
    }

    /* Dropdowns full width */
    #course-selector-overlay .selector-dropdown {
        width: 100%;
        height: 44px;
        font-size: 15px;
    }

    /* Sliders full width */
    #course-selector-overlay .selector-filter-group.expand-group {
        min-width: 100%;
    }

    /* --- Course list: cards instead of table --- */
    #course-selector-overlay .selector-table {
        display: none !important;
    }

    .selector-count-bar {
        padding: 8px 16px;
        font-size: 12px;
        position: sticky;
        top: 0;
        background: var(--header-bg);
        z-index: 1;
    }

    /* Mobile course selector cards */
    .mobile-selector-list {
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 12px 16px;
    }

    .selector-card {
        background: var(--bg-surface);
        border: 1px solid var(--border-color);
        border-radius: 10px;
        overflow: hidden;
        transition: border-color 0.2s;
    }

    .selector-card:active {
        border-color: var(--primary-color);
    }

    .selector-card.already-added {
        opacity: 0.5;
        background: #f8f9fa;
    }

    .selector-card-top {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 12px 14px;
    }

    .selector-card-info {
        flex: 1;
        min-width: 0;
    }

    .selector-card-info .name {
        font-size: 15px;
        font-weight: 700;
        color: var(--text-primary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .selector-card-info .code {
        font-size: 12px;
        color: var(--text-secondary);
        margin-top: 2px;
    }

    .selector-card-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding: 0 14px 10px;
        font-size: 12px;
        color: var(--text-secondary);
    }

    .selector-card-meta .meta-item {
        display: flex;
        align-items: center;
        gap: 4px;
        background: var(--bg-main);
        padding: 3px 8px;
        border-radius: 6px;
        font-weight: 600;
    }

    .selector-card-actions {
        display: flex;
        border-top: 1px solid var(--border-color);
    }

    .selector-card-actions .selector-add-btn {
        flex: 1;
        padding: 12px;
        border-radius: 0;
        font-size: 14px;
        font-weight: 700;
        border: none;
        background: var(--primary-color);
        color: white;
        cursor: pointer;
        transition: background 0.2s;
    }

    .selector-card-actions .selector-add-btn:active {
        background: #0b5ed7;
    }

    .selector-card-actions .added-badge {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 12px;
        font-size: 14px;
        font-weight: 700;
        color: var(--success-color);
        background: var(--success-bg-light);
    }

    .selector-card-actions .tau-link-mobile {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 48px;
        border-right: 1px solid var(--border-color);
        color: var(--primary-color);
        text-decoration: none;
    }

    .selector-card-actions .tau-link-mobile:active {
        background: #f0f6ff;
    }
}

/* Hide mobile elements on desktop */
.mobile-filter-toggle {
    display: none;
}

.mobile-selector-list {
    display: none;
}

@media (max-width: 768px) {
    .mobile-selector-list {
        display: flex;
    }
}

/* ============================================= */
/* Mobile/Tablet Header Cleanup (≤1024px)         */
/* ============================================= */

@media (max-width: 1024px) {
    .bottom-nav-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        background: none;
        border: none;
        cursor: pointer;
        color: var(--text-secondary);
        font-family: var(--font-family);
        font-size: 10px;
        font-weight: 600;
        padding: 6px 2px;
        position: relative;
        transition: color 0.2s;
        -webkit-tap-highlight-color: transparent;
        min-width: 0;
        overflow: hidden;
    }

    .bottom-nav-tab svg {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
    }

    .bottom-nav-tab span {
        line-height: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }
        .bottom-nav-tab.active {
        color: var(--primary-color);
    }

    .bottom-nav-tab.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 20%;
        right: 20%;
        height: 3px;
        background: var(--primary-color);
        border-radius: 0 0 3px 3px;
    }

    .bottom-nav-tab.active svg {
        transform: scale(1.1);
    }

    .bottom-nav-tab:active {
        background-color: rgba(0, 0, 0, 0.03);
    }
    /* Hide from header */
    .major-selector-center {
        display: none !important;
    }


    .bug-report-link {
        display: none !important;
    }

    /* Keep logo text on tablet */
    .logo span {
        display: inline;
    }

    /* Bottom nav visible */
    :root {
        --bottom-nav-height: 60px;
    }

    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1100;
        background: var(--bg-surface);
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
        height: var(--bottom-nav-height);
        align-items: stretch;
        direction: rtl;
    }

    body {
        padding-bottom: var(--bottom-nav-height) !important;
    }

    body.simulation-mode {
        padding-bottom: var(--bottom-nav-height) !important;
    }

    /* Simulation active on nav tab */
    body.simulation-mode .bottom-nav-tab[data-tab="simulation"] {
        color: var(--simulation-color);
    }

    body.simulation-mode .bottom-nav-tab[data-tab="simulation"]::before {
        background: var(--simulation-color);
    }

    /* Summary as tab */
    .summary {
        display: none !important;
    }

    .summary.tab-active {
        display: block !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(var(--bottom-nav-height) + 20px);
        border-right: none !important;
        border-left: none !important;
        width: 100%;
    }

    .main.tab-hidden {
        display: none !important;
    }

    .summary.tab-active .total-progress-card {
        position: relative;
        top: auto;
    }

    /* Content wrapper */
    .content-wrapper {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - var(--header-height) - var(--bottom-nav-height));
    }

    .summary, .main {
        overflow: visible;
        max-height: none;
    }

    /* Toast above nav */
    .toast-notification {
        bottom: calc(var(--bottom-nav-height) + 16px) !important;
    }

    /* Auth banner above nav */
    .auth-banner {
        bottom: calc(var(--bottom-nav-height) + 16px) !important;
    }

    /* Add semester button */
    #add-semester-btn {
        margin-bottom: calc(var(--bottom-nav-height) + 20px);
        width: 100%;
    }

    .site-footer-bottom {
        padding-bottom: calc(var(--bottom-nav-height) + 24px);
    }

    /* Settings modal full screen */
    #settings-overlay .modal-content {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    #settings-overlay .modal-body {
        padding: 20px 16px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Bigger adjustment buttons */
    .adj-btn {
        width: 44px;
        height: 44px;
        font-size: 22px;
    }

    .adj-value {
        min-width: 56px;
        height: 44px;
        font-size: 18px;
    }

    /* Simulation banner */
    body.simulation-mode .content-wrapper {
        min-height: calc(100vh - var(--header-height) - 44px - var(--bottom-nav-height));
    }

    /* Hide settings btn from header */
    #settings-btn {
        display: none !important;
    }
}

/* ============================================= */
/* Small Mobile (≤768px)                          */
/* ============================================= */

@media (max-width: 768px) {

    /* Hide logo text */
    .logo span {
        display: none;
    }

    .header-container {
        gap: 8px;
    }

    /* Profile menu position */
    .auth-profile-menu {
        left: 12px;
        right: 12px;
        top: auto !important;
        bottom: calc(var(--bottom-nav-height) + 12px);
        border-radius: 14px;
    }

    /* Auth banner responsive */
    .auth-banner {
        left: 12px;
        right: 12px;
        transform: none;
        border-radius: 14px;
        flex-wrap: wrap;
        justify-content: center;
        white-space: normal;
        text-align: center;
        gap: 10px;
        padding: 14px 18px;
    }

    /* Auth button text hidden */
    .auth-btn-text {
        display: none !important;
    }

    /* Simulation banner compact */
    .simulation-banner {
        flex-direction: column;
        gap: 8px;
        padding: 12px;
    }
}

/* ============================================= */
/* Safe area insets                                */
/* ============================================= */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 1024px) {
        .bottom-nav {
            padding-bottom: env(safe-area-inset-bottom);
            height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
        }

        body {
            padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom)) !important;
        }
    }
}