/* Espace « Documents » (screens/documents.js) : Tous les fichiers, Dossiers, Documentation, À valider, et volet de la visionneuse.
   Variables nouvelles de ce fichier (types de documents, vignettes, cartes) en tête : la refonte visuelle ne retouche que ce bloc. Tout le reste = variables du thème. */
:root {
  /* couleur par type de document : registre Z.typeDoc (documents.js) */
  --td-rapport: var(--success);
  --td-photo: var(--blue);
  --td-plan: var(--orange);
  --td-pv: color-mix(in oklab, var(--success) 55%, var(--blue));
  --td-devis: var(--accent);
  --td-bdc: color-mix(in oklab, var(--blue) 60%, var(--danger));
  --td-facture: color-mix(in oklab, var(--accent) 45%, var(--danger));
  --td-notice: var(--muted);
  --td-bl: color-mix(in oklab, var(--orange) 55%, var(--success));
  --td-autre: var(--muted);
  /* vignettes dessinées */
  --dm-carte-min: 210px;
  --dm-ratio: 4 / 3;
  --dm-photo-a: color-mix(in oklab, var(--blue) 70%, var(--bg));
  --dm-photo-b: color-mix(in oklab, var(--blue) 25%, var(--surface));
  --dm-photo-c: color-mix(in oklab, var(--success) 65%, var(--bg));
  --dm-photo-d: color-mix(in oklab, var(--orange) 55%, var(--bg));
  --dm-photo-e: color-mix(in oklab, var(--danger) 45%, var(--bg));
  --dm-trait: var(--border);
  --dm-ombre-survol: var(--e-3);
  --dm-barre-sel: var(--fg);
  --dm-barre-sel-txt: var(--bg);
}

.dm { display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }
.dm[hidden] { display: none; }
.dm-ecran { min-width: 0; }
.dm-todo { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; padding: var(--s-3) var(--s-4); margin-bottom: var(--s-3); border: 1px solid var(--accent); border-radius: var(--r-md); background: var(--accent-d); }
.dm-todo .btn { margin-left: auto; }
.dm-tri-s { height: var(--fl-champ-h); border: 1px solid var(--fl-bord); border-radius: var(--r-md); background: var(--surface); color: var(--fg); font: inherit; font-size: 13px; padding: 0 var(--s-3); }
.dm-vue button { width: 40px; height: calc(var(--fl-champ-h) - 2px); display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.dm-puces { display: flex; gap: var(--s-2); overflow-x: auto; padding: var(--s-1) 0; scrollbar-width: none; }
.dm-puces[hidden] { display: none; }
.dm-puce { display: inline-flex; align-items: center; gap: var(--s-2); height: 34px; padding: 0 var(--s-3); border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--fg); font: inherit; font-size: 13px; white-space: nowrap; cursor: pointer; transition: border-color var(--t-fast), background var(--t-fast); }
.dm-puce i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.dm-puce b { font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.dm-puce:hover { border-color: var(--muted); }
.dm-puce.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.dm-puce.on b { color: inherit; opacity: .7; }
.dm-compte { font-size: 13px; color: var(--muted); }
.dm-corps { min-width: 0; transition: opacity var(--t-base); }
.dm-corps.dm-charge { opacity: .55; }
.dm-groupe { margin-top: var(--s-4); }
.dm-groupe:first-child { margin-top: 0; }
.dm-groupe-t { display: flex; align-items: center; gap: var(--s-2); margin: 0 0 var(--s-3); font-size: 13px; font-weight: 600; color: var(--muted); }
.dm-groupe-t span { font-weight: 500; font-variant-numeric: tabular-nums; }
.dm-groupe-t::after { content: ""; flex: 1; height: 1px; background: var(--border); order: 3; }
.dm-grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--dm-carte-min), 1fr)); gap: var(--s-4); }

/* Carte (vignettes) */
.dm-card { position: relative; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; cursor: pointer; transition: transform var(--t-base), box-shadow var(--t-base), border-color var(--t-fast); }
.dm-card:hover { transform: translateY(-2px); box-shadow: var(--dm-ombre-survol); }
.dm-card.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.dm-vign { position: relative; aspect-ratio: var(--dm-ratio); background: var(--surface2); overflow: hidden; }
.dm-th { position: absolute; inset: 0; display: grid; place-items: center; }
.dm-page { display: grid; align-content: start; gap: 5px; width: 56%; height: 82%; padding: 9% 8%; border-radius: var(--r-sm); background: var(--surface); box-shadow: var(--e-2); transform: translateY(6%); transition: transform var(--t-base); }
.dm-card:hover .dm-page { transform: translateY(2%) scale(1.03); }
.dm-page s { display: block; height: 4px; border-radius: 2px; background: var(--dm-trait); }
.dm-page s:nth-child(1) { width: 60%; height: 6px; background: var(--c); }
.dm-page s:nth-child(4) { width: 80%; }
.dm-page s:nth-child(6) { width: 50%; }
.dm-page i { display: block; height: 20px; border-radius: 2px; background: color-mix(in oklab, var(--c) 14%, var(--surface2)); }
.dm-th-photo { background: linear-gradient(135deg, var(--dm-photo-a), var(--dm-photo-b)); color: var(--surface); }
.dm-th-photo.dm-g1 { background: linear-gradient(135deg, var(--dm-photo-c), var(--dm-photo-b)); }
.dm-th-photo.dm-g2 { background: linear-gradient(135deg, var(--dm-photo-d), var(--dm-photo-b)); }
.dm-th-photo.dm-g3 { background: linear-gradient(135deg, var(--dm-photo-e), var(--dm-photo-b)); }
.dm-th-plan { background: repeating-linear-gradient(0deg, transparent 0 17px, color-mix(in oklab, var(--c) 22%, transparent) 17px 18px), repeating-linear-gradient(90deg, transparent 0 17px, color-mix(in oklab, var(--c) 22%, transparent) 17px 18px), var(--surface2); color: var(--c); }
.dm-th-ico svg { width: 38px; height: 38px; opacity: .85; }
.dm-tag { position: absolute; left: var(--s-3); top: var(--s-3); max-width: calc(100% - 56px); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 3px var(--s-2); border-radius: var(--r-sm); background: var(--surface); color: var(--c); font-size: 11.5px; font-weight: 650; box-shadow: var(--e-2); }
.dm-tag i { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: var(--c); }
.dm-chk { all: unset; box-sizing: border-box; position: absolute; right: var(--s-2); top: var(--s-2); width: 26px; height: 26px; display: grid; place-items: center; border: 1.5px solid var(--fl-bord); border-radius: var(--r-sm); background: var(--surface); color: transparent; cursor: pointer; opacity: 0; transition: opacity var(--t-fast); }
.dm-chk:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dm-card:hover .dm-chk, .dm-card:focus-within .dm-chk, .dm-card.sel .dm-chk, .dm-mode-sel .dm-chk { opacity: 1; }
.dm-card.sel .dm-chk { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.dm-acts { position: absolute; right: var(--s-2); bottom: var(--s-2); display: flex; gap: var(--s-2); opacity: 0; transform: translateY(6px); transition: opacity var(--t-base), transform var(--t-base); z-index: 2; }
.dm-card:hover .dm-acts, .dm-card:focus-within .dm-acts { opacity: 1; transform: none; }
.dm-acts button { all: unset; box-sizing: border-box; width: 32px; height: 32px; display: grid; place-items: center; border-radius: var(--r-sm); background: var(--surface); color: var(--fg); box-shadow: var(--e-2); cursor: pointer; }
.dm-acts button:hover, .dm-acts button:focus-visible { background: var(--accent); color: var(--accent-text); }
.dm-meta { display: flex; flex-direction: column; gap: 3px; padding: var(--s-3); min-width: 0; }
.dm-titre { all: unset; cursor: pointer; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-titre:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.dm-rat { font-size: 12.5px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow-wrap: anywhere; }      /* deux lignes au plus, la ligne complète est en infobulle */
.dm-rat .crumb-link { display: inline; color: inherit; text-decoration: underline; text-decoration-color: var(--border); }
.dm-sous { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1) var(--s-2); font-size: 12.5px; color: var(--muted); }
.dm-raison { padding: 1px var(--s-2); border-radius: 999px; background: var(--surface2); border: 1px solid var(--border); font-size: 11.5px; }

/* Mode liste compacte */
.dm-liste .dm-grille { display: block; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.dm-liste .dm-card { display: grid; grid-template-columns: 44px minmax(0, 1.3fr) minmax(0, 1.6fr) auto; align-items: center; gap: var(--s-3); border: 0; border-top: 1px solid var(--border); border-radius: 0; padding: var(--s-2) var(--s-3); transform: none; box-shadow: none; }
.dm-liste .dm-card:first-child { border-top: 0; }
.dm-liste .dm-card:hover { background: var(--surface2); }
.dm-liste .dm-card.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.dm-liste .dm-vign { display: contents; }
.dm-liste .dm-th { position: relative; inset: auto; grid-column: 1; grid-row: 1 / 3; width: 44px; aspect-ratio: 1; border-radius: var(--r-md); overflow: hidden; background: var(--surface2); }
.dm-liste .dm-page { width: 60%; padding: 12% 10%; gap: 3px; }
.dm-liste .dm-page s { height: 2px; }
.dm-liste .dm-th-ico svg { width: 22px; height: 22px; }
.dm-liste .dm-tag, .dm-liste .dm-chk { display: none; }
.dm-liste .dm-meta { display: contents; }
.dm-liste .dm-titre { grid-column: 2; grid-row: 1; }
.dm-liste .dm-rat { grid-column: 3; grid-row: 1; }
.dm-liste .dm-sous { grid-column: 2 / 4; grid-row: 2; }
.dm-liste .dm-acts { position: static; opacity: 1; transform: none; grid-column: 4; grid-row: 1 / 3; }
.dm-liste .dm-card:hover .dm-th { transform: none; }
.dm-liste .dm-acts button { box-shadow: none; border: 1px solid var(--border); }

/* Barre de sélection flottante */
.dm-selbar { position: fixed; left: 50%; bottom: var(--s-5); transform: translateX(-50%); z-index: 60; display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4); border-radius: var(--r-lg); background: var(--dm-barre-sel); color: var(--dm-barre-sel-txt); box-shadow: var(--e-4); white-space: nowrap; }
.dm-selbar[hidden] { display: none; }
.dm-selbar .btn:not(.btn-primary) { background: transparent; color: inherit; border-color: var(--border); }
.dm-sel-n { font-weight: 600; font-size: 13px; }
@media (prefers-reduced-motion: no-preference) {
  .dm-selbar { animation: dm-monte var(--t-base) ease-out; }
  .dm-card { animation: dm-entree .3s ease-out both; animation-delay: calc(var(--i, 0) * 25ms); }
  .dm-sk { animation: dm-pouls 1.2s ease-in-out infinite; }
  @keyframes dm-monte { from { opacity: 0; transform: translate(-50%, 12px); } }
  @keyframes dm-entree { from { opacity: 0; transform: translateY(8px); } }
  @keyframes dm-pouls { 50% { opacity: .5; } }
}

/* États : vide et squelette */
.dm-vide { text-align: center; padding: 56px var(--s-4); border: 1px dashed var(--fl-bord); border-radius: var(--r-lg); color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: var(--s-3); }
.dm-vide h3 { margin: 0; color: var(--fg); font-size: 16px; }
.dm-sk { display: flex; flex-direction: column; gap: var(--s-2); }
.dm-sk span { display: block; aspect-ratio: var(--dm-ratio); border-radius: var(--r-lg); background: var(--surface2); }
.dm-sk i, .dm-sk b { display: block; height: 14px; border-radius: var(--r-sm); background: var(--surface2); width: 80%; }
.dm-sk b { height: 12px; width: 55%; }
.dm-pages { display: flex; align-items: center; justify-content: center; gap: var(--s-3); font-size: 13px; }

/* Dossiers */
.dm-dossiers { display: grid; grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); gap: var(--s-4); align-items: start; }
.dm-arbre { border: 1px solid var(--border); border-radius: var(--r-md); padding: 6px; max-height: calc(100vh - 220px); overflow: auto; position: sticky; top: var(--s-2); }
.dm-arbre ul { list-style: none; margin: 0; padding: 0; }
.dm-n { display: flex; align-items: center; gap: 2px; padding-left: calc(var(--niv, 0) * 14px); }
.dm-pli, .dm-pli-v { flex: 0 0 26px; width: 26px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12px; }
.dm-n-b { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; border: 0; background: none; color: inherit; font: inherit; font-size: 13px; text-align: left; padding: 5px 6px; border-radius: 6px; cursor: pointer; min-height: 32px; }
.dm-n-b svg { flex: 0 0 auto; color: var(--muted); }
.dm-n-b:hover { background: var(--surface2); }
.dm-n.actif .dm-n-b { background: var(--surface2); font-weight: 600; }
.dm-n.actif .dm-n-b svg { color: var(--accent); }
.dm-n-l { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-n-c { flex: 0 0 auto; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; padding: 0 6px; border-radius: 999px; background: var(--bg); }
.dm-contenu { min-width: 0; display: flex; flex-direction: column; gap: var(--s-3); }
.dm-ariane { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.dm-ariane-b { border: 0; background: none; color: inherit; font: inherit; padding: 2px 4px; cursor: pointer; text-decoration: underline; text-decoration-color: var(--border); }
.dm-ariane [aria-current] { color: var(--fg); font-weight: 600; }
.dm-h { display: flex; align-items: center; gap: var(--s-2); margin: 0; font-size: 17px; flex-wrap: wrap; }
.dm-h .pm-muted { font-size: 13px; font-weight: 400; }
.dm-dossiers-cartes { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--s-3); }
.dm-dos { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "ico nom" "ico nb" "barre barre"; column-gap: var(--s-3); row-gap: 2px; align-items: center; text-align: left; padding: var(--s-3) var(--s-4); border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); color: inherit; font: inherit; cursor: pointer; transition: border-color var(--t-fast), transform var(--t-base), box-shadow var(--t-base); }
.dm-dos:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--dm-ombre-survol); }
.dm-dos-ico { grid-area: ico; display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--r-md); background: var(--accent-d); color: var(--accent); }
.dm-dos-ico svg { width: 22px; height: 22px; }
.dm-dos-nom { grid-area: nom; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-dos-nb { grid-area: nb; font-size: 12.5px; color: var(--muted); }
.dm-dos-barre { grid-area: barre; display: flex; gap: 2px; height: 6px; margin-top: var(--s-2); border-radius: 3px; overflow: hidden; background: var(--surface2); }
.dm-dos-barre i { display: block; min-width: 3px; }

.zv-repli .dm-th { position: relative; width: 140px; aspect-ratio: var(--dm-ratio); border-radius: var(--r-md); overflow: hidden; background: var(--surface); }

@media (max-width: 860px) { .dm-dossiers { grid-template-columns: minmax(0, 1fr); } .dm-arbre { display: none; } }
@media (max-width: 640px) {
  .dm-grille { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
  .dm-chk { opacity: 1; }
  .dm-grille .dm-acts { display: none; }                      /* tactile : un appui ouvre l'aperçu (Partager et Télécharger y sont) */
  .dm-tri-s { flex: 1 1 90px; min-width: 0; }
  .dm-vue button { width: 34px; }
  .fl-wrap, .dm-vue { flex: 0 0 auto; }
  .dm-liste .dm-card { grid-template-columns: 44px minmax(0, 1fr) auto; }
  .dm-liste .dm-rat { display: none; }
  .dm-liste .dm-sous { grid-column: 2; }
  .dm-liste .dm-acts { grid-column: 3; }
  .dm-liste .dm-acts button:not(:first-child) { display: none; }
  .dm-selbar { left: var(--s-3); right: var(--s-3); transform: none; justify-content: space-between; flex-wrap: wrap; white-space: normal; }
  @keyframes dm-monte { from { opacity: 0; } }
}
.dm-q { display: block; width: 100%; max-width: 420px; margin: var(--s-2) 0 var(--s-3); }
.dm-q-vide { grid-column: 1 / -1; }
