/* PIM — feuille de style. Même famille visuelle que Qarto (DM Sans, fonds chauds), accent bleu pétrole propre au PIM. */
:root {
  --bg: #f5f4f0; --surface: #ffffff; --surface2: #f8f7f3; --ink: #1d1e24; --muted: #5d606c; --faint: #8b8d97;
  --line: #e6e3dc; --line2: #c8c4ba; --accent: #1f6f8b; --accent-ink: #ffffff; --accent-soft: #e3f0f4;
  --ok: #23845a; --ok-soft: #e3f3ea; --warn: #b7791f; --warn-soft: #fbf0dc; --danger: #c0392f; --danger-soft: #fbe5e3;
  --f-ui: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "DM Mono", ui-monospace, Menlo, monospace;
  --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141310; --surface: #1d1c18; --surface2: #23221e; --ink: #ecebe6; --muted: #aaa79d; --faint: #7d7a71;
    --line: #34322c; --line2: #4f4b43; --accent: #5fb3cf; --accent-ink: #0d1b21; --accent-soft: #19313a;
    --ok: #52c58c; --ok-soft: #173327; --warn: #e5b04a; --warn-soft: #3a2e14; --danger: #ef6b60; --danger-soft: #3d1c19;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--f-ui); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-family: var(--f-mono); font-size: .92em; }

/* En-tête */
.haut {
  position: sticky; top: 0; z-index: 30; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.marque { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--ink); text-decoration: none; }
.choix { display: flex; gap: 8px; flex-wrap: wrap; }
.choix select { max-width: 260px; }
.onglets { display: flex; gap: 2px; background: var(--surface2); border: 1px solid var(--line); border-radius: var(--r); padding: 3px; }
.onglets a { padding: 5px 12px; border-radius: 6px; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap; }
.onglets a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.moi { margin-left: auto; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.moi form { margin: 0; }

select, input[type="text"], input[type="search"], input[type="password"], input[type="email"], textarea {
  background: var(--surface); border: 1px solid var(--line2); border-radius: 6px; padding: 6px 9px; min-height: 36px;
}
textarea { width: 100%; min-height: 90px; resize: vertical; }
.bouton {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 6px 12px; border-radius: 6px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line2); font-weight: 500;
}
.bouton:hover { border-color: var(--accent); }
.bouton.principal { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.bouton.discret { border-color: transparent; background: transparent; color: var(--muted); }
.bouton.danger { color: var(--danger); }
.bouton[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }

#vue { padding: 16px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left)); max-width: 1680px; margin: 0 auto; }
h1 { font-size: 22px; margin: 4px 0 14px; line-height: 1.2; }
h2 { font-size: 16px; margin: 0 0 10px; }
.sous { color: var(--muted); margin: -8px 0 16px; }
.vide { color: var(--muted); padding: 24px 0; }
.barre { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.barre .espace { flex: 1; }

/* Pastilles d'état */
.pastille { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.pastille::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pastille.pret { color: var(--ok); background: var(--ok-soft); }
.pastille.manque { color: var(--warn); background: var(--warn-soft); }
.pastille.statut { color: var(--muted); background: var(--surface2); border: 1px solid var(--line); }
.pastille.statut::before { display: none; }

/* Tableau de bord */
.cartes { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 14px; align-items: start; }
.carte { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; min-width: 0; }
.jauge { height: 8px; background: var(--surface2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; margin: 6px 0 14px; }
.jauge i { display: block; height: 100%; background: var(--ok); }
.chiffre { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.liste { list-style: none; margin: 0; padding: 0; }
.liste li { display: flex; gap: 10px; justify-content: space-between; align-items: baseline; padding: 7px 0; border-top: 1px solid var(--line); min-width: 0; }
.liste li:first-child { border-top: 0; }
.liste .txt { min-width: 0; overflow-wrap: anywhere; }
.liste .nb { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.liste li.pile { flex-direction: column; align-items: flex-start; gap: 2px; }
.liste li.pile .nb { white-space: normal; font-size: 12.5px; }
.envois li { flex-wrap: wrap; }
.envois .txt { flex: 1 1 220px; }
.envois details.confirmer { flex: 1 1 100%; }
.liste li.inactif .txt { color: var(--faint); }
select { max-width: 100%; }
.ajout select { flex: 1 1 200px; min-width: 0; }
.ajout input[type="file"] { flex: 1 1 200px; min-width: 0; max-width: 100%; }
.gravite-bloquant { color: var(--danger); }
.gravite-corriger { color: var(--warn); }
.gravite-verifier { color: var(--muted); }

/* Grille (Jspreadsheet) */
/* Jspreadsheet met son conteneur en inline-block (il prend la largeur du tableau) : on le garde dans la page */
.grille-hote.jexcel_container { display: block; width: 100%; max-width: 100%; padding-right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.grille-hote > .jexcel_content { width: 100% !important; max-width: 100%; }
.grille-hote > .jexcel_filter { display: flex; justify-content: flex-end; padding: 8px; border-bottom: 1px solid var(--line); background: var(--surface2); }
.grille-hote > .jexcel_filter > div:empty { display: none; }
.jexcel, .jexcel thead td, .jexcel tbody td { font-family: var(--f-ui); font-size: 13.5px; }
.jexcel thead td { background: var(--surface2) !important; color: var(--muted); font-weight: 600; white-space: normal; line-height: 1.2; }
.jexcel tbody td { background: var(--surface); color: var(--ink); border-color: var(--line) !important; }
.jexcel > tbody > tr > td.readonly { color: var(--muted); }
.jexcel > tbody > tr > td:first-child, .jexcel > thead > tr > td:first-child { background: var(--surface2); color: var(--faint); }
.jexcel .highlight { background: var(--accent-soft) !important; }
.jexcel > tbody > tr > td.refuse { background: var(--danger-soft) !important; }
.jexcel > tbody > tr > td.lien-fiche { color: var(--accent); text-decoration: underline; cursor: pointer; }
.jexcel_search_container input { min-height: 32px; }
.jexcel_filter { padding: 8px; }
.jdropdown-container, .jexcel_contextmenu { background: var(--surface); color: var(--ink); }
.cartes-produits { display: none; }

/* Fiche */
.fiche-tete { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 10px; }
.fiche-tete h1 { margin: 0; }
.fiche-corps { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.fiche-corps.sans-panneau { grid-template-columns: minmax(0, 1fr); }
.fiche-corps.sans-panneau .panneau { display: none; }
.fiche-tete .ref { font-family: var(--f-mono); font-size: 13px; color: var(--muted); }
.statut-fiche { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }
.statut-fiche select { min-height: 34px; color: var(--muted); }
.pastille.st-brouillon { background: var(--surface2); color: var(--muted); }
.pastille.st-a_relire { background: var(--warn-soft); color: var(--warn); }
.pastille.st-valide, .pastille.st-importe { background: var(--ok-soft); color: var(--ok); }
/* Onglet « À faire » : une ligne par chose à faire, le bouton mène au bon endroit */
.taches { list-style: none; margin: 0; padding: 0; }
.tache { display: flex; align-items: center; gap: 12px; padding: 12px 0 12px 18px; border-top: 1px solid var(--line); position: relative; }
.tache:first-child { border-top: 0; }
.tache::before { content: ""; position: absolute; left: 0; top: 19px; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.tache.bloquant::before { background: var(--danger); }
.tache.verifier::before { background: var(--line2); }
.tache-txt { flex: 1; min-width: 0; display: grid; gap: 2px; }
.tache-txt details { font-size: 13px; color: var(--muted); }
.tache-txt details ul { margin: 4px 0 0; padding-left: 18px; }
.tache .bouton { flex: 0 0 auto; }
.fiche-corps > *, .carte, details.bloc { min-width: 0; }
.manques a, .liste a { overflow-wrap: anywhere; }
.fiche-onglets { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; scrollbar-width: thin; }
.fiche-onglets button { white-space: nowrap; flex: 0 0 auto; }
.fiche-onglets button.afaire { font-weight: 600; }
.fiche-onglets button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 10px; color: var(--muted); cursor: pointer; font-weight: 500; }
.fiche-onglets button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.fiche-onglets .compte { font-size: 11.5px; color: var(--warn); margin-left: 4px; }
.champs { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 14px 18px; }
.champ { display: grid; gap: 4px; min-width: 0; }
.champ.large { grid-column: 1 / -1; }
.champ label { font-weight: 600; font-size: 13.5px; }
.champ .aide { color: var(--muted); font-size: 12.5px; display: flex; gap: 8px; justify-content: space-between; }
.champ.manquant label::after { content: " — à remplir"; color: var(--warn); font-weight: 500; }
.champ .etat-enreg { font-size: 12px; color: var(--ok); min-height: 1em; }
.champ .etat-enreg.erreur { color: var(--danger); }
.champ input[type="text"], .champ select { width: 100%; }
.panneau { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; position: sticky; top: 70px; }
.panneau h2 { font-size: 14px; }
.manques { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 13.5px; }
.manques li { display: flex; gap: 8px; align-items: baseline; }
.manques li::before { content: ""; flex: 0 0 8px; height: 8px; border-radius: 50%; background: var(--warn); transform: translateY(1px); }
.manques li.bloquant::before { background: var(--danger); }
.manques li.verifier::before { background: var(--line2); }
.tableau { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tableau th, .tableau td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tableau th { color: var(--muted); font-weight: 600; }
.tableau input[type="text"], .tableau select { width: 100%; min-width: 70px; }
.defile { overflow-x: auto; }
.bloc { margin-bottom: 22px; }
.bloc h2 { display: flex; gap: 8px; align-items: center; }
.ajout { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.ajout input[type="text"] { flex: 1 1 220px; }
.note { color: var(--muted); font-size: 13px; }
.histo { font-size: 13px; }
.histo li { display: block; overflow-wrap: anywhere; }
.histo .quand { color: var(--muted); font-family: var(--f-mono); font-size: 12px; }

/* Annonces */
.annonces { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); display: grid; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.annonce { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: var(--r); box-shadow: 0 4px 14px rgba(0, 0, 0, .2); }
.annonce.erreur { background: var(--danger); color: #fff; }

/* Page de connexion */
.connexion { max-width: 380px; margin: 14vh auto 40px; padding: 0 16px; }
.connexion h1 { display: flex; align-items: center; gap: 10px; }
.connexion form { display: grid; gap: 6px; margin: 18px 0 14px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.connexion label { font-weight: 600; font-size: 13.5px; margin-top: 6px; }
.connexion input { width: 100%; }
.connexion .bouton { margin-top: 12px; justify-content: center; }
.provisoire { font-family: var(--f-mono); font-size: 18px; letter-spacing: .04em; padding: 10px 12px; background: var(--accent-soft); border-radius: 6px; user-select: all; overflow-wrap: anywhere; }

/* Téléphone et petites tablettes : la grille laisse place à une liste ; la fiche passe sur une colonne */
@media (max-width: 860px) {
  .fiche-corps { grid-template-columns: minmax(0, 1fr); }
  .panneau { position: static; order: -1; }
  .moi { display: none; }
}
@media (max-width: 760px) {
  .tache { flex-wrap: wrap; }
  .statut-fiche { margin-left: 0; width: 100%; }
  .grille-hote.jexcel_container, .grille-outils { display: none; }
  .cartes-produits { display: grid; gap: 8px; }
  .cartes-produits a { display: grid; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; color: var(--ink); text-decoration: none; }
  .cartes-produits .pastille { justify-self: start; }
  .cartes-produits .ref { font-family: var(--f-mono); font-size: 12.5px; color: var(--muted); }
  .haut { gap: 8px; }
  .choix { order: 3; width: 100%; }
  .choix select { flex: 1; max-width: none; }
  .onglets { order: 4; width: 100%; overflow-x: auto; }
  .onglets a { flex: 1 0 auto; text-align: center; padding: 6px 8px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
/* Grille : une ligne par produit (une description longue ne doit pas étirer la ligne) */
.grille-hote .jexcel tbody td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px; height: 32px; line-height: 1.3; }

/* Icônes (dessinées dans app.js) */
.ico { display: inline-flex; vertical-align: -3px; margin-right: 6px; flex: 0 0 auto; }
.onglets a .ico { margin-right: 5px; opacity: .8; }
.tache-txt strong .ico { color: var(--muted); }

/* Recherche globale de l'en-tête */
.recherche { position: relative; flex: 1 1 200px; max-width: 340px; min-width: 0; }
.recherche input { width: 100%; padding-right: 30px; }
.recherche kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font: 11px var(--f-mono); color: var(--faint); border: 1px solid var(--line2); border-radius: 4px; padding: 0 5px; }
.recherche input:focus ~ kbd, .recherche input:not(:placeholder-shown) ~ kbd { display: none; }
.resultats { position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line2); border-radius: var(--r); box-shadow: 0 6px 20px rgba(0, 0, 0, .12); padding: 4px; min-width: 260px; }
.resultats a { display: block; padding: 7px 9px; border-radius: 6px; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.resultats a.actif, .resultats a:hover { background: var(--accent-soft); }
.resultats .ref { font-family: var(--f-mono); font-size: 12.5px; color: var(--muted); }
.resultats p { margin: 6px 9px; }

/* Filtres en pastilles et actions groupées de la grille */
.filtres { display: grid; gap: 6px; margin: 4px 0 10px; }
.groupe-filtre { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.groupe-filtre > .note { min-width: 64px; }
.pastille-filtre { border: 1px solid var(--line2); background: var(--surface); border-radius: 999px; padding: 3px 11px; font-size: 13px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.pastille-filtre .n { color: var(--faint); font-variant-numeric: tabular-nums; }
.pastille-filtre[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.barre-masse { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px; margin: 0 0 8px; border-radius: var(--r); background: var(--surface2); border: 1px solid var(--line); }
.barre-masse.active { background: var(--accent-soft); border-color: var(--accent); }
.barre-masse select { max-width: 240px; }

/* Miniatures des médias */
.vignette { display: flex; align-items: center; justify-content: center; gap: 4px; width: 72px; height: 54px; border-radius: 6px; overflow: hidden; cursor: pointer; background: var(--surface2); border: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.vignette img { width: 100%; height: 100%; object-fit: cover; }
.vignette.vide { border-style: dashed; flex-direction: column; }
.vignette.vide .ico { margin: 0; }
.vignette.survol, .depot.survol { border-color: var(--accent); background: var(--accent-soft); }
.fiche-tete .couverture { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }

/* Import d'un classeur */
.import { margin-bottom: 16px; }
.depot { display: block; border: 1.5px dashed var(--line2); border-radius: var(--r); padding: 18px; text-align: center; color: var(--muted); cursor: pointer; margin: 8px 0 12px; }
@media (max-width: 760px) {
  .recherche { order: 2; max-width: none; flex-basis: 100%; }
  .groupe-filtre > .note { min-width: 0; width: 100%; }
}
