:root {
  --nuit: #2b1e4a;
  --accent: #6a4fc4;
  --accent-pale: #f3effd;
  --texte: #1d1b22;
  --doux: #6b6775;
  --bord: #d6d2de;
  --fond: #faf9fc;
  --carte: #ffffff;
  --ok-fond: #e6f5ec;
  --ok: #1f6b42;
  --ko-fond: #fdecea;
  --ko: #a3231a;
  --rayon: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
/* Un champ amené à l'écran ne doit finir ni sous l'en-tête collant, ni sous la barre d'action */
html { scroll-padding: 84px 0 136px; }
body {
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.ecran { max-width: 560px; margin: 0 auto; min-height: 100dvh; background: var(--carte); }

/* En-tête */
.entete {
  position: sticky; top: 0; z-index: 2;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--nuit); color: #fff;
}
.entete strong { font-size: 17px; display: block; }
.entete-lieu { font-size: 13px; opacity: .8; }
.entete > div:first-child { min-width: 0; }
.entete-actions { display: flex; gap: 6px; flex: none; }
@media (max-width: 380px) { .btn-entete { padding: 0 9px; font-size: 13px; } .entete strong { font-size: 15px; } }
.btn-entete {
  min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,.35);
  background: transparent; color: #fff; font-size: 14px; white-space: nowrap;
}
/* Un prénom long se coupe ; « · changer » reste lisible */
#ecran-accueil .entete > div:first-child { flex: none; }
#ecran-accueil .entete strong { white-space: nowrap; }
#btn-prenom { display: inline-flex; align-items: center; min-width: 0; flex: 0 1 auto; }
#btn-prenom .nom-prenom { min-width: 0; overflow: hidden; text-overflow: ellipsis; margin-left: 4px; }

.corps { padding: 4px 16px 24px; }
.lbl { display: block; margin: 16px 0 6px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--doux); }
.lbl em { font-style: normal; text-transform: none; letter-spacing: 0; font-weight: 400; }
.aide { margin: 6px 0 0; font-size: 13px; color: var(--doux); }
.notes { white-space: pre-line; background: var(--fond); border-radius: 8px; padding: 8px 10px; }
.erreur { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--ko-fond); color: var(--ko); font-weight: 500; }

.champ {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1px solid var(--bord); border-radius: var(--rayon); background: #fff;
}
/* Contour plein : le violet à 45 % ne faisait que 2:1 sur blanc (WCAG demande 3:1) */
.champ:focus, .selecteur:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.entete :focus-visible { outline-color: #fff; }
textarea.champ { resize: vertical; }

/* Photos */
.photos { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.vignettes { display: contents; }
.vignette { position: relative; width: 76px; height: 76px; border-radius: 10px; overflow: hidden; background: var(--fond); }
.vignette img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vignette .retirer {
  position: absolute; top: 2px; right: 2px; width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 28px; padding: 0;
}
.vignette .etiquette-nouvelle { position: absolute; left: 0; bottom: 0; right: 0; background: var(--accent); color: #fff; font-size: 10px; text-align: center; }
.btn-photo {
  flex: 1 1 140px; min-height: 76px; display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 2px dashed #b9a6e8; border-radius: var(--rayon); background: var(--accent-pale); color: var(--accent); font-weight: 600;
}

.existe { margin-top: 8px; width: 100%; text-align: left; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid #f0c36d; background: #fff8e6; }

/* Quantité */
.qte { display: flex; gap: 10px; align-items: center; }
.btn-qte, .btn-qte-achat { width: 56px; height: 52px; border-radius: var(--rayon); border: 0; background: #ece9f2; font-size: 26px; font-weight: 600; }
.champ-qte { width: 90px; text-align: center; font-size: 20px; font-weight: 600; }

/* Puces État */
.puces { display: flex; flex-wrap: wrap; gap: 8px; }
.puce { min-height: 44px; padding: 0 16px; border-radius: 22px; border: 1px solid var(--bord); background: #fff; }
.puce[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.ligne-cat, .ligne-parent { display: flex; gap: 8px; align-items: center; }
.ligne-cat .champ { flex: 1; }
.pastille-famille { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--doux); white-space: nowrap; }
.dot { display: inline-block; width: 20px; height: 20px; border-radius: 5px; border: 1px solid rgba(0,0,0,.18); flex: none; }

.selecteur {
  flex: 1; width: 100%; min-height: 48px; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 12px; border: 1px solid var(--bord); border-radius: var(--rayon); background: #fff; text-align: left;
}
.btn-croix { width: 48px; height: 48px; border-radius: var(--rayon); border: 1px solid var(--bord); background: #fff; }

.btn-principal {
  width: 100%; min-height: 54px; margin-top: 20px; border: 0; border-radius: var(--rayon);
  background: var(--accent); color: #fff; font-weight: 700; font-size: 17px;
}
.btn-principal:disabled { opacity: .55; }

/* Fiche : la caisse en cours (--caisse, posée par app.js) borde l'en-tête de sa couleur de scotch */
#ecran-fiche > .entete { border-bottom: 6px solid var(--caisse, var(--nuit)); }
.entete-lieu .dot { width: 14px; height: 14px; border-radius: 4px; margin-right: 6px; vertical-align: -2px; border-color: rgba(255,255,255,.55); }
#txt-emplacement { display: flex; align-items: center; gap: 8px; min-width: 0; }

/* Famille qui ne colle pas avec la caisse */
.alerte { margin-top: 8px; padding: 10px 12px; border-radius: 10px; border: 1px solid #f0c36d; background: #fff8e6; }
.alerte p { margin: 0 0 8px; }
.alerte button { min-height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid #b7791f; background: #fff; color: #6b4400; font-weight: 600; }

/* Champ à corriger */
.champ[aria-invalid="true"] { border-color: var(--ko); box-shadow: 0 0 0 3px var(--ko-fond); }
.puces[aria-invalid="true"] .puce { border-color: var(--ko); background: var(--ko-fond); }

/* Barre d'action collée en bas de la fiche */
.barre-action {
  position: sticky; bottom: var(--clavier, 0px); z-index: 1;
  margin: 20px -16px -24px; padding: 10px 16px max(12px, env(safe-area-inset-bottom));
  background: var(--carte); border-top: 1px solid var(--bord);
  box-shadow: 0 -4px 14px rgba(43, 30, 74, .08);
}
.barre-action .btn-principal { margin-top: 0; }
.barre-action .erreur { margin: 0 0 10px; }

/* Bandeau */
.bandeau { margin: 12px 16px 0; padding: 12px; border-radius: var(--rayon); background: var(--ok-fond); color: var(--ok); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.bandeau.ko { background: var(--ko-fond); color: var(--ko); }
.bandeau .choix { display: flex; gap: 8px; flex: none; }
.bandeau button { min-height: 44px; padding: 0 12px; border-radius: 8px; border: 1px solid currentColor; background: transparent; color: inherit; }

/* Feuilles */
.feuille { position: fixed; inset: 0; z-index: 10; overflow-y: auto; background: var(--carte); max-width: 560px; margin: 0 auto; }
.liste { padding: 0 8px; }
.ligne {
  width: 100%; min-height: 56px; display: flex; gap: 12px; align-items: center; text-align: left;
  padding: 10px 8px; border: 0; border-bottom: 1px solid #eeeaf3; background: transparent;
}
.ligne[aria-current="true"] { background: var(--accent-pale); }
.ligne .code { font: 700 16px ui-monospace, Consolas, monospace; min-width: 52px; }
.ligne .sous { display: block; font-size: 13px; color: var(--doux); }
.ligne img, .ligne .sans-photo { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; background: #ece9f2; flex: none; }
.titre-groupe { margin: 14px 8px 4px; font-size: 12px; font-weight: 600; text-transform: uppercase; color: var(--doux); }

.grille-familles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.famille { min-height: 48px; display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; border: 2px solid var(--bord); background: #fff; text-align: left; }
/* La famille choisie prend sa couleur de scotch (--f, posée par app.js) */
.famille[aria-checked="true"] {
  border-color: var(--f, var(--nuit)); background: color-mix(in srgb, var(--f, var(--accent)) 16%, #fff); font-weight: 600;
}
.grand-code { margin-top: 4px; padding: 16px; border: 6px solid var(--f, var(--accent)); border-radius: 16px; text-align: center;
  background: color-mix(in srgb, var(--f, var(--accent)) 10%, #fff); }
.grand-code .scotch { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.grand-code .scotch .dot { width: 18px; height: 18px; border-radius: 4px; }
.grand-code b { display: block; font: 800 64px/1 ui-monospace, Consolas, monospace; letter-spacing: .03em; margin: 6px 0; }

/* Code d'équipe */
.carte-code { padding: 72px 24px; text-align: center; }
.carte-code .hibou { font-size: 56px; }
.carte-code .hibou-logo { display: block; margin: 0 auto; width: 58px; height: 80px; color: var(--nuit); stroke-width: 11; }
.carte-code h1 { margin: 8px 0 4px; font-size: 24px; }
#champ-code { width: 100%; min-height: 56px; margin-top: 16px; text-align: center; font-size: 28px; letter-spacing: .3em; border: 1px solid var(--bord); border-radius: var(--rayon); }

/* Accueil */
.accueil { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-top: 20px; }
.tuile {
  min-height: 132px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  border: 1px solid var(--bord); border-radius: 16px; background: #fff; color: var(--texte);
  font-weight: 700; font-size: 16px; text-align: center; text-decoration: none; padding: 12px;
}
.tuile:active { background: var(--accent-pale); }
.tuile-icone { font-size: 38px; line-height: 1; }

/* Deux boutons photo */
.btn-photo { flex: 1 1 120px; }
.btn-galerie { border-style: solid; border-color: var(--bord); background: #fff; color: var(--texte); font-weight: 500; }
.vignette img, .ligne img { cursor: zoom-in; }

/* Familles dans la fiche */
#familles-fiche .famille { min-height: 52px; }

/* Boîtes */
.compte { margin-left: auto; min-width: 32px; padding: 2px 8px; border-radius: 12px; background: #ece9f2; text-align: center; font-size: 13px; font-weight: 600; }

/* Visionneuse */
.visionneuse { position: fixed; inset: 0; z-index: 30; background: rgba(10, 8, 16, .92); display: flex; align-items: center; justify-content: center; }
.visionneuse img { max-width: 100%; max-height: 100%; object-fit: contain; }
.visionneuse-aide { position: absolute; bottom: max(16px, env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; color: #fff; opacity: .7; font-size: 14px; }

/* Accueil : tuile pleine largeur et liens */
.tuile-large { grid-column: 1 / -1; min-height: 72px; flex-direction: row; background: var(--accent-pale); border-color: #b9a6e8; color: var(--accent); }
.tuile-large .tuile-icone { font-size: 28px; }
.liens { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.liens a { display: flex; align-items: center; min-height: 44px; padding: 0 4px; color: var(--accent); font-weight: 500; text-decoration: none; }

/* Tout l'inventaire */
.filtres { display: grid; gap: 8px; padding-top: 12px; }
.puces-familles { gap: 6px; }
.puces-familles .puce { min-height: 44px; padding: 0 12px; display: inline-flex; align-items: center; gap: 4px; font-size: 14px; }
.puces-familles .puce .dot { width: 14px; height: 14px; border-radius: 4px; }
.titre-groupe { display: flex; align-items: center; gap: 6px; }
.titre-groupe .dot { width: 14px; height: 14px; border-radius: 4px; }
.pied { padding: 16px; text-align: center; }
.pied a, .acces a { color: var(--accent); }

/* Accès au stock */
.acces h2 { margin: 24px 0 8px; font-size: 17px; }
.acces h2:first-child { margin-top: 12px; }
.acces p, .acces li { margin: 6px 0; }
.acces ol, .acces ul { padding-left: 22px; margin: 6px 0; }
.adresse { font-size: 17px; line-height: 1.5; }
.btn-lien { display: flex; align-items: center; justify-content: center; text-decoration: none; margin-top: 10px; }
.acces .btn-lien { color: #fff; }
.carte-box { margin: 8px 0; padding: 12px; border: 1px solid var(--bord); border-radius: var(--rayon); }
.carte-box p { margin: 4px 0 0; }
.contacts { list-style: none; padding-left: 0 !important; }
.contacts li { min-height: 44px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.filtres .aide:empty { display: none; }
.champ-prenom { margin-top: 16px; min-height: 56px; text-align: center; font-size: 22px; }

/* ---------- Hibou Glowy ---------- */
.logo-entete { width: 20px; height: 28px; margin-right: 8px; vertical-align: -7px; color: #fff; stroke-width: 16; }

/* Ouverture : le hibou se dessine trait par trait, l'œil tourne, puis tout s'illumine.
   Durée ~1,8 s ; un toucher la passe ; app.js la retire quand l'appli est prête. */
.ouverture {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-content: center; justify-items: center; gap: 22px;
  background: radial-gradient(circle at 50% 40%, #3e2b6e 0%, var(--nuit) 62%);
  transition: opacity .42s ease;
}
.ouverture-hibou {
  width: min(46vmin, 210px); height: auto; overflow: visible;
  stroke: #f7e6c0; stroke-width: 8.5;
  animation: hibou-lueur 1.9s ease-out both;
  transition: transform .42s ease;
}
.trace use {
  stroke-dasharray: 1 2; stroke-dashoffset: 1; opacity: 0;
  animation: hibou-trait var(--d) cubic-bezier(.55, .1, .3, 1) var(--t) forwards;
}
.oeil { stroke: #ffd27a; }
.oeil-tourne { transform-box: fill-box; transform-origin: center; animation: hibou-oeil 1.25s cubic-bezier(.2, .75, .2, 1) both; }
.ouverture-titre {
  margin: 0; color: #f3ead6; font-size: 18px; font-weight: 600; letter-spacing: .08em;
  opacity: 0; animation: hibou-titre .5s ease-out 1.15s forwards;
}
.ouverture.fini { opacity: 0; pointer-events: none; }
.ouverture.fini .ouverture-hibou { transform: scale(1.08); }

@keyframes hibou-trait {
  0% { opacity: 0; stroke-dashoffset: 1; }
  1% { opacity: 1; }
  100% { opacity: 1; stroke-dashoffset: 0; }
}
@keyframes hibou-oeil { from { transform: rotate(-220deg); } to { transform: rotate(0deg); } }
@keyframes hibou-lueur {
  0%, 62% { filter: drop-shadow(0 0 2px rgba(255, 205, 130, .35)); }
  78% { filter: drop-shadow(0 0 10px rgba(255, 205, 130, .95)) drop-shadow(0 0 26px rgba(255, 160, 80, .5)); }
  100% { filter: drop-shadow(0 0 5px rgba(255, 205, 130, .6)); }
}
@keyframes hibou-titre { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .trace use { animation: none; opacity: 1; stroke-dashoffset: 0; }
  .oeil-tourne, .ouverture-hibou, .ouverture-titre { animation: none; }
  .ouverture-titre { opacity: 1; }
  .ouverture.fini .ouverture-hibou { transform: none; }
}

/* ---------- Suivi : À réparer, tâches ---------- */
.tuile { position: relative; }
.tuile-compte {
  position: absolute; top: 10px; right: 10px; min-width: 28px; padding: 2px 8px; border-radius: 14px;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 700; line-height: 1.5;
}
.badge-hors { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 10px; background: #ece9f2; color: var(--doux); font-size: 12px; font-weight: 600; vertical-align: 1px; }
.replie { margin: 8px 0; }
.replie > summary { min-height: 44px; display: flex; align-items: center; padding: 0 8px; color: var(--doux); font-weight: 600; cursor: pointer; }
.taches { display: grid; gap: 6px; }
.carte-reparer { border-bottom: 1px solid #eeeaf3; }
.carte-reparer > .ligne { border-bottom: 0; }
.carte-reparer > .taches { padding: 0 8px 12px; }
.tache { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; padding: 8px 10px; border-radius: 10px; background: var(--fond); border: 1px solid #eeeaf3; }
.tache-texte { flex: 1 1 160px; min-width: 0; padding: 0; border: 0; background: none; text-align: left; }
.tache-texte b { display: block; font-weight: 600; }
.tache-texte .sous { display: block; font-size: 13px; color: var(--doux); }
.en-retard { color: var(--ko) !important; font-weight: 600; }
.tache-actions { display: flex; gap: 6px; margin-left: auto; }
.btn-petit { min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--bord); background: #fff; font-size: 14px; white-space: nowrap; }
.btn-fait { border-color: var(--ok); color: var(--ok); font-weight: 600; }
.note-objet { font-style: italic; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.btn-secondaire { width: 100%; min-height: 48px; margin-top: 8px; border-radius: var(--rayon); border: 1px dashed #b9a6e8; background: var(--accent-pale); color: var(--accent); font-weight: 600; }
.btn-moi { flex: none; min-height: 48px; padding: 0 14px; border-radius: var(--rayon); border: 1px solid var(--bord); background: #fff; }
.btn-discret { display: block; margin-top: 16px; min-height: 44px; padding: 0 4px; border: 0; background: none; color: var(--ko); text-decoration: underline; }
.tache-faite { margin: 4px 8px; }
.bandeau-local { margin: 8px 0 0; }
/* Avertissement long (suppression) : le texte en entier, les boutons dessous, le choix sûr en premier à droite */
#confirmer-suppression { flex-direction: column; align-items: stretch; }
#confirmer-suppression .choix { flex-wrap: wrap; justify-content: flex-end; }
#confirmer-suppression button:first-child { background: var(--ko); color: #fff; border-color: var(--ko); }
.bandeau-bas { position: sticky; bottom: max(12px, env(safe-area-inset-bottom)); margin: 12px; box-shadow: 0 4px 18px rgba(43, 30, 74, .18); }

/* ---------- À acheter ---------- */
.carte-achat > .actions-achat { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; padding: 0 8px 12px; }
.lien-produit { display: inline-flex; align-items: center; margin-right: auto; color: var(--accent); text-decoration: none; }
.carte-achat > .refus { display: grid; gap: 6px; padding: 0 8px 12px; }
.carte-achat > .refus .choix { display: flex; gap: 6px; justify-content: flex-end; }
.total-achats { margin: 0 8px 4px; font-weight: 700; }
.champ-euro { display: flex; align-items: center; gap: 8px; }
.champ-euro .champ { flex: 1; }
.champ-euro span { color: var(--doux); white-space: nowrap; }

/* ---------- Boîtes : ranger, sortir, modifier ---------- */
.ligne-objet { display: flex; align-items: center; gap: 6px; padding-right: 8px; border-bottom: 1px solid #eeeaf3; }
.ligne-objet > .ligne { flex: 1; min-width: 0; border-bottom: 0; }
.ligne-objet > .btn-petit { flex: none; }
.actions-caisse { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.actions-caisse .btn-petit { flex: 1 1 140px; }
#feuille-boites > .corps { padding-bottom: 4px; }
.message-accueil { grid-column: 1 / -1; margin: 0; padding: 12px 14px; border-radius: 12px; background: var(--ok-fond); color: var(--ok); font-weight: 600; }
.btn-discret:disabled { color: var(--doux); text-decoration: none; cursor: default; }

/* Enregistrer et dupliquer | Enregistrer et suivant */
.boutons-enregistrer { display: flex; gap: 8px; }
.boutons-enregistrer .btn-principal { flex: 1; margin-top: 0; font-size: 15px; line-height: 1.2; padding: 4px 8px; }
.btn-dupliquer { order: -1; background: #fff; color: var(--accent); border: 2px solid var(--accent); }

/* Appareil photo intégré */
.camera { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; }
.camera video { flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #000; }
.camera-barre { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 16px 16px max(20px, env(safe-area-inset-bottom)); background: #000; color: #fff; }
.camera-fermer { justify-self: start; min-height: 48px; padding: 0 18px; border: 1px solid rgba(255,255,255,.5); border-radius: 999px; background: transparent; color: #fff; font: inherit; font-weight: 600; }
.camera-declencher { width: 76px; height: 76px; border-radius: 50%; border: 5px solid #fff; background: rgba(255,255,255,.25); padding: 0; }
.camera-declencher:active { background: #fff; }
.camera-compte { justify-self: end; font-weight: 600; }
.camera.flash video { animation: flash-camera .25s ease-out; }
@keyframes flash-camera { from { opacity: .2; } to { opacity: 1; } }
