/* Tableau de bord de l'outil Automatisation FBA — feuille sobre, sans dépendance externe.
   Contrastes AA (texte ≥ 4,5:1), focus visible, cibles tactiles de 44 px sur mobile, lisible sur mobile.
   Mise en page : menu latéral fixe à partir de 1024 px, tiroir en dessous. */

:root {
  --fond: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --texte: #1a2130;
  --texte-doux: #4a5568;
  --bordure: #dde1e7;
  --bordure-forte: #c3c9d3;
  --accent: #1d4ed8;
  --accent-texte: #ffffff;
  --accent-fond: #e8eefc;
  --ok: #166534;
  --ok-fond: #dcfce7;
  --ko: #9f1239;
  --ko-fond: #ffe4e6;
  --attention: #92400e;
  --attention-fond: #fef3c7;
  --info: #1e40af;
  --info-fond: #dbeafe;
  --focus: #f59e0b;
  --menu-fond: #151b26;
  --menu-texte: #c9d1dd;
  --menu-titre: #8f9bad;
  --menu-survol: #232b38;
  --menu-actif: #2b3a55;
  --rayon: 8px;
  --rayon-petit: 6px;
  --ombre: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.08);
  --largeur-menu: 15rem;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #0f131a;
    --surface: #171c25;
    --surface-2: #1c222d;
    --texte: #e8ecf2;
    --texte-doux: #b4bdca;
    --bordure: #2c3442;
    --bordure-forte: #3d4757;
    --accent: #93b4ff;
    --accent-texte: #0b1220;
    --accent-fond: #1b2740;
    --ok: #86efac;
    --ok-fond: #12301f;
    --ko: #fda4af;
    --ko-fond: #3b1219;
    --attention: #fcd34d;
    --attention-fond: #3a2a09;
    --info: #93c5fd;
    --info-fond: #172554;
    --menu-fond: #0b0f15;
    --menu-survol: #1a212c;
    --menu-actif: #22314d;
    --ombre: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 100%; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.9375rem;
  line-height: 1.5;
}

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main:focus { outline: none; }

h1 { font-size: 1.5rem; margin: 0 0 1.25rem; line-height: 1.25; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 2rem 0 0.75rem; }
h3 { font-size: 1rem; margin: 0.5rem 0; }
small { color: var(--texte-doux); }
code { font-size: 0.9em; background: var(--surface-2); border: 1px solid var(--bordure); padding: 0 0.3em; border-radius: 4px; }
kbd { font: 600 0.75rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; }

.masque {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.evitement { position: absolute; left: -9999px; top: 0; }
.evitement:focus { left: 1rem; top: 1rem; z-index: 30; background: var(--surface); padding: 0.5rem 1rem; }

/* ---------------------------------------------------------------- menu latéral */

.barre-mobile { display: none; }

.menu {
  position: fixed; inset: 0 auto 0 0; z-index: 20; width: var(--largeur-menu);
  display: flex; flex-direction: column; gap: 0.25rem;
  background: var(--menu-fond); color: var(--menu-texte);
  padding: 1rem 0.75rem; overflow-y: auto; overscroll-behavior: contain;
}
.menu__marque {
  display: block; padding: 0.25rem 0.5rem 0.75rem; color: #ffffff; font-weight: 700; font-size: 1rem;
  text-decoration: none; line-height: 1.3;
}
.menu__recherche { position: relative; margin: 0 0 0.5rem; }
.menu__recherche input {
  width: 100%; max-width: none; min-height: 36px; padding: 0.3rem 2rem 0.3rem 0.6rem;
  background: var(--menu-survol); color: #ffffff; border: 1px solid #343e4e; border-radius: var(--rayon-petit);
}
.menu__recherche input::placeholder { color: var(--menu-titre); }
.menu__raccourci {
  position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%);
  padding: 0.15rem 0.35rem; border: 1px solid #485366; border-radius: 4px; color: var(--menu-titre);
}
.menu__groupe {
  margin: 0.9rem 0 0.25rem; padding: 0 0.5rem;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--menu-titre);
}
.menu__liste { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.menu__liste a {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  min-height: 36px; padding: 0.3rem 0.6rem; border-radius: var(--rayon-petit);
  color: var(--menu-texte); text-decoration: none;
}
.menu__liste a:hover { background: var(--menu-survol); color: #ffffff; }
.menu__liste a[aria-current="page"] { background: var(--menu-actif); color: #ffffff; font-weight: 600; box-shadow: inset 3px 0 0 #93b4ff; }
.menu__liste a.menu__lien--masque { display: none; }
.menu__liste a.menu__lien--choisi { outline: 2px solid var(--focus); outline-offset: -2px; }
.menu__compteur {
  min-width: 1.5rem; padding: 0 0.4rem; border-radius: 999px; text-align: center;
  font-size: 0.75rem; font-weight: 700; line-height: 1.4rem; background: #343e4e; color: #ffffff;
  font-variant-numeric: tabular-nums;
}
.menu__compteur--fort { background: #f59e0b; color: #1a1205; }
.menu__groupe--vide { display: none; }
.menu__sortie {
  margin: auto 0 0; padding: 0.75rem 0.5rem 0; border-top: 1px solid #262f3d;
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
}
.menu__nom { color: var(--menu-titre); font-size: 0.875rem; overflow: hidden; text-overflow: ellipsis; }
.menu .bouton--discret { color: #c7d6ff; border-color: #485366; }

.avec-menu .contenu { margin-left: var(--largeur-menu); }
.contenu { max-width: calc(1320px + var(--largeur-menu)); padding: 1.75rem 2rem 4rem; }
body:not(.avec-menu) .contenu { margin: 0 auto; }

/* ---------------------------------------------------------------- boutons et formulaires */

.bouton {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; min-height: 40px;
  padding: 0 1rem; border: 1px solid var(--accent); border-radius: var(--rayon-petit);
  background: var(--accent); color: var(--accent-texte); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.bouton:hover { filter: brightness(1.08); }
.bouton[disabled] { opacity: 0.6; cursor: not-allowed; }
.bouton--discret { background: var(--surface); color: var(--accent); border-color: var(--bordure-forte); }
.bouton--discret:hover { background: var(--accent-fond); filter: none; }
.bouton--danger { background: var(--ko); border-color: var(--ko); color: var(--surface); }
.bouton--petit { min-height: 32px; padding: 0 0.6rem; font-size: 0.85rem; }
.menu .bouton--discret { background: transparent; }
summary.bouton { list-style: none; }
summary.bouton::-webkit-details-marker { display: none; }

label { display: block; font-weight: 600; margin: 0.75rem 0 0.25rem; font-size: 0.875rem; }
input, select, textarea {
  font: inherit; color: var(--texte); background: var(--surface);
  border: 1px solid var(--bordure-forte); border-radius: var(--rayon-petit);
  min-height: 40px; padding: 0.35rem 0.6rem; width: 100%; max-width: 32rem;
}
input:hover, select:hover, textarea:hover { border-color: var(--texte-doux); }
textarea { min-height: 6rem; }
input[type="checkbox"] { width: 1.15rem; min-height: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--accent); }
fieldset { border: 1px solid var(--bordure); border-radius: var(--rayon); margin: 1rem 0; padding: 0.5rem 1rem 1rem; }
legend { font-weight: 600; padding: 0 0.25rem; }

.formulaire > .bouton, .formulaire .actions { margin-top: 1rem; }
.formulaire--grille { display: grid; gap: 0 1.5rem; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); align-items: end; }
.formulaire--grille fieldset { grid-column: 1 / -1; display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); }
.formulaire--grille small { display: block; margin-top: 0.25rem; }
.ligne-formulaire { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin: 0.5rem 0 1rem; }
.ligne-formulaire label { margin: 0; }
.ligne-formulaire input, .ligne-formulaire select { width: auto; flex: 0 1 16rem; }
.filtres {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: flex-end; margin-bottom: 1rem;
  background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon); padding: 0.75rem 1rem;
}
.filtres > div { flex: 1 1 10rem; }
.filtres label { margin-top: 0; }
.filtres .case { align-self: center; flex: 0 1 auto; }
.case { display: flex; align-items: center; gap: 0.5rem; margin: 0.5rem 0; }
.case label { margin: 0; font-weight: 400; }
.aide { color: var(--texte-doux); max-width: 60rem; }

/* ---------------------------------------------------------------- messages */

.message { border-radius: var(--rayon); padding: 0.75rem 1rem; margin: 0 0 1rem; border-left: 4px solid; }
.message--succes { background: var(--ok-fond); border-color: var(--ok); }
.message--erreur { background: var(--ko-fond); border-color: var(--ko); }
.message--info { background: var(--info-fond); border-color: var(--info); }
.message p { margin: 0.25rem 0; }
.vide {
  color: var(--texte-doux); background: var(--surface); border: 1px dashed var(--bordure-forte);
  border-radius: var(--rayon); padding: 1rem; text-align: center;
}
.synthese { font-size: 1rem; display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; }

.encart { background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon); padding: 0.5rem 1.25rem 1rem; margin: 1rem 0; box-shadow: var(--ombre); }
.encart--alerte { border-color: var(--ko); background: var(--ko-fond); }
.encart h2 { margin-top: 0.5rem; }

/* ---------------------------------------------------------------- tuiles d'accueil */

.tuiles { list-style: none; padding: 0; margin: 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); }
.tuile a {
  display: flex; flex-direction: column; gap: 0.15rem; height: 100%; padding: 1rem 1.1rem;
  background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon);
  color: var(--texte); text-decoration: none; box-shadow: var(--ombre);
}
.tuile a:hover { border-color: var(--accent); }
.tuile--alerte a { border-top: 3px solid var(--ko); }
.tuile__titre { color: var(--texte-doux); font-weight: 600; font-size: 0.85rem; }
.tuile__valeur { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tuile__detail { color: var(--texte-doux); font-size: 0.85rem; }

/* ---------------------------------------------------------------- cartes */

.cartes { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.6rem; }
.carte { background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon); padding: 0.75rem 1rem; box-shadow: var(--ombre); }
.carte p { margin: 0.25rem 0; }
.carte__entete { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.5rem; color: var(--texte-doux); font-size: 0.875rem; }
.carte--urgent { border-color: color-mix(in srgb, var(--ko) 55%, var(--bordure)); }
.carte--attention { border-color: color-mix(in srgb, var(--attention) 45%, var(--bordure)); }
.carte--vue { opacity: 0.8; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }
.actions form { margin: 0; }
.correction[open] { flex-basis: 100%; }

/* ---------------------------------------------------------------- badges et pastilles */

.badge {
  display: inline-block; padding: 0.05rem 0.5rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600;
  background: var(--surface-2); color: var(--texte); border: 1px solid var(--bordure); white-space: nowrap;
}
.badge--urgent, .badge--refusee, .badge--a_eviter, .badge--basse, .badge--casse, .badge--echec, .badge--a_corriger, .badge--echec_diagnostic, .badge--refuse, .badge--manquante, .badge--invendable { background: var(--ko-fond); color: var(--ko); border-color: transparent; }
.badge--attention, .badge--moyenne, .badge--en_test, .badge--insuffisant, .badge--inactive, .badge--en_attente, .badge--en_attente_amazon, .badge--non_renvoye, .badge--diagnostic { background: var(--attention-fond); color: var(--attention); border-color: transparent; }
.badge--info, .badge--a_traiter, .badge--en_creation, .badge--envoye, .badge--detecte, .badge--nouveau { background: var(--info-fond); color: var(--info); border-color: transparent; }
.badge--ok, .badge--achete, .badge--debloquee, .badge--haute, .badge--stable, .badge--active, .badge--rembourse, .badge--remis_en_stock, .badge--baisse { background: var(--ok-fond); color: var(--ok); border-color: transparent; }

.pastille { font-weight: 600; white-space: nowrap; }
.pastille--ok { color: var(--ok); }
.pastille--ko { color: var(--ko); }

.statuts { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.statut { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon); padding: 0.6rem 1rem; box-shadow: var(--ombre); }
.statut--ko { border-color: color-mix(in srgb, var(--ko) 55%, var(--bordure)); }
.statut__libelle { font-weight: 600; }
.statut__detail { color: var(--texte-doux); flex-basis: 100%; }

/* ---------------------------------------------------------------- deals */
.score { font-weight: 700; font-variant-numeric: tabular-nums; }
.score--fort { color: var(--ok); }
.deal__produit { min-width: 18rem; }
.deal__explication { color: var(--texte-doux); font-weight: 400; font-size: .85em; margin-top: .25rem; }
.deal__explication summary { cursor: pointer; }
.pays-deal { display: flex; flex-wrap: wrap; gap: .25rem; list-style: none; margin: .35rem 0 0; padding: 0; font-weight: 400; }
.pays-deal__pastille {
  padding: .05rem .45rem; border: 1px solid var(--bordure); border-radius: 999px; background: var(--surface-2);
  font-size: .8rem; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.pays-deal__pastille--meilleur { background: var(--ok-fond); color: var(--ok); border-color: transparent; }
.pays-deal__code { font-weight: 700; }
.deal__repondre { margin-top: .4rem; }
.deal__repondre[open] { min-width: 15rem; }
.deal__repondre .formulaire { margin-top: .5rem; }
.deal__repondre .formulaire + .formulaire { border-top: 1px solid var(--bordure); padding-top: .5rem; }
.champ-court { max-width: 8rem; }

/* ---------------------------------------------------------------- onglets (filtres par statut) et pagination */

.onglets {
  display: inline-flex; flex-wrap: wrap; gap: 2px; margin: 0 0 1rem; padding: 3px;
  background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon);
}
.onglets a {
  display: inline-flex; align-items: center; min-height: 34px; padding: 0 0.75rem;
  border-radius: var(--rayon-petit); text-decoration: none; color: var(--texte-doux); font-weight: 500;
}
.onglets a:hover { background: var(--surface-2); color: var(--texte); }
.onglets a[aria-current="page"] { background: var(--accent); color: var(--accent-texte); font-weight: 600; }
.pagination { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; }
.pagination a {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 0.75rem;
  border: 1px solid var(--bordure-forte); border-radius: var(--rayon-petit); background: var(--surface); text-decoration: none;
}

/* ---------------------------------------------------------------- tableaux */

.tableau {
  overflow: auto; background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon);
  margin: 0.5rem 0 1rem; box-shadow: var(--ombre);
}
.tableau--long { max-height: 72vh; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 0.875rem; }
th, td { padding: 0.55rem 0.75rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--bordure); }
thead th {
  background: var(--surface-2); font-weight: 600; font-size: 0.8rem; color: var(--texte-doux);
  white-space: nowrap; position: sticky; top: 0; z-index: 1; border-bottom-color: var(--bordure-forte);
}
tbody tr:last-child > * { border-bottom: none; }
tbody tr:hover > * { background: var(--surface-2); }
tbody th { font-weight: 600; }
tfoot th, tfoot td { border-top: 2px solid var(--bordure-forte); border-bottom: none; background: var(--surface-2); position: sticky; bottom: 0; }
td.nombre, th.nombre { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.negatif { color: var(--ko); }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 0.5rem 0; }
.details dt { font-weight: 600; }
.details dd { margin: 0; overflow-wrap: anywhere; }
.captures { margin: 0.25rem 0; padding-left: 1.2rem; }
.liste { padding-left: 1.2rem; }

/* En-têtes triables (ajoutés par interface.js) */
.tri {
  all: unset; display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer;
  color: inherit; font: inherit; border-radius: 4px;
}
.tri:hover { color: var(--texte); }
.tri:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.tri__sens { display: inline-block; width: 0.7rem; opacity: 0.35; font-size: 0.7rem; }
th[aria-sort] .tri { color: var(--texte); }
th[aria-sort] .tri__sens { opacity: 1; color: var(--accent); }
th.nombre .tri { flex-direction: row-reverse; }

/* Barre d'outils des tableaux (ajoutée par interface.js) */
.outils-tableau {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem 0.75rem; margin: 0.75rem 0 0;
}
.outils-tableau__champ { display: flex; flex-direction: column; flex: 0 1 12rem; }
.outils-tableau__champ--recherche { flex: 1 1 16rem; max-width: 24rem; }
.outils-tableau label { margin: 0 0 0.2rem; font-size: 0.75rem; color: var(--texte-doux); }
.outils-tableau input, .outils-tableau select { min-height: 36px; padding: 0.25rem 0.5rem; font-size: 0.875rem; }
.outils-tableau__fin { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.outils-tableau__compte { color: var(--texte-doux); font-size: 0.85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.outils-tableau__note { flex-basis: 100%; margin: 0; color: var(--texte-doux); font-size: 0.8rem; }
tr.ligne--masquee { display: none; }
.aucun-resultat td { text-align: center; color: var(--texte-doux); font-style: italic; padding: 1.25rem; }

/* ---------------------------------------------------------------- connexion */

.connexion { max-width: 26rem; margin: 3rem auto; background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon); padding: 1rem 1.5rem 1.5rem; box-shadow: var(--ombre); }
.connexion input { max-width: none; }

/* ---------------------------------------------------------------- tablette et mobile */

@media (max-width: 1023px) {
  .barre-mobile {
    position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 0.75rem;
    min-height: 56px; padding: 0.5rem 1rem; background: var(--menu-fond); color: #ffffff;
  }
  .barre-mobile__marque { color: #ffffff; font-weight: 700; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .barre-mobile__bouton {
    display: inline-flex; align-items: center; gap: 0.4rem; min-height: 44px; padding: 0 0.85rem;
    background: var(--menu-survol); color: #ffffff; border: 1px solid #343e4e; border-radius: var(--rayon-petit);
    font: inherit; font-weight: 600; cursor: pointer;
  }
  .barre-mobile__bouton[hidden] { display: none; }

  /* Sans JavaScript, le menu reste affiché dans le flux de la page ; avec, il devient un tiroir. */
  .menu { position: static; width: auto; }
  .js .menu {
    position: fixed; inset: 56px 0 0 0; width: min(20rem, 85vw); transform: translateX(-100%);
    visibility: hidden; transition: transform 0.18s ease, visibility 0.18s;
    box-shadow: 4px 0 24px rgb(0 0 0 / 0.3);
  }
  .js .menu--ouvert { transform: none; visibility: visible; transition: transform 0.18s ease, visibility 0s; }
  .js .menu .menu__marque { display: none; }
  .menu__liste a { min-height: 44px; }
  .avec-menu .contenu { margin-left: 0; }
  .contenu { padding: 1.25rem 1rem 3rem; }
}

@media (max-width: 720px) {
  h1 { font-size: 1.3rem; }
  .details { grid-template-columns: 1fr; }
  .details dd { margin-bottom: 0.5rem; }
  .bouton, .onglets a { min-height: 44px; }
  .outils-tableau__champ, .outils-tableau__champ--recherche { flex: 1 1 100%; max-width: none; }
  .outils-tableau__fin { margin-left: 0; }
  .menu__raccourci { display: none; }
  .tableau table { min-width: 40rem; } /* défiler de côté plutôt que couper chaque mot */
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media print {
  .menu, .barre-mobile, .outils-tableau, .evitement { display: none !important; }
  .avec-menu .contenu { margin: 0; padding: 0; }
  .tableau, .tableau--long { max-height: none; overflow: visible; box-shadow: none; }
}
