/* ==========================================================================
   Mon Cahier Numérique — styles communes (layout, typographie, composants)
   Palette sobre : blanc, bleu, gris clair et couleurs de statut.
   ========================================================================== */

:root {
    --blue-900: #12305c;
    --blue-700: #1f4f96;
    --blue-600: #2563c9;
    --blue-500: #3b7ddd;
    --blue-100: #e3edfb;
    --blue-50: #f2f7fe;

    --gray-900: #1d2533;
    --gray-700: #3e4a5c;
    --gray-600: #5b6678;
    --gray-400: #a3acba;
    --gray-300: #cfd5de;
    --gray-200: #e4e8ee;
    --gray-100: #f1f3f7;
    --white: #ffffff;

    --green: #1e7b4f;
    --green-bg: #e3f4ea;
    --orange: #a65b00;
    --orange-bg: #fff1dc;
    --red: #b42318;
    --red-bg: #fde8e6;
    --purple: #5b3cc4;
    --purple-bg: #eeeafc;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(18, 48, 92, .06);
    --shadow: 0 2px 8px rgba(18, 48, 92, .08), 0 1px 2px rgba(18, 48, 92, .06);
    --focus: 0 0 0 3px rgba(59, 125, 221, .45);

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --container: 1180px;
}

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

/* L'attribut hidden doit toujours l'emporter sur les display des composants. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.55;
    color: var(--gray-900);
    background: var(--gray-100);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

img { max-width: 100%; height: auto; }

a { color: var(--blue-600); text-decoration: none; }
a:hover { color: var(--blue-700); }

h1, h2, h3 { line-height: 1.25; color: var(--gray-900); margin: 0 0 .6em; }
h1 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 1em; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }

.visually-hidden {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
    position: absolute; left: 1rem; top: -3rem; z-index: 100;
    background: var(--blue-700); color: #fff; padding: .5rem 1rem; border-radius: var(--radius-sm);
}
.skip-link:focus { top: .5rem; }

.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 16px; }
.container-wide { width: 100%; max-width: 1500px; margin: 0 auto; padding: 0 16px; }

.icon { flex-shrink: 0; vertical-align: middle; }

/* ---------- En-tête ---------- */

.site-header {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    position: sticky; top: 0; z-index: 50;
}

.header-inner { display: flex; align-items: center; gap: 1rem; min-height: 60px; }

.brand {
    display: flex; align-items: center; gap: .6rem;
    text-decoration: none; color: var(--blue-900); font-weight: 700; font-size: 1.08rem;
    margin-right: auto;
}

.brand-logo {
    width: 30px; height: 34px; border-radius: 3px 6px 6px 3px;
    background:
        linear-gradient(to right, transparent 7px, #e06666 7px, #e06666 9px, transparent 9px),
        repeating-linear-gradient(to bottom, #fffdf7 0, #fffdf7 6px, #b9d3f1 6px, #b9d3f1 7px);
    border: 2px solid var(--blue-600);
    box-shadow: -3px 0 0 var(--blue-700);
}

.main-nav { display: flex; align-items: center; gap: 1.25rem; }
.main-nav ul { list-style: none; display: flex; gap: .25rem; margin: 0; padding: 0; }
.main-nav a {
    display: block; padding: .45rem .75rem; border-radius: var(--radius-sm);
    color: var(--gray-700); text-decoration: none; font-weight: 500;
}
.main-nav a:hover { background: var(--blue-50); color: var(--blue-700); }
.main-nav a.active { background: var(--blue-100); color: var(--blue-700); }

.user-box { display: flex; align-items: center; gap: .75rem; padding-left: 1rem; border-left: 1px solid var(--gray-200); }
.user-name { display: flex; flex-direction: column; line-height: 1.2; font-weight: 600; font-size: .92rem; }
.user-name small { font-weight: 400; color: var(--gray-600); }

.nav-toggle {
    display: none; background: none; border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
    padding: .4rem; color: var(--gray-700); cursor: pointer;
}

@media (max-width: 900px) {
    .nav-toggle { display: inline-flex; }
    .main-nav {
        display: none; position: absolute; left: 0; right: 0; top: 60px;
        flex-direction: column; align-items: stretch; gap: .5rem;
        background: var(--white); border-bottom: 1px solid var(--gray-200);
        padding: .75rem 16px 1rem; box-shadow: var(--shadow);
    }
    .main-nav.open { display: flex; }
    .main-nav ul { flex-direction: column; }
    .user-box { border-left: 0; border-top: 1px solid var(--gray-200); padding: .75rem 0 0; justify-content: space-between; }
}

/* ---------- Contenu ---------- */

.site-main { flex: 1; padding: 1.75rem 0 3rem; }
.site-main:focus { outline: none; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-head h1 { margin: 0; }
.page-head p { margin: .3rem 0 0; color: var(--gray-600); }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.breadcrumb { font-size: .9rem; color: var(--gray-600); margin-bottom: .75rem; }
.breadcrumb a { color: var(--gray-600); }

.card {
    background: var(--white); border: 1px solid var(--gray-200); border-radius: var(--radius);
    padding: 1.25rem; box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 1.25rem; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.card-title h2 { margin: 0; }

.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.muted { color: var(--gray-600); }
.small { font-size: .875rem; }
.empty { color: var(--gray-600); text-align: center; padding: 1.5rem 1rem; }
.text-right { text-align: right; }

/* ---------- Boutons ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .55rem 1rem; border-radius: var(--radius-sm); border: 1px solid transparent;
    font: inherit; font-weight: 600; font-size: .95rem; line-height: 1.2;
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background-color .15s, border-color .15s, color .15s;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue-600); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-700); color: #fff; }
.btn-secondary { background: var(--white); color: var(--blue-700); border-color: var(--gray-300); }
.btn-secondary:hover:not(:disabled) { background: var(--blue-50); border-color: var(--blue-500); color: var(--blue-700); }
.btn-ghost { background: transparent; color: var(--gray-700); }
.btn-ghost:hover:not(:disabled) { background: var(--gray-100); color: var(--gray-900); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover:not(:disabled) { background: #176340; color: #fff; }
.btn-danger { background: var(--white); color: var(--red); border-color: #f1b8b2; }
.btn-danger:hover:not(:disabled) { background: var(--red-bg); color: var(--red); }
.btn-sm { padding: .35rem .65rem; font-size: .85rem; }
.btn-lg { padding: .75rem 1.3rem; font-size: 1.05rem; }
.btn-block { width: 100%; }

.inline-form { display: inline; }

/* ---------- Formulaires ---------- */

.form-grid { display: grid; gap: 1.1rem; }
.form-row { display: grid; gap: 1.1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.field { display: flex; flex-direction: column; gap: .35rem; }
.field label, .field .label { font-weight: 600; font-size: .93rem; color: var(--gray-700); }
.field .hint { font-size: .84rem; color: var(--gray-600); }
.field .error { font-size: .85rem; color: var(--red); }

.input, .select, .textarea {
    width: 100%; font: inherit; font-size: 1rem; color: var(--gray-900);
    background: var(--white); border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
    padding: .6rem .75rem;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--blue-500); box-shadow: var(--focus); outline: none; }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--red); }
.textarea { min-height: 7rem; resize: vertical; }

.checkbox { display: flex; align-items: flex-start; gap: .55rem; font-weight: 500; cursor: pointer; }
.checkbox input { width: 1.1rem; height: 1.1rem; margin-top: .2rem; accent-color: var(--blue-600); }

.checklist {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .4rem .9rem;
    max-height: 320px; overflow: auto; padding: .75rem; border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm); background: var(--gray-100);
}

.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; padding-top: .5rem; }

.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1.25rem; }
.filters .field { min-width: 170px; flex: 1 1 170px; }
.filters .btn { flex: 0 0 auto; }

/* ---------- Alertes ---------- */

.alert {
    display: flex; align-items: flex-start; gap: .65rem;
    padding: .8rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1.25rem; border: 1px solid;
}
.alert p { margin: 0; flex: 1; }
.alert ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.alert .icon { margin-top: .15rem; }
.alert-success { background: var(--green-bg); border-color: #b7e0c8; color: #14532d; }
.alert-error { background: var(--red-bg); border-color: #f5c2bd; color: #7a1a12; }
.alert-info { background: var(--blue-50); border-color: var(--blue-100); color: var(--blue-900); }
.alert-warning { background: var(--orange-bg); border-color: #f6d3a1; color: #6b3b00; }
.alert-close { background: none; border: 0; font-size: 1.3rem; line-height: 1; cursor: pointer; color: inherit; padding: 0 .2rem; }

/* ---------- Pastilles de statut ---------- */

.badge {
    display: inline-block; padding: .18rem .6rem; border-radius: 999px;
    font-size: .78rem; font-weight: 700; letter-spacing: .01em; white-space: nowrap;
    background: var(--gray-200); color: var(--gray-700);
}
.badge-todo { background: var(--blue-100); color: var(--blue-700); }
.badge-draft { background: var(--orange-bg); color: var(--orange); }
.badge-submitted { background: var(--purple-bg); color: var(--purple); }
.badge-corrected, .badge-published { background: var(--green-bg); color: var(--green); }
.badge-archived { background: var(--gray-200); color: var(--gray-600); }
.badge-late { background: var(--red-bg); color: var(--red); }
.badge-subject { background: var(--blue-50); color: var(--blue-700); border: 1px solid var(--blue-100); }

/* ---------- Tableaux ---------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .94rem; }
.table th, .table td { padding: .7rem .75rem; text-align: left; border-bottom: 1px solid var(--gray-200); vertical-align: middle; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--gray-600); background: var(--gray-100); }
.table tr:last-child td { border-bottom: 0; }
.table .actions { display: flex; gap: .4rem; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Statistiques ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat {
    background: var(--white); border: 1px solid var(--gray-200); border-radius: var(--radius);
    padding: 1rem 1.1rem; box-shadow: var(--shadow-sm);
}
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--blue-900); line-height: 1.1; }
.stat-label { font-size: .88rem; color: var(--gray-600); margin-top: .25rem; }

.progress { height: 8px; background: var(--gray-200); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--blue-500); border-radius: 999px; }

/* ---------- Pagination ---------- */

.pagination { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: center; margin-top: 1.25rem; }
.page-link {
    padding: .4rem .75rem; border-radius: var(--radius-sm); border: 1px solid var(--gray-300);
    background: var(--white); text-decoration: none; color: var(--gray-700); font-size: .9rem;
}
.page-link.current { background: var(--blue-600); border-color: var(--blue-600); color: #fff; }
.page-link.disabled { color: var(--gray-400); }

/* ---------- Pied de page ---------- */

.site-footer { background: var(--white); border-top: 1px solid var(--gray-200); padding: 1.25rem 0; font-size: .88rem; color: var(--gray-600); }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; }
.footer-inner p { margin: 0; }

/* ---------- Contenu riche (énoncés) ---------- */

.rich-content { line-height: 1.65; overflow-wrap: anywhere; }
.rich-content > :first-child { margin-top: 0; }
.rich-content img { border-radius: var(--radius-sm); margin: .5rem 0; }
.rich-content table { border-collapse: collapse; margin: .75rem 0; }
.rich-content td, .rich-content th { border: 1px solid var(--gray-300); padding: .35rem .6rem; }
.rich-content blockquote { margin: .75rem 0; padding: .5rem 1rem; border-left: 4px solid var(--blue-100); background: var(--blue-50); }
.rich-content sup, .rich-content sub { line-height: 0; }

/* ---------- Pages d'erreur ---------- */

.error-page { max-width: 560px; margin: 3rem auto; text-align: center; }
.error-code { font-size: 4rem; font-weight: 800; color: var(--blue-100); line-height: 1; margin-bottom: .5rem; }

@media (max-width: 600px) {
    .site-main { padding-top: 1.25rem; }
    .card { padding: 1rem; }
    .page-head { align-items: flex-start; }
    .stat-value { font-size: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- Chrono ---------- */

.badge-chrono { display: inline-flex; align-items: center; gap: .25rem; background: #fdf0e1; color: #9a4d00; }
.time-spent { display: inline-flex; align-items: center; gap: .3rem; font-size: .85rem; color: var(--gray-600); white-space: nowrap; }
.time-running { color: #9a4d00; font-weight: 600; }
