/* ============================
   VARIABLES GLOBALES
============================ */
:root {
    --topbar-bg: #1f2937;
    --topbar-fg: #ffffff;

    --main-bg: rgba(255, 255, 255, 0.96);
    --card-bg: #ffffff;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;

    --success: #15803d;
    --success-bg: #dcfce7;
    --error: #b91c1c;
    --error-bg: #fee2e2;

    --border-soft: #dbe3ee;
    --border-strong: #94a3b8;

    --text-main: #1f2937;
    --text-muted: #6b7280;

    --surface-1: #ffffff;
    --surface-2: #f8fbff;
    --surface-3: #f3f6fb;
    --surface-4: #f3f4f6;
    --table-row-alt: #fafafa;

    --shadow-soft: 0 10px 30px rgba(15, 23, 42, 0.08);
    --shadow-card: 0 6px 18px rgba(15, 23, 42, 0.05);
}

/* ============================
   FONTS
============================ */
@font-face {
    font-family: 'Indie_Flower';
    src: url('/static/polices/Indie_Flower/Indie_Flower.ttf') format('truetype');
}

@font-face {
    font-family: 'Lobster';
    src: url('/static/polices/Lobster/Lobster.ttf');
}

@font-face {
    font-family: 'KiloGram';
    src: url('/static/polices/KiloGram.otf');
}

@font-face {
    font-family: 'AlexBrush';
    src: url('/static/polices/AlexBrush.ttf');
}

/* ============================
   RESET / GLOBAL
============================ */
*,
*::before,
*::after {
    box-sizing: border-box;
}
html {
    overflow-y: scroll;
}

html,
body {
    margin: 0;
    padding: 0;
    max-width: 100%;
    min-height: 100vh;
    overflow-x: hidden;
    font-family: Arial, sans-serif;
    color: var(--text-main);
    background: linear-gradient(180deg, #eef4ff 0%, #f8fbff 40%, #f4f6f8 100%);
}

body {
    line-height: 1.45;
}

a {
    color: inherit;
}

/* ============================
   BADGES + DARK MODE TOGGLE
============================ */
#top-left-badges,
.badges-container {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

#top-left-badges text {
    fill: #fff;
}

.badge {
    width: 60px;
    text-align: center;
    font-family: sans-serif;
}

.badge-icon {
    font-size: 0.7em;
    margin-top: 2px;
}

.badge-name {
    font-size: 0.6em;
    color: #ddd;
}

.badge svg {
    width: 60px;
    height: 60px;
}

#dark-mode-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    font-size: 28px;
    line-height: 1;
    background-color: #000;
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    flex: 0 0 42px;
}

#dark-mode-toggle:hover {
    background-color: #444;
}

/* ============================
   HEADER / TOPBAR
   volontairement remis proche de l'ancien
============================ */
.topbar {
    position: sticky;
    top: 0;
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1rem;
    background: linear-gradient(90deg, #1f2937, #334155);
    color: var(--topbar-fg);
    box-shadow: 0 4px 18px rgba(0,0,0,0.15);
    z-index: 9999;
}

.topbar .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 1400px;
    padding: 0 1rem;
    gap: 1rem;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    min-width: 220px;
}

.header-left {
    visibility: hidden;
}

.header-center {
    display: flex;
    flex: 1 1 auto;
    justify-content: center;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    text-align: center;
}

.greeting-text {
    display: block;
    width: 100%;
    text-align: center;
    margin: 0 0 0.2rem 0;
    font-family: 'Indie_Flower', cursive;
    font-size: 1.5rem;
    font-weight: 600;
    color: #fff;
}

.logout-form {
    display: inline-flex;
    margin: 0;
}

.logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
}

.logout-btn img {
    display: block;
    width: 50px;
    height: auto;
}

/* ============================
   USER GREETING
============================ */
.user-greeting {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-family: 'Indie_Flower', cursive;
    font-size: 1.5rem;
    font-weight: 600;
    color: #fff;
}

/* ============================
   NAVIGATION / BUTTONS
============================ */
.main-nav {
    flex: 1;
    display: flex;
    justify-content: center;
}

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

.nav > a,
.nav > form {
    display: inline-flex;
    align-items: center;
}

.nav-item,
.nav-item-bis,
.btn,
.action-btn,
.exercise-btn {
    border-radius: 10px;
    transition: 0.18s ease;
    appearance: none;
    -webkit-appearance: none;
    text-decoration: none;
    cursor: pointer;
}

.nav-item,
.nav-item-bis,
.btn {
    padding: 9px 15px;
    font-size: 1rem;
    line-height: 1.2;
    color: #1f2937;
    background-color: #fff;
    border: 1px solid #cfd8e3;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
}

.nav-item:hover,
.nav-item-bis:hover,
.btn:hover {
    background-color: #f3f6fb;
    transform: translateY(-1px);
}

.tab-container,
.list-tabs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    margin: 0 auto 20px auto;
}

.list-tabs button {
    padding: 8px 16px;
    border-radius: 10px;
    border: 1px solid #cfd8e3;
    background-color: #fff;
    color: #111827;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
}

.list-tabs button:hover {
    background-color: #f3f6fb;
}

.tab-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 120px;
    max-width: 220px;
    min-height: 62px;
    padding: 10px 18px;
    font-size: 0.95rem;
    border: 1px solid #cfd8e3;
    border-radius: 18px;
    text-decoration: none;
    text-align: center;
    background-color: #fff;
    color: #111827;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.2s, color 0.2s, transform 0.18s ease;
}

.tab-link.active {
    background-color: #2563eb;
    color: #fff;
    font-weight: 700;
    border-color: #2563eb;
}

.tab-link:hover {
    background-color: #f3f6fb;
    transform: translateY(-1px);
}

/* ============================
   MAIN CONTENT
============================ */
.main-content {
    display: flex;
    justify-content: center;
    padding-left: 1rem;
    padding-right: 1rem;
}

.main-container {
    width: 100%;
    min-width: 300px;
    max-width: 1300px;
    margin: 18px auto 28px auto;
    padding: 1.5rem;
    background-color: var(--main-bg);
    border: 1px solid rgba(219, 227, 238, 0.9);
    border-radius: 18px;
    box-shadow: var(--shadow-soft);
    color: var(--text-main);
    text-align: center;
    overflow-x: auto;
    overflow-y: hidden;
}

.main-container h1 {
    margin-top: 0;
    margin-bottom: 1.2rem;
    font-size: 2rem;
    line-height: 1.15;
    font-weight: 700;
    color: var(--text-main);
}

.main-container p {
    max-width: none;
}

/* ============================
   INTRO / TITRES
============================ */
.introduction {
    display: block;
    font-family: "Lobster", sans-serif;
    font-size: 2rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 1.5rem;
    color: #1f2937;
}

/* ============================
   MENU EXERCICES / TUILES
============================ */
.navigation-autres,
.exercises-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin: 2rem 0;
    padding: 0 10px;
}

/* IMPORTANT :
   les templates themes_list / chapitres_list / exercises_list
   utilisent .tile-container > .menu-tile en enfants directs */
.tile-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 320px));
    justify-content: center; /* centre le bloc complet */
    gap: 20px;
}

.tile-container > .menu-tile,
.tile-container > .exercise-tile {
    width: 100%;
    min-width: 0;
}

.exercise-tile {
    width: 100%;
}

.menu-tile {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-width: 0;
    min-height: 74px;
    padding: 1rem 0.8rem;
    text-align: center;
    text-decoration: none;
    color: #111827;
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1.35;
    word-break: break-word;
    background: #fff;
    border: 1px solid #d7e1ec;
    border-radius: 18px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.06);
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s, border-color 0.2s;
}

.menu-tile:hover {
    background: #f8fbff;
    transform: translateY(-3px);
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.10);
    border-color: var(--border-strong);
}

.menu-tile:active {
    transform: translateY(0);
}

/* ============================
   TABLEAUX / STATS / HISTORIQUE
============================ */
table {
    border-collapse: separate;
    border-spacing: 0;
}

.stats-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

#historyTable,
.stats-table,
.stats-table-centered {
    width: 100%;
    background: #fff;
    border: 2px solid var(--border-soft);
    border-radius: 18px;
    overflow: hidden;
    border-collapse: separate;
    border-spacing: 0;
}

.stats-table-centered {
    max-width: 500px;
    margin: 20px 0;
    text-align: center;
}

#historyTable th,
#historyTable td,
.stats-table th,
.stats-table td,
.stats-table-centered th,
.stats-table-centered td {
    padding: 10px 12px;
    vertical-align: top;
    border-right: 1px solid var(--border-strong);
    border-bottom: 1px solid var(--border-strong);
}

#historyTable th:last-child,
#historyTable td:last-child,
.stats-table th:last-child,
.stats-table td:last-child,
.stats-table-centered th:last-child,
.stats-table-centered td:last-child {
    border-right: none;
}

#historyTable tbody tr:last-child td,
.stats-table tbody tr:last-child td,
.stats-table-centered tbody tr:last-child td {
    border-bottom: none;
}

#historyTable thead th,
.stats-table th,
.stats-table-centered th {
    background: #f3f4f6;
    color: #374151;
    font-weight: 700;
    text-align: center;
}

#historyTable tbody tr:nth-child(even),
.stats-table tbody tr:nth-child(even),
.stats-table-centered tbody tr:nth-child(even) {
    background: #fafafa;
}

.stats-table td.latex,
#historyTable td.latex {
    font-size: 0.8em;
    word-wrap: break-word;
    white-space: normal;
    max-width: 400px;
}

td.math,
#historyTable td.math {
    max-width: 400px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
}

#historyTable td.latex,
#historyTable td.math {
    max-width: 320px;
}

#historyTable td:nth-child(2),
#historyTable td:nth-child(4) {
    min-width: 220px;
}

#historyTable mjx-container {
    max-width: 100%;
}

/* ============================
   MATHJAX GLOBAL
============================ */
mjx-container[jax="CHTML"][display="true"] {
    text-align: center !important;
    margin: 0.3rem 0 !important;
}

.MathJax {
    text-align: center !important;
}

/* ============================
   EXERCISES
============================ */
.exercise-page,
.exercise-card {
    max-width: 820px;
    margin: 0 auto;
}

.exercise-card {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.exercise-toolbar,
.exercise-controls-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 22px;
    padding: 14px 16px;
    background: #f8fbff;
    border: 1px solid var(--border-soft);
    border-radius: 16px;
}

.toolbar-group,
.exercise-control-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.toolbar-label,
.exercise-control-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

.toolbar-select,
.exercise-select {
    height: 42px;
    min-width: 150px;
    padding: 0 0.8rem;
    border: 1px solid #cfd8e3;
    border-radius: 10px;
    background: #fff;
    font-size: 0.98rem;
    color: var(--text-main);
}

.action-btn,
.exercise-btn {
    min-height: 42px;
    padding: 0.7rem 1rem;
    border: 1px solid transparent;
    font-size: 0.98rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.primary-btn,
.exercise-btn-primary {
    background: var(--accent);
    color: #fff;
}

.primary-btn:hover,
.exercise-btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.secondary-btn,
.exercise-btn-secondary {
    background: #fff;
    color: var(--text-main);
    border-color: #cfd8e3;
}

.secondary-btn:hover,
.exercise-btn-secondary:hover {
    background: #f3f6fb;
    transform: translateY(-1px);
}

.icon-btn {
    min-width: 42px;
    padding-left: 0.8rem;
    padding-right: 0.8rem;
}

.statement-card,
.exercise-statement-card,
.exercise-form-card,
.exercise-answer-card,
.correction-card,
.exercise-correction-card {
    background: var(--card-bg);
    border: 1px solid var(--border-soft);
    border-radius: 18px;
    padding: 20px;
    box-shadow: var(--shadow-card);
    margin-bottom: 18px;
}

.card-label,
.exercise-card-title {
    display: inline-block;
    margin-bottom: 12px;
    padding: 6px 12px;
    border-radius: 999px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.exercise-statement {
    width: 100%;
    margin: 0;
    font-size: 1.35rem;
    line-height: 1.7;
    text-align: center;
    max-width: 100%;
}

.exercise-form-card,
.exercise-answer-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.answer-label,
.exercise-answer-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

.exercise-answer-input,
.exercise-form input[type="text"] {
    width: 100%;
    max-width: 340px;
    padding: 14px 16px;
    font-size: 1.1rem;
    border: 1px solid #cfd5e1;
    border-radius: 12px;
    background: #fff;
    text-align: center;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.exercise-answer-input:focus,
.exercise-form input[type="text"]:focus {
    border-color: #93c5fd;
    box-shadow: 0 0 0 4px rgba(147, 197, 253, 0.25);
}

.exercise-actions,
.exercise-answer-actions,
.exercise-form {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 0;
}

.keyboard-wrapper,
.exercise-keyboard {
    width: 100%;
    max-width: 520px;
    padding: 12px;
    border: 1px dashed #cbd5e1;
    border-radius: 12px;
    background: #f8fafc;
}

.feedback-box,
.exercise-feedback {
    margin: 0 0 18px 0;
    padding: 14px 16px;
    border-radius: 14px;
    font-weight: 700;
    font-size: 1rem;
    text-align: center;
    border: 1px solid transparent;
}

.feedback-success,
.feedback-ok {
    background: var(--success-bg);
    color: var(--success);
    border-color: #86efac;
}

.feedback-error,
.feedback-ko {
    background: var(--error-bg);
    color: var(--error);
    border-color: #fca5a5;
}

.inline-action,
.exercise-inline-form {
    text-align: center;
    margin-bottom: 18px;
}

.correction-card,
.exercise-correction-card {
    text-align: left;
}

.correction-card h3,
.exercise-correction-card h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.1rem;
    color: var(--text-main);
}

.correction-steps,
.exercise-correction-steps {
    margin: 0 0 20px 22px;
    padding: 0;
}

.correction-steps li,
.exercise-correction-steps li {
    margin-bottom: 12px;
    padding: 12px 14px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
}

.final-result,
.exercise-final-result {
    margin-bottom: 18px;
    padding: 14px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    text-align: center;
    font-weight: 700;
}

.exercise-statement-card,
.statement-card,
.exercise-correction-card,
.correction-card,
.exercise-correction-steps li,
.correction-steps li,
.exercise-final-result,
.final-result {
    overflow-x: auto;
    overflow-y: hidden;
}

.exercise-statement mjx-container,
.exercise-correction-card mjx-container,
.correction-card mjx-container,
.exercise-correction-steps li mjx-container,
.correction-steps li mjx-container,
.exercise-final-result mjx-container,
.final-result mjx-container {
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    display: block !important;
    -webkit-overflow-scrolling: touch;
}

.exercise-correction-card mjx-container[jax="CHTML"][display="true"],
.correction-card mjx-container[jax="CHTML"][display="true"],
.exercise-correction-steps li mjx-container[jax="CHTML"][display="true"],
.correction-steps li mjx-container[jax="CHTML"][display="true"] {
    text-align: left !important;
    white-space: nowrap !important;
}

.exercise-final-result mjx-container[jax="CHTML"][display="true"],
.final-result mjx-container[jax="CHTML"][display="true"] {
    text-align: center !important;
    white-space: nowrap !important;
}

/* ============================
   FILTERS FORM
============================ */
.filters-form {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    flex-wrap: wrap;
    width: 100%;
}

/* ============================
   FORMULAIRES GÉNÉRAUX
============================ */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select,
textarea {
    background: #fff;
    color: var(--text-main);
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    padding: 10px 12px;
}

/* ============================
   MESSAGES DJANGO
============================ */
.main-container > div[style*="margin-bottom:20px"] > div[style*="padding:12px 16px"] {
    border: 1px solid var(--border-soft) !important;
    background: var(--surface-2) !important;
    color: var(--text-main) !important;
}

/* ============================
   DARK MODE
============================ */
body.dark {
    color: #e5e7eb;
    background: linear-gradient(180deg, #111827 0%, #0f172a 100%);
    --main-bg: rgba(17, 24, 39, 0.96);
    --card-bg: #1f2937;
    --text-main: #e5e7eb;
    --text-muted: #94a3b8;
    --border-soft: #334155;
    --border-strong: #475569;
    --surface-1: #1f2937;
    --surface-2: #1f2937;
    --surface-3: #111827;
    --surface-4: #111827;
    --table-row-alt: #182230;
    --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.35);
}

body.dark .topbar {
    color: #e5e7eb;
}

body.dark .main-container {
    background-color: rgba(17, 24, 39, 0.96);
    color: #e5e7eb;
    border-color: #334155;
}

body.dark .nav-item,
body.dark .nav-item-bis,
body.dark .btn,
body.dark .tab-link,
body.dark .list-tabs button,
body.dark .toolbar-select,
body.dark .exercise-select,
body.dark .exercise-answer-input,
body.dark .secondary-btn,
body.dark .exercise-btn-secondary,
body.dark input[type="text"],
body.dark input[type="number"],
body.dark input[type="email"],
body.dark input[type="password"],
body.dark select,
body.dark textarea {
    background: #111827;
    color: #e5e7eb;
    border-color: #475569;
}

body.dark .nav-item:hover,
body.dark .nav-item-bis:hover,
body.dark .btn:hover,
body.dark .tab-link:hover,
body.dark .list-tabs button:hover,
body.dark .secondary-btn:hover,
body.dark .exercise-btn-secondary:hover {
    background: #1e293b;
}

body.dark .tab-link.active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

body.dark .statement-card,
body.dark .exercise-statement-card,
body.dark .exercise-form-card,
body.dark .exercise-answer-card,
body.dark .correction-card,
body.dark .exercise-correction-card,
body.dark .stats-table,
body.dark .stats-table-centered,
body.dark #historyTable,
body.dark .menu-tile,
body.dark .exercise-toolbar,
body.dark .exercise-controls-bar {
    background: #1f2937;
    color: #e5e7eb;
    border-color: #334155;
}

body.dark .correction-steps li,
body.dark .exercise-correction-steps li,
body.dark .keyboard-wrapper,
body.dark .exercise-keyboard,
body.dark .stats-table th,
body.dark .stats-table-centered th,
body.dark #historyTable th {
    background: #111827;
    color: #e5e7eb;
    border-color: #334155;
}

body.dark .stats-table td,
body.dark .stats-table-centered td,
body.dark #historyTable td {
    border-color: #475569;
}

body.dark #historyTable tbody tr:nth-child(even),
body.dark .stats-table tbody tr:nth-child(even),
body.dark .stats-table-centered tbody tr:nth-child(even) {
    background: #182230;
}

body.dark .final-result,
body.dark .exercise-final-result {
    background: #172554;
    border-color: #1d4ed8;
    color: #e5e7eb;
}

body.dark .card-label,
body.dark .exercise-card-title {
    background: #1e3a8a;
    color: #dbeafe;
}

body.dark .menu-tile {
    color: #e5e7eb;
}

body.dark .menu-tile:hover {
    background: #243244;
}

body.dark .badge-name {
    color: #eee;
}

body.dark .badge-pct {
    fill: #fff;
}

body.dark .introduction,
body.dark h1,
body.dark h2,
body.dark h3,
body.dark h4,
body.dark h5,
body.dark h6 {
    color: #e5e7eb;
}

/* ============================
   RESPONSIVE
============================ */
@media (max-width: 980px) {
    .tile-container {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .topbar .container {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 0.6rem;
        padding: 0;
    }

    .header-left {
        display: none;
    }

    .header-right {
        min-width: 0;
        justify-content: center;
        flex-wrap: wrap;
    }

    .header-center {
        justify-content: center;
    }

    .header-right svg {
        transform: scale(0.8);
        transform-origin: center;
    }
}

@media (max-width: 768px) {
    .tile-container {
        grid-template-columns: 1fr;
    }

    .nav,
    .tab-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        width: 100%;
    }

    .nav > a,
    .nav > form {
        width: 100%;
        margin: 0;
    }

    .nav-item,
    .nav-item-bis,
    .tab-link,
    .btn {
        display: block;
        width: 100%;
        margin: 0;
        text-align: center;
    }

    .tab-container {
        max-width: 420px;
    }

    .tab-link {
        max-width: none;
    }
}

@media (max-width: 700px) {
    .main-container {
        padding: 1rem;
        border-radius: 14px;
    }

    .main-container h1 {
        font-size: 1.5rem;
    }

    .exercise-toolbar,
    .exercise-controls-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar-group,
    .exercise-control-form {
        width: 100%;
        justify-content: center;
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-select,
    .exercise-select,
    .action-btn,
    .exercise-btn {
        width: 100%;
        max-width: 280px;
    }

    .exercise-statement {
        font-size: 1.05rem;
        line-height: 1.5;
    }

    .exercise-answer-input,
    .exercise-form input[type="text"] {
        max-width: 100%;
    }

    .exercise-actions,
    .exercise-answer-actions,
    .exercise-form {
        width: 100%;
        flex-direction: column;
        align-items: center;
    }

    .statement-card,
    .exercise-statement-card,
    .exercise-form-card,
    .exercise-answer-card,
    .correction-card,
    .exercise-correction-card {
        padding: 16px 12px;
    }

    .exercise-page,
    .exercise-card {
        max-width: 100%;
    }

    .exercise-statement mjx-container,
    .exercise-correction-card mjx-container,
    .correction-card mjx-container,
    .correction-steps li,
    .exercise-correction-steps li,
    .final-result,
    .exercise-final-result {
        font-size: 1.05rem;
        line-height: 1.5;
    }

    .exercise-statement mjx-container[jax="CHTML"][display="true"],
    .correction-steps li mjx-container[jax="CHTML"][display="true"],
    .exercise-correction-steps li mjx-container[jax="CHTML"][display="true"],
    .final-result mjx-container[jax="CHTML"][display="true"],
    .exercise-final-result mjx-container[jax="CHTML"][display="true"] {
        font-size: 0.7em !important;
    }

    .introduction {
        font-size: 1.6rem;
    }

    .menu-tile {
        font-size: 1.05rem;
        min-height: 68px;
    }

    .filters-form {
        flex-direction: column;
        align-items: center;
        gap: 0.8rem;
    }

    .filters-form label,
    .filters-form select {
        width: 90%;
        max-width: 300px;
        text-align: center;
    }

    .stats-table-centered {
        width: 95%;
        max-width: 100%;
    }
}

@media (max-width: 600px) {
    body {
        background-attachment: scroll;
    }

    .header-center {
        gap: 0.45rem;
    }

    .greeting-text {
        font-size: 1.3rem;
    }

    .logout-btn img {
        width: 42px;
    }

    #dark-mode-toggle {
        width: 38px;
        height: 38px;
        font-size: 24px;
        flex-basis: 38px;
    }
}

@media (max-width: 480px) {
    .nav,
    .tab-container {
        grid-template-columns: 1fr;
    }
}

/* ============================
   PATCH FINAL TABLEAU ÉLÈVES
============================ */
.stats-table-centered.students-table {
    width: 100% !important;
    max-width: 700px !important;
    min-width: 200px;
    background: #ffffff;
    border: 2px solid #bfc8d6 !important;
    border-radius: 16px;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    overflow: hidden;
    box-shadow: none;
}

.stats-table-centered.students-table th,
.stats-table-centered.students-table td {
    padding: 16px 18px;
    vertical-align: middle;
    text-align: center;
    border-right: 1px solid #8f99a8 !important;
    border-bottom: 1px solid #8f99a8 !important;
}

.stats-table-centered.students-table th:last-child,
.stats-table-centered.students-table td:last-child {
    border-right: none !important;
}

.stats-table-centered.students-table tbody tr:last-child td {
    border-bottom: none !important;
}

.stats-table-centered.students-table thead th,
.stats-table-centered.students-table > tbody > tr:first-child > th {
    background: #f4f6f8;
    color: #334155;
    font-weight: 700;
}

.stats-table-centered.students-table tbody tr {
    background: #ffffff;
}

.stats-table-centered.students-table tbody tr:nth-child(even) {
    background: #fbfcfd;
}

body.dark .stats-table-centered.students-table {
    background: #1f2937;
    border-color: #475569 !important;
}

body.dark .stats-table-centered.students-table th,
body.dark .stats-table-centered.students-table td {
    border-right-color: #475569 !important;
    border-bottom-color: #475569 !important;
}

body.dark .stats-table-centered.students-table thead th,
body.dark .stats-table-centered.students-table > tbody > tr:first-child > th {
    background: #111827;
    color: #e5e7eb;
}

body.dark .stats-table-centered.students-table tbody tr {
    background: #1f2937;
}

body.dark .stats-table-centered.students-table tbody tr:nth-child(even) {
    background: #182230;
}


/* ============================
   TEACHER DASHBOARD
============================ */
.teacher-actions-row {
    margin-top: 10px;
    margin-bottom: 22px;
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.teacher-panel,
.teacher-subpanel {
    background: var(--card-bg);
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    padding: 16px;
    margin: 18px auto;
    max-width: 820px;
}

.teacher-subpanel {
    margin-top: 16px;
    text-align: left;
}

.teacher-filter-form,
.teacher-create-form,
.teacher-inline-actions,
.teacher-form-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.teacher-filter-form {
    margin-bottom: 14px;
}

.teacher-chip-list {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.teacher-chip {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 999px;
    background: #eaf2ff;
    border: 1px solid #bfdbfe;
    text-decoration: none;
    color: #1d4ed8;
    font-size: 0.92rem;
}

.teacher-chip:hover {
    background: #dbeafe;
}

.teacher-card-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 20px;
}

.teacher-card {
    background: var(--card-bg);
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    padding: 18px;
    text-align: left;
}

.teacher-card-muted {
    background: #f8fafc;
}

.teacher-card-header {
    margin-bottom: 12px;
    font-size: 1.05rem;
}

.teacher-card-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.teacher-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px 14px;
    margin: 10px 0 14px 0;
}

.teacher-checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.teacher-student-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.teacher-student-link {
    font-weight: 600;
}

.teacher-student-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.teacher-completed-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.teacher-completed-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
}

.teacher-score {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.teacher-empty-state {
    margin-top: 20px;
    padding: 18px;
    border: 1px dashed var(--border-soft);
    border-radius: 14px;
    background: #f8fafc;
}

.teacher-muted {
    color: var(--text-muted);
}

body.dark .teacher-panel,
body.dark .teacher-subpanel,
body.dark .teacher-card {
    background: #1f2937;
    border-color: #334155;
}

body.dark .teacher-card-muted,
body.dark .teacher-empty-state {
    background: #111827;
    border-color: #334155;
}

body.dark .teacher-chip {
    background: #172554;
    border-color: #2563eb;
    color: #dbeafe;
}

body.dark .teacher-chip:hover {
    background: #1e3a8a;
}

body.dark .teacher-score,
body.dark .teacher-muted {
    color: #94a3b8;
}

@media (max-width: 768px) {
    .teacher-actions-row,
    .teacher-filter-form,
    .teacher-create-form,
    .teacher-inline-actions,
    .teacher-form-actions {
        flex-direction: column;
    }

    .teacher-checkbox-grid {
        grid-template-columns: 1fr;
    }
}

#historyTable {
    min-width: 1850px;
    table-layout: auto;
}

#historyTable th:nth-child(2),
#historyTable td:nth-child(2) {
    min-width: 520px;
    width: 42%;
}


/* ============================
   BADGES (light + dark)
============================ */
.badge-level {
    font-family: 'Indie_Flower';
    font-size: 1.2em;
    font-weight: bold;
    margin-bottom: 4px;
    color: #111827; /* noir en mode normal */
}

.badge-icon {
    font-size: 20px;
    color: #111827;
}

/* DARK MODE */
body.dark .badge-level,
body.dark .badge-icon {
    color: #ffffff;
}