:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1b1f24;
    --muted: #5d6673;
    --border: #dfe3e8;
    --primary: #1f5eff;
    --primary-hover: #1749cc;
    --danger: #c62828;
    --success-bg: #e8f5e9; --success-text: #1b5e20;
    --error-bg: #fdecea;   --error-text: #8e1b1b;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1216; --surface: #171b21; --text: #e8ebef; --muted: #9aa4b1; --border: #2a3039;
        --primary: #5b8cff; --primary-hover: #7aa2ff;
        --success-bg: #12301a; --success-text: #a5e3b0;
        --error-bg: #3a1616;   --error-text: #ffb4ab;
        --shadow: none;
    }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 1rem; }
.muted { color: var(--muted); margin-top: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Barre du haut */
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .75rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--primary); }
.userbox { display: flex; align-items: center; gap: .6rem; position: relative; }
.userbox form { margin: 0; }
.userbox-menu { display: flex; align-items: center; gap: .3rem; }
.userbox-menu .btn { padding: .35rem .6rem; font-size: .8rem; }
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; }
.avatar-fallback { display: grid; place-items: center; background: var(--primary); color: #fff; font-weight: 700; font-size: .85rem; width: 30px; height: 30px; border-radius: 50%; }
.username { font-weight: 600; }
@media (max-width: 560px) { .username { display: none; } }

/* Mise en page */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.auth-wrap { min-height: calc(100vh - 60px); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem 1rem; }
.auth-wrap > .alert { width: 100%; max-width: 420px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.auth-card { width: 100%; max-width: 420px; }
.narrow { max-width: 640px; }
.grid { display: grid; grid-template-columns: 340px 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }
.page-head { margin-bottom: 1.25rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

/* Formulaires */
label { display: block; font-weight: 600; font-size: .9rem; margin: .9rem 0 .3rem; }
input, select, textarea {
    width: 100%; padding: .6rem .7rem; font: inherit; color: var(--text);
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
textarea { resize: vertical; }
.hint { display: block; color: var(--muted); font-size: .8rem; margin-top: .35rem; }
.form-actions { display: flex; gap: .5rem; margin-top: 1.25rem; }
.danger-zone { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* Boutons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    padding: .6rem 1rem; font: inherit; font-weight: 600; border-radius: 8px;
    border: 1px solid transparent; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; margin-top: 1.25rem; }
.btn-social { width: 100%; background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-social:hover { background: var(--bg); }
.social { display: grid; gap: .6rem; margin-top: 1.25rem; }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .85rem; margin: 1.25rem 0 .25rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.switch { text-align: center; margin: 1.25rem 0 0; color: var(--muted); }

/* Alertes */
.alert { padding: .7rem .9rem; border-radius: 8px; margin: .75rem 0; font-size: .92rem; }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }

/* Liste */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.filters input { flex: 1 1 180px; width: auto; }
.filters select { width: auto; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.desc { color: var(--muted); font-size: .88rem; margin-top: .2rem; max-width: 46ch; }
.meta { color: var(--muted); font-size: .78rem; margin-top: .25rem; }
.nowrap { white-space: nowrap; }
.actions { text-align: right; }
.empty { color: var(--muted); text-align: center; padding: 2rem 0; }
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-todo { background: #eef1f5; color: #3d4652; }
.badge-in_progress { background: #fff4d6; color: #7a5300; }
.badge-done { background: #e3f6e8; color: #1b5e20; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1rem; }
.back { text-decoration: none; }

/* Mobile : la liste passe en cartes empilées */
.grid > * { min-width: 0; }
@media (max-width: 640px) {
    .container { padding: 1rem; }
    .card { padding: 1.1rem; }
    .filters select, .filters .btn { flex: 1 1 45%; }
    thead { display: none; }
    table, tbody, tr, td { display: block; width: 100%; }
    tr { border-bottom: 1px solid var(--border); padding: .75rem 0; }
    td { border: 0; padding: .15rem 0; }
    td.actions { text-align: left; padding-top: .5rem; }
    td[data-label]::before { content: attr(data-label) " : "; color: var(--muted); font-size: .85rem; }
}

/* Lien « Mot de passe oublié » aligné avec le libellé */
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.small-link { font-size: .85rem; text-decoration: none; }
.small-link:hover { text-decoration: underline; }

/* Timeline */
.timeline-card { min-width: 0; margin-bottom: 1.25rem; }
.timeline-legend { display: flex; justify-content: space-between; gap: 1rem; color: var(--muted); font-size: .85rem; margin: -.35rem 0 1rem; }
.timeline-legend > span:first-child { display: inline-flex; align-items: center; gap: .45rem; }
.timeline-legend-swatch { display: inline-block; width: 13px; height: 13px; border-radius: 3px; background: #31a852; }
.timeline-chart { display: grid; gap: .35rem; max-height: 480px; overflow-y: auto; padding: .2rem .25rem .2rem 0; }
.timeline-row { display: grid; grid-template-columns: minmax(105px, 145px) minmax(0, 1fr) 42px; align-items: center; gap: .75rem; min-height: 34px; }
.timeline-month-label { display: flex; justify-content: space-between; gap: .5rem; color: var(--muted); font-size: .85rem; }
.timeline-year { color: var(--text); font-weight: 700; }
.timeline-track { height: 24px; min-width: 0; overflow: hidden; border-radius: 4px; background: var(--bg); }
.timeline-month-block { height: 100%; min-width: 5px; border-radius: inherit; background: #8ccf9e; }
.timeline-month-block.is-start { box-shadow: inset 3px 0 #176b32; }
.timeline-month-block.is-current { background: #31a852; color: #fff; }
.timeline-days { color: var(--muted); font-size: .8rem; text-align: right; white-space: nowrap; }
.timeline-not-started { margin: 0; padding: 1rem; border-radius: 8px; background: var(--bg); color: var(--muted); }

@media (max-width: 560px) {
    .timeline-row { grid-template-columns: minmax(90px, 120px) minmax(0, 1fr) 34px; gap: .55rem; }
    .timeline-month-label { font-size: .78rem; }
    .timeline-year { font-size: .75rem; }
    .timeline-days { font-size: .72rem; }
}

.home-rings .rings { display:block; width:100%; max-width:420px; margin:0 auto 1rem; }
.home-rings .rings text { fill: var(--text, #e8ecf4); }

label.checkbox { display:flex; align-items:center; gap:.5rem; margin-top:.9rem; font-weight:500; cursor:pointer; }
label.checkbox input[type=checkbox] { width:auto; margin:0; }

.home-rings h2.rings-title { text-align:center !important; font-weight:700; margin:0 0 .5rem; overflow-wrap:anywhere; }
