:root {
    /* Palette Premium */
    --bg-body: #0F1115;
    --bg-card: #1A1D23;
    --bg-card-hover: #1E222A;
    --bg-input: #13161C;
    --border: #2A2F3A;

    --text-main: #FFFFFF;
    --text-muted: #A0A6B1;
    --text-inactive: #6B7280;

    --primary: #2BB0ED;
    /* Bleu actions */
    --success: #4ADE80;
    /* Vert succès */
    --warning: #FB923C;
    /* Orange alerte */
    --danger: #F472B6;
    /* Rose attention */
    --reward: #FACC15;
    /* Jaune points */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Plus Jakarta Sans', sans-serif;
}

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- UI COMPONENTS --- */
.btn {
    padding: 10px 20px;
    background: var(--primary);
    color: #000;
    /* Contrast text on bright blue */
    border: none;
    border-radius: 8px;
    /* Slightly softer corners */
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.9rem;
}

.btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.btn-ghost:hover {
    background: var(--bg-card-hover);
    color: var(--text-main);
    border-color: var(--text-muted);
}

.btn-danger {
    background: rgba(244, 114, 182, 0.15);
    /* Pink tint */
    color: var(--danger);
    border: 1px solid rgba(244, 114, 182, 0.3);
}

.btn-danger:hover {
    background: rgba(244, 114, 182, 0.25);
}

.btn-icon-only {
    padding: 0;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

input,
select {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-main);
    outline: none;
    transition: 0.2s;
    font-size: 0.95rem;
}

input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(43, 176, 237, 0.2);
}

/* --- LOADING & LOGIN --- */
#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-body);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 0.8s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* LOGIN PAGE */
#login-overlay {
    position: fixed;
    inset: 0;
    z-index: 5000;
    background: radial-gradient(circle at top right, #1e2630, #0a0c10);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: rgba(26, 29, 35, 0.8);
    backdrop-filter: blur(12px);
    padding: 40px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-title {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 5px;
    background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 30px;
}

.login-input {
    width: 100%;
    padding: 14px 16px;
    margin-bottom: 15px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: white;
    font-size: 1rem;
    transition: all 0.2s;
}

.login-input:focus {
    border-color: var(--primary);
    outline: none;
    background: rgba(43, 176, 237, 0.05);
}

.login-btn {
    width: 100%;
    padding: 14px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    color: white;
    font-weight: 600;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.4);
}

.btn-loading {
    color: transparent !important;
    position: relative;
    pointer-events: none;
    cursor: not-allowed;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin-top: -10px;
    margin-left: -10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: btn-spin 0.8s linear infinite;
}

@keyframes btn-spin {
    to {
        transform: rotate(360deg);
    }
}

/* DASHBOARD */
#dashboard {
    display: none;
    height: 100%;
    flex-direction: column;
}

header {
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-body);
    position: relative;
    /* Solid bg */
}

.brand-title {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-main);
}

.promo-text {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 1px;
    white-space: nowrap;
    pointer-events: none;
}

main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

aside {
    width: 260px;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-right: 1px solid var(--border);
    background: var(--bg-body);
}

.nav-item {
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
    transition: 0.2s;
    font-weight: 500;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-item:hover {
    background: var(--bg-card-hover);
    color: var(--text-main);
}

.nav-item.active {
    background: rgba(43, 176, 237, 0.1);
    /* Primary tint */
    color: var(--primary);
    border: 1px solid rgba(43, 176, 237, 0.2);
}

/* SIDEBAR REDESIGN */
.sem-tabs {
    display: flex;
    gap: 10px;
    padding: 10px 0;
    margin-bottom: 20px;
}

.sem-tab {
    flex: 1;
    text-align: center;
    padding: 8px;
    border-radius: 8px;
    background: #1A1D23;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.sem-tab:hover {
    border-color: var(--primary);
    color: var(--text-main);
}

.sem-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(43, 176, 237, 0.4);
}

.sidebar-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    max-height: calc(100vh - 200px);
    /* Adjust based on header/footer */
}

.sidebar-module-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    overflow: hidden;
    /* Prevent item from expanding */
}

.sidebar-module-item:hover {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
}

.sidebar-module-item.active {
    background: rgba(43, 176, 237, 0.08);
    /* Very subtle tint */
    color: var(--primary);
    border: 1px solid rgba(43, 176, 237, 0.2);
}

.sidebar-module-item i {
    width: 20px;
    flex-shrink: 0;
    /* Icon never shrinks */
    text-align: center;
    font-size: 1.1rem;
    color: inherit;
    /* Icon takes color from parent */
}

.sidebar-module-item span {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    /* Required for ellipsis inside flex */
}

/* CONTENT */
.content-area {
    flex: 1;
    padding: 2rem 3rem;
    overflow-y: auto;
    background: var(--bg-body);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.section-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

/* MODULE CARD (Solid, Premium) */
.module-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: 3px solid var(--primary);
    /* Blue Top Border */
    border-radius: 12px;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, box-shadow 0.2s;
    overflow: hidden;
}

.module-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    border-color: #3f4552;
}

.mod-header {
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(90deg, rgba(43, 176, 237, 0.08) 0%, transparent 100%);
    /* Subtle Gradient */
}

.mod-body {
    padding: 1.5rem;
}

/* CHAPTER / GROUP */
.group-container {
    margin-top: 1.5rem;
    padding: 1rem;
    padding-left: 1.25rem;
    background: rgba(255, 255, 255, 0.02);
    /* Slight tint */
    border-left: 3px solid var(--warning);
    /* Orange Left Border */
    border-radius: 0 8px 8px 0;
}

.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.group-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--reward);
    /* Yellow/Gold for visibility */
}

.file-row {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px 14px;
    margin-top: 6px;
    background: var(--bg-body);
    /* Darker than group to pop */
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: 0.2s;
}

.file-row:hover {
    background: var(--bg-card-hover);
    border-color: var(--primary);
}

/* TOAST */
.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    padding: 14px 20px;
    background: var(--bg-card);
    border: 1px solid var(--success);
    /* Green border */
    border-left-width: 4px;
    border-radius: 6px;
    color: var(--text-main);
    font-weight: 500;
    transform: translateY(100px);
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    z-index: 3000;
    display: flex;
    align-items: center;
    gap: 12px;
}

.toast.show {
    transform: translateY(0);
}

.toast i {
    color: var(--success);
}

/* MODAL */
#file-modal {
    background: rgba(0, 0, 0, 0.7);
    /* Darker overlay */
    backdrop-filter: blur(4px);
}

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
    padding: 2rem;
    width: 100%;
    max-width: 480px;
}

/* TYPE SELECTOR */
.type-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 15px 0;
}

.type-opt {
    padding: 8px;
    text-align: center;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: 0.2s;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

.type-opt:hover,
.type-opt.active {
    background: var(--bg-card-hover);
    color: var(--primary);
    border-color: var(--primary);
}

/* DRAG & DROP STUDIOS */
.file-row.dragging {
    opacity: 0.4;
    border: 1px dashed var(--text-muted);
}

.file-row.drag-over {
    border-bottom: 2px solid var(--primary);
    background: rgba(43, 176, 237, 0.1);
}

/* Clickable Row */
.file-row:hover {
    background-color: var(--bg-card-hover);
    cursor: pointer;
}

/* --- MOBILE RESPONSIVENESS --- */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.hamburger-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
}

.admin-logo {
    height: 40px;
    border-radius: 8px;
    background: white;
    padding: 4px;
}

@media (max-width: 768px) {

    /* Layout Reset */
    header {
        padding: 0 1rem;
        height: 60px;
    }

    .admin-logo {
        display: none;
    }

    aside {
        position: fixed;
        left: -280px;
        /* Hide off-screen */
        top: 0;
        bottom: 0;
        z-index: 1001;
        width: 260px;
        transition: transform 0.3s ease;
        box-shadow: 4px 0 15px rgba(0, 0, 0, 0.5);
    }

    aside.open {
        transform: translateX(280px);
    }

    #sidebar-overlay.show {
        display: block;
    }

    .content-area {
        padding: 1.5rem 1rem;
    }

    /* Elements */
    /* Elements */
    .brand-title {
        display: block;
        /* SHOW BD2C Manager */
        font-size: 1rem;
    }

    .hamburger-btn {
        display: block;
    }

    .section-header {
        flex-direction: row;
        gap: 10px;
        margin-bottom: 1.5rem;
    }

    .promo-text {
        display: none;
        /* HIDE PROMO TEXT */
    }


    .section-title {
        font-size: 1.2rem;
    }

    /* Modals */
    .modal-box {
        width: 90% !important;
        margin: auto;
        padding: 1.5rem;
    }

    /* File Rows */
    .file-row {
        gap: 10px;
        padding: 10px;
    }

    .file-row>div:nth-child(2) {
        /* Name container */
        overflow: hidden;
    }

    .file-row div[style*="font-size:0.9rem"] {
        /* Title */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Login */
    .login-card {
        width: 90%;
        padding: 25px;
    }
}

/* MODULE SINGLE VIEW */
.module-header-lg {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px 25px;
    margin-bottom: 25px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
    border-left: 4px solid var(--primary);
}

.mh-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 12px;
}

/* INTERNAL TABS (Cours, Revision, Exams) */
.module-internal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 25px;
}

.mit-tab {
    padding: 12px 20px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.mit-tab:hover {
    color: var(--text-main);
}

.mit-tab.active {
    font-weight: 700;
}

/* Cours Magistraux → Bleu (primary) */
.mit-tab[data-tab="chapters"].active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* TD/TP → Emeraude (Vert) */
.mit-tab[data-tab="td"].active {
    color: #10b981;
    border-bottom-color: #10b981;
}

/* Projets → Ambre / Orange */
.mit-tab[data-tab="projects"].active {
    color: #fb923c;
    border-bottom-color: #fb923c;
}

/* Examens → Rose / Rouge */
.mit-tab[data-tab="exams"].active {
    color: #f472b6;
    border-bottom-color: #f472b6;
}

.module-content-wrapper {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- BACK BUTTON (Login Screen) --- */
.back-btn-overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: var(--bg-panel, rgba(26, 29, 35, 0.8));
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    user-select: none;
    backdrop-filter: blur(12px);
}

.back-btn-overlay:hover {
    border-color: var(--primary);
    background: var(--bg-card-hover, rgba(30, 34, 42, 0.9));
    color: var(--text-main);
}