/* Page d'admin : pensée d'abord pour le téléphone (cartes), en lignes compactes sur ordinateur.
   Clair ou sombre selon le système. */
:root {
  color-scheme: light dark;
  --fond: #f5f5f7;
  --carte: #ffffff;
  --survol: #f0f0f3;
  --texte: #1c1c1e;
  --discret: #6e6e73;
  --bord: #d8d8dc;
  --accent: #2563eb;
  --erreur: #c62828;
  --nouveau: #2563eb;
  --vu: #a16207;
  --corrige: #15803d;
  --ignore: #6e6e73;
  --lum-app: 38%; /* luminosité des couleurs d'app */
  /* Sévérité : rouge et orange réservés aux urgences (jamais utilisés pour les apps). */
  --sev-a: #c62828;
  --sev-b: #d9480f;
  --sev-c: #a16207;
  --sev-d: #6e6e73;
  --regression: #c62828;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #111113;
    --carte: #1c1c1f;
    --survol: #26262a;
    --texte: #ececf0;
    --discret: #9a9aa2;
    --bord: #33333a;
    --accent: #60a5fa;
    --erreur: #f87171;
    --nouveau: #60a5fa;
    --vu: #facc15;
    --corrige: #4ade80;
    --ignore: #9a9aa2;
    --lum-app: 72%;
    --sev-a: #f87171;
    --sev-b: #fb923c;
    --sev-c: #facc15;
    --sev-d: #9a9aa2;
    --regression: #f87171;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fond);
  color: var(--texte);
}
[hidden] { display: none !important; }

/* --- Barre du haut */
.barre {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--carte);
  border-bottom: 1px solid var(--bord);
}
.titre { font-weight: 700; color: inherit; text-decoration: none; display: flex; align-items: center; gap: 8px; }
.compteur {
  min-width: 22px; padding: 0 7px; border-radius: 99px;
  background: var(--nouveau); color: var(--carte);
  font-size: .8rem; line-height: 22px; text-align: center;
}
main { max-width: 760px; margin: 0 auto; padding: 16px; }

.carte {
  background: var(--carte);
  border: 1px solid var(--bord);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.etroite { max-width: 420px; margin: 32px auto; }
h1 { font-size: 1.3rem; margin: 0 0 12px; }
h2 { font-size: 1.05rem; margin: 0 0 8px; }

/* --- Formulaires et boutons */
label { display: block; margin-bottom: 12px; font-weight: 600; }
label .discret { font-weight: 400; font-size: .85rem; }
input, select, textarea, button { font: inherit; }
input, select, textarea {
  display: block; width: 100%;
  margin-top: 4px; padding: 10px 12px;
  background: var(--fond); color: inherit;
  border: 1px solid var(--bord); border-radius: 8px;
}
textarea { resize: vertical; font-weight: 400; }
button {
  padding: 10px 16px; min-height: 44px;
  border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 600;
  cursor: pointer;
}
button.secondaire { background: transparent; color: var(--accent); border: 1px solid var(--bord); width: 100%; }
button.petit { width: auto; min-height: 36px; padding: 6px 12px; }
button.discret, .discret { background: none; color: var(--discret); min-height: 0; padding: 4px 0; font-weight: 400; }
button:disabled { opacity: .5; cursor: default; }
.erreur { color: var(--erreur); margin: 8px 0; }
.erreur:empty, .message:empty { display: none; }
.message { color: var(--discret); margin: 8px 0 0; font-size: .9rem; }

/* --- Couleur propre à chaque app (teinte posée par le script) */
.couleur-app { color: hsl(var(--teinte, 220) 65% var(--lum-app)); }
.reference {
  font: 600 .85rem/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
}
.reference.couleur-app::before {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px;
  border-radius: 50%; background: currentColor; vertical-align: 1px;
}

/* --- Barre de filtres */
.recherche { margin: 0 0 10px; }
.defilant {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px;
  scrollbar-width: thin;
}
.puce, .onglet {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 6px 12px;
  background: var(--carte); color: var(--texte); font-weight: 500;
  border: 1px solid var(--bord); border-radius: 99px;
}
.puce[aria-pressed="true"], .onglet[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.onglet[aria-pressed="true"] { background: var(--accent); color: #fff; }
.nombre { color: var(--discret); font-size: .85rem; font-variant-numeric: tabular-nums; }
.onglet[aria-pressed="true"] .nombre { color: inherit; opacity: .85; }
.nombre.zero { opacity: .5; }

.outils { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.outils select { width: auto; flex: 1 1 140px; margin: 0; padding: 6px 10px; min-height: 36px; }
.outils select.actif { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
#filtre-regression[aria-pressed="true"] { border-color: var(--regression); box-shadow: inset 0 0 0 1px var(--regression); color: var(--regression); }
.filtre-actif {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 10px;
  border: 1px dashed var(--accent); border-radius: 99px; font-size: .9rem;
}
.filtre-actif button { padding: 0 8px; min-height: 28px; }

/* --- Liste : cartes sur téléphone */
.liste { list-style: none; margin: 0 0 16px; padding: 0; }
.liste li { display: flex; align-items: stretch; gap: 8px; margin-bottom: 8px; }
.liste .case { width: 22px; height: 22px; flex: none; align-self: center; margin: 0; }
.ligne {
  flex: 1; min-width: 0;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 8px;
  color: inherit; text-decoration: none;
  background: var(--carte); border: 1px solid var(--bord); border-radius: 12px;
  padding: 12px 14px;
}
.ligne:hover { background: var(--survol); }
.ligne .tete { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ligne .date { grid-column: 2; grid-row: 1; color: var(--discret); font-size: .85rem; white-space: nowrap; }
.ligne .corps { grid-column: 1 / -1; min-width: 0; }
.apercu {
  overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3;
  -webkit-box-orient: vertical; overflow: hidden;
}
.vide { text-align: center; padding: 24px 0; }

.pastille {
  display: inline-block; padding: 0 8px; border-radius: 99px;
  font-size: .78rem; font-weight: 600; line-height: 1.6;
  border: 1px solid currentColor;
}
.statut-nouveau { color: var(--nouveau); }
.statut-vu { color: var(--vu); }
.statut-corrige { color: var(--corrige); }
.statut-ignore { color: var(--ignore); }
/* Sévérité : carré plein pour A et B (à voir tout de suite), contour pour C et D. */
.sev {
  display: inline-grid; place-items: center; flex: none;
  width: 22px; height: 22px; border-radius: 6px;
  font: 700 .8rem/1 system-ui, sans-serif; border: 1.5px solid currentColor;
}
.sev-A { color: var(--sev-a); }
.sev-B { color: var(--sev-b); }
.sev-C { color: var(--sev-c); }
.sev-D { color: var(--sev-d); }
.sev.sev-A { background: var(--sev-a); border-color: var(--sev-a); color: #fff; }
.sev.sev-B { background: var(--sev-b); border-color: var(--sev-b); color: #fff; }
.sev-aucune { color: var(--bord); border-style: dashed; }
.pastille.regression { color: var(--regression); font-weight: 700; }
.classement-court { color: var(--discret); font-size: .82rem; white-space: nowrap; }

.etiquettes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.etiquette {
  display: inline-block; padding: 0 8px; border-radius: 6px; cursor: pointer;
  font-size: .8rem; line-height: 1.6; background: var(--fond); border: 1px solid var(--bord); color: var(--discret);
  overflow-wrap: anywhere;
}
.etiquette:hover { border-color: var(--accent); color: var(--accent); }

/* --- Actions groupées (collées en bas de l'écran) */
.barre-lot {
  position: sticky; bottom: 0; z-index: 2;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin: 0 -16px; padding: 10px 16px;
  background: var(--carte); border-top: 1px solid var(--bord);
}
.barre-lot #lot-compte { flex: 1 1 100%; font-size: .9rem; color: var(--discret); }

/* --- Fiche */
.navigation-fiche { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.retour, .secondaire-lien { color: var(--accent); text-decoration: none; padding: 6px 0; }
.secondaire-lien { padding: 6px 10px; border: 1px solid var(--bord); border-radius: 8px; background: var(--carte); }
.secondaire-lien.inactif { opacity: .35; pointer-events: none; }
.precedent-suivant { display: flex; align-items: center; gap: 8px; }
.precedent-suivant .discret { font-size: .85rem; font-variant-numeric: tabular-nums; }

.entete { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0 0 12px; }
.entete .reference { font-size: 1.25rem; }
.entete .date { margin-left: auto; font-size: .9rem; }

.statuts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.statuts button {
  min-height: 40px; padding: 6px 4px;
  background: transparent; color: var(--discret); font-weight: 500;
  border: 1px solid var(--bord);
}
.statuts button[aria-pressed="true"] { border-color: currentColor; box-shadow: inset 0 0 0 1px currentColor; font-weight: 700; }
.statuts button.statut-nouveau { color: var(--nouveau); }
.statuts button.statut-vu { color: var(--vu); }
.statuts button.statut-corrige { color: var(--corrige); }
.statuts button.statut-ignore { color: var(--ignore); }
#f-statut-message { margin: 6px 0 0; }

/* Classement dans la fiche */
.classement {
  display: grid; grid-template-columns: 1fr; gap: 10px;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--bord);
}
.champ { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.libelle { width: 80px; flex: none; font-size: .9rem; color: var(--discret); font-weight: 400; margin: 0; }
.segments { display: flex; gap: 4px; }
.segments button {
  min-height: 36px; min-width: 40px; padding: 4px 10px;
  background: transparent; color: var(--texte); font-weight: 500;
  border: 1px solid var(--bord);
}
.segments button[aria-pressed="true"] { border-color: currentColor; box-shadow: inset 0 0 0 1px currentColor; font-weight: 700; }
#f-severite button { font-weight: 700; }
#f-severite button.sev-A { color: var(--sev-a); }
#f-severite button.sev-B { color: var(--sev-b); }
#f-severite button.sev-C { color: var(--sev-c); }
#f-severite button.sev-D { color: var(--sev-d); }
#f-severite button.sev-A[aria-pressed="true"] { background: var(--sev-a); border-color: var(--sev-a); color: #fff; }
#f-severite button.sev-B[aria-pressed="true"] { background: var(--sev-b); border-color: var(--sev-b); color: #fff; }
#f-nature button[aria-pressed="true"] { color: var(--accent); }
.aide { font-size: .85rem; padding: 0; }
.champ select { width: auto; flex: 1 1 180px; max-width: 260px; margin: 0; padding: 6px 10px; }
.case-regression { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 600; color: var(--regression); }
.case-regression input { width: 20px; height: 20px; margin: 0; accent-color: var(--regression); }
.case-regression .discret { font-size: .85rem; padding: 0; }

/* Onglets de la fiche (soulignés, plus discrets que les onglets de la liste) */
.onglets-fiche {
  display: flex; gap: 4px; overflow-x: auto; margin: 0 -16px 16px; padding: 0 16px;
  border-bottom: 1px solid var(--bord); scrollbar-width: none;
}
.onglets-fiche button {
  flex: none; min-height: 40px; padding: 8px 12px; border-radius: 0;
  background: none; color: var(--discret); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.onglets-fiche button:hover { color: var(--texte); }
.onglets-fiche button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.onglets-fiche .nombre { margin-left: 4px; }

.libelle-bloc {
  margin: 0 0 6px; font-size: .78rem; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--discret);
}
/* La description : encadré dédié, c'est le cœur de la fiche. */
.description-bloc {
  padding: 14px 16px; margin-bottom: 12px;
  background: var(--fond); border: 1px solid var(--bord); border-left: 3px solid var(--accent); border-radius: 8px;
}
.description { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font-size: 1.05rem; line-height: 1.55; }
#f-etiquettes .etiquettes { margin: 0 0 12px; }

/* Détails techniques : repliés, avec un résumé d'une ligne. */
.details-techniques { margin-top: 16px; border-top: 1px solid var(--bord); padding-top: 4px; }
.details-techniques summary {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  padding: 8px 0; cursor: pointer; list-style: none;
}
.details-techniques summary::-webkit-details-marker { display: none; }
.details-techniques summary::before {
  content: "▸"; color: var(--discret); transition: transform .15s; display: inline-block;
}
.details-techniques[open] summary::before { transform: rotate(90deg); }
.details-titre { font-size: .9rem; font-weight: 600; color: var(--discret); }
.details-techniques summary .discret { font-size: .85rem; padding: 0; }
.details-techniques .infos { padding: 4px 0 8px 18px; }

/* Panneau de tri */
.tri .carte { margin-bottom: 16px; }
.tri .classement { margin-top: 14px; }
.tri .champ select { max-width: none; }
.tri #form-fiche label { font-size: .9rem; }
.infos { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 0; font-size: .9rem; }
.infos dt { color: var(--discret); }
.infos dd { margin: 0; overflow-wrap: anywhere; }

.ligne-json { margin-top: 16px; }
.ligne-entete { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; color: var(--discret); font-size: .9rem; }
.ligne-json pre {
  margin: 0; padding: 12px; overflow-x: auto;
  background: var(--fond); border: 1px solid var(--bord); border-radius: 8px;
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre; user-select: all;
}

.historique { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.historique li { padding: 6px 0; border-top: 1px solid var(--bord); overflow-wrap: anywhere; }
.historique li:first-child { border-top: 0; }

/* --- Ordinateur : page plus large, liste en lignes compactes */
@media (min-width: 900px) {
  main { max-width: 1120px; padding: 20px 24px; }
  .barre { padding: 10px 24px; }
  .barre-lot { margin: 0 -24px; padding: 10px 24px; }
  .barre-lot #lot-compte { flex: 1 1 auto; }
  .recherche { max-width: 520px; }
  .outils select { flex: 0 1 172px; }
  #mode-selection { margin-left: auto; }

  .liste { border: 1px solid var(--bord); border-radius: 12px; overflow: hidden; background: var(--carte); }
  .liste li { margin: 0; gap: 0; border-top: 1px solid var(--bord); }
  .liste li:first-child { border-top: 0; }
  .liste .case { margin-left: 14px; }
  .ligne {
    grid-template-columns: 290px minmax(0, 1fr) 120px; align-items: center; gap: 12px;
    border: 0; border-radius: 0; padding: 10px 14px;
  }
  .ligne .tete { grid-column: 1; grid-row: 1; }
  .ligne .corps { grid-column: 2; grid-row: 1; display: flex; align-items: center; gap: 8px; }
  .ligne .date { grid-column: 3; text-align: right; }
  .apercu { -webkit-line-clamp: 1; line-clamp: 1; flex: 1; min-width: 0; }
  .ligne .etiquettes { margin: 0; flex: none; flex-wrap: nowrap; max-width: 40%; overflow: hidden; }

  /* Fiche : ce qu'on lit à gauche, le panneau de tri à droite (il reste visible en défilant). */
  #vue-fiche:not([hidden]) {
    display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 0 16px; align-items: start;
  }
  #vue-fiche .navigation-fiche { grid-column: 1 / -1; }
  #vue-fiche .principal { grid-column: 1; }
  #vue-fiche .tri { grid-column: 2; position: sticky; top: 64px; }
}

/* Doublons */
.doublon-form { display: flex; gap: 6px; align-items: center; }
.doublon-form input { width: 9em; min-height: 32px; padding: 4px 8px; }
.doublon-form button.secondaire { width: auto; }
.doublon-actuel { display: inline-flex; gap: 10px; align-items: baseline; font-weight: 600; }
.pastille.fois { color: var(--accent); }
.pastille.doublon { color: var(--discret); font-weight: 500; }
#f-rappels .texte { display: block; margin-top: 2px; }
