/* ========================================
   Variables CSS
   ======================================== */
:root {
    --primary-color: #4f46e5;
    --secondary-color: #06b6d4;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;

    /* Codes couleur progression */
    --status-pending: #9ca3af;
    --status-in-progress: #f59e0b;
    --status-completed: #10b981;

    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;

    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;

    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --radius-sm: 0.25rem;
    --radius: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
}

/* ========================================
   Reset & Base
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* ========================================
   Header
   ======================================== */
.app-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.user-selector {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-selector label {
    font-weight: 500;
    color: var(--text-secondary);
}

.user-select-dropdown {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    min-width: 250px;
}

.user-select-dropdown:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.btn-profile {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 120px;
    white-space: nowrap;
}

.btn-profile:hover:not(:disabled) {
    background: #4338ca;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-profile:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--text-tertiary);
}

/* ========================================
   Sections
   ======================================== */
section {
    padding: 2rem 0;
}

section h2 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.hidden {
    display: none !important;
}

/* ========================================
   Programmes Grid
   ======================================== */
.programmes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.programme-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow);
}

.programme-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.programme-card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.programme-icon {
    font-size: 2rem;
}

.programme-card h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.programme-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.programme-description {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

/* ========================================
   Cours Section
   ======================================== */
.cours-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.btn-back {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.cours-columns {
    display: flex;
    gap: 1.5rem;
    overflow-x: auto;
    padding-bottom: 1rem;
}

.cours-column {
    flex: 0 0 350px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.cours-column-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.cours-column-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    cursor: pointer;
    color: var(--primary-color);
    transition: color 0.2s ease;
}

.cours-column-header h3:hover {
    color: var(--secondary-color);
}

.cours-type {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* ========================================
   Fiches Tiles
   ======================================== */
.fiches-section {
    margin-bottom: 1.5rem;
}

.fiches-section h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.fiches-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.fiche-tile {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border: 2px solid #6366f1;
    border-radius: var(--radius);
    padding: 1.25rem 0.75rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

.fiche-tile:hover {
    transform: translateY(-4px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
    border-color: #818cf8;
}

.fiche-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.fiche-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
    line-height: 1.3;
    text-align: center;
}

.fiche-type {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
    margin-top: 0.25rem;
}

/* ========================================
   Cours Chat Item (Tuile de discussion)
   ======================================== */
.cours-chat-item {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 2px solid #667eea;
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: white;
}

.cours-chat-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.cours-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.cours-title {
    font-weight: 600;
    font-size: 0.95rem;
}

/* ========================================
   Exercices List
   ======================================== */
.exercices-section h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.exercice-item {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.exercice-item:last-child {
    margin-bottom: 0;
}

/* États des exercices */
.exercice-item.pending {
    border-color: var(--status-pending);
    background: #f9fafb;
    opacity: 0.7;
}

.exercice-item.in-progress {
    border-color: var(--status-in-progress);
    background: #fffbeb;
}

.exercice-item.completed {
    border-color: var(--status-completed);
    background: #f0fdf4;
}

.exercice-item.locked {
    opacity: 0.5;
    cursor: not-allowed;
    background: #f9fafb;
    border-color: var(--text-tertiary);
}

.exercice-item:not(.locked):hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-md);
}

.exercice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.exercice-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.exercice-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-badge {
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.pending {
    background: var(--status-pending);
    color: white;
}

.status-badge.in-progress {
    background: var(--status-in-progress);
    color: white;
}

.status-badge.completed {
    background: var(--status-completed);
    color: white;
}

.btn-complete {
    padding: 0.25rem 0.75rem;
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-complete:hover {
    background: #059669;
}

.exercice-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.lock-icon {
    font-size: 1.25rem;
    color: var(--text-tertiary);
}

/* ========================================
   Fiches (Multi-fenêtres draggable & resizable)
   ======================================== */
.fiche-window {
    position: fixed;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 2px solid #000;
    min-width: 400px;
    min-height: 300px;
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
}

.fiche-window.dragging {
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    cursor: move;
}

.fiche-window.resizing {
    user-select: none;
}

.fiche-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 2px solid #000;
    background: #000;
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
}

.fiche-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: #fff;
}

.fiche-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #fff;
    cursor: pointer;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    transition: all 0.2s ease;
}

.fiche-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.fiche-body {
    flex: 1;
    overflow: hidden;
    padding: 1.5rem;
}

.fiche-iframe {
    width: 100%;
    height: 100%;
    min-height: 500px;
    border: none;
    border-radius: var(--radius);
}

/* Drag handle */
.fiche-drag-handle {
    cursor: move;
    user-select: none;
}

/* Resize handles (desktop only) */
@media (min-width: 769px) {
    .fiche-resize-right {
        position: absolute;
        top: 0;
        right: 0;
        width: 8px;
        height: 100%;
        cursor: ew-resize;
    }

    .fiche-resize-bottom {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 8px;
        cursor: ns-resize;
    }

    .fiche-resize-corner {
        position: absolute;
        bottom: 0;
        right: 0;
        width: 20px;
        height: 20px;
        cursor: nwse-resize;
        background: linear-gradient(135deg, transparent 50%, var(--border-color) 50%);
        border-bottom-right-radius: var(--radius-lg);
    }

    .fiche-resize-right:hover,
    .fiche-resize-bottom:hover {
        background: rgba(79, 70, 229, 0.1);
    }
}

/* Mobile: full-screen */
@media (max-width: 768px) {
    .fiche-window {
        width: 100vw !important;
        height: 100vh !important;
        left: 0 !important;
        top: 0 !important;
        border-radius: 0;
        min-width: unset;
        min-height: unset;
    }

    .fiche-drag-handle {
        cursor: default;
    }

    .fiche-resize-right,
    .fiche-resize-bottom,
    .fiche-resize-corner {
        display: none;
    }
}

/* ========================================
   Loading Overlay
   ======================================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.loading-spinner {
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

.loading-spinner p {
    color: var(--text-secondary);
    font-weight: 500;
}

/* ========================================
   Profile Modal & Form
   ======================================== */
.profile-form {
    max-width: 500px;
    margin: 0 auto;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.2s ease;
    color: var(--text-primary);
    background: var(--bg-primary);
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.form-hint {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.btn-save {
    padding: 0.75rem 1.5rem;
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1rem;
}

.btn-save:hover {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-cancel {
    padding: 0.75rem 1.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-primary);
    font-size: 1rem;
}

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

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 768px) {
    .app-header .container {
        flex-direction: column;
        align-items: flex-start;
    }

    .user-selector {
        width: 100%;
        flex-wrap: wrap;
    }

    .user-select-dropdown {
        flex: 1;
        min-width: 200px;
    }

    .btn-profile {
        width: 100%;
    }

    .programmes-grid {
        grid-template-columns: 1fr;
    }

    .cours-columns {
        flex-direction: column;
    }

    .cours-column {
        flex: 1 1 auto;
    }

    .modal-content {
        width: 95%;
        max-height: 95vh;
    }

    .fiches-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
}

@media (max-width: 480px) {
    .app-header h1 {
        font-size: 1.25rem;
    }

    .cours-column {
        padding: 1rem;
    }

    .fiches-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}
