/**
 * Courses Archive - Black Dog Kung Fu
 * Style: Gaming tiles inspiré Dofus
 * 
 * Version 3.0 - Nouvelles fonctionnalités :
 * - Mode aperçu pour visiteurs non connectés
 * - Checkbox "Voir tous les cours" pour utilisateurs connectés
 * - Badge Premium sur les vignettes visiteurs
 * - Animations de feedback
 * 
 * @version 3.0
 */

/* ============================================================
   VARIABLES LOCALES
   ============================================================ */
.courses-archive {
    --tile-bg: #252320;
    --tile-bg-hover: #302d2a;
    --tile-border: #3d3a38;
    --tile-completed-glow: rgba(22, 163, 74, 0.3);
    --level-fondamentaux: #16A34A;
    --level-intermediaire: #F59E0B;
    --level-avance: #EF4444;
    --progress-height: 4px;
    --icon-size: 40px;
    --exam-circle-size: 70px;
    --blur-amount: 8px;
}

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
.courses-archive {
    padding-top: calc(var(--header-height, 75px) + 30px);
    padding-bottom: 60px;
    min-height: 100vh;
    background: var(--bg-primary);
}

/* ============================================================
   HEADER DE LA PAGE
   ============================================================ */
.courses-header {
    text-align: center;
    padding: 40px 20px 30px;
    max-width: 800px;
    margin: 0 auto;
}

.courses-header__title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.courses-header__subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin: 0;
}

/* ============================================================
   MESSAGE D'INTRODUCTION
   ============================================================ */
.progression-intro {
    max-width: 900px;
    margin: 0 auto 40px;
    padding: 0 20px;
}

.progression-intro__box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px 25px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.progression-intro__icon {
    font-size: 2rem;
    flex-shrink: 0;
    line-height: 1;
}

.progression-intro__content {
    flex: 1;
}

.progression-intro__title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 8px 0;
}

.progression-intro__text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.6;
}

.progression-intro__text strong {
    color: var(--accent);
}

/* Tags de niveau inline */
.level-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.level-tag--fondamentaux {
    background: rgba(22, 163, 74, 0.15);
    color: var(--level-fondamentaux);
}

.level-tag--intermediaire {
    background: rgba(245, 158, 11, 0.15);
    color: var(--level-intermediaire);
}

.level-tag--avance {
    background: rgba(239, 68, 68, 0.15);
    color: var(--level-avance);
}

/* ============================================================
   NOUVEAU : CHECKBOX MODE APERÇU (v3.0)
   ============================================================ */
.preview-toggle {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.preview-toggle__label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.preview-toggle__checkbox {
    display: none;
}

/* Switch custom */
.preview-toggle__switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    transition: all 0.3s ease;
}

.preview-toggle__switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: all 0.3s ease;
}

.preview-toggle__checkbox:checked + .preview-toggle__switch {
    background: var(--accent);
    border-color: var(--accent);
}

.preview-toggle__checkbox:checked + .preview-toggle__switch::after {
    transform: translateX(20px);
    background: white;
}

.preview-toggle__text {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 500;
}

.preview-toggle__hint {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(234, 88, 12, 0.15);
    border: 1px solid #EA580C;
    border-radius: 6px;
    color: #EA580C;
    font-size: 0.8rem;
    font-weight: 500;
    animation: fadeIn 0.3s ease;
}

.preview-toggle__hint--flash {
    animation: flash 0.3s ease;
}

@keyframes flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; transform: scale(1.05); }
}

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

/* ============================================================
   NOUVEAU : NOTICE POUR VISITEURS NON CONNECTÉS (v3.0)
   ============================================================ */
.visitor-notice {
    margin-top: 15px;
    padding: 12px 16px;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid #3B82F6;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.visitor-notice__icon {
    font-size: 1.2rem;
}

.visitor-notice__text {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.visitor-notice__link {
    color: #3B82F6;
    font-weight: 600;
    text-decoration: none;
    transition: opacity 0.2s;
}

.visitor-notice__link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* ============================================================
   GRILLE PRINCIPALE : 2 COLONNES
   ============================================================ */
.courses-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ============================================================
   COLONNE DISCIPLINE
   ============================================================ */
.discipline-column {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

/* Header de discipline */
.discipline-header {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px 20px;
    background: var(--bg-card);
    border-radius: 10px;
    border-left: 4px solid var(--accent);
}

.discipline-header__icon {
    font-size: 2rem;
    line-height: 1;
}

.discipline-header__info {
    display: flex;
    flex-direction: column;
}

.discipline-header__title {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.discipline-header__chinese {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ============================================================
   SECTIONS DE NIVEAU
   ============================================================ */
.level-section {
    background: var(--bg-card);
    border-radius: 10px;
    overflow: hidden;
    transition: all 0.3s ease;
}

/* Header de niveau */
.level-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: rgba(var(--level-color), 0.08);
}

.level-header__left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.level-header__icon {
    font-size: 1.1rem;
}

.level-header__title {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    color: var(--level-color, var(--text-primary));
}

.level-header__lock-badge {
    font-size: 0.85rem;
    opacity: 0.8;
}

.level-header__stats {
    display: flex;
    align-items: center;
}

.level-header__count {
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--bg-elevated);
    padding: 3px 10px;
    border-radius: 12px;
}

/* Couleurs des headers par niveau */
.level-section--fondamentaux .level-header {
    background: rgba(22, 163, 74, 0.08);
}
.level-section--fondamentaux .level-header__title {
    color: var(--level-fondamentaux);
}

.level-section--intermediaire .level-header {
    background: rgba(245, 158, 11, 0.08);
}
.level-section--intermediaire .level-header__title {
    color: var(--level-intermediaire);
}

.level-section--avance .level-header {
    background: rgba(239, 68, 68, 0.08);
}
.level-section--avance .level-header__title {
    color: var(--level-avance);
}

/* ============================================================
   CONTENU DU NIVEAU - ZONE FLOUE
   ============================================================ */
.level-content {
    position: relative;
    padding: 12px;
    transition: filter 0.3s ease;
}

/* Zone floue pour niveaux verrouillés - appliqué aux enfants */
.level-content--blurred .courses-tiles,
.level-content--blurred .final-exam {
    filter: blur(var(--blur-amount));
    pointer-events: none;
    user-select: none;
}

/* L'overlay reste net et cliquable */
.level-locked-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: auto;
    background: rgba(13, 11, 9, 0.3);
}

.level-locked-message {
    background: rgba(13, 11, 9, 0.95);
    border: 1px solid var(--accent);
    border-radius: 10px;
    padding: 20px 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    max-width: 80%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    filter: none !important;
    backdrop-filter: none;
}

.level-locked-message__icon {
    font-size: 2rem;
}

.level-locked-message__text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ============================================================
   GRILLE DES TUILES DE COURS
   ============================================================ */
.courses-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}

.courses-tiles__empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 20px;
    color: var(--text-disabled);
    font-size: 0.85rem;
    font-style: italic;
}

/* ============================================================
   TUILE DE COURS INDIVIDUELLE
   ============================================================ */
.course-tile {
    position: relative;
}

.course-tile__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--tile-bg);
    border: 1px solid var(--tile-border);
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

.course-tile__link:hover {
    background: var(--tile-bg-hover);
    border-color: var(--accent);
    transform: translateY(-2px);
}

/* Tuile désactivée (niveau verrouillé) */
.course-tile__link--disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.course-tile__link--disabled:hover {
    background: var(--tile-bg);
    border-color: var(--tile-border);
    transform: none;
}

/* NOUVEAU : Style pour visiteurs (v3.0) */
.course-tile__link--visitor {
    position: relative;
}

.course-tile__link--visitor:hover {
    border-color: #3B82F6;
}

/* Icône du cours */
.course-tile__icon {
    position: relative;
    width: var(--icon-size);
    height: var(--icon-size);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-elevated);
    border-radius: 6px;
    overflow: hidden;
}

.course-tile__thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.course-tile__emoji {
    font-size: 1.5rem;
}

/* Badge de complétion */
.course-tile__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: bold;
}

.course-tile__badge--completed {
    background: var(--level-fondamentaux);
    color: white;
}

/* NOUVEAU : Badge Premium pour visiteurs (v3.0) */
.course-tile__badge--premium {
    width: auto;
    height: auto;
    padding: 2px 6px;
    border-radius: 3px;
    top: auto;
    bottom: -4px;
    right: -4px;
    background: var(--accent);
    color: white;
    font-size: 0.55rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Titre du cours */
.course-tile__title {
    flex: 1;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Barre de progression */
.course-tile__progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--progress-height);
    background: var(--bg-elevated);
    border-radius: 0 0 6px 6px;
    overflow: hidden;
}

.course-tile__progress-bar {
    height: 100%;
    width: 100%;
}

.course-tile__progress-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s ease;
}

/* Cours complété */
.course-tile--completed .course-tile__link {
    border-color: var(--level-fondamentaux);
    box-shadow: 0 0 10px var(--tile-completed-glow);
}

/* Cours en progression */
.course-tile--in-progress .course-tile__link {
    border-color: var(--accent);
}

/* ============================================================
   MODE APERÇU GLOBAL (v3.0)
   ============================================================ */

/* Mode aperçu activé par checkbox (utilisateurs connectés) */
.courses-archive--preview-mode .course-tile__link {
    cursor: not-allowed !important;
    pointer-events: auto !important;
}

.courses-archive--preview-mode .course-tile__link:hover {
    transform: none;
    border-color: var(--tile-border);
}

.courses-archive--preview-mode .course-tile__link::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(13, 11, 9, 0.3);
    border-radius: 6px;
    pointer-events: none;
}

/* Mode aperçu pour visiteurs */
.courses-archive--preview .level-section--locked {
    /* Retirer l'apparence verrouillée pour les visiteurs */
}

/* ============================================================
   EXAMEN FINAL
   ============================================================ */
.final-exam {
    margin-top: 15px;
    padding: 15px;
    background: linear-gradient(135deg, rgba(45, 42, 40, 0.8) 0%, rgba(35, 32, 30, 0.9) 100%);
    border: 2px solid var(--border);
    border-radius: 10px;
    transition: all 0.3s ease;
}

.final-exam__content {
    display: flex;
    align-items: center;
    gap: 20px;
}

/* ============================================================
   CERCLE DE PROGRESSION SVG (Style Dofus)
   ============================================================ */
.final-exam__lock-circle {
    position: relative;
    width: var(--exam-circle-size);
    height: var(--exam-circle-size);
    flex-shrink: 0;
}

.final-exam__progress-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.final-exam__progress-bg {
    fill: none;
    stroke: var(--bg-elevated);
    stroke-width: 6;
}

.final-exam__progress-fill {
    fill: none;
    stroke: var(--accent);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 283;
    transition: stroke-dashoffset 0.5s ease;
}

.final-exam__lock-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    line-height: 1;
}

.final-exam__check {
    color: var(--level-fondamentaux);
    font-weight: bold;
    font-size: 1.8rem;
}

.final-exam__unlock {
    font-size: 1.6rem;
}

.final-exam__padlock {
    opacity: 0.6;
}

/* Infos de l'examen */
.final-exam__info {
    flex: 1;
}

.final-exam__title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 5px 0;
}

.final-exam__description {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.4;
}

/* Bouton d'action */
.final-exam__button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.final-exam__button:hover {
    background: var(--accent-hover, #7a1526);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(155, 27, 48, 0.3);
}

/* Badge validé */
.final-exam__badge-validated {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    background: rgba(22, 163, 74, 0.15);
    border: 1px solid var(--level-fondamentaux);
    border-radius: 6px;
    color: var(--level-fondamentaux);
    font-weight: 600;
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* États de l'examen */
.final-exam--locked {
    opacity: 0.7;
    border-style: dashed;
}

.final-exam--accessible {
    border-color: var(--accent);
    box-shadow: 0 0 15px rgba(155, 27, 48, 0.2);
}

.final-exam--accessible .final-exam__progress-fill {
    stroke: var(--level-fondamentaux);
}

.final-exam--passed {
    border-color: var(--level-fondamentaux);
    background: linear-gradient(135deg, rgba(22, 163, 74, 0.1) 0%, rgba(22, 163, 74, 0.05) 100%);
}

.final-exam--passed .final-exam__progress-fill {
    stroke: var(--level-fondamentaux);
    stroke-dashoffset: 0 !important;
}

/* ============================================================
   RESPONSIVE - MOBILE FIRST
   ============================================================ */

/* Tablette (< 1024px) */
@media (max-width: 1024px) {
    .courses-grid {
        gap: 20px;
    }
    
    .discipline-header__title {
        font-size: 1.1rem;
    }
    
    .courses-tiles {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 6px;
    }
    
    .course-tile__link {
        padding: 8px 10px;
        gap: 8px;
    }
    
    .course-tile__icon {
        --icon-size: 35px;
    }
    
    .course-tile__title {
        font-size: 0.8rem;
    }
    
    .final-exam__content {
        gap: 15px;
    }
    
    .final-exam__lock-circle {
        --exam-circle-size: 60px;
    }
    
    .preview-toggle {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
    .courses-archive {
        padding-top: calc(var(--header-height, 75px) + 20px);
    }
    
    .courses-header {
        padding: 20px 15px;
    }
    
    .courses-header__title {
        font-size: 1.6rem;
    }
    
    .progression-intro {
        padding: 0 15px;
        margin-bottom: 25px;
    }
    
    .progression-intro__box {
        flex-direction: column;
        align-items: flex-start;
        padding: 15px;
        gap: 12px;
    }
    
    .progression-intro__text br {
        display: none;
    }
    
    /* Stack les disciplines verticalement */
    .courses-grid {
        grid-template-columns: 1fr;
        gap: 25px;
        padding: 0 15px;
    }
    
    .discipline-header {
        padding: 12px 15px;
    }
    
    .discipline-header__icon {
        font-size: 1.6rem;
    }
    
    .discipline-header__title {
        font-size: 1.15rem;
    }
    
    /* Tuiles en grille compacte */
    .courses-tiles {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .course-tile__link {
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 12px 8px;
    }
    
    .course-tile__icon {
        --icon-size: 45px;
    }
    
    .course-tile__title {
        font-size: 0.75rem;
        -webkit-line-clamp: 2;
    }
    
    .level-header {
        padding: 10px 12px;
    }
    
    .level-header__title {
        font-size: 0.85rem;
    }
    
    /* Examen final en colonne */
    .final-exam__content {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }
    
    .final-exam__lock-circle {
        --exam-circle-size: 70px;
    }
    
    .final-exam__button {
        width: 100%;
    }
    
    /* Message de verrouillage adapté */
    .level-locked-message {
        padding: 15px 20px;
        max-width: 90%;
    }
    
    .level-locked-message__icon {
        font-size: 1.5rem;
    }
    
    .level-locked-message__text {
        font-size: 0.8rem;
    }
    
    /* Preview toggle mobile */
    .preview-toggle__label {
        flex-wrap: wrap;
    }
    
    .preview-toggle__hint {
        width: 100%;
        justify-content: center;
    }
    
    .visitor-notice {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }
}

/* Petit mobile (< 400px) */
@media (max-width: 400px) {
    .courses-tiles {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .course-tile__icon {
        --icon-size: 40px;
    }
    
    .course-tile__title {
        font-size: 0.7rem;
    }
}

/* ============================================================
   LIGHT MODE OVERRIDES
   ============================================================ */
.light-mode .courses-archive {
    --tile-bg: #f8f7f6;
    --tile-bg-hover: #efeeed;
    --tile-border: #d4d0cd;
}

.light-mode .course-tile--completed .course-tile__link {
    box-shadow: 0 0 8px rgba(22, 163, 74, 0.2);
}

.light-mode .final-exam {
    background: linear-gradient(135deg, rgba(248, 247, 246, 0.9) 0%, rgba(232, 228, 225, 0.9) 100%);
}

.light-mode .level-locked-message {
    background: rgba(245, 243, 240, 0.98);
}

.light-mode .preview-toggle__switch {
    background: #d4d0cd;
}

.light-mode .visitor-notice {
    background: rgba(59, 130, 246, 0.08);
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes pulse-glow {
    0%, 100% {
        box-shadow: 0 0 10px var(--tile-completed-glow);
    }
    50% {
        box-shadow: 0 0 20px var(--tile-completed-glow);
    }
}

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

.final-exam--accessible .final-exam__unlock {
    animation: unlock-pulse 2s ease-in-out infinite;
}

/* Transition douce pour le blur */
.level-content {
    transition: filter 0.4s ease;
}
