/* ==========================================================================
   tab-fournisseurs — charte PERRIN / Groupe Burnel (alignée sur TAB-CLIENTS).
   Écrans : connexion, commandes MDO.
   Polices : Archivo (titres, libellés capitales) + Manrope (texte), chargées
   depuis Google Fonts dans le <head> de base.html.
   ========================================================================== */
:root {
  /* Charte Perrin du 28/07/2026 — orange épicée, bleu de Prusse, cuivre, lin.
     L'orange et le cuivre pleins ne portent JAMAIS de texte sous 18 px (4,43 et
     3,45 de contraste) : pour du texte, utiliser leurs versions assombries. */
  --blue: #1B2A44;         /* bleu de Prusse — anneau focus, chips actives */
  --blue-d: #12203A;       /* prusse foncé — survol des aplats sombres */
  --blue-l: #4A6285;       /* prusse éclairci — texte secondaire (6,22) */
  --orange: #C45727;       /* orange épicée — aplats, filets, marque. JAMAIS en petit texte */
  --orange-ink: #A0421A;   /* orange version texte (6,39) — liens, eyebrows */
  --orange-d: #A0421A;     /* alias de compatibilité */
  --cuivre: #B67F3E;       /* accent secondaire — aplats seulement */
  --cuivre-ink: #7E5522;   /* cuivre version texte (6,54) */
  --lin: #F1EADD;

  --dark: #1B2A44;
  --navy: #1B2A44;
  --ink: #1B2A44;
  --gray: #4A6285;
  --muted: #4A6285;
  --muted-2: #7C8AA0;      /* texte tertiaire */

  --bg: #F1EADD;           /* lin, en remplacement des gris neutres */
  --card: #ffffff;
  --surface-2: #FAF7F1;    /* en-tête de tableau, en-tête de groupe */
  --track: #F1EADD;        /* piste du segmented control */
  --line: #E0D7C7;
  --line-soft: #EFE9DF;    /* séparateur interne */
  --line-hover: #C9BCA6;

  --ok: #1B2A44;           /* pastille « production » : prusse, pas de vert dans la charte */
  --danger: #A0421A;
  --danger-bg: #F7E6DC;
  --danger-line: #E3C9B4;
  --note-bg: #FAF3EC;
  --note-line: #E3C9B4;

  --shadow: 0 1px 2px rgba(27, 42, 68, .04), 0 4px 16px rgba(27, 42, 68, .06);
  --spring: transform .16s cubic-bezier(.34, 1.56, .64, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Manrope, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--orange-ink); text-decoration: none; }
a:hover { color: var(--orange-ink); text-decoration: underline; }
input, textarea, select, button { font-family: inherit; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ── Topbar ──────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  height: 64px; padding: 0 28px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 18px; min-width: 0; }
.topbar-logo { height: 26px; width: auto; display: block; }
.wordmark { border-left: 2px solid var(--line); padding-left: 16px; }
.wordmark-text { display: flex; align-items: baseline; gap: 9px; }
.wordmark-name {
  font-family: Archivo, sans-serif; font-size: 19px; font-weight: 900;
  letter-spacing: .02em; color: var(--navy);
}
.wordmark-sub {
  font-family: Archivo, sans-serif; font-size: 10px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
}
.topbar-right { display: flex; align-items: center; gap: 14px; min-width: 0; }
.env {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 700; color: var(--gray); white-space: nowrap;
}
.env-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok); box-shadow: 0 0 0 3px rgba(27, 42, 68, .14);
}
.env.is-dev .env-dot { background: var(--cuivre); box-shadow: 0 0 0 3px rgba(182, 127, 62, .22); }
.who {
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── Onglets ─────────────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 4px; padding: 0 28px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.tab {
  display: inline-flex; align-items: center; height: 44px; padding: 0 16px;
  font-family: Archivo, sans-serif; font-size: 12.5px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); text-decoration: none;
  transition: color .16s ease, box-shadow .16s ease;
}
.tab:hover { color: var(--gray); text-decoration: none; }
.tab.is-active {
  font-weight: 800; color: var(--dark);
  box-shadow: inset 0 -3px 0 0 var(--orange);
}

/* ── Conteneur & en-tête de page ─────────────────────────────────────── */
.page { max-width: 1320px; margin: 0 auto; padding: 26px 28px 60px; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; flex-wrap: wrap; margin-bottom: 22px;
}
.eyebrow {
  font-family: Archivo, sans-serif; font-size: 10.5px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase; color: var(--orange-ink);
}
.page-head h1 {
  font-family: Archivo, sans-serif; font-size: 25px; font-weight: 800;
  letter-spacing: -.01em; color: var(--dark); margin: 2px 0 3px;
}
.page-sub { font-size: 12.5px; font-weight: 500; color: var(--muted); margin: 0; }
.head-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ── Recherche ───────────────────────────────────────────────────────── */
.search-wrap { position: relative; }
.search-hint {
  position: absolute; left: 15px; top: 50%; transform: translateY(-50%);
  font-family: Archivo, sans-serif; font-size: 13px; font-weight: 800;
  color: var(--orange-ink); pointer-events: none;
}
.search {
  width: 300px; max-width: 100%;
  border: 2px solid var(--line); border-radius: 11px;
  padding: 11px 16px 11px 40px;
  font-size: 14px; font-weight: 600; color: var(--ink);
  background: var(--card); box-shadow: var(--shadow);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.search::placeholder { color: var(--muted-2); font-weight: 600; }
.search:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(27, 42, 68, .14);
}

/* ── Boutons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: Archivo, sans-serif; font-size: 12px; font-weight: 700;
  letter-spacing: .02em; border-radius: 999px; padding: 10px 18px;
  border: 1.5px solid var(--line); background: var(--card); color: var(--gray);
  cursor: pointer; text-decoration: none;
  transition: var(--spring), box-shadow .2s ease, color .18s ease,
              border-color .16s ease, background-color .16s ease;
}
.btn:hover {
  border-color: var(--orange); color: var(--orange-d);
  transform: translateY(-2px); box-shadow: 0 6px 16px rgba(196, 87, 39, .18);
}
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-quiet { font-family: Manrope, sans-serif; font-size: 11.5px; font-weight: 700; padding: 7px 15px; }

/* ── Panneau de filtres ──────────────────────────────────────────────── */
.filters {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 13px 16px; margin-bottom: 18px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.filters-label {
  font-family: Archivo, sans-serif; font-size: 9.5px; font-weight: 800;
  letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
}
.seg {
  display: flex; gap: 3px; padding: 4px;
  background: var(--track); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: inset 0 1px 2px rgba(16, 24, 40, .06);
  flex-wrap: wrap;
}
.chip {
  border: none; background: transparent; cursor: pointer;
  font-size: 12px; font-weight: 700; color: var(--gray);
  padding: 6px 15px; border-radius: 999px;
  transition: background-color .16s ease, color .16s ease, box-shadow .2s ease;
}
.chip:hover { color: var(--dark); }
.chip-count { font-weight: 800; opacity: .62; margin-left: 7px; }
.chip.is-active {
  background: var(--blue); color: #fff;
  box-shadow: 0 3px 9px rgba(27, 42, 68, .28), inset 0 1px 0 rgba(255, 255, 255, .16);
}
.filters-count {
  margin-left: auto; font-size: 11.5px; font-weight: 600; color: var(--muted-2);
}
/* Champ fournisseur dans la barre de filtres (plus compact que la recherche). */
.input {
  border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 13px;
  background: var(--card); color: var(--ink);
  font-size: 14px; font-weight: 600;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(27, 42, 68, .14);
}
.filter-search {
  width: 230px; max-width: 100%; padding: 7px 13px; border-radius: 999px;
  font-size: 12px; font-weight: 700; color: var(--gray);
}
.filter-search::placeholder { color: var(--muted-2); font-weight: 600; }

/* ── Tableau des commandes MDO ───────────────────────────────────────── */
.tbl-wrap {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: clip;
}
.tbl-head, .tbl-row { display: grid; gap: 16px; align-items: center; }
.tbl-head {
  background: var(--surface-2); box-shadow: inset 0 -1.5px 0 var(--line);
  padding: 11px 16px;
  font-size: 11px; font-weight: 800; letter-spacing: .04em;
  text-transform: uppercase; color: var(--gray);
}
.tbl-row {
  padding: 10px 16px; border-bottom: 1px solid var(--line-soft);
  transition: background-color .14s ease;
}
.tbl-row:last-child { border-bottom: none; }
.tbl-row:hover { background: #FBF8F3; }
.cell-r { text-align: right; }
/* n° · date · entreprise · affaire/chantier · montant — le fournisseur est porté
   par l'en-tête de groupe, pas par les lignes. */
.tbl-mdo .tbl-head, .tbl-mdo .tbl-row {
  grid-template-columns: 108px 92px 152px minmax(200px, 1fr) 128px;
}

/* ── En-têtes de colonne triables (même geste que TAB-CLIENTS) ────────── */
/* Des <button> pour l'accès clavier : on neutralise donc l'habillage natif et on
   hérite de la typographie de `.tbl-head`. */
.tbl-mdo .th {
  display: inline-flex; align-items: baseline; gap: 4px;
  margin: 0; padding: 0; border: none; background: none;
  font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit;
  text-align: left; cursor: pointer; user-select: none;
  transition: color .14s ease;
}
.tbl-mdo .th.cell-r { justify-content: flex-end; }
.tbl-mdo .th:hover { color: var(--dark); }
.tbl-mdo .th:focus-visible { outline: 2px solid var(--orange); outline-offset: 3px; }
.tbl-mdo .arr { font-size: 9px; opacity: .35; }
.tbl-mdo .th.sorted { color: var(--dark); }
/* Flèche en orange **version texte** : c'est un glyphe, l'orange plein est
   réservé aux aplats et aux filets. */
.tbl-mdo .th.sorted .arr { opacity: 1; color: var(--orange-ink); }

/* ── Regroupement par fournisseur ────────────────────────────────────── */
/* L'en-tête est un vrai <button> : il est donc au clavier et porte
   `aria-expanded`, ce qu'un <div> cliquable ne donnerait pas. */
.grp-head {
  display: flex; align-items: baseline; gap: 10px; width: 100%;
  padding: 11px 16px; border: none; border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2); cursor: pointer; text-align: left;
  transition: background-color .14s ease;
}
.grp-head:hover { background: #F4EFE6; }
.grp-head:focus-visible { outline: 2px solid var(--orange); outline-offset: -2px; }
.grp:first-child .grp-head { border-top: none; }
.grp + .grp .grp-head { border-top: 1px solid var(--line); }
.grp-caret {
  flex: 0 0 auto; width: 12px; color: var(--muted-2); font-size: 10px; line-height: 1.6;
  transition: transform .16s ease;
}
.grp.is-closed .grp-caret { transform: rotate(-90deg); }
.grp-name {
  font-family: Archivo, sans-serif; font-size: 13.5px; font-weight: 800;
  color: var(--dark); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.grp-count { font-size: 11.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
/* Même largeur et même gouttière que la colonne Montant : le total du groupe
   tombe donc exactement sous les montants des lignes. */
.grp-total {
  margin-left: auto; flex: 0 0 128px; text-align: right;
  font-size: 13px; font-weight: 800; color: var(--dark); white-space: nowrap;
}
/* Les lignes d'un groupe sont légèrement en retrait : on lit la hiérarchie sans
   avoir à répéter le fournisseur. */
.tbl-mdo .grp-body .tbl-row { padding-left: 26px; }

/* ── Cellules ────────────────────────────────────────────────────────── */
.cell-code {
  font-family: Archivo, sans-serif; font-size: 12.5px; font-weight: 800;
  letter-spacing: .02em; color: var(--dark);
}
.cell-date { font-size: 12px; font-weight: 600; color: var(--gray); }
.badge {
  display: inline-block; border-radius: 6px; padding: 2px 9px;
  font-size: 10.5px; font-weight: 700;
}
/* Badge d'entreprise : prusse pour Perrin, cuivre pour le Grand Ouest. Aplats
   clairs et non teintes pleines — l'orange et le cuivre saturés ne portent jamais
   de texte sous 18 px. Une société non rattachée côté serveur retombe sur le
   badge neutre plutôt que d'être rangée d'office. */
.cell-ent { min-width: 0; }
.cell-ent .badge {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  letter-spacing: .02em;
}
.ent-perrin      { background: #DEE4EE; color: #1B2A44; }
.ent-grand-ouest { background: #F3E9D8; color: #7E5522; }
.ent-default     { background: #EDE6DA; color: #4A6285; }
.cell-work { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.cell-aff {
  font-size: 12px; font-weight: 700; color: var(--gray);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cell-desc {
  font-size: 11px; font-weight: 500; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cell-amount { font-size: 13px; font-weight: 800; color: var(--dark); white-space: nowrap; }

/* Ligne de total, détachée par un filet orange épicée — emploi conforme de la
   couleur de signature (filet, pas de texte). */
.tbl-total {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: 13px 16px; background: var(--surface-2);
  border-top: 2px solid var(--orange);
}
.tbl-total-label {
  font-family: Archivo, sans-serif; font-size: 10.5px; font-weight: 800;
  letter-spacing: .1em; text-transform: uppercase; color: var(--gray);
}
.tbl-total-value {
  font-family: Archivo, sans-serif; font-size: 15px; font-weight: 800;
  color: var(--dark); white-space: nowrap;
}
.tbl-note {
  margin-top: 14px; background: var(--note-bg); border: 1px solid var(--note-line);
  border-radius: 10px; padding: 11px 15px;
  font-size: 11.5px; font-weight: 600; color: var(--muted);
}

/* ── État vide ───────────────────────────────────────────────────────── */
.empty {
  padding: 50px; text-align: center;
  font-size: 14px; font-weight: 600; color: var(--muted);
}

/* ── Chargement & erreurs ────────────────────────────────────────────── */
#overlay {
  position: fixed; inset: 0; z-index: 80; background: rgba(244, 246, 248, .72);
  display: flex; align-items: center; justify-content: center;
}
.loader {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--orange);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert {
  background: var(--danger-bg); border: 1px solid var(--danger-line);
  border-radius: 12px; padding: 14px 18px; margin-bottom: 18px;
  font-size: 13px; font-weight: 600; color: var(--orange-ink);
}
/* Pas de vert dans la charte : la confirmation se dit en bleu de Prusse. */
.notice {
  background: #EDF0F5; border: 1px solid #CFD8E5; border-radius: 12px;
  padding: 12px 18px; margin-bottom: 18px;
  font-size: 13px; font-weight: 600; color: var(--blue);
}

/* ── Page de connexion ───────────────────────────────────────────────── */
.login-page {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 40px; width: 100%; max-width: 420px; text-align: center;
  box-shadow: 0 18px 50px rgba(27, 42, 68, .12);
}
.login-brand {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  margin-bottom: 22px; text-align: left;
}
.login-brand img { height: 34px; width: auto; max-width: 200px; }
.brand-name {
  font-family: Archivo, sans-serif; font-size: 13px; font-weight: 900;
  letter-spacing: .04em; color: var(--dark);
}
.brand-sub {
  font-family: Archivo, sans-serif; font-size: 9.5px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-top: 3px;
}
.login-title {
  font-family: Archivo, sans-serif; font-size: 25px; font-weight: 800;
  letter-spacing: -.01em; color: var(--dark); margin: .2em 0 .3em;
}
.login-subtitle { font-size: 12.5px; font-weight: 500; color: var(--muted); margin: 0 0 24px; }
.ms-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 12px 16px;
  border: 1.5px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--gray);
  font-family: Archivo, sans-serif; font-size: 12.5px; font-weight: 700;
  transition: var(--spring), box-shadow .2s ease, color .18s ease, border-color .16s ease;
}
.ms-btn:hover {
  border-color: var(--orange); color: var(--orange-d); text-decoration: none;
  transform: translateY(-2px); box-shadow: 0 6px 16px rgba(196, 87, 39, .18);
}
.sso-error {
  background: var(--danger-bg); border: 1px solid var(--danger-line);
  border-radius: 10px; padding: 11px 13px; margin-bottom: 18px;
  font-size: 12.5px; font-weight: 600; color: var(--orange-ink); text-align: left;
}
code {
  font-family: ui-monospace, "DejaVu Sans Mono", monospace;
  background: var(--track); border: 1px solid var(--line); border-radius: 4px;
  padding: .08em .35em; font-size: .9em; color: var(--cuivre-ink);
}

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .topbar { height: auto; flex-wrap: wrap; row-gap: 10px; padding: 10px 16px; }
  .topbar-right { flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
  .tabs { padding: 0 16px; flex-wrap: wrap; }
  .tab { padding: 0 12px; }
  .page { padding: 20px 16px 48px; }
  .page-head { align-items: stretch; }
  .head-actions { width: 100%; }
  .search-wrap { flex: 1 1 auto; }
  .search { width: 100%; }
  .filters-count { margin-left: 0; }
  .filter-search { width: 100%; }

  /* Les lignes passent en cartes empilées. */
  .tbl-mdo .tbl-row { grid-template-columns: 1fr; gap: 4px; }
  /* Le tableau garde son en-tête en mobile : c'est lui qui porte le tri, le
     masquer priverait le téléphone de la fonction. Il devient une simple rangée
     de boutons qui passe à la ligne. */
  .tbl-mdo .tbl-head {
    display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 10px 16px;
  }
  /* L'en-tête de groupe passe sur deux lignes plutôt que de comprimer le nom du
     fournisseur : c'est l'information qui sert à replier. */
  .grp-head { flex-wrap: wrap; row-gap: 3px; }
  .grp-name { flex: 1 1 auto; }
  .grp-count { flex: 0 0 100%; padding-left: 22px; }
  .grp-total { flex: 0 0 auto; margin-left: auto; }
  .tbl-mdo .grp-body .tbl-row { padding-left: 22px; }
  .cell-r { text-align: left; }
  .cell-desc { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .btn:hover, .ms-btn:hover { transform: none; }
}
