/* ========================================================= *
 *  Python Interactif — Athénée Royal Robert Campin
 *  Palette inspirée de la charte du manuel (orange/bleu/vert)
 * ========================================================= */

:root {
    /* ================================================================
     *  Palette neutre de base (couleur par défaut, non liée à un cours)
     * ================================================================ */
    --c-primary: #475569;           /* slate-600 : neutre, pro, lisible */
    --c-primary-dark: #334155;      /* slate-700 */
    --c-primary-soft: #f1f5f9;      /* slate-100 */
    --c-accent: #fbbf24;            /* ambre pour highlights */

    /* Tokens sémantiques — ces variables bougent en dark mode */
    --c-bg: #f6f8fb;
    --c-surface: #ffffff;
    --c-surface-alt: #fafbfc;
    --c-text: #1f2430;
    --c-text-muted: #4a5160;
    --c-text-faint: #7c8495;
    --c-border: #d8dde6;
    --c-border-soft: #eceff4;

    /* Couleurs sémantiques (constantes) */
    --c-success: #2f855a;           /* vert succès */
    --c-success-soft: #e6f4ea;
    --c-danger: #c53030;            /* rouge erreur */
    --c-danger-soft: #fbeaea;
    --c-warning: #d97706;
    --c-warning-soft: #fff4e0;
    --c-info: #2b6cb0;
    --c-info-soft: #e8f0fa;

    /* Aliases de compatibilité (anciens noms encore utilisés) */
    --c-blue: var(--c-info);
    --c-blue-soft: var(--c-info-soft);
    --c-green: var(--c-success);
    --c-green-soft: var(--c-success-soft);
    --c-yellow: var(--c-accent);
    --c-red: var(--c-danger);
    --c-grey-900: var(--c-text);
    --c-grey-700: var(--c-text-muted);
    --c-grey-500: var(--c-text-faint);
    --c-grey-300: var(--c-border);
    --c-grey-100: var(--c-border-soft);
    --c-grey-50: var(--c-bg);
    --c-white: var(--c-surface);

    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(15,20,30,0.08);
    --shadow-md: 0 4px 12px rgba(15,20,30,0.08);
    --shadow-lg: 0 10px 28px rgba(15,20,30,0.12);

    --font-sans: "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
}

/* ================================================================
 *  Mode sombre (activé via html[data-theme="dark"])
 * ================================================================ */
html[data-theme="dark"] {
    --c-bg: #0b111e;
    --c-surface: #141c2c;
    --c-surface-alt: #1b2436;
    --c-text: #e2e8f0;
    --c-text-muted: #a9b4c2;
    --c-text-faint: #6b7689;
    --c-border: #2a364b;
    --c-border-soft: #1a2234;

    /* Primary neutre un peu moins brillant en dark */
    --c-primary: #7c8ba1;
    --c-primary-dark: #546278;
    --c-primary-soft: #1e293b;

    --c-success: #4ade80;
    --c-success-soft: #14532d;
    --c-danger: #f87171;
    --c-danger-soft: #4c1d1d;
    --c-info: #60a5fa;
    --c-info-soft: #1e3a5f;
    --c-warning: #fbbf24;
    --c-warning-soft: #3b2706;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 28px rgba(0,0,0,0.55);
}

/* ================================================================
 *  Thèmes par cours (override --c-primary uniquement)
 *  Appliqué via une classe sur un wrapper contextuel
 * ================================================================ */
.theme-python {
    --c-primary: #2f855a;           /* vert Python */
    --c-primary-dark: #1f6e43;
    --c-primary-soft: #e6f4ea;
    --c-accent: #ffd43b;
}
html[data-theme="dark"] .theme-python {
    --c-primary: #22c55e;           /* vert riche lisible (pas fluo) */
    --c-primary-dark: #15803d;      /* vert foncé pour dégradés/hover */
    --c-primary-soft: #0e3a21;
    --c-accent: #ffd43b;
}

.theme-web {
    --c-primary: #2563eb;           /* bleu HTML/CSS */
    --c-primary-dark: #1d4ed8;
    --c-primary-soft: #e0edff;
    --c-accent: #f59e0b;
}
html[data-theme="dark"] .theme-web {
    --c-primary: #3b82f6;
    --c-primary-dark: #1e40af;
    --c-primary-soft: #0b2247;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--c-grey-50);
    color: var(--c-grey-900);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.55;
}

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

h1, h2, h3, h4 { color: var(--c-grey-900); font-weight: 700; line-height: 1.25; }
h1 { font-size: 1.85rem; color: var(--c-primary); margin: 0 0 .6em; }
h2 { font-size: 1.4rem; color: var(--c-primary); margin: 1.4em 0 .6em; }
h3 { font-size: 1.15rem; color: var(--c-blue); margin: 1.2em 0 .4em; }
h4 { font-size: 1rem; margin: 1em 0 .3em; }

code { font-family: var(--font-mono); font-size: 0.92em; background: var(--c-border-soft); padding: 1px 5px; border-radius: 4px; color: #a02f69; }
html[data-theme="dark"] code { color: #f472b6; background: #2a1c2c; }
/* Dans un bloc <pre>, on reste sur la couleur du bloc (pas de rose) */
pre code,
html[data-theme="dark"] pre code { color: inherit; background: transparent; padding: 0; }
pre { font-family: var(--font-mono); background: #21252e; color: #eef1f5; padding: 14px 18px; border-radius: var(--radius-sm); overflow-x: auto; font-size: .9em; line-height: 1.5; margin: .8em 0; }
pre code { background: transparent; padding: 0; color: inherit; }

blockquote { border-left: 4px solid var(--c-blue); background: var(--c-blue-soft); padding: 10px 16px; margin: 1em 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

table { border-collapse: collapse; margin: 1em 0; background: var(--c-white); box-shadow: var(--shadow-sm); border-radius: var(--radius-sm); overflow: hidden; width: 100%; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--c-grey-300); text-align: left; font-size: .95em; }
th { background: var(--c-primary-soft); color: var(--c-primary-dark); }

/* ========== LAYOUT ========== */
.topbar {
    background: var(--c-white);
    border-bottom: 1px solid var(--c-grey-300);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar .brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--c-primary);
    font-weight: 700;
    font-size: 1.1rem;
    text-decoration: none;
}
.topbar .brand .logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-primary) 55%, var(--c-accent) 55%, var(--c-accent) 100%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    font-weight: 800;
    text-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.topbar nav { display: flex; gap: 8px; align-items: center; }
.topbar nav a, .topbar nav .user-chip {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    color: var(--c-grey-700);
    text-decoration: none;
    font-weight: 500;
    font-size: .95em;
}
.topbar nav a:hover { background: var(--c-border-soft); color: var(--c-text); text-decoration: none; }
.topbar nav .user-chip { background: var(--c-primary-soft); color: var(--c-primary-dark); font-weight: 600; }

.theme-toggle {
    background: transparent;
    border: 1px solid var(--c-border);
    color: var(--c-text-muted);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.05rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    line-height: 1;
    padding: 0;
    margin-left: 4px;
    transition: background .15s, border-color .15s, color .15s;
}
.theme-toggle:hover { background: var(--c-border-soft); color: var(--c-text); border-color: var(--c-primary); }
.theme-toggle .theme-icon-light,
.theme-toggle .theme-icon-dark { display: none; }
html[data-theme="light"] .theme-toggle .theme-icon-dark,
html:not([data-theme="dark"]) .theme-toggle .theme-icon-dark { display: inline; }
html[data-theme="dark"] .theme-toggle .theme-icon-light { display: inline; }

.container { max-width: 1100px; margin: 0 auto; padding: 28px; }
.container-narrow { max-width: 720px; margin: 0 auto; padding: 28px; }
.container-wide { max-width: 1400px; margin: 0 auto; padding: 28px; }

.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 14px; font-weight: 500; }
.flash-success { background: var(--c-green-soft); color: var(--c-green); border-left: 4px solid var(--c-green); }
.flash-error   { background: #fbeaea; color: var(--c-red); border-left: 4px solid var(--c-red); }
.flash-info    { background: var(--c-blue-soft); color: var(--c-blue); border-left: 4px solid var(--c-blue); }

/* ========== LOGIN ========== */
.auth-wrap { min-height: calc(100vh - 70px); display: flex; align-items: center; justify-content: center; padding: 40px 20px; }
.auth-card { background: var(--c-white); padding: 36px 38px; border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 420px; }
.auth-card h1 { text-align: center; margin-bottom: .2em; }
.auth-card .subtitle { text-align: center; color: var(--c-grey-500); margin-bottom: 22px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .88em; font-weight: 600; color: var(--c-grey-700); margin-bottom: 4px; }
.field input[type="text"], .field input[type="password"], .field input[type="email"], .field select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1em;
    color: var(--c-text);
    background: var(--c-surface-alt);
    transition: border-color .15s, box-shadow .15s;
}
html[data-theme="light"] .field input[type="text"],
html[data-theme="light"] .field input[type="password"],
html[data-theme="light"] .field input[type="email"],
html[data-theme="light"] .field select,
html:not([data-theme="dark"]) .field input[type="text"],
html:not([data-theme="dark"]) .field input[type="password"],
html:not([data-theme="dark"]) .field input[type="email"],
html:not([data-theme="dark"]) .field select { background: var(--c-surface); }
.field input:focus, .field select:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(47,133,90,.20); }
.field .hint { font-size: .82em; color: var(--c-grey-500); margin-top: 3px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: .95em;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, transform .05s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--c-primary); color: white; }
.btn-primary:hover { background: var(--c-primary-dark); color: white; }
.btn-secondary { background: var(--c-grey-100); color: var(--c-grey-700); }
.btn-secondary:hover { background: var(--c-grey-300); color: var(--c-grey-900); }
.btn-success { background: var(--c-green); color: white; }
.btn-danger  { background: var(--c-red); color: white; }
.btn-block { display: flex; width: 100%; }
.btn-sm { padding: 5px 10px; font-size: .85em; }

/* ========== DASHBOARD ========== */
.greeting { color: var(--c-grey-700); margin-bottom: 24px; }

.modules-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.module-card {
    background: var(--c-white);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--c-grey-300);
    text-decoration: none;
    color: inherit;
    display: block;
    transition: transform .12s, box-shadow .12s, border-color .12s;
}
.module-card:hover:not(.course-wip) { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--c-primary); text-decoration: none; }
.course-wip { cursor: not-allowed; opacity: .72; }
.course-wip:hover { box-shadow: var(--shadow-sm); }
.course-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.module-card .number { color: var(--c-primary); font-weight: 700; font-size: .85em; letter-spacing: .04em; text-transform: uppercase; }
.module-card h3 { color: var(--c-grey-900); margin: 4px 0 8px; font-size: 1.2em; }
.module-card p { color: var(--c-grey-500); margin: 0; font-size: .92em; }
.module-card .meta { margin-top: 16px; display: flex; gap: 16px; font-size: .85em; color: var(--c-grey-700); }
.module-card .meta span { display: inline-flex; align-items: center; gap: 4px; }

.progress-bar { height: 6px; background: var(--c-grey-100); border-radius: 3px; margin-top: 12px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: linear-gradient(90deg, var(--c-green), #6cc158); transition: width .3s; }

.empty-state { background: var(--c-white); padding: 40px; text-align: center; border-radius: var(--radius); color: var(--c-grey-500); border: 2px dashed var(--c-grey-300); }

/* ========== MODULE VIEW ========== */
.module-header { background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-primary-dark) 100%); color: white; padding: 32px 28px; border-radius: var(--radius); margin-bottom: 24px; box-shadow: var(--shadow-md); }
.module-header .number { font-size: .85em; opacity: .85; letter-spacing: .1em; text-transform: uppercase; }
.module-header h1 { color: white; margin: 4px 0 6px; font-size: 2em; }
.module-header .subtitle { opacity: .95; font-size: 1.05em; }
.module-header .meta-row { display: flex; gap: 22px; margin-top: 14px; font-size: .9em; opacity: .9; }

.objectives { background: var(--c-primary-soft); padding: 18px 22px; border-radius: var(--radius-sm); margin-bottom: 22px; border-left: 4px solid var(--c-primary); }
.objectives h4 { margin: 0 0 8px; color: var(--c-primary-dark); font-size: .95em; text-transform: uppercase; letter-spacing: .05em; }
.objectives ul { margin: 0; padding-left: 20px; }
.objectives li { margin: 4px 0; }

/* Section tabs */
.section-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--c-grey-300);
    margin: 24px 0 16px;
    overflow-x: auto;
}
.section-tab {
    padding: 12px 22px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    font-family: inherit;
    font-size: .95em;
    font-weight: 600;
    color: var(--c-grey-500);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.section-tab:hover { color: var(--c-grey-700); }
.section-tab.active { color: var(--c-primary); border-bottom-color: var(--c-primary); }
.section-tab .icon { font-size: 1.1em; }

.section-panel { background: var(--c-white); padding: 26px 30px; border-radius: var(--radius); box-shadow: var(--shadow-sm); display: none; }
.section-panel.active { display: block; }
.section-panel ul, .section-panel ol { padding-left: 22px; }
.section-panel li { margin: 4px 0; }

/* ========== EXERCISES ========== */
.exercise {
    background: var(--c-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 22px 26px;
    margin-bottom: 18px;
    border-left: 4px solid var(--c-grey-300);
    transition: border-color .2s;
}
.exercise.is-correct  { border-left-color: var(--c-green); }
.exercise.is-wrong    { border-left-color: var(--c-red); }

.exercise .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.exercise .tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: .72em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 3px 9px;
    border-radius: 12px;
}
.tag-qcm  { background: var(--c-blue-soft); color: var(--c-blue); }
.tag-fill { background: #fff7d6; color: #8a6a00; }
.tag-code { background: var(--c-primary-soft); color: var(--c-primary-dark); }
.tag-html { background: #e0edff; color: #1e40af; }
html[data-theme="dark"] .tag-html { background: #0b2247; color: #93c5fd; }

.exercise h3 { margin: 0; font-size: 1.08em; color: var(--c-grey-900); }
.exercise .statement { margin: 10px 0 14px; color: var(--c-grey-700); }
.exercise .statement p:first-child { margin-top: 0; }

/* QCM */
.qcm-options { display: grid; gap: 8px; }
.qcm-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--c-grey-300);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background .12s, border-color .12s;
}
.qcm-option:hover { background: var(--c-grey-100); }
.qcm-option input { margin: 0; }
.qcm-option.is-correct { background: var(--c-green-soft); border-color: var(--c-green); }
.qcm-option.is-wrong   { background: #fbeaea; border-color: var(--c-red); }

/* Fill */
.fill-template {
    font-family: var(--font-mono);
    background: #21252e;
    color: #eef1f5;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    font-size: .95em;
    line-height: 1.7;
    white-space: pre;
}
.fill-blank {
    display: inline-block;
    min-width: 90px;
    padding: 2px 8px;
    margin: 0 2px;
    border: 1px dashed var(--c-yellow);
    border-radius: 4px;
    background: rgba(247,201,72,.15);
    color: var(--c-yellow);
    font-family: var(--font-mono);
    font-size: .95em;
    text-align: center;
}
.fill-blank:focus { outline: none; background: rgba(247,201,72,.3); color: white; border-color: var(--c-yellow); }

/* Code editor */
.code-editor-wrap { border: 1px solid var(--c-grey-300); border-radius: var(--radius-sm); overflow: hidden; }
.code-editor {
    width: 100%;
    min-height: 160px;
    padding: 12px 14px;
    font-family: var(--font-mono);
    font-size: .92em;
    line-height: 1.55;
    background: #21252e;
    color: #eef1f5;
    border: none;
    resize: vertical;
    tab-size: 4;
}
.code-editor:focus { outline: 2px solid var(--c-primary); outline-offset: -2px; }
.code-output {
    background: #11141a;
    color: #eef1f5;
    padding: 12px 14px;
    font-family: var(--font-mono);
    font-size: .88em;
    min-height: 40px;
    max-height: 280px;
    overflow: auto;
    white-space: pre-wrap;
    border-top: 1px solid #2b313c;
}
.code-output .ok { color: #8ed87c; }
.code-output .ko { color: #ff8d8d; }
.code-output .info { color: #9ec9ff; }

.exercise-actions { margin-top: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.feedback { padding: 10px 14px; border-radius: var(--radius-sm); font-size: .92em; margin-top: 12px; }
.feedback.ok { background: var(--c-green-soft); color: var(--c-green); border-left: 3px solid var(--c-green); }
.feedback.ko { background: #fbeaea; color: var(--c-red); border-left: 3px solid var(--c-red); }
.feedback pre { background: transparent; color: inherit; margin: 6px 0 0; padding: 0; font-size: .88em; }

.hints { margin-top: 10px; }
.hints summary { cursor: pointer; color: var(--c-blue); font-weight: 600; font-size: .9em; }
.hints ul { margin: 8px 0 0; padding-left: 22px; }

.correction-slot { margin-top: 12px; }
.correction {
    background: var(--c-primary-soft);
    border-left: 3px solid var(--c-primary);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-top: 6px;
}
.correction summary {
    cursor: pointer;
    color: var(--c-primary-dark);
    font-weight: 600;
    font-size: .92em;
    list-style: none;
}
.correction summary::before { content: "▸ "; display: inline-block; transition: transform .15s; }
.correction[open] summary::before { transform: rotate(90deg); }
.correction-body { margin-top: 10px; color: var(--c-grey-900); font-size: .92em; }
.correction-body p { margin: 4px 0; }
.correction-body ul { margin: 6px 0 10px; padding-left: 22px; }
.correction-body mark {
    background: var(--c-accent);
    color: #5a4700;
    padding: 0 4px;
    border-radius: 3px;
    font-weight: 600;
}
.correction-code {
    background: #21252e;
    color: #eef1f5;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: .88em;
    line-height: 1.5;
    overflow-x: auto;
    margin: 4px 0 8px;
    white-space: pre;
}
.correction-note { font-style: italic; color: var(--c-grey-700); font-size: .88em; }

/* ================================================================
 *  Exercices HTML (éditeur split + preview iframe)
 * ================================================================ */
.html-editor-wrap {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-top: 8px;
}
.html-editor-col, .html-preview-col {
    display: flex;
    flex-direction: column;
    min-height: 280px;
}
.html-editor {
    flex: 1;
    padding: 12px 14px;
    font-family: var(--font-mono);
    font-size: .88em;
    line-height: 1.5;
    background: #21252e;
    color: #eef1f5;
    border: none;
    resize: vertical;
    tab-size: 2;
    min-height: 280px;
}
.html-editor:focus { outline: 2px solid var(--c-primary); outline-offset: -2px; }
.html-preview-col { background: white; border-left: 1px solid var(--c-border); }
.html-preview-label {
    padding: 5px 12px;
    background: var(--c-border-soft);
    color: var(--c-text-muted);
    font-size: .8em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 1px solid var(--c-border);
}
.html-preview {
    flex: 1;
    width: 100%;
    border: none;
    background: white;
    min-height: 240px;
}
.html-test-output {
    margin-top: 10px;
    padding: 12px 14px;
    background: var(--c-border-soft);
    border-radius: var(--radius-sm);
    font-size: .9em;
    color: var(--c-text);
}
.html-test-output:empty { display: none; }
.html-test-line { padding: 4px 0; }
.html-test-line.ok { color: var(--c-success); }
.html-test-line.ko { color: var(--c-danger); font-weight: 600; }
.html-test-detail {
    margin-left: 18px;
    margin-top: 2px;
    font-weight: normal;
    font-size: .88em;
    color: var(--c-text-muted);
    font-style: italic;
}

@media (max-width: 860px) {
    .html-editor-wrap { grid-template-columns: 1fr; }
    .html-preview-col { border-left: none; border-top: 1px solid var(--c-border); }
}

/* ================================================================
 *  Navigation en bas de section (précédent / suivant)
 * ================================================================ */
.section-nav {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--c-border);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.section-nav-slot { display: flex; }
.section-nav-slot-next { justify-content: flex-end; }

.section-nav-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 12px 16px;
    background: var(--c-surface-alt);
    color: var(--c-text);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
    transition: border-color .15s, transform .05s, background .15s;
    max-width: 360px;
    min-width: 160px;
}
.section-nav-btn:hover {
    border-color: var(--c-primary);
    background: var(--c-primary-soft);
    text-decoration: none;
}
.section-nav-btn:active { transform: translateY(1px); }
.section-nav-btn-next { align-items: flex-end; text-align: right; }

.section-nav-dir {
    font-size: .78em;
    font-weight: 600;
    color: var(--c-primary);
    letter-spacing: .05em;
    text-transform: uppercase;
}
.section-nav-label {
    font-size: .95em;
    font-weight: 600;
    color: var(--c-text);
}

@media (max-width: 600px) {
    .section-nav { grid-template-columns: 1fr; }
    .section-nav-slot-next { justify-content: flex-start; }
    .section-nav-btn { max-width: none; width: 100%; }
    .section-nav-btn-next { align-items: flex-start; text-align: left; }
}

/* ========== ADMIN ========== */
.admin-layout { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 66px); }
.admin-sidebar { background: #0f172a; color: #cbd5e1; padding: 22px 0; }
.admin-sidebar .brand { padding: 0 22px 16px; color: white; font-weight: 700; font-size: 1.1em; border-bottom: 1px solid #1e293b; margin-bottom: 12px; }
.admin-sidebar a {
    display: block;
    padding: 10px 22px;
    color: #cbd5e1;
    text-decoration: none;
    border-left: 3px solid transparent;
    font-size: .95em;
}
.admin-sidebar a:hover { background: rgba(255,255,255,.05); color: white; text-decoration: none; }
.admin-sidebar a.active { background: rgba(100,116,139,.22); color: white; border-left-color: var(--c-primary); }
.admin-content { padding: 28px 32px; background: var(--c-grey-50); }
.admin-content h1 { font-size: 1.5rem; color: var(--c-grey-900); margin-top: 0; }

.data-table { width: 100%; background: var(--c-white); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.data-table th { background: var(--c-grey-100); color: var(--c-grey-700); padding: 12px 14px; text-align: left; font-size: .82em; text-transform: uppercase; letter-spacing: .06em; }
.data-table td { padding: 10px 14px; border-top: 1px solid var(--c-grey-100); font-size: .95em; }
.data-table tr:hover td { background: var(--c-grey-50); }
.data-table .actions { display: flex; gap: 6px; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: .78em; font-weight: 600; }
.badge-admin { background: var(--c-primary-soft); color: var(--c-primary-dark); }
.badge-student { background: var(--c-blue-soft); color: var(--c-blue); }
.badge-inactive { background: var(--c-border-soft); color: var(--c-text-faint); }

.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: .78em;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
}
.pill-success { background: var(--c-success-soft); color: var(--c-success); }
.pill-danger  { background: var(--c-danger-soft);  color: var(--c-danger); }
.pill-warning { background: var(--c-warning-soft); color: var(--c-warning); }
.pill-info    { background: var(--c-info-soft);    color: var(--c-info); }
html[data-theme="dark"] .pill-success { color: #86efac; }
html[data-theme="dark"] .pill-danger  { color: #fca5a5; }

.card { background: var(--c-white); border-radius: var(--radius); padding: 22px 26px; box-shadow: var(--shadow-sm); margin-bottom: 18px; }
.card h2 { margin-top: 0; color: var(--c-grey-900); }

.row-actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

/* Loading overlay */
.pyodide-loading {
    position: fixed;
    top: 16px;
    right: 16px;
    background: var(--c-grey-900);
    color: white;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: .88em;
    z-index: 999;
    display: none;
}
.pyodide-loading.visible { display: flex; align-items: center; gap: 10px; }
.pyodide-loading .spinner {
    width: 14px; height: 14px; border-radius: 50%;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: white;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Footer */
.site-footer {
    margin-top: 40px;
    padding: 18px 0;
    border-top: 1px solid var(--c-grey-300);
    background: var(--c-white);
    color: var(--c-grey-500);
    font-size: .85em;
}
.site-footer-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.site-footer strong { color: var(--c-primary); font-weight: 700; }
.version-tag {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 8px;
    background: var(--c-grey-100);
    color: var(--c-grey-700);
    border-radius: 10px;
    font-size: .78em;
    font-family: var(--font-mono);
    font-weight: 500;
}

/* Responsive */
@media (max-width: 740px) {
    .container, .container-narrow, .container-wide { padding: 16px; }
    .admin-layout { grid-template-columns: 1fr; }
    .admin-sidebar { padding: 10px 0; }
    .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 10px; }
    .section-tabs { overflow-x: scroll; }
}
