/* ============================================================
   CIM ACADEMY — Système de design (Phase 1)
   ------------------------------------------------------------
   Palette dérivée du logo officiel :
     Bleu   #00529B  (structure, navigation, primaire)
     Orange #EF7E32  (accent, appels à l'action)
     Vert   #029A00  (réussite, progression — jamais décoratif)
   Typographie : Sora (display, interface) + Inter (texte courant)
                 + Fraunces (accroche de la page publique uniquement)
   Signature : l'arc de progression circulaire, écho direct de
   l'anneau ouvert du logo, réutilisé pour toute donnée "en cours".
   ============================================================ */

:root {
    --cim-blue: #00529B;
    --cim-blue-dark: #003B73;
    --cim-blue-light: #E9F2FA;
    --cim-orange: #EF7E32;
    --cim-orange-dark: #D9661F;
    --cim-orange-light: #FDEEE2;
    --cim-green: #029A00;
    --cim-green-dark: #027A00;
    --cim-green-light: #E4F6E4;
    --cim-ink: #10233D;
    --cim-ink-soft: #55677E;
    --cim-bg: #F2F5FA;
    --cim-card: #FFFFFF;
    --cim-border: #E4E9F1;
    --cim-danger: #D6432F;
    --cim-danger-light: #FBEAE7;

    --font-display: 'Sora', 'Segoe UI', sans-serif;
    --font-body: 'Inter', 'Segoe UI', sans-serif;
    --font-serif: 'Fraunces', Georgia, serif;

    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --shadow-card: 0 12px 32px -16px rgba(16, 35, 61, .18);
    --shadow-soft: 0 4px 14px -6px rgba(16, 35, 61, .10);
}

/* Rétro-compatibilité : anciennes variables encore utilisées par
   les pages non encore repassées en revue de design (Phase 1
   suite). Elles pointent vers la nouvelle palette pour rester
   visuellement cohérentes en attendant. */
:root {
    --cim-primary: var(--cim-blue);
    --cim-primary-dark: var(--cim-blue-dark);
}

* { box-sizing: border-box; }

body {
    background-color: var(--cim-bg);
    font-family: var(--font-body);
    color: var(--cim-ink);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6, .fw-bold, .display-4, .display-5, .h3, .h4 {
    font-family: var(--font-display);
    color: var(--cim-ink);
}

a { color: var(--cim-blue); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--cim-blue-dark); }

/* Focus visible cohérent (accessibilité) */
a:focus-visible, button:focus-visible, input:focus-visible,
textarea:focus-visible, select:focus-visible {
    outline: 2px solid var(--cim-orange);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ============================================================
   BOUTONS
   ============================================================ */
.btn { font-family: var(--font-display); font-weight: 600; border-radius: var(--radius-sm); }

.btn-primary {
    background-color: var(--cim-blue);
    border-color: var(--cim-blue);
}
.btn-primary:hover, .btn-primary:focus {
    background-color: var(--cim-blue-dark);
    border-color: var(--cim-blue-dark);
}

.btn-cim-accent {
    background: linear-gradient(135deg, var(--cim-orange) 0%, var(--cim-orange-dark) 100%);
    border: none;
    color: #fff;
    box-shadow: 0 8px 20px -8px rgba(239, 126, 50, .55);
    transition: transform .15s ease, box-shadow .15s ease;
}
.btn-cim-accent:hover {
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 10px 24px -8px rgba(239, 126, 50, .65);
}

.btn-outline-primary {
    color: var(--cim-blue);
    border-color: var(--cim-blue);
}
.btn-outline-primary:hover {
    background-color: var(--cim-blue);
    border-color: var(--cim-blue);
}

/* ============================================================
   PAGE DE CONNEXION
   ============================================================ */
.login-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at 15% 20%, rgba(239, 126, 50, .35), transparent 45%),
        radial-gradient(circle at 85% 80%, rgba(2, 154, 0, .25), transparent 45%),
        linear-gradient(135deg, var(--cim-blue) 0%, var(--cim-blue-dark) 100%);
}
.login-card {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}
.login-logo { height: 52px; margin-bottom: .75rem; }

/* ============================================================
   COQUILLE APPLICATIVE (sidebar) — admin & élève
   ============================================================ */
.app-shell {
    display: flex;
    min-height: 100vh;
    align-items: flex-start;
}

.app-sidebar {
    width: 260px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--cim-ink) 0%, #0A1930 100%);
    color: #C9D4E3;
    min-height: 100vh;
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    z-index: 1030;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .25rem .5rem 1.5rem;
    color: #fff;
}
.sidebar-brand img { height: 34px; width: auto; }
.sidebar-brand span {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: .02em;
}

.sidebar-section-label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #6C7E96;
    padding: 1rem .75rem .35rem;
    font-weight: 600;
}

.sidebar-nav { list-style: none; margin: 0; padding: 0; }
.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .6rem .75rem;
    border-radius: var(--radius-sm);
    color: #C9D4E3;
    font-size: .92rem;
    font-weight: 500;
    margin-bottom: .15rem;
    transition: background-color .15s ease, color .15s ease;
}
.sidebar-nav-item i { font-size: 1.05rem; width: 1.3rem; text-align: center; }
.sidebar-nav-item:hover {
    background-color: rgba(255, 255, 255, .06);
    color: #fff;
    text-decoration: none;
}
.sidebar-nav-item.active {
    background-color: var(--cim-card);
    color: var(--cim-blue);
    font-weight: 700;
    box-shadow: var(--shadow-soft);
}
.sidebar-nav-item .badge-count {
    margin-left: auto;
    background: var(--cim-orange);
    color: #fff;
    border-radius: 50px;
    font-size: .7rem;
    padding: .1rem .45rem;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-footer .sidebar-nav-item { color: #E39A8A; }
.sidebar-footer .sidebar-nav-item:hover { color: #fff; background-color: rgba(214, 67, 47, .25); }

.app-main {
    flex: 1;
    min-width: 0;
    padding: 1.75rem clamp(1rem, 3vw, 2.5rem);
}

.app-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.app-topbar-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.5rem;
    margin: 0;
}
.app-topbar-actions { display: flex; align-items: center; gap: .75rem; }
.app-topbar-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--cim-blue-light);
    color: var(--cim-blue);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-family: var(--font-display);
}

/* Mobile : sidebar devient un panneau off-canvas */
.sidebar-mobile-toggle { display: none; }

@media (max-width: 991.98px) {
    .app-shell { flex-direction: column; }
    .app-sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: 20px 0 40px rgba(0,0,0,.25);
    }
    .app-sidebar.is-open { transform: translateX(0); }
    .sidebar-mobile-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 42px; height: 42px;
        border-radius: var(--radius-sm);
        background: var(--cim-card);
        border: 1px solid var(--cim-border);
        color: var(--cim-ink);
    }
    .sidebar-backdrop {
        display: none;
        position: fixed; inset: 0;
        background: rgba(16, 35, 61, .45);
        z-index: 1020;
    }
    .sidebar-backdrop.is-open { display: block; }
    .app-main { padding: 1.25rem 1rem; }
}

/* ============================================================
   BANNIÈRE DE BIENVENUE
   ============================================================ */
.welcome-banner {
    background: linear-gradient(120deg, var(--cim-blue) 0%, var(--cim-blue-dark) 100%);
    border-radius: var(--radius-lg);
    padding: 1.75rem 2rem;
    color: #fff;
    position: relative;
    overflow: hidden;
    margin-bottom: 1.5rem;
}
.welcome-banner::before {
    content: "";
    position: absolute;
    top: -60px; right: -40px;
    width: 220px; height: 220px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(239,126,50,.45) 0%, transparent 70%);
}
.welcome-banner::after {
    content: "";
    position: absolute;
    bottom: -80px; right: 120px;
    width: 180px; height: 180px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(2,154,0,.35) 0%, transparent 70%);
}
.welcome-banner h1 {
    color: #fff;
    font-size: 1.6rem;
    margin-bottom: .25rem;
    position: relative;
}
.welcome-banner p { color: rgba(255,255,255,.85); margin: 0; position: relative; }

/* ============================================================
   CARTES STATISTIQUES (avec visualisation dédiée)
   ============================================================ */
.stat-card-v2 {
    background: var(--cim-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-soft);
    padding: 1.1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 100%;
}
.stat-card-v2 .stat-icon-circle {
    width: 46px; height: 46px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}
.stat-card-v2 .stat-value {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.4rem;
    line-height: 1.1;
    color: var(--cim-ink);
}
.stat-card-v2 .stat-label {
    font-size: .78rem;
    color: var(--cim-ink-soft);
}

.progress-ring-wrap { position: relative; width: 64px; height: 64px; flex-shrink: 0; }
.progress-ring-wrap svg { transform: rotate(-90deg); }
.progress-ring-label {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: .82rem;
    color: var(--cim-ink);
}

/* Simples couleurs d'icônes (remplacent bg-*-subtle générique) */
.icon-blue   { background: var(--cim-blue-light);   color: var(--cim-blue); }
.icon-orange { background: var(--cim-orange-light); color: var(--cim-orange-dark); }
.icon-green  { background: var(--cim-green-light);  color: var(--cim-green-dark); }

/* ============================================================
   CARTES DE COURS / MODULES
   ============================================================ */
.course-card-v2 {
    background: var(--cim-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
    height: 100%;
    display: flex;
    flex-direction: column;
    transition: transform .18s ease, box-shadow .18s ease;
}
.course-card-v2:hover { transform: translateY(-3px); box-shadow: var(--shadow-card); }
.course-card-v2 .course-cover {
    height: 120px;
    background: linear-gradient(135deg, var(--cim-blue-light), var(--cim-orange-light));
    background-size: cover;
    background-position: center;
    position: relative;
}
.course-card-v2 .course-badge {
    position: absolute; top: .6rem; left: .6rem;
    background: rgba(16,35,61,.75);
    color: #fff;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: .2rem .55rem;
    border-radius: 50px;
}
.course-card-v2 .course-body { padding: 1rem 1.1rem 1.1rem; flex: 1; display: flex; flex-direction: column; }
.course-card-v2 .course-title { font-weight: 700; font-family: var(--font-display); margin-bottom: .35rem; }
.course-card-v2 .course-progress-track {
    height: 7px; border-radius: 50px; background: var(--cim-border); overflow: hidden; margin: .6rem 0 .4rem;
}
.course-card-v2 .course-progress-fill {
    height: 100%; border-radius: 50px;
    background: linear-gradient(90deg, var(--cim-blue), var(--cim-orange));
}
.course-card-v2 .course-meta { font-size: .78rem; color: var(--cim-ink-soft); margin-top: auto; }

/* ============================================================
   HISTORIQUE D'ACTIVITÉ / NOTIFICATIONS
   ============================================================ */
.activity-list { list-style: none; margin: 0; padding: 0; }
.activity-item {
    display: flex;
    gap: .75rem;
    padding: .75rem 0;
    border-bottom: 1px solid var(--cim-border);
}
.activity-item:last-child { border-bottom: none; }
.activity-item .activity-bar {
    width: 4px;
    border-radius: 50px;
    flex-shrink: 0;
}
.activity-item .activity-bar.bar-blue   { background: var(--cim-blue); }
.activity-item .activity-bar.bar-orange { background: var(--cim-orange); }
.activity-item .activity-bar.bar-green  { background: var(--cim-green); }
.activity-item .activity-bar.bar-muted  { background: var(--cim-border); }
.activity-item .activity-title { font-weight: 600; font-size: .88rem; color: var(--cim-ink); }
.activity-item .activity-time { font-size: .74rem; color: var(--cim-ink-soft); }

/* ============================================================
   CARTES GÉNÉRIQUES / TABLES (pages existantes, Phase 1 suite)
   ============================================================ */
.card { border-radius: var(--radius-md); border: none; box-shadow: var(--shadow-soft); }
.card-header { border-radius: var(--radius-md) var(--radius-md) 0 0 !important; background: #fff; font-family: var(--font-display); font-weight: 600; }

.table thead th {
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--cim-ink-soft);
    border-bottom-width: 1px;
}

.badge.bg-success-subtle { background: var(--cim-green-light) !important; color: var(--cim-green-dark) !important; }
.badge.bg-danger-subtle  { background: var(--cim-danger-light) !important; color: var(--cim-danger) !important; }
.badge.bg-primary-subtle { background: var(--cim-blue-light) !important; color: var(--cim-blue) !important; }
.badge.bg-secondary-subtle { background: #EEF1F5 !important; color: var(--cim-ink-soft) !important; }

.progress { height: 10px; border-radius: 6px; background: var(--cim-border); }
.progress-bar { background-color: var(--cim-blue); }

/* Anciennes classes de la Phase 0, conservées pour les pages pas
   encore repassées en revue visuelle (rétro-compatibilité) */
.admin-navbar { background-color: var(--cim-blue); }
.admin-navbar .nav-link { color: rgba(255,255,255,.85); }
.admin-navbar .nav-link.active, .admin-navbar .nav-link:hover { color: #fff; font-weight: 600; }
.stat-card { border-radius: var(--radius-md); }
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; }

/* ============================================================
   MODE SOMBRE
   ============================================================ */
[data-theme="dark"] {
    --cim-bg: #0B1626;
    --cim-card: #14213A;
    --cim-ink: #EAF0F8;
    --cim-ink-soft: #93A2B8;
    --cim-border: #223252;
    --cim-blue-light: rgba(0, 82, 155, .22);
    --cim-orange-light: rgba(239, 126, 50, .18);
    --cim-green-light: rgba(2, 154, 0, .18);
    --shadow-card: 0 12px 32px -16px rgba(0, 0, 0, .55);
    --shadow-soft: 0 4px 14px -6px rgba(0, 0, 0, .45);
}
[data-theme="dark"] body { color: var(--cim-ink); }
[data-theme="dark"] .app-sidebar { background: linear-gradient(180deg, #060D18 0%, #0A1220 100%); }
[data-theme="dark"] .table thead th { color: var(--cim-ink-soft); }
[data-theme="dark"] .table { color: var(--cim-ink); }
[data-theme="dark"] .table-hover > tbody > tr:hover > * { color: var(--cim-ink); background-color: rgba(255,255,255,.04); }
[data-theme="dark"] .form-control, [data-theme="dark"] .form-select {
    background-color: #0F1B30; border-color: var(--cim-border); color: var(--cim-ink);
}
[data-theme="dark"] .form-control:focus, [data-theme="dark"] .form-select:focus {
    background-color: #0F1B30; color: var(--cim-ink);
}
[data-theme="dark"] .modal-content { background-color: var(--cim-card); color: var(--cim-ink); }
[data-theme="dark"] .app-topbar-avatar { background: rgba(0, 82, 155, .3); }
[data-theme="dark"] .course-progress-track { background: var(--cim-border); }
[data-theme="dark"] .stat-icon-circle.icon-blue { background: rgba(0, 82, 155, .25); }
[data-theme="dark"] .stat-icon-circle.icon-orange { background: rgba(239, 126, 50, .22); }
[data-theme="dark"] .stat-icon-circle.icon-green { background: rgba(2, 154, 0, .22); }

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .55rem .75rem;
    border-radius: var(--radius-sm);
    color: #C9D4E3;
    font-size: .82rem;
    margin-top: .35rem;
}
.theme-toggle-switch {
    position: relative;
    width: 38px; height: 21px;
    background: rgba(255,255,255,.15);
    border-radius: 50px;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
}
.theme-toggle-switch::before {
    content: "";
    position: absolute;
    top: 2px; left: 2px;
    width: 17px; height: 17px;
    border-radius: 50%;
    background: #fff;
    transition: transform .18s ease;
}
[data-theme="dark"] .theme-toggle-switch::before { transform: translateX(17px); }
[data-theme="dark"] .theme-toggle-switch { background: var(--cim-orange); }

/* ============================================================
   MICRO-ANIMATIONS
   ============================================================ */
@keyframes cim-fade-up {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.cim-animate {
    animation: cim-fade-up .35s ease both;
}
.cim-animate:nth-child(1) { animation-delay: 0ms; }
.cim-animate:nth-child(2) { animation-delay: 40ms; }
.cim-animate:nth-child(3) { animation-delay: 80ms; }
.cim-animate:nth-child(4) { animation-delay: 120ms; }

.sidebar-nav-item, .btn, .course-card-v2, .stat-card-v2 {
    transition: background-color .15s ease, color .15s ease, transform .15s ease, box-shadow .15s ease;
}

@media (max-width: 576px) {
    .h3 { font-size: 1.3rem; }
    .welcome-banner { padding: 1.35rem 1.4rem; }
}

/* ============================================================
   CONTENU RICHE (éditeur Quill) — édition et affichage
   ============================================================ */
.rich-editor {
    min-height: 160px;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
.ql-toolbar.ql-snow {
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    background: #F8FAFC;
}
.ql-container.ql-snow {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    font-family: var(--font-body);
    font-size: .95rem;
}

.rich-text-display :first-child { margin-top: 0; }
.rich-text-display :last-child { margin-bottom: 0; }
.rich-text-display h1, .rich-text-display h2, .rich-text-display h3 { font-family: var(--font-display); margin-top: 1.2em; }
.rich-text-display blockquote {
    border-left: 3px solid var(--cim-blue);
    padding-left: 1rem;
    color: var(--cim-ink-soft);
    margin: 1rem 0;
}
.rich-text-display pre {
    background: #F3F5F9;
    border-radius: var(--radius-sm);
    padding: .75rem 1rem;
    overflow-x: auto;
}
.rich-text-display code {
    background: #F3F5F9;
    padding: .1rem .35rem;
    border-radius: 4px;
    font-size: .9em;
}
.rich-text-display a { text-decoration: underline; }
