/*
 * Étape 2 : « Documents de ce client » (devis, factures, retards issus de Clyna) : barre d'outils, bandeau de sélection,
 * liste structurée et avertissements. Couleurs via les variables du thème (clair / sombre) ; focus visible au clavier ;
 * la couleur n'est jamais le seul signal (texte + icône sur les pastilles, coche + « Sélectionné » sur la ligne choisie).
 */

/* Teintes sémantiques (pastilles, repères) : contraste AA texte/fond dans les deux thèmes. */
:root {
    --doc-hover: #fff7f3;
    --doc-sel-bg: #fde4d6;
    --doc-sel-line: #d9531f;
    --tone-info-bg: #fde8dd; --tone-info-fg: #8f3209;
    --tone-ok-bg: #dcf5e4; --tone-ok-fg: #14632f;
    --tone-warn-bg: #fff1d6; --tone-warn-fg: #8a4b00;
    --tone-danger-bg: #fde2e2; --tone-danger-fg: #a11b1b;
    --tone-muted-bg: #ececf0; --tone-muted-fg: #4b4b5c;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --doc-hover: #12151d;
        --doc-sel-bg: #262f14;
        --doc-sel-line: #c8ff57;
        --tone-info-bg: #26301a; --tone-info-fg: #d5ff8a;
        --tone-ok-bg: #0f2e22; --tone-ok-fg: #6ee7b7;
        --tone-warn-bg: #3b2a07; --tone-warn-fg: #fcd34d;
        --tone-danger-bg: #44181b; --tone-danger-fg: #ffa3a6;
        --tone-muted-bg: #22232e; --tone-muted-fg: #c4c4d0;
    }
}
:root[data-theme="dark"] {
    --doc-hover: #12151d;
    --doc-sel-bg: #262f14;
    --doc-sel-line: #c8ff57;
    --tone-info-bg: #26301a; --tone-info-fg: #d5ff8a;
    --tone-ok-bg: #0f2e22; --tone-ok-fg: #6ee7b7;
    --tone-warn-bg: #3b2a07; --tone-warn-fg: #fcd34d;
    --tone-danger-bg: #44181b; --tone-danger-fg: #ffa3a6;
    --tone-muted-bg: #22232e; --tone-muted-fg: #c4c4d0;
}

.docs-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.docs-head .lab { margin-bottom: 0; }
.docs-loading { display: flex; align-items: center; gap: 6px; }
.docs-loading[hidden] { display: none; }
.docs-note { border: 1px dashed var(--line); border-radius: 9px; padding: 10px 12px; font-size: 13px; color: var(--sub); background: var(--card); }
.muted { color: var(--sub); }

/* Boutons « lien » et puces */
.linklike { font: 500 12.5px var(--font); color: var(--sub); background: transparent; border: 0; padding: 4px 2px; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; display: inline-flex; align-items: center; gap: 5px; border-radius: 6px; }
.linklike:hover { color: var(--acc-strong); }
.linklike svg { width: 14px; height: 14px; flex: none; }
.fchip, .achip, .seg-btn { font: 500 12.5px var(--font); color: var(--ink); background: var(--card); border: 1px solid var(--ctl); border-radius: 99px; padding: 5px 11px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; min-height: 30px; }
.fchip svg, .achip svg { width: 13px; height: 13px; flex: none; }
.fchip:hover, .achip:hover, .seg-btn:hover { border-color: var(--acc); }
.fchip[aria-pressed="true"], .seg-btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--card); }
.achip { background: var(--tint); border-color: transparent; color: var(--ink); }
.achip:hover { border-color: var(--acc); }
:is(.fchip, .achip, .seg-btn, .linklike):focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }

/* Bandeau de sélection : toujours visible, distinct de la liste */
.docs-selection { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; margin-bottom: 10px; font-size: 13px; background: var(--card); }
.docs-selection.has { border-color: var(--doc-sel-line); background: var(--doc-sel-bg); }
.docs-selection .sel-ic { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--doc-sel-line); color: var(--card); flex: none; }
.docs-selection .sel-ic svg { width: 14px; height: 14px; }
.docs-selection .sel-text { flex: 1 1 14rem; min-width: 0; overflow-wrap: anywhere; }
.docs-selection .sel-k { color: var(--sub); }
.docs-selection .sel-clear { margin-left: auto; }
.docs-selection .sel-items { flex-basis: 100%; list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.docs-selection .sel-warn { flex-basis: 100%; display: flex; align-items: center; gap: 6px; color: var(--warn); }
.docs-selection .sel-warn svg { width: 14px; height: 14px; flex: none; }
.docs-issue { font-size: 12.5px; color: var(--warn); margin: 6px 0; }

/* Barre d'outils : recherche + tri + « Filtres » sur une rangée ; période, statuts et retard rangés dans un panneau repliable */
.docs-toolbar { min-width: 0; display: grid; gap: 12px; margin-bottom: 14px; container-type: inline-size; }
.docs-search-row { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.docs-search { position: relative; flex: 1 1 16rem; min-width: 0; }
.docs-search .inp { padding-left: 34px; padding-right: 36px; min-height: 40px; }
.docs-search .docs-search-ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--sub); pointer-events: none; width: 16px; height: 16px; }
.docs-search .docs-search-clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.docs-sort { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--sub); }
.docs-sort label { margin: 0; white-space: nowrap; }
.docs-sort select { width: auto; min-height: 40px; font-size: 13px; padding: 7px 9px; }
.docs-filters-toggle { min-height: 40px; padding-inline: 14px; gap: 8px; }
.docs-filters-toggle svg { flex: none; }
.docs-filters-toggle[aria-expanded="true"] { background: var(--tint); border-color: var(--acc); }
.docs-filters-count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--acc-strong); color: var(--on-acc); font-size: 11.5px; font-weight: 700; line-height: 1; }
.docs-filters { display: grid; gap: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.docs-filters[hidden] { display: none; }
.docs-group { min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.docs-group-l { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--sub); min-width: 7rem; }
.docs-seg, .docs-chips { display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; flex: 1 1 12rem; }
.docs-dates { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 13px; }
.docs-dates label { margin: 0; color: var(--sub); }
.docs-dates .inp { width: auto; padding: 6px 9px; font-size: 13px; }
.docs-dates .inp[aria-invalid="true"] { border-color: var(--warn); }
.docs-legacy { margin: 0; font-size: 12.5px; color: var(--sub); }
.docs-summary-r { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
.docs-perpage { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--sub); }
.docs-perpage label { margin: 0; white-space: nowrap; }
.docs-perpage select { width: auto; min-height: 32px; font-size: 13px; padding: 4px 8px; }
.docs-summary { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 14px; }
.docs-count { margin: 0; font-size: 13px; font-weight: 600; color: var(--ink); }
.docs-active { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
@container (max-width: 759px) {
    .docs-sort label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}
@container (max-width: 559px) {
    .docs-search { flex-basis: 100%; }
    .docs-sort { flex: 1 1 0; min-width: 0; }
    .docs-sort select { flex: 1; min-width: 0; }
    .docs-group-l { flex-basis: 100%; }
}

/* Liste structurée : le CONTENEUR décide (la colonne latérale rétrécit la place disponible).
   Par défaut (< 860 px de conteneur, donc ~700 px et mobile) : lignes empilées en deux étages.
   Au-dessus : une ligne à colonnes alignées (gabarit --doc-cols, partagé avec l'en-tête). */
.docs-results { transition: opacity .15s; }
.docs-table { container-type: inline-size; min-width: 0; }
.docs-table.type-devis { --doc-cols: 20px minmax(0, 2.4fr) minmax(0, 1fr) minmax(0, 1.1fr) minmax(0, 1.6fr) minmax(0, 1.1fr); }
.docs-table.type-factures { --doc-cols: 20px minmax(0, 3fr) minmax(0, 1.1fr) minmax(0, 1.2fr) minmax(0, 1.1fr) minmax(0, 1.1fr); }
.docs-table.type-retards { --doc-cols: 20px minmax(0, 3fr) minmax(0, 1fr) minmax(0, .9fr) minmax(0, 1.9fr) minmax(0, 1fr) minmax(0, 1fr); }
.docs-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; padding: 0 2px 8px; font-size: 13px; }
.docs-all { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; margin: 0; text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 500; color: var(--ink); min-height: 28px; }
.docs-all input, .doc-pick input { appearance: none; -webkit-appearance: none; display: grid; place-content: center; width: 18px; height: 18px; margin: 0; cursor: pointer;
    border: 2px solid var(--sub); border-radius: 5px; background: var(--card); }
.doc-pick input[type="radio"] { border-radius: 50%; }
.docs-all input:checked, .doc-pick input:checked { background: var(--acc); border-color: var(--acc); }
.docs-all input:checked::after, .doc-pick input[type="checkbox"]:checked::after { content: ""; width: 10px; height: 5px; border-left: 2.5px solid var(--card); border-bottom: 2.5px solid var(--card); transform: translateY(-1px) rotate(-45deg); }
.doc-pick input[type="radio"]:checked::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--card); }
.doc-row.is-disabled input { cursor: not-allowed; }
.docs-quota { color: var(--sub); }
.docs-cols { display: none; }
.docs-list { display: grid; gap: 8px; }

.doc-row { position: relative; display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; column-gap: 12px; row-gap: 3px; align-items: start;
    padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); cursor: pointer;
    box-shadow: 0 1px 2px color-mix(in srgb, var(--ink) 8%, transparent);
    font-size: 13px; line-height: 1.4; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--ink); margin: 0; }
/* Survol : fond + bordure teintée. Focus clavier : anneau net. Sélection : fond + bordure épaisse + coche + « Sélectionné ». */
.doc-row:hover { background: var(--doc-hover); border-color: color-mix(in srgb, var(--acc) 50%, var(--line)); }
.doc-row.on { background: var(--doc-sel-bg); border-color: var(--doc-sel-line); box-shadow: inset 4px 0 0 var(--doc-sel-line), 0 0 0 1px var(--doc-sel-line); }
.doc-row:has(input:focus-visible) { outline: 3px solid var(--acc); outline-offset: 2px; }
.doc-row.is-disabled { opacity: .55; cursor: not-allowed; }
.doc-row.is-disabled:hover { background: var(--card); border-color: var(--line); }

.doc-pick { grid-column: 1; grid-row: 1; display: grid; place-items: center; align-self: start; padding-top: 1px; }
/* Étage 1 : numéro, statut, repères */
.doc-id { grid-column: 2; grid-row: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.doc-num { font-size: 15px; font-weight: 700; line-height: 1.4; overflow-wrap: anywhere; }
.doc-picked { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; color: var(--ink); white-space: nowrap; }
.doc-picked svg { width: 14px; height: 14px; color: var(--doc-sel-line); }
.c-amount { grid-column: 3; grid-row: 1; text-align: right; justify-items: end; }
.c-amount .num { font-size: 16px; font-weight: 600; line-height: 1.4; }
.c-amount .cell-label { display: none; }
/* Étage 2 : informations secondaires en ligne « libellé valeur », retour à la ligne seulement si la place manque */
.doc-meta { grid-column: 2 / -1; grid-row: 2; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; color: var(--ink); }
.doc-cell { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 0 5px; min-width: 0; }
.cell-label { font-size: 13px; font-weight: 400; line-height: 1.4; color: var(--sub); opacity: .85; }
.cell-label::after { content: none; }
.cell-val { font-size: 13px; line-height: 1.4; font-weight: 500; min-width: 0; }
.doc-sub { font-size: 12px; line-height: 1.4; color: var(--sub); }
.c-rel .cell-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.c-rel .doc-sub::before { content: "· "; }
.doc-site { overflow-wrap: anywhere; }
.nw, .num { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; font-weight: 600; }
.num.due { color: var(--ink); }
.late { color: var(--tone-danger-fg); font-weight: 700; font-size: 14px; }
mark { background: color-mix(in srgb, var(--acc) 30%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

/* Pastilles de statut et repères : teinte + icône + texte. Ne dépassent jamais leur cellule : le libellé passe à la ligne. */
.pill, .flag { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; min-width: 0; font-size: 12px; font-weight: 600; line-height: 1.4; padding: 1px 8px 1px 6px; border-radius: 99px; }
.pill > span, .flag > span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill-ic { width: 13px; height: 13px; flex: none; }
.pill-info { background: var(--tone-info-bg); color: var(--tone-info-fg); }
.pill-ok { background: var(--tone-ok-bg); color: var(--tone-ok-fg); }
.pill-warn, .flag-warn { background: var(--tone-warn-bg); color: var(--tone-warn-fg); }
.pill-danger, .flag-danger { background: var(--tone-danger-bg); color: var(--tone-danger-fg); }
.pill-muted { background: var(--tone-muted-bg); color: var(--tone-muted-fg); }

/* Grande largeur : une ligne à colonnes alignées */
@container (min-width: 860px) {
    .docs-cols { display: grid; grid-template-columns: var(--doc-cols); column-gap: 16px; padding: 0 15px 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--sub); }
    .docs-cols .r { text-align: right; }
    .doc-row { grid-template-columns: var(--doc-cols); align-items: center; row-gap: 0; padding: 10px 14px; }
    .doc-meta { display: contents; }
    .doc-pick, .doc-id, .c-amount, .doc-cell { grid-column: auto; grid-row: auto; }
    .doc-pick { order: 0; padding-top: 0; align-self: center; } .doc-id { order: 1; }
    .c-a { order: 2; } .c-b { order: 3; } .c-site, .c-rel { order: 4; } .c-amount { order: 5; } .c-due { order: 6; }
    .doc-cell { display: grid; align-content: center; gap: 0; }
    .c-rel .cell-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.c-rel .doc-sub::before { content: none; }
    .doc-cell .cell-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    .doc-cell.r { text-align: right; justify-items: end; }
    .c-amount .num { font-size: 14px; }
}

/* États, pagination, mode manuel */
.docs-empty { display: grid; justify-items: start; gap: 6px; border: 1px dashed var(--line); border-radius: 10px; padding: 16px; font-size: 13px; color: var(--sub); background: var(--card); }
.docs-empty strong { color: var(--ink); font-size: 14px; }
/* Pagination : libellé « 11-20 sur 32 » + Précédent / numéros / Suivant. Colonne étroite : Précédent / « Page 2 sur 4 » / Suivant. */
.docs-pager-wrap { container-type: inline-size; margin-top: 14px; }
.docs-pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.docs-range { margin: 0; font-size: 13px; color: var(--sub); font-variant-numeric: tabular-nums; }
.docs-pg { display: flex; align-items: center; gap: 6px; min-width: 0; }
.pg-nums { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: 4px; }
.pg-gap { min-width: 24px; text-align: center; color: var(--sub); }
.pg-of { display: none; font-size: 13px; color: var(--sub); white-space: nowrap; }
.pg-btn { font: 500 13px var(--font); display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 40px; min-height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--ctl); background: var(--card); color: var(--ink); cursor: pointer; font-variant-numeric: tabular-nums; }
.pg-btn svg { width: 16px; height: 16px; flex: none; }
.pg-btn:hover:not(:disabled) { border-color: var(--acc); background: var(--tint); }
.pg-btn:focus-visible { outline: 3px solid var(--acc); outline-offset: 2px; }
.pg-btn[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: var(--card); font-weight: 700; cursor: default; }
.pg-btn:disabled { opacity: .6; cursor: not-allowed; }
.docs-truncated { flex-basis: 100%; margin: 0; }
@container (max-width: 559px) {
    .docs-pager { justify-content: center; }
    .docs-range { flex-basis: 100%; text-align: center; }
    .docs-pg { width: 100%; justify-content: space-between; }
    .pg-nums { display: none; }
    .pg-of { display: block; }
}
.docs-manual { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); }
.docs-manual .linklike[aria-pressed="true"] { color: var(--ink); font-weight: 700; }

.chip.warn { background: transparent; color: var(--warn); border: 1px solid var(--warn); }
.alert.warn { border-color: var(--warn); color: var(--warn); border-left-width: 4px; }
.hist .hist-ref { color: var(--acc-strong); }

@media (prefers-reduced-motion: reduce) { .docs-results { transition: none; } }

/* Aide sous la liste : une ligne courte + disclosure « Quelles données sont envoyées à l'IA ? » */
.docs-help { margin-top: 12px; }
.docs-ai { margin-top: 6px; font-size: 12.5px; color: var(--sub); }
.docs-ai summary { cursor: pointer; display: inline-block; padding: 4px 2px; border-radius: 6px; text-decoration: underline; text-underline-offset: 2px; }
.docs-ai summary:hover { color: var(--acc-strong); }
.docs-ai summary:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.docs-ai p { margin: 4px 0 0; max-width: 62ch; }
