/*
 * DTM Dashboard — palette inspirée de l'identité Bradesco
 * (rouge institutionnel, dégradé rouge vers magenta réservé au bandeau).
 * Aucune ressource externe : police système, compatible CSP stricte.
 */
:root {
    --red: #cc092f;
    --red-deep: #9e0723;
    --magenta: #b81570;
    --red-soft: #eea2b1;
    --red-tint: #fcebee;
    --ink: #26272b;
    --graphite: #5d5f67;
    --mute: #8a8c94;
    --paper: #f4f4f6;
    --surface: #ffffff;
    --line: #e1e1e6;
    --line-strong: #c9c9d0;
    --track: #ececf0;
    --inactive: #d3d4da;
    --ok: #1d7a4e;
    --ok-tint: #e5f4ec;
    --warn: #a35400;
    --warn-tint: #fdf1e2;
    --info: #2d5b88;
    --info-tint: #e8eff7;

    --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --font-display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --step--1: 0.8125rem;
    --step-0: 0.9375rem;
    --step-1: 1.125rem;
    --step-2: 1.5rem;
    --step-5: clamp(3.5rem, 8vw, 5.75rem);
    --radius: 6px;
    --wrap: 1440px;
    --gutter: clamp(1rem, 3vw, 2rem);
}

@media (prefers-color-scheme: dark) {
    :root {
        --red: #ff4d6a;
        --red-deep: #ff7a8f;
        --red-soft: #8a3445;
        --red-tint: #3a1b22;
        --ink: #ececf0;
        --graphite: #b4b6be;
        --mute: #8e9099;
        --paper: #18181b;
        --surface: #222226;
        --line: #34343a;
        --line-strong: #4a4a52;
        --track: #2e2e34;
        --inactive: #4a4a52;
        --ok: #5fc794;
        --ok-tint: #18352a;
        --warn: #f0a24b;
        --warn-tint: #3a2a15;
        --info: #85b3e0;
        --info-tint: #1c2a3a;
    }
}

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

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

body {
    margin: 0;
    font-family: var(--font);
    font-size: var(--step-0);
    line-height: 1.5;
    color: var(--ink);
    background: var(--paper);
}

a { color: var(--red); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { color: var(--red-deep); }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; border-radius: 2px; }

code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.86em; }

.num, .grid td.num, .grid tfoot td { font-variant-numeric: tabular-nums lining-nums; }
.strong { font-weight: 600; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 0.5rem 1rem; z-index: 10; }
.skip:focus { left: 1rem; }

/* ---- Bandeau ---------------------------------------------------------------- */
.masthead { background: var(--surface); border-bottom: 1px solid var(--line); }

.masthead-inner {
    background: linear-gradient(100deg, #cc092f 0%, #c30c3f 45%, #b81570 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem 2rem;
    flex-wrap: wrap;
    padding: 0.85rem var(--gutter);
}

.brand { display: flex; align-items: center; gap: 0.6rem; color: #fff; text-decoration: none; }
.brand:hover { color: #fff; }
.brand-mark { width: 26px; height: 26px; fill: #fff; }
.brand-name { font-family: var(--font-display); font-weight: 650; font-size: var(--step-1); letter-spacing: -0.01em; }
.brand-org { font-size: var(--step--1); opacity: 0.85; padding-left: 0.6rem; border-left: 1px solid rgb(255 255 255 / 0.4); }

.file-picker { display: flex; align-items: center; gap: 0.6rem; font-size: var(--step--1); }
.file-picker label { opacity: 0.9; }
.file-picker select {
    font: inherit;
    color: var(--ink);
    background: #fff;
    border: 0;
    border-radius: var(--radius);
    padding: 0.35rem 0.6rem;
    max-width: 22rem;
}

.tabs {
    display: flex;
    gap: 0.25rem;
    padding: 0 var(--gutter);
    max-width: var(--wrap);
    overflow-x: auto;
}
.tabs a {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.8rem 0.9rem 0.7rem;
    color: var(--graphite);
    text-decoration: none;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--red); }
.tab-count {
    font-size: 0.75rem;
    font-weight: 600;
    min-width: 1.4rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    text-align: center;
    line-height: 1.4rem;
}
.tab-count.is-error { background: var(--red); color: #fff; }
.tab-count.is-warning { background: var(--warn-tint); color: var(--warn); }

/* ---- Structure -------------------------------------------------------------- */
.page { max-width: var(--wrap); margin: 0 auto; padding: 1.75rem var(--gutter) 3rem; }

.page-title { font-family: var(--font-display); font-size: var(--step-2); font-weight: 650; letter-spacing: -0.015em; margin: 0 0 0.75rem; }
.section-title { font-family: var(--font-display); font-size: var(--step-1); font-weight: 650; margin: 0 0 0.75rem; letter-spacing: -0.005em; }
.lead { color: var(--graphite); max-width: 75ch; margin: 0 0 1rem; }
.note { color: var(--graphite); font-size: var(--step--1); max-width: 80ch; }

.block { margin-top: 2.5rem; }
.block-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.block-head .section-title, .block-head .page-title { margin-bottom: 0.5rem; }
.block-actions { margin: 0; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font: inherit;
    font-size: var(--step--1);
    font-weight: 600;
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius);
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
    cursor: pointer;
}
.btn:hover { border-color: var(--red); color: var(--red); }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-deep); border-color: var(--red-deep); color: #fff; }

.scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.scroll-tall { max-height: 34rem; overflow-y: auto; }

/* ---- Hero : identité de version + avancement -------------------------------- */
.hero {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: 2rem 3rem;
    align-items: end;
    padding-bottom: 1.75rem;
    border-bottom: 1px solid var(--line);
}
.hero-doc { margin: 0; color: var(--graphite); font-weight: 600; letter-spacing: 0.01em; word-break: break-all; }
.hero-version {
    font-family: var(--font-display);
    font-size: var(--step-5);
    font-weight: 700;
    line-height: 0.95;
    letter-spacing: -0.045em;
    margin: 0.2rem 0 0.9rem;
    color: var(--red);
}
.hero-sub { margin: 0.15rem 0; color: var(--graphite); max-width: 52ch; }

.funnel ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.45rem; }
.funnel li {
    display: grid;
    grid-template-columns: 12.5rem minmax(0, 1fr) 4rem 3.5rem;
    align-items: center;
    gap: 0.75rem;
}
.funnel-label { color: var(--graphite); }
.funnel-value { text-align: right; font-weight: 650; font-size: var(--step-1); }
.funnel-share { text-align: right; color: var(--mute); font-size: var(--step--1); }
.funnel .note { margin: 0.75rem 0 0; }

.bar { display: block; width: 100%; height: 12px; }
.bar-track { fill: var(--track); }
.bar-fill { fill: var(--red); }
.bar.is-muted .bar-fill { fill: var(--graphite); }

/* ---- Chiffres clés ---------------------------------------------------------- */
.figures dl {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    margin: 1.75rem 0 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.figures dl > div { padding: 1rem 1.15rem; border-left: 1px solid var(--line); }
.figures dl > div:first-child { border-left: 0; }
.figures dt { color: var(--graphite); font-size: var(--step--1); }
.figures dt abbr { text-decoration: none; color: var(--mute); }
.figures dd { margin: 0; }
.figures dd.num { font-family: var(--font-display); font-size: 2rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
.figures .fig-note { font-size: var(--step--1); color: var(--mute); }
.figures .fig-strong dd.num { color: var(--red); }
.figures .fig-strong { box-shadow: inset 0 3px 0 var(--red); }

/* ---- Points d'attention ----------------------------------------------------- */
.issues { margin-top: 1.25rem; padding: 0.8rem 1.1rem; background: var(--warn-tint); border-radius: var(--radius); }
.issues p { margin: 0; }
.sev { font-weight: 600; text-decoration: none; white-space: nowrap; }
.issues .sev { white-space: normal; }
.sev-error { color: var(--red); }
.sev-warning { color: var(--warn); }
.sev-info { color: var(--info); }
.sev-ok { color: var(--ok); }

/* ---- Tableaux --------------------------------------------------------------- */
.grid { width: 100%; border-collapse: collapse; font-size: var(--step--1); }
.grid th, .grid td { padding: 0.5rem 0.55rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.grid thead th {
    position: sticky;
    top: 0;
    background: var(--surface);
    color: var(--graphite);
    font-weight: 600;
    vertical-align: bottom;
    border-bottom: 1px solid var(--line-strong);
    z-index: 1;
}
.grid-compact thead th { white-space: nowrap; }
.grid tbody th { font-weight: 600; }
.grid tbody tr:hover { background: var(--red-tint); }
.grid tfoot th, .grid tfoot td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; background: var(--surface); }
.grid .r { text-align: right; }
.grid .sub, .sub { display: block; font-weight: 400; color: var(--mute); font-size: 0.78rem; }
.grid .col-bar { width: 7rem; min-width: 6rem; vertical-align: middle; }
.grid tbody th a { color: var(--red); text-decoration: none; white-space: nowrap; }
.grid tbody th a:hover { text-decoration: underline; }
.grid-compact th, .grid-compact td { padding: 0.4rem 0.65rem; }
.sub-cell { color: var(--mute); max-width: 26rem; }
.mono-ish { color: var(--graphite); white-space: nowrap; }

th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: ""; display: inline-block; width: 0.8em; margin-left: 0.2em; color: var(--mute); }
th[aria-sort="ascending"]::after { content: "▲"; font-size: 0.65em; }
th[aria-sort="descending"]::after { content: "▼"; font-size: 0.65em; }
th[data-sort]:hover { color: var(--ink); }

.stack { display: block; width: 100%; height: 10px; }
.seg-am { fill: var(--red); }
.seg-a { fill: var(--red-soft); }
.seg-i { fill: var(--inactive); }

.legend { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem 0.9rem; font-size: var(--step--1); color: var(--graphite); margin: 0 0 0.6rem; }
.key { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 2px; margin-right: -0.5rem; vertical-align: -0.1rem; }
.key-am { background: var(--red); }
.key-a { background: var(--red-soft); }
.key-i { background: var(--inactive); }
.legend-hint { margin-left: auto; color: var(--mute); }

/* ---- Répartitions ----------------------------------------------------------- */
.splits { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.split { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1rem 0.6rem; }
.split.is-wide { grid-column: span 2; }
.split figcaption { font-weight: 600; margin-bottom: 0.4rem; }
.split-table { width: 100%; border-collapse: collapse; font-size: var(--step--1); }
.split-table a { text-decoration: none; }
.split-table a:hover { text-decoration: underline; }
.split-table th, .split-table td { padding: 0.3rem 0.4rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.split-table tbody tr:last-child th, .split-table tbody tr:last-child td { border-bottom: 0; }
.split-table thead th { color: var(--mute); font-weight: 500; }
.split-table tbody th { font-weight: 500; max-width: 16rem; overflow-wrap: anywhere; }
.split-table .r { text-align: right; font-variant-numeric: tabular-nums; }
.split-table .col-bar { width: 32%; }

/* ---- Explorateur de champs -------------------------------------------------- */
.table-head h1 { font-family: var(--font-display); font-size: var(--step-2); margin: 0.1rem 0 0.4rem; letter-spacing: -0.015em; }
.crumb { margin: 0; font-size: var(--step--1); }
.facts { display: flex; flex-wrap: wrap; gap: 0.5rem 2rem; margin: 0.75rem 0 1.25rem; font-size: var(--step--1); }
.facts dt { color: var(--mute); }
.facts dd { margin: 0; font-weight: 600; }

.filters {
    display: grid;
    grid-template-columns: minmax(14rem, 2fr) repeat(7, minmax(7.5rem, 1fr));
    gap: 0.75rem;
    align-items: end;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.filters label { display: grid; gap: 0.25rem; font-size: var(--step--1); color: var(--graphite); }
.filters input[type="search"], .filters select, .upload input[type="file"] {
    font: inherit;
    font-size: var(--step-0);
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    padding: 0.4rem 0.55rem;
    width: 100%;
}
.filters .f-check { display: flex; align-items: center; gap: 0.4rem; padding-bottom: 0.45rem; }
.f-check input { accent-color: var(--red); width: 1rem; height: 1rem; }
.f-actions { display: flex; gap: 0.5rem; grid-column: -3 / -1; justify-content: flex-end; }

.result-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 1rem 0 0.6rem; }
.result-bar p { margin: 0; color: var(--graphite); }
.result-bar strong { color: var(--ink); }

.grid-fields tbody th { min-width: 12rem; }
.grid-fields tr.is-inactive td, .grid-fields tr.is-inactive th { color: var(--mute); }

.flag { display: inline-block; padding: 0 0.4rem; border-radius: 3px; font-weight: 600; font-size: 0.78rem; line-height: 1.5; max-width: 14rem; }
.flag-y { background: var(--red); color: #fff; }
.flag-c { background: var(--red-tint); color: var(--red-deep); }
.flag-n { color: var(--mute); }
.flag-e { color: var(--warn); }
.pk { font-size: 0.7rem; font-weight: 700; color: var(--red); border: 1px solid currentColor; border-radius: 3px; padding: 0 0.25rem; vertical-align: 0.1em; }

.status { white-space: nowrap; }
.status-todo { color: var(--graphite); }
.status-mapped { color: var(--warn); font-weight: 600; }
.status-validated { color: var(--ok); font-weight: 600; }

.empty { padding: 2rem; text-align: center; background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--graphite); }

/* ---- Contrôles -------------------------------------------------------------- */
.checks { display: grid; gap: 0.5rem; }
.check { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line-strong); border-radius: var(--radius); }
.check-error { border-left-color: var(--red); }
.check-warning { border-left-color: var(--warn); }
.check-info { border-left-color: var(--info); }
.check-ok { border-left-color: var(--ok); }
.check summary {
    display: grid;
    grid-template-columns: 7.5rem minmax(0, 1fr) auto;
    gap: 1rem;
    align-items: baseline;
    padding: 0.75rem 1rem;
    cursor: pointer;
    list-style: none;
}
.check summary::-webkit-details-marker { display: none; }
.check-title { font-weight: 600; }
.check-count { color: var(--graphite); font-size: var(--step--1); }
.check-desc { margin: 0 1rem 0.75rem; color: var(--graphite); font-size: var(--step--1); }
.check .scroll { margin: 0 1rem 1rem; }
.check[open] summary { border-bottom: 1px solid var(--line); margin-bottom: 0.75rem; }

/* ---- Référentiel ------------------------------------------------------------ */
.timeline { list-style: none; margin: 0; padding: 0 0 0 1.25rem; border-left: 2px solid var(--line-strong); display: grid; gap: 1.1rem; }
.timeline li { position: relative; }
.timeline li::before {
    content: "";
    position: absolute;
    left: calc(-1.25rem - 6px);
    top: 0.45rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--line-strong);
}
.timeline li.is-current::before { background: var(--red); border-color: var(--red); }
.tl-head { display: flex; gap: 0.75rem; align-items: baseline; flex-wrap: wrap; }
.tl-version { font-family: var(--font-display); font-weight: 700; font-size: var(--step-1); }
.is-current .tl-version { color: var(--red); }
.tl-date, .tl-author { color: var(--graphite); font-size: var(--step--1); }
.timeline p { margin: 0.25rem 0 0; font-size: var(--step--1); }
.tl-label { color: var(--mute); margin-right: 0.35rem; }
.timeline code { display: inline-block; background: var(--surface); border: 1px solid var(--line); border-radius: 3px; padding: 0 0.3rem; margin: 0.1rem 0.15rem 0.1rem 0; }
.tl-note { color: var(--graphite); }

tr.is-impossible td { color: var(--graphite); }
td.is-bad { color: var(--red); font-weight: 700; }
tr.has-template th a { font-weight: 700; }
tr.is-current th { color: var(--red); }

.glossary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 2rem; margin: 0; }
.glossary > div { padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.glossary dt code { font-weight: 700; font-size: 0.85rem; }
.glossary dt .sub { display: inline; margin-left: 0.4rem; }
.glossary dd { margin: 0.15rem 0 0; color: var(--graphite); font-size: var(--step--1); max-width: 70ch; }

/* ---- Fichiers --------------------------------------------------------------- */
.upload { display: flex; flex-wrap: wrap; align-items: end; gap: 1rem; padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.upload label { display: grid; gap: 0.3rem; font-size: var(--step--1); color: var(--graphite); }
.upload .f-check { display: flex; align-items: center; gap: 0.4rem; padding-bottom: 0.45rem; }

.flash { padding: 0.7rem 1rem; border-radius: var(--radius); margin: 0 0 1.25rem; font-weight: 500; }
.flash-ok { background: var(--ok-tint); color: var(--ok); }
.flash-error { background: var(--red-tint); color: var(--red-deep); }

/* ---- Pied de page ----------------------------------------------------------- */
.footer { max-width: var(--wrap); margin: 0 auto; padding: 1.25rem var(--gutter) 2.5rem; border-top: 1px solid var(--line); color: var(--mute); font-size: var(--step--1); display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem 2rem; }
.footer p { margin: 0; }
.footer-links { display: flex; gap: 1.25rem; }

/* ---- Adaptatif -------------------------------------------------------------- */
@media (max-width: 1180px) {
    .figures dl { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .figures dl > div:nth-child(4) { border-left: 0; }
    .figures dl > div:nth-child(n + 4) { border-top: 1px solid var(--line); }
    .splits { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .filters .f-search { grid-column: 1 / -1; }
    .f-actions { grid-column: auto; }
}

@media (max-width: 860px) {
    .hero { grid-template-columns: 1fr; align-items: start; }
    .funnel li { grid-template-columns: 9rem minmax(0, 1fr) 3.5rem 3rem; gap: 0.5rem; }
    .splits { grid-template-columns: 1fr; }
    .split.is-wide { grid-column: auto; }
    .glossary { grid-template-columns: 1fr; }
    .legend-hint { margin-left: 0; width: 100%; }
    .check summary { grid-template-columns: 1fr auto; }
    .check summary .sev { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
    .figures dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .figures dl > div { border-left: 0; border-top: 1px solid var(--line); }
    .figures dl > div:nth-child(-n + 2) { border-top: 0; }
    .figures dl > div:nth-child(even) { border-left: 1px solid var(--line); }
    .filters { grid-template-columns: 1fr 1fr; }
    .brand-org { display: none; }
    .file-picker label { display: none; }
}

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

@media print {
    .masthead-inner { background: none; color: var(--ink); border-bottom: 2px solid var(--red); }
    .brand, .brand:hover { color: var(--ink); }
    .brand-mark { fill: var(--red); }
    .tabs, .file-picker, .btn, .filters, .footer-links { display: none; }
    .scroll { overflow: visible; border: 0; }
    body { background: #fff; }
}

/* Unique animation : les barres d'avancement se déploient au chargement. */
@media (prefers-reduced-motion: no-preference) {
    .funnel .bar-fill { transform-box: fill-box; transform-origin: left center; animation: grow 700ms cubic-bezier(0.2, 0.7, 0.2, 1) both; }
    .funnel li:nth-child(2) .bar-fill { animation-delay: 80ms; }
    .funnel li:nth-child(3) .bar-fill { animation-delay: 160ms; }
    .funnel li:nth-child(4) .bar-fill { animation-delay: 240ms; }
    .funnel li:nth-child(5) .bar-fill { animation-delay: 320ms; }
}
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ---- Marque ASCEND et session ------------------------------------------------ */
.brand-name { letter-spacing: 0.06em; }
.brand-tagline { opacity: 0.85; }
.session { display: flex; align-items: center; gap: 0.75rem; font-size: var(--step--1); margin-left: auto; }
.file-picker + .session { margin-left: 0; }
.session-user { opacity: 0.95; }
.session-role { font-size: 0.7rem; font-weight: 700; padding: 0 0.35rem; border: 1px solid rgb(255 255 255 / 0.7); border-radius: 3px; margin-left: 0.2rem; }
.session-out { font: inherit; color: #fff; background: transparent; border: 1px solid rgb(255 255 255 / 0.6); border-radius: var(--radius); padding: 0.3rem 0.65rem; cursor: pointer; }
.session-out:hover { background: rgb(255 255 255 / 0.15); }
.session-out:focus-visible { outline-color: #fff; }

/* ---- Connexion --------------------------------------------------------------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: var(--gutter); }
.login {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    width: min(880px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}
.login-brand {
    background: linear-gradient(150deg, #cc092f 0%, #c30c3f 50%, #b81570 100%);
    color: #fff;
    padding: 2.5rem 2rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    min-height: 22rem;
}
.login-mark { width: 44px; height: 44px; fill: #fff; margin-bottom: auto; }
.login-project { font-family: var(--font-display); font-size: clamp(2.6rem, 6vw, 3.6rem); font-weight: 700; letter-spacing: 0.08em; line-height: 1; margin: 0; }
.login-tagline { margin: 0.6rem 0 0; opacity: 0.9; }
.login-panel { padding: 2.5rem 2.25rem; }
.login-panel h1 { font-family: var(--font-display); font-size: var(--step-2); margin: 0 0 0.25rem; }
.login-form { display: grid; gap: 1rem; margin-top: 1.25rem; }
.login-form label { display: grid; gap: 0.3rem; font-size: var(--step--1); color: var(--graphite); }
.login-form input, .sql-form input[type="text"], .sql-form input[type="number"], .sql-form select {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    padding: 0.55rem 0.65rem;
    width: 100%;
}
.login-form .btn { justify-self: start; padding: 0.6rem 1.4rem; font-size: var(--step-0); }
.login-panel pre { white-space: pre-wrap; margin: 0.4rem 0 0; font-size: 0.8rem; }
.login-panel .flash p { margin: 0; }

/* ---- Génération SQL ---------------------------------------------------------- */
.sql-form { display: grid; gap: 1rem; padding: 1rem 1.1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.sql-form fieldset { border: 0; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem 1rem; }
.sql-form legend { font-weight: 600; margin-bottom: 0.5rem; }
.sql-form label { display: grid; gap: 0.25rem; font-size: var(--step--1); color: var(--graphite); align-content: start; }
.sql-form label.wide { grid-column: span 2; }
.sql-form .opts { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.opt { display: flex !important; gap: 0.5rem; align-items: flex-start; padding: 0.6rem 0.7rem; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.opt:has(input:checked) { border-color: var(--red); background: var(--red-tint); }
.opt input { accent-color: var(--red); width: 1rem; height: 1rem; margin-top: 0.15rem; flex: none; }
.opt strong { color: var(--ink); font-weight: 600; }
.sql-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.sql-form .note { margin: 0; }
td.actions { white-space: nowrap; }
td.actions a + a { margin-left: 0.75rem; }

pre.code {
    margin: 0;
    max-height: 38rem;
    overflow: auto;
    padding: 1rem 1.1rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 0.8rem;
    line-height: 1.45;
    tab-size: 4;
}

/* ---- Code mapping ------------------------------------------------------------ */
.num-of { font-size: 1.1rem; color: var(--mute); font-weight: 500; }
.figures dt a { color: inherit; }
.request-text { margin-top: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.7rem 1rem; }
.request-text summary { cursor: pointer; font-weight: 600; }
.request-text textarea { width: 100%; margin-top: 0.75rem; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.8rem; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem; }
.copy-status { color: var(--ok); font-size: var(--step--1); margin-left: 0.5rem; }
.grid .sub.fn { color: var(--red); text-decoration: none; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.72rem; }
.grid .sub.fn:hover { text-decoration: underline; }
.cm-missing { color: var(--warn) !important; font-weight: 600; }

@media (max-width: 1180px) {
    .sql-form fieldset { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sql-form .opts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .login { grid-template-columns: 1fr; }
    .login-brand { min-height: 0; padding: 1.75rem; }
    .login-mark { margin-bottom: 1.5rem; }
    .session-user { display: none; }
}
@media (max-width: 560px) {
    .sql-form fieldset, .sql-form .opts { grid-template-columns: 1fr; }
    .sql-form label.wide { grid-column: auto; }
    .brand-tagline { display: none; }
}

/* ======================================================================
   Scripts versionnés : états, bannières, éditeur, comparaison, audit
   ====================================================================== */
:root {
    --tk-kw: #b4131f; --tk-ty: #7a3e9d; --tk-fn: #0b6e8a; --tk-str: #1d7a4e; --tk-id: #8a5a00;
    --tk-cm: #7b7d86; --tk-num: #2d5b88; --tk-dl: #cc092f;
    --ed-bg: #ffffff; --ed-gutter: #f4f4f6; --ed-line: #e1e1e6;
    --add-bg: #e7f6ec; --add-fg: #14623d; --del-bg: #fdebee; --del-fg: #9e0723;
}
@media (prefers-color-scheme: dark) {
    :root {
        --tk-kw: #ff7a8f; --tk-ty: #c79bf0; --tk-fn: #6fcbe3; --tk-str: #7fd6a4; --tk-id: #e6b85c;
        --tk-cm: #8e9099; --tk-num: #85b3e0; --tk-dl: #ff4d6a;
        --ed-bg: #1c1c20; --ed-gutter: #222226; --ed-line: #34343a;
        --add-bg: #17352a; --add-fg: #8fe0b2; --del-bg: #3a1b22; --del-fg: #ff9aac;
    }
}

.state { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.72rem; font-weight: 650; letter-spacing: 0.01em; vertical-align: middle; white-space: nowrap; border: 1px solid transparent; }
.state-new { background: var(--info-tint); color: var(--info); }
.state-synced { background: var(--ok-tint); color: var(--ok); }
.state-modified { background: var(--warn-tint); color: var(--warn); }
.state-update { background: var(--red-tint); color: var(--red-deep); border-color: var(--red-soft); }
.state-conflict { background: var(--red); color: #fff; }

.crumbs { margin: 0 0 0.35rem; font-size: var(--step--1); color: var(--mute); }
.crumbs a { color: var(--graphite); }
.obj { font-size: 0.8em; font-weight: 600; }
.facts { display: flex; flex-wrap: wrap; gap: 0.5rem 2rem; margin: 0 0 1.25rem; }
.facts > div { min-width: 12rem; }
.facts dt { color: var(--mute); font-size: 0.78rem; }
.facts dd { margin: 0; font-size: var(--step-0); }
.banner { border-left: 4px solid var(--info); background: var(--info-tint); padding: 0.75rem 1rem; border-radius: var(--radius); margin: 0 0 1.25rem; }
.banner-warn { border-color: var(--red); background: var(--red-tint); }
.banner p { margin: 0 0 0.5rem; }
.banner p:last-child { margin-bottom: 0; }
.inline-form { display: flex; flex-wrap: wrap; align-items: end; gap: 0.75rem 1rem; margin: 0.5rem 0; }
.inline-form label, .ed-save label { display: grid; gap: 0.25rem; font-size: var(--step--1); color: var(--graphite); }
.inline-form input[type="text"], .ed-save input[type="text"], .ed-goto input, .filters input[type="date"] {
    font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 0.4rem 0.55rem; min-width: 16rem;
}
.inline-form input[type="text"][name="why"], .ed-save input[name="why"] { min-width: min(34rem, 80vw); }
.inline-form input[name="ref"], .ed-save input[name="ref"] { min-width: 10rem; }
.bulk { display: grid; gap: 0.75rem; }
.req { color: var(--red-deep); }
kbd { font: 0.75rem ui-monospace, "Cascadia Mono", Consolas, monospace; padding: 0.05rem 0.35rem; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); }
.grid-facts th { width: 14rem; color: var(--graphite); }
.grid .nowrap, .nowrap { white-space: nowrap; }
.grid .why { max-width: 28rem; }
.grid tr.is-current { background: var(--red-tint); }
.is-bad { color: var(--red-deep); }
.is-bad-row td { background: color-mix(in srgb, var(--red-tint) 55%, transparent); }
.pager { display: flex; gap: 0.5rem; margin: 1rem 0; }
.det summary { cursor: pointer; color: var(--mute); font-size: 0.75rem; }
.det pre { margin: 0.35rem 0 0; padding: 0.5rem; background: var(--paper); border-radius: var(--radius); font-size: 0.72rem; white-space: pre-wrap; max-width: 36rem; overflow: auto; max-height: 14rem; }
.grid-audit td { vertical-align: top; }

/* --- Éditeur --- */
.ed { border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--ed-bg); overflow: hidden; }
.ed-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.65rem; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--ed-line); background: var(--ed-gutter); }
.ed-check, .ed-goto { display: inline-flex; align-items: center; gap: 0.4rem; font-size: var(--step--1); color: var(--graphite); }
.ed-check input { accent-color: var(--red); }
.ed-goto input { min-width: 0; width: 5rem; padding: 0.3rem 0.45rem; }
.ed-save { display: flex; flex-wrap: wrap; align-items: end; gap: 0.6rem 0.9rem; padding: 0.75rem; border-bottom: 1px solid var(--ed-line); background: var(--red-tint); }
.ed-save[hidden], .ed-msg[hidden] { display: none; }
.ed-msg { margin: 0; border-radius: 0; }
.ed-body { display: grid; grid-template-columns: auto 1fr; height: clamp(22rem, 68vh, 46rem); }
.ed-gutter { overflow: hidden; background: var(--ed-gutter); border-right: 1px solid var(--ed-line); color: var(--mute); user-select: none; }
.ed-nums, .ed-hl, .ed-ta {
    margin: 0; border: 0; padding: 0.75rem 0.75rem; box-sizing: border-box;
    font-family: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 13px; line-height: 20px; letter-spacing: 0; tab-size: 4; white-space: pre;
}
.ed-nums { text-align: right; padding-left: 0.5rem; padding-right: 0.6rem; }
.ed-scroll { position: relative; overflow: hidden; min-width: 0; }
.ed-hl { position: absolute; inset: 0; overflow: hidden; pointer-events: none; color: var(--ink); background: transparent; }
.ed-hl code { display: block; font: inherit; will-change: transform; }
.ed-ta {
    position: absolute; inset: 0; width: 100%; height: 100%; resize: none; overflow: auto; outline: none;
    background: transparent; color: transparent; caret-color: var(--ink); -webkit-text-fill-color: transparent;
}
.ed-ta::selection { background: color-mix(in srgb, var(--red) 28%, transparent); -webkit-text-fill-color: transparent; }
.ed-ta:focus-visible { box-shadow: inset 0 0 0 2px var(--red); }
.ed.is-plain .ed-ta { color: var(--ink); -webkit-text-fill-color: var(--ink); }
.ed.is-plain .ed-hl { visibility: hidden; }
.tk-kw { color: var(--tk-kw); font-weight: 600; } .tk-ty { color: var(--tk-ty); } .tk-fn { color: var(--tk-fn); }
.tk-str { color: var(--tk-str); } .tk-id { color: var(--tk-id); } .tk-cm { color: var(--tk-cm); font-style: italic; }
.tk-num { color: var(--tk-num); } .tk-dl { color: var(--tk-dl); font-weight: 700; }
.ed-status { display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; padding: 0.35rem 0.75rem; border-top: 1px solid var(--ed-line); background: var(--ed-gutter); font-size: 0.78rem; color: var(--graphite); font-variant-numeric: tabular-nums; }
.ed-dirty { color: var(--red-deep); font-weight: 650; }
.ed.is-dirty { border-color: var(--red); }

/* --- Comparaison --- */
.diff { width: 100%; border-collapse: collapse; font: 12.5px/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace; border: 1px solid var(--line); }
.diff td { padding: 0 0.5rem; vertical-align: top; }
.diff .ln { width: 3.2rem; text-align: right; color: var(--mute); user-select: none; border-right: 1px solid var(--line); background: var(--paper); }
.diff .sg { width: 1.2rem; text-align: center; font-weight: 700; }
.diff .tx { white-space: pre-wrap; word-break: break-word; }
.diff-add td:not(.ln) { background: var(--add-bg); color: var(--add-fg); }
.diff-del td:not(.ln) { background: var(--del-bg); color: var(--del-fg); }
.diff-gap td { text-align: center; color: var(--mute); background: var(--paper); padding: 0.1rem; }
.diff-stats { font-weight: 600; }
.diff-add-n { color: var(--add-fg); } .diff-del-n { color: var(--del-fg); margin-left: 0.5rem; }

@media (max-width: 720px) {
    .ed-body { height: 60vh; }
    .inline-form input[type="text"] { min-width: 0; width: 100%; }
}
.seg { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin: 0 0 0.5rem; font-size: var(--step--1); color: var(--graphite); }
.seg-item { padding: 0.3rem 0.8rem; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--ink); text-decoration: none; background: var(--surface); }
.seg-item[aria-current="true"] { background: var(--red); border-color: var(--red); color: #fff; }
.filters input[type="search"], .filters input[type="date"] { width: 100%; box-sizing: border-box; min-width: 0; }
.grid td.actions { white-space: nowrap; }
.filters select { width: 100%; box-sizing: border-box; min-width: 9rem; }
