/* ===== Layout ===== */
:root {
    --sidebar-width: 260px;
    --sidebar-bg: #1a1f2e;
    --sidebar-hover: #252b3d;
    --sidebar-active: #0d6efd;
    --sidebar-text: #c0c6d4;
    --sidebar-text-light: #fff;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: #f5f7fa;
    margin: 0;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    z-index: 1040;
    overflow: hidden;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

/* Panel principal */
#panel-main {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* Flyout sub-panels : s'ouvrent à droite de la sidebar */
.sidebar-panel {
    position: fixed;
    left: var(--sidebar-width);
    top: var(--topbar-h, 0px);
    width: 240px;
    height: calc(100vh - var(--topbar-h, 0px));
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg);
    overflow-y: auto;
    z-index: 1041;
    transform: translateX(-20px);
    opacity: 0;
    visibility: hidden;
    transition: left 0.28s ease, transform 0.25s ease, opacity 0.25s ease, visibility 0.25s;
    box-shadow: 5px 0 20px rgba(0,0,0,0.35);
    border-left: 1px solid rgba(255,255,255,0.06);
}

.sidebar-panel.flyout-open {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
}

/* Item actif dans le menu principal quand un flyout est ouvert */
.sidebar-link.flyout-active {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-light);
    position: relative;
}
.sidebar-link.flyout-active::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: var(--sidebar-bg);
}

/* Overlay pour fermer le flyout en cliquant en dehors */
.flyout-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1038;
}
.flyout-overlay.show {
    display: block;
}

/* Header sidebar */
.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--sidebar-text-light);
    text-decoration: none;
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1.2;
}

.sidebar-brand i {
    font-size: 1.6rem;
    color: var(--sidebar-active);
}

.sidebar-brand small {
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--sidebar-text);
    letter-spacing: 1px;
}

/* Sous-panel header (flyout) */
.sidebar-panel-header {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-panel-header h6 {
    margin: 0;
    color: var(--sidebar-text-light);
    font-size: 0.95rem;
    font-weight: 700;
}

.sidebar-back {
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
    width: 28px;
    height: 28px;
}

.sidebar-back:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

/* Menu */
.sidebar-menu {
    list-style: none;
    padding: 8px 0;
    margin: 0;
    flex: 1;
}

.sidebar-menu li {
    margin: 2px 8px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.2s;
    cursor: pointer;
}

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-light);
}

.sidebar-link.active {
    background: var(--sidebar-active);
    color: #fff;
}

.sidebar-link i:first-child {
    font-size: 1.15rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-link .bi-chevron-right {
    font-size: 0.75rem;
    margin-left: auto;
    opacity: 0.5;
}

.sidebar-has-sub .badge {
    font-size: 0.7rem;
}

/* Footer sidebar */
.sidebar-footer {
    padding: 8px 0;
    border-top: 1px solid rgba(255,255,255,0.08);
    margin-top: auto;
}

.sidebar-footer .sidebar-link.text-danger {
    color: #e57373 !important;
}

.sidebar-footer .sidebar-link.text-danger:hover {
    background: rgba(229,115,115,0.1);
}

/* ===== Main content ===== */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
}

.main-content main {
    flex: 1;
}

.main-content.no-sidebar {
    margin-left: 0;
}

/* ===== Hamburger mobile ===== */
.sidebar-toggle {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1050;
    background: var(--sidebar-bg);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 42px;
    height: 42px;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1035;
}

.sidebar-overlay.show {
    display: block;
}

/* ===== Mobile ===== */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    /* Flyouts en mobile : plein écran par-dessus */
    .sidebar-panel {
        left: 0;
        width: 100%;
        box-shadow: none;
    }
}

/* ===== Footer ===== */
.site-footer {
    transition: opacity 0.4s ease, transform 0.4s ease;
}

/* ===== Composants existants ===== */
.module-card {
    transition: transform 0.15s, box-shadow 0.15s;
    border: 1px solid #dee2e6;
}

.module-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.course-selector:hover {
    border-color: #0d6efd !important;
    box-shadow: 0 6px 20px rgba(13, 110, 253, 0.2);
}

.question-card {
    border-left: 4px solid #0d6efd;
}

.form-check-label {
    cursor: pointer;
}

.form-check-input:checked + .form-check-label {
    font-weight: 600;
}

.progress {
    height: 22px;
    border-radius: 4px;
}

.progress-bar {
    font-size: 0.8rem;
    line-height: 22px;
}

.profile-avatar {
    width: 130px;
    height: 130px;
    object-fit: cover;
    border: 2px solid #dee2e6;
    transition: opacity 0.2s;
}

.profile-avatar:hover {
    opacity: 0.7;
}

/* Bannière défilante classement */
.leaderboard-banner {
    overflow: hidden;
    white-space: nowrap;
    font-size: 0.85rem;
}

.leaderboard-track {
    display: flex;
    justify-content: center;
}

.leaderboard-content {
    display: inline-block;
    animation: scroll-leaderboard 20s linear infinite;
}

.leaderboard-item {
    display: inline-block;
    padding: 0 1.5rem;
}

@keyframes scroll-leaderboard {
    0% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(-50%);
    }
}

/* ===== Sidebar rétractable ===== */
.sidebar {
    transition: width 0.28s ease, transform 0.3s ease;
}

.sidebar.collapsed {
    width: 64px;
}

.sidebar.collapsed .sidebar-link > span:not(.badge) {
    display: none !important;
}
.sidebar.collapsed .sidebar-brand > span {
    display: none !important;
}
.sidebar.collapsed .bi-chevron-right {
    display: none !important;
}
.sidebar.collapsed .sidebar-link > .badge {
    display: none !important;
}
.sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding: 10px 0;
    gap: 0;
}
.sidebar.collapsed .sidebar-brand {
    justify-content: center;
    padding: 16px 0;
}
.sidebar.collapsed .sidebar-link i:first-child {
    font-size: 1.3rem;
    width: auto;
}
.sidebar.collapsed .sidebar-profile-link > div {
    display: none !important;
}
.sidebar.collapsed .sidebar-profile-link {
    justify-content: center;
    padding: 6px 4px;
}
.sidebar.collapsed .sidebar-footer .sidebar-link span {
    display: none !important;
}
.sidebar.collapsed .sidebar-header {
    padding: 12px 6px;
}
.sidebar.collapsed .sidebar-menu li {
    margin: 2px 4px;
}

/* Bouton toggle collapse */
#sidebarCollapseBtn {
    position: fixed;
    left: calc(var(--sidebar-width) - 13px);
    top: calc(var(--topbar-h, 0px) + 72px);
    z-index: 1041;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--sidebar-active, #0d6efd);
    color: #fff;
    border: 2.5px solid #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    transition: left 0.28s ease;
    box-shadow: 0 1px 8px rgba(0,0,0,0.35);
    outline: none;
    padding: 0;
}
#sidebarCollapseBtn:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}
@media (max-width: 991.98px) {
    #sidebarCollapseBtn { display: none !important; }
}
