/* ahmBDD26 — feuille de style unique, servie localement (aucune ressource externe : CSP stricte) */

:root {
    --chart-bar: #1f7a4d;
    --row-actifs: #ffffff;
    --row-invalides: #fff6c2;
    --row-etudiants: #dcebfa;
    --row-sanspap: #f1e0f5;
    --row-refused: #fbe0de;
    --row-unsubscribed: #e6e6e6;
    --bg: #f4f6f4;
    --surface: #ffffff;
    --text: #1d2420;
    --muted: #5d6a63;
    --border: #d5ddd8;
    --brand: #1f7a4d;
    --brand-strong: #155c39;
    --on-brand: #ffffff;
    --danger: #b3261e;
    --ok-bg: #e5f4ea;
    --ok-text: #155c39;
    --error-bg: #fbe9e7;
    --error-text: #8c1d18;
    --wait-bg: #fff4dc;
    --wait-text: #7a5300;
    --radius: 8px;
    --focus: 0 0 0 3px rgba(31, 122, 77, .35);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121614;
        --surface: #1b211e;
        --text: #e6ece8;
        --muted: #9fada5;
        --border: #313b36;
        --brand: #3fae76;
        --brand-strong: #5cc48f;
        --on-brand: #0d1a13;
        --danger: #f2a49e;
        --ok-bg: #173323;
        --ok-text: #9fe0bb;
        --error-bg: #3a1b19;
        --error-text: #f6b8b2;
        --wait-bg: #3a2e12;
        --wait-text: #f3cf7c;
        --chart-bar: #38a06c;
        --row-actifs: #1b211e;
        --row-invalides: #3a3517;
        --row-etudiants: #172a3d;
        --row-sanspap: #33203a;
        --row-refused: #3d1d1b;
        --row-unsubscribed: #2a2d2b;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--brand); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
.muted, .help { color: var(--muted); }
.help { font-size: .875rem; margin: -.25rem 0 .75rem; }
.mono, .codes { font-family: ui-monospace, Menlo, Consolas, monospace; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* Pages invitées (connexion, invitation…) */
.guest { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.guest-card {
    width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 2rem 1.5rem;
}
.guest-header { margin-bottom: 1.5rem; text-align: center; }
.guest-header .logo { max-width: 100%; height: auto; }
.brand { display: inline-flex; align-items: center; gap: .5rem; margin: 0; color: var(--brand); text-decoration: none; }
.brand .logo { display: block; height: 50px; width: auto; }
.brand-tag {
    font-weight: 700; font-size: .8rem; letter-spacing: .08em; color: var(--brand);
    border: 1px solid var(--brand); border-radius: 4px; padding: .05rem .35rem;
}
.print-head .logo { display: block; height: auto; }

/* Application */
.topbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: .75rem 16px;
}
.menu { display: flex; flex-wrap: wrap; gap: .25rem; flex: 1; }
.menu a { padding: .4rem .75rem; border-radius: var(--radius); text-decoration: none; color: var(--text); }
.menu a.active, .menu a:hover { background: var(--ok-bg); color: var(--ok-text); }
.logout { display: flex; align-items: center; gap: .75rem; margin-left: auto; }
.who { color: var(--muted); font-size: .875rem; }
.page { max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px 3rem; }
.panel {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.25rem; margin-bottom: 1rem;
}
.actions { display: flex; flex-wrap: wrap; gap: .75rem; }
.panel > h2:first-child, .panel > section > h2:first-child { margin-top: 0; }

/* Formulaires */
.form { display: flex; flex-direction: column; max-width: 480px; }
.form label { font-weight: 600; margin-bottom: .25rem; }
.form input, .form select { margin-bottom: .75rem; }
.form-inline { max-width: 260px; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="tel"],
input[type="date"], input[type="number"], select, textarea {
    font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius); padding: .55rem .7rem; width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: none; box-shadow: var(--focus); }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 600; margin-bottom: .75rem; }

.button {
    display: inline-block; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
    background: var(--brand); color: var(--on-brand); border: 1px solid var(--brand);
    border-radius: var(--radius); padding: .55rem 1rem;
}
.button:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.button-ghost { background: transparent; color: var(--brand); }
.button-ghost:hover { background: var(--ok-bg); color: var(--ok-text); }
.button-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.button-danger:hover { background: var(--error-bg); color: var(--error-text); border-color: var(--danger); }

/* Messages */
.alert { border-radius: var(--radius); padding: .75rem 1rem; margin: 0 0 1rem; }
.alert p { margin: 0; }
.alert-success { background: var(--ok-bg); color: var(--ok-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }
.alert-warning { background: var(--wait-bg); color: var(--wait-text); }
.ok { color: var(--ok-text); font-weight: 600; }
.details { margin-top: 1rem; }
.details summary { cursor: pointer; color: var(--brand); }

/* Double authentification */
.otp { font-size: 1.6rem; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; }
.qr { display: inline-block; background: #ffffff; padding: 12px; border-radius: var(--radius); }
.qr svg { display: block; width: 200px; height: 200px; }
.codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .4rem; padding: 0; list-style: none; }
.codes li { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem .6rem; }

/* Tableaux */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: .875rem; color: var(--muted); }
.table tbody tr:last-child td { border-bottom: 0; }
.tag { display: inline-block; font-size: .8rem; border-radius: 999px; padding: .1rem .6rem; }
.tag-on { background: var(--ok-bg); color: var(--ok-text); }
.tag-off { background: var(--error-bg); color: var(--error-text); }
.tag-wait { background: var(--wait-bg); color: var(--wait-text); }

[hidden] { display: none !important; }
textarea { resize: vertical; }
.ko { color: var(--danger); font-weight: 600; }
.pre { white-space: pre-line; }
.button-small { padding: .3rem .7rem; font-size: .875rem; }
.button-muted { background: var(--bg); color: var(--muted); border-color: var(--border); }
.button-muted:hover { background: var(--border); color: var(--text); border-color: var(--border); }

/* Bénéficiaires : liste et filtres */
.filters-main { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.filters-main input[type="search"] { flex: 1 1 220px; width: auto; }
.filters-main select { width: auto; }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-top: .75rem; }
.filters-grid fieldset, .documents, .groups { border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .75rem; margin: 0; }
.filters-grid legend, .documents legend, .groups legend { font-weight: 600; padding: 0 .25rem; }
.filters-grid .check, .documents .check, .groups .check { font-weight: 400; margin: .25rem 0; }
.sub-legend { display: block; font-weight: 600; margin-top: .5rem; }
.sizes { display: grid; grid-template-columns: repeat(3, 1fr); }
.list-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; }
.legend { color: var(--muted); font-size: .875rem; display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; }
.swatch { display: inline-block; width: 14px; height: 14px; border: 1px solid var(--border); border-radius: 3px; margin-left: .5rem; }
.table-beneficiaries td a { color: inherit; font-weight: 600; }
.row-actifs, .swatch.row-actifs { background: var(--row-actifs); }
.row-invalides, .swatch.row-invalides { background: var(--row-invalides); }
.row-etudiants, .swatch.row-etudiants { background: var(--row-etudiants); }
.row-sanspap, .swatch.row-sanspap { background: var(--row-sanspap); }
.row-refused, .swatch.row-refused { background: var(--row-refused); }
.row-unsubscribed, .swatch.row-unsubscribed { background: var(--row-unsubscribed); color: var(--muted); }
.badges { width: 60px; }
.badge {
    display: inline-block; min-width: 1.5rem; text-align: center; font-weight: 700; font-size: .8rem; text-decoration: none;
    background: var(--brand); color: var(--on-brand); border-radius: 4px; padding: .05rem .3rem;
}
.badge-exempt { background: var(--danger); color: #ffffff; }
.row-actions form { margin: 0; }

/* Bénéficiaires : formulaire et fiche */
.beneficiary-form legend { font-weight: 700; font-size: 1.05rem; padding: 0 .25rem; }
.beneficiary-form label { display: block; font-weight: 600; margin: .5rem 0 .25rem; }
.beneficiary-form .check { display: flex; font-weight: 400; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }
.grid + .grid { margin-top: .5rem; }
.span-2 { grid-column: span 2; }
@media (max-width: 520px) { .span-2 { grid-column: auto; } }
.repeater-row { border-bottom: 1px dashed var(--border); padding-bottom: .5rem; margin-bottom: .5rem; }
.rav { font-size: 1.05rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.two-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.danger-zone summary { color: var(--danger); }

/* Synthèse : tuiles chiffrées et graphiques (SVG côté serveur) */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi {
    display: flex; flex-direction: column; gap: .15rem; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem 1.25rem; color: var(--text); text-decoration: none;
}
a.kpi:hover { border-color: var(--brand); }
.kpi-label { color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 2.5rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-hint { color: var(--muted); font-size: .85rem; }
.chart { margin: 0; }
.chart-svg { width: 100%; height: auto; display: block; font: 15px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.chart-bar { fill: var(--chart-bar); }
.chart-hit { fill: transparent; }
.chart-row:hover .chart-hit { fill: var(--bg); }
.chart-label { fill: var(--muted); }
.chart-value { fill: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-axis { stroke: var(--border); stroke-width: 1; }

/* Interactions (public/js) */
.field-error { color: var(--danger); font-size: .875rem; font-weight: 600; margin: -.4rem 0 .6rem; }
fieldset > .field-error { margin: .4rem 0 0; }
[aria-invalid="true"] { border-color: var(--danger) !important; box-shadow: 0 0 0 2px var(--error-bg); }
.field-warning { background: var(--wait-bg); color: var(--wait-text); border-radius: var(--radius); padding: .4rem .6rem; font-size: .875rem; margin: .25rem 0 0; }
.field-warning a { color: inherit; font-weight: 700; }
.age { display: inline-block; color: var(--muted); font-size: .85rem; margin: -.4rem 0 .5rem; }
.rules { list-style: none; padding: 0; margin: -.25rem 0 .75rem; font-size: .875rem; color: var(--muted); }
.rules li::before { content: "○ "; }
.rules li.rule-ok { color: var(--ok-text); }
.rules li.rule-ok::before { content: "✔ "; }
.inline-form { display: flex; gap: .4rem; align-items: center; margin: 0; }
.inline-form select { width: auto; padding: .3rem .5rem; }
.row-remove { display: flex; align-items: flex-end; padding-bottom: .5rem; }
tr[data-href] { cursor: pointer; }
tr[data-href]:hover td { box-shadow: inset 0 0 0 9999px rgba(127, 127, 127, .08); }
[aria-busy="true"] { opacity: .6; cursor: progress; }
.dialog {
    width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); padding: 1rem;
}
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: .75rem; }
.dialog-head h2 { margin: 0; font-size: 1.1rem; }
.dialog .panel { margin-bottom: .75rem; }
.dialog .form { max-width: none; }

/* Impression */
.print-page { padding: 16px; max-width: 1100px; margin: 0 auto; }
.table-print td, .table-print th { white-space: normal; }
@media print {
    :root { color-scheme: light; --bg: #ffffff; --surface: #ffffff; --text: #000000; --muted: #444444; --border: #999999; }
    .no-print, .topbar { display: none !important; }
    body { font-size: 11pt; }
    .panel, .table-wrap { border: 0; padding: 0; }
    .table th, .table td { padding: .25rem .4rem; }
    .table-print td:nth-last-child(-n+2) { min-width: 6rem; }
    a { color: inherit; text-decoration: none; }
}
