/* ==========================================================
   NAVIGATION GLOBALE MATHAFOND
   Première étape : navigation élève uniquement
   ========================================================== */

.app-topbar,
.app-topbar *,
.app-topbar *::before,
.app-topbar *::after {
    box-sizing: border-box;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 10000;
    min-height: 72px;
    padding: 10px 18px;
    color: #ffffff;
    background: linear-gradient(90deg, #1f2937, #334155);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
}

.app-topbar-inner {
    display: grid;
    grid-template-columns: minmax(180px, auto) minmax(0, 1fr) auto;
    align-items: center;
    gap: 20px;
    width: min(100%, 1500px);
    margin: 0 auto;
}

/* Marque et utilisateur */

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
    color: #ffffff;
    text-decoration: none;
}

.app-brand:hover {
    color: #ffffff;
    text-decoration: none;
}

.app-brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.10);
    font-size: 1.25rem;
    font-weight: 950;
}

.app-brand-text {
    min-width: 0;
}

.app-brand-text strong,
.app-brand-text small {
    display: block;
}

.app-brand-text strong {
    font-size: 1rem;
    font-weight: 900;
    line-height: 1.1;
}

.app-brand-text small {
    margin-top: 3px;
    overflow: hidden;
    color: #cbd5e1;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Navigation principale */

.app-role-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
}

.app-nav-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 46px;
    padding: 8px 12px;
    border: 1px solid transparent;
    border-radius: 14px;
    color: #e2e8f0;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 850;
    line-height: 1;
    white-space: nowrap;
    transition:
        background 0.16s ease,
        border-color 0.16s ease,
        color 0.16s ease,
        transform 0.16s ease;
}

.app-nav-link:hover {
    color: #ffffff;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.10);
    border-color: rgba(255, 255, 255, 0.13);
    transform: translateY(-1px);
}

.app-nav-link.is-active {
    color: #ffffff;
    background: rgba(37, 99, 235, 0.65);
    border-color: rgba(147, 197, 253, 0.55);
}

.app-nav-link.is-disabled {
    color: #94a3b8;
    cursor: not-allowed;
    opacity: 0.72;
}

.app-nav-link.is-disabled:hover {
    background: transparent;
    border-color: transparent;
    transform: none;
}

.app-nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 21px;
    height: 21px;
}

.app-nav-icon svg {
    display: block;
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.app-nav-label {
    display: inline-block;
}

/* Actions de droite */

.app-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
}

.app-header-actions #dark-mode-toggle {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
    font-size: 25px;
}

.app-header-actions .logout-btn img {
    width: 40px;
}

/* ==========================================================
   BOUTON S’ENTRAÎNER
   ========================================================== */

.student-practice-menu {
    position: relative;
}

.student-practice-menu > summary {
    list-style: none;
}

.student-practice-menu > summary::-webkit-details-marker {
    display: none;
}

.student-practice-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 46px;
    padding: 11px 17px;
    border: 1px solid #2563eb;
    border-radius: 14px;
    background: linear-gradient(180deg, #3b82f6, #2563eb);
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 900;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.24);
    transition:
        transform 0.16s ease,
        box-shadow 0.16s ease,
        filter 0.16s ease;
}

.student-practice-trigger:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 28px rgba(37, 99, 235, 0.28);
    filter: brightness(0.99);
}

.student-practice-trigger svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.student-practice-popover {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 200;
    display: grid;
    gap: 9px;
    width: 330px;
    padding: 12px;
    border: 1px solid var(--student-border, #dbe3ee);
    border-radius: 18px;
    background: var(--student-panel-bg, #ffffff);
    box-shadow: 0 20px 48px rgba(15, 23, 42, 0.18);
}

.student-practice-choice {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 11px;
    align-items: center;
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--student-border, #dbe3ee);
    border-radius: 14px;
    background: var(--student-soft-bg, #f8fafc);
    color: var(--student-text, #0f172a);
    text-decoration: none;
    text-align: left;
    transition:
        background 0.16s ease,
        border-color 0.16s ease,
        transform 0.16s ease;
}

.student-practice-choice:hover {
    color: var(--student-text, #0f172a);
    text-decoration: none;
    background: var(--student-blue-soft, #eff6ff);
    border-color: var(--student-border-hover, #93c5fd);
    transform: translateY(-1px);
}

.student-practice-choice-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 13px;
    background: var(--student-blue-soft, #dbeafe);
    font-size: 1.2rem;
}

.student-practice-choice strong,
.student-practice-choice small {
    display: block;
}

.student-practice-choice strong {
    color: inherit;
    font-size: 0.95rem;
    font-weight: 900;
}

.student-practice-choice small {
    margin-top: 3px;
    color: var(--student-muted, #475569);
    font-size: 0.79rem;
    font-weight: 650;
    line-height: 1.3;
}

/* Dark mode du menu d’entraînement */

body.dark .student-practice-popover,
body.dark-mode .student-practice-popover,
body.theme-dark .student-practice-popover,
html[data-theme="dark"] .student-practice-popover {
    background: #0f172a;
    border-color: #334155;
}

body.dark .student-practice-choice,
body.dark-mode .student-practice-choice,
body.theme-dark .student-practice-choice,
html[data-theme="dark"] .student-practice-choice {
    background: #1e293b;
    border-color: #334155;
    color: #f8fafc;
}

body.dark .student-practice-choice small,
body.dark-mode .student-practice-choice small,
body.theme-dark .student-practice-choice small,
html[data-theme="dark"] .student-practice-choice small {
    color: #cbd5e1;
}

/* ==========================================================
   SMARTPHONE
   ========================================================== */

@media (max-width: 760px) {
    body.has-app-mobile-nav {
        padding-bottom: calc(76px + env(safe-area-inset-bottom));
    }

    .app-topbar {
        min-height: 60px;
        padding: 8px 12px;
    }

    .app-topbar-inner {
        display: flex;
        justify-content: space-between;
        gap: 12px;
    }

    .app-brand {
        min-width: 0;
    }

    .app-brand-mark {
        width: 38px;
        height: 38px;
        border-radius: 12px;
    }

    .app-brand-text strong {
        font-size: 0.92rem;
    }

    .app-brand-text small {
        max-width: 145px;
        font-size: 0.72rem;
    }

    .app-header-actions {
        gap: 7px;
    }

    .app-header-actions #dark-mode-toggle {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
        font-size: 22px;
    }

    .app-header-actions .logout-btn img {
        width: 36px;
    }

    .app-role-nav {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 10000;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 2px;
        height: calc(68px + env(safe-area-inset-bottom));
        padding:
            5px
            6px
            calc(5px + env(safe-area-inset-bottom));
        border-top: 1px solid rgba(148, 163, 184, 0.28);
        background: rgba(255, 255, 255, 0.98);
        box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.11);
        backdrop-filter: blur(14px);
    }

    .app-nav-link {
        flex-direction: column;
        gap: 3px;
        min-width: 0;
        min-height: 56px;
        padding: 6px 3px;
        border-radius: 12px;
        color: #475569;
    }

    .app-nav-link:hover {
        color: #1d4ed8;
        background: #eff6ff;
        border-color: transparent;
        transform: none;
    }

    .app-nav-link.is-active {
        color: #1d4ed8;
        background: #dbeafe;
        border-color: #bfdbfe;
    }

    .app-nav-link.is-disabled {
        color: #94a3b8;
        background: transparent;
    }

    .app-nav-icon {
        width: 24px;
        height: 24px;
    }

    .app-nav-label {
        display: none;
    }

    body.dark .app-role-nav,
    body.dark-mode .app-role-nav,
    body.theme-dark .app-role-nav,
    html[data-theme="dark"] .app-role-nav {
        border-color: #334155;
        background: rgba(15, 23, 42, 0.98);
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.34);
    }

    body.dark .app-nav-link,
    body.dark-mode .app-nav-link,
    body.theme-dark .app-nav-link,
    html[data-theme="dark"] .app-nav-link {
        color: #cbd5e1;
    }

    body.dark .app-nav-link.is-active,
    body.dark-mode .app-nav-link.is-active,
    body.theme-dark .app-nav-link.is-active,
    html[data-theme="dark"] .app-nav-link.is-active {
        color: #dbeafe;
        background: #172554;
        border-color: #2563eb;
    }

    .student-practice-menu,
    .student-practice-trigger {
        width: 100%;
    }

    .student-practice-popover {
        right: 0;
        left: 0;
        width: 100%;
        min-width: min(330px, calc(100vw - 56px));
    }
}

@media (max-width: 420px) {
    .app-brand-text small {
        display: none;
    }

    .app-brand-mark {
        width: 36px;
        height: 36px;
    }
}

/* ==========================================================
   NAVIGATION PARENT
   Quatre destinations au lieu de cinq
   ========================================================== */

@media (max-width: 760px) {
    .app-role-nav-parent {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* ==========================================================
   CONTRÔLES DU BANDEAU
   Thème, connexion et déconnexion
   ========================================================== */

.app-header-actions,
.app-public-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.app-control-button,
.app-login-button {
    box-sizing: border-box;
    height: 38px;
    border: 1px solid rgba(37, 99, 235, 0.16);
    border-radius: 12px;
    background: rgba(37, 99, 235, 0.07);
    color: #475569;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
    transition:
        color 0.16s ease,
        background 0.16s ease,
        border-color 0.16s ease,
        box-shadow 0.16s ease,
        transform 0.16s ease;
}

.app-control-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    min-width: 38px;
    padding: 0;
    font: inherit;
    cursor: pointer;
}

/* Annule l’ancien gros bouton noir défini dans styles.css. */
#dark-mode-toggle.app-theme-toggle {
    display: inline-flex;
    width: 38px;
    height: 38px;
    min-width: 38px;
    flex: 0 0 38px;
    padding: 0;
    border: 1px solid rgba(37, 99, 235, 0.16);
    border-radius: 12px;
    background: rgba(37, 99, 235, 0.07);
    color: #475569;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
    font-size: inherit;
    line-height: 1;
}

.app-control-button:hover,
#dark-mode-toggle.app-theme-toggle:hover {
    border-color: rgba(37, 99, 235, 0.32);
    background: rgba(37, 99, 235, 0.12);
    color: #1d4ed8;
    box-shadow: 0 5px 14px rgba(37, 99, 235, 0.12);
    transform: translateY(-1px);
}

.app-control-button:focus-visible,
.app-login-button:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.22);
    outline-offset: 2px;
}

.app-control-icon,
.app-theme-icon,
.app-login-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

.app-control-icon svg,
.app-theme-icon svg,
.app-login-icon svg {
    display: block;
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* La lune est affichée en mode clair. */
.app-theme-icon-sun {
    display: none;
}

/* Le soleil est affiché en mode sombre. */
html[data-theme="dark"] .app-theme-icon-moon {
    display: none;
}

html[data-theme="dark"] .app-theme-icon-sun {
    display: inline-flex;
}

/* ----------------------------------------------------------
   Connexion
   ---------------------------------------------------------- */

.app-login-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: auto;
    padding: 0 13px;
    color: #1e40af;
    font-size: 0.86rem;
    font-weight: 850;
    line-height: 1;
    text-decoration: none;
}

.app-login-button:hover {
    border-color: #2563eb;
    background: #2563eb;
    color: #ffffff;
    box-shadow: 0 7px 17px rgba(37, 99, 235, 0.22);
    transform: translateY(-1px);
    text-decoration: none;
}

/* ----------------------------------------------------------
   Déconnexion
   ---------------------------------------------------------- */

.app-logout-button:hover {
    border-color: rgba(220, 38, 38, 0.25);
    background: rgba(220, 38, 38, 0.08);
    color: #dc2626;
    box-shadow: 0 5px 14px rgba(220, 38, 38, 0.10);
}

/* ----------------------------------------------------------
   Ancien bandeau sombre professeur / visiteur
   ---------------------------------------------------------- */

.topbar .app-control-button,
.topbar #dark-mode-toggle.app-theme-toggle,
.topbar .app-login-button {
    border-color: rgba(255, 255, 255, 0.20);
    background: rgba(255, 255, 255, 0.09);
    color: rgba(255, 255, 255, 0.92);
    box-shadow: none;
}

.topbar .app-control-button:hover,
.topbar #dark-mode-toggle.app-theme-toggle:hover {
    border-color: rgba(255, 255, 255, 0.36);
    background: rgba(255, 255, 255, 0.16);
    color: #ffffff;
}

.topbar .app-login-button:hover {
    border-color: #ffffff;
    background: #ffffff;
    color: #1e3a8a;
}

.topbar .app-logout-button:hover {
    border-color: rgba(254, 202, 202, 0.35);
    background: rgba(220, 38, 38, 0.20);
    color: #fecaca;
}

/* ----------------------------------------------------------
   Mode sombre du nouveau bandeau
   ---------------------------------------------------------- */

html[data-theme="dark"] .app-control-button,
html[data-theme="dark"] #dark-mode-toggle.app-theme-toggle,
html[data-theme="dark"] .app-login-button {
    border-color: rgba(148, 163, 184, 0.22);
    background: rgba(148, 163, 184, 0.10);
    color: #cbd5e1;
    box-shadow: none;
}

html[data-theme="dark"] .app-control-button:hover,
html[data-theme="dark"] #dark-mode-toggle.app-theme-toggle:hover {
    border-color: rgba(96, 165, 250, 0.38);
    background: rgba(96, 165, 250, 0.15);
    color: #bfdbfe;
}

html[data-theme="dark"] .app-login-button:hover {
    border-color: #60a5fa;
    background: #2563eb;
    color: #ffffff;
}

html[data-theme="dark"] .app-logout-button:hover {
    border-color: rgba(248, 113, 113, 0.32);
    background: rgba(248, 113, 113, 0.14);
    color: #fca5a5;
}

/* ----------------------------------------------------------
   Smartphone
   ---------------------------------------------------------- */

@media (max-width: 600px) {
    .app-login-button {
        width: 38px;
        min-width: 38px;
        padding: 0;
    }

    .app-login-label {
        display: none;
    }
}

/* ==========================================================
   CONTRÔLES SUR LE NOUVEAU BANDEAU SOMBRE
   ========================================================== */

.app-topbar .app-control-button,
.app-topbar #dark-mode-toggle.app-theme-toggle {
    border-color: rgba(255, 255, 255, 0.24);
    background: rgba(255, 255, 255, 0.10);
    color: #f8fafc;
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.14),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.app-topbar .app-control-button:hover,
.app-topbar #dark-mode-toggle.app-theme-toggle:hover {
    border-color: rgba(255, 255, 255, 0.48);
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
    box-shadow:
        0 6px 16px rgba(0, 0, 0, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.10);
}

.app-topbar .app-logout-button:hover {
    border-color: rgba(248, 113, 113, 0.50);
    background: rgba(220, 38, 38, 0.20);
    color: #fecaca;
}

.app-topbar .app-control-icon,
.app-topbar .app-theme-icon {
    opacity: 1;
}

/* ==========================================================
   NAVIGATION PROFESSEUR
   Quatre destinations principales
   ========================================================== */

@media (max-width: 760px) {
    .app-role-nav-teacher {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

/* ==========================================================
   PARENT — APPEL PREMIUM DANS LE BANDEAU
   ========================================================== */

.parent-premium-header-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 4px 11px 4px 5px;
    overflow: hidden;
    border: 1px solid rgba(147, 197, 253, 0.42);
    border-radius: 13px;
    background:
        linear-gradient(
            135deg,
            rgba(37, 99, 235, 0.34),
            rgba(59, 130, 246, 0.18)
        );
    color: #ffffff;
    box-shadow:
        0 5px 14px rgba(15, 23, 42, 0.16),
        inset 0 1px 0 rgba(255, 255, 255, 0.10);
    text-decoration: none;
    white-space: nowrap;
    transition:
        background 0.16s ease,
        border-color 0.16s ease,
        box-shadow 0.16s ease,
        transform 0.16s ease;
}

.parent-premium-header-button::after {
    content: "";
    position: absolute;
    top: -28px;
    right: -20px;
    width: 64px;
    height: 64px;
    border-radius: 999px;
    background: rgba(191, 219, 254, 0.10);
    pointer-events: none;
}

.parent-premium-header-button:hover {
    border-color: rgba(191, 219, 254, 0.70);
    background:
        linear-gradient(
            135deg,
            rgba(37, 99, 235, 0.60),
            rgba(59, 130, 246, 0.34)
        );
    color: #ffffff;
    box-shadow:
        0 8px 20px rgba(15, 23, 42, 0.22),
        inset 0 1px 0 rgba(255, 255, 255, 0.14);
    transform: translateY(-1px);
    text-decoration: none;
}

.parent-premium-header-button:focus-visible {
    outline: 3px solid rgba(147, 197, 253, 0.30);
    outline-offset: 3px;
}

.parent-premium-header-icon {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    border: 1px solid rgba(191, 219, 254, 0.22);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.10);
    color: #bfdbfe;
}

.parent-premium-header-icon svg {
    display: block;
    width: 17px;
    height: 17px;
    fill: rgba(191, 219, 254, 0.08);
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.parent-premium-header-copy {
    position: relative;
    z-index: 1;
    display: grid;
    gap: 2px;
    min-width: 0;
    text-align: left;
}

.parent-premium-header-copy small,
.parent-premium-header-copy strong {
    display: block;
}

.parent-premium-header-copy small {
    color: #bfdbfe;
    font-size: 0.58rem;
    font-weight: 850;
    line-height: 1;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.parent-premium-header-copy strong {
    color: #ffffff;
    font-size: 0.76rem;
    font-weight: 950;
    line-height: 1.05;
}

/* Tablette intermédiaire */

@media (min-width: 761px) and (max-width: 1050px) {
    .parent-premium-header-button {
        padding-right: 9px;
    }

    .parent-premium-header-copy small {
        display: none;
    }
}

/* Smartphone : étoile uniquement */

@media (max-width: 760px) {
    .parent-premium-header-button {
        width: 36px;
        min-width: 36px;
        height: 36px;
        flex: 0 0 36px;
        padding: 0;
        border-radius: 12px;
    }

    .parent-premium-header-copy {
        display: none;
    }

    .parent-premium-header-icon {
        width: 22px;
        height: 22px;
        flex-basis: 22px;
        border: 0;
        border-radius: 0;
        background: transparent;
    }

    .parent-premium-header-icon svg {
        width: 20px;
        height: 20px;
    }
}