/* ==================== ACHATS COGEKOM (préfixe cga-) ==================== */
/* Charte DoliMIS : en-tête h1 couleur principale, KPI cartes blanches, tableau thead #f8f9fa
   (même socle que Gestion des impayés / Prospection). */
.page_cogekom_achats {
  --cga-bg: #F5F6F8;
  --cga-line: #DDE1E7;
  --cga-txt: #22272E;
  --cga-muted: #6B7280;
  --cga-red: #C0392B;
  --cga-green: #2E7D52;
  --cga-orange: #E67E22;

  padding: 18px 22px 30px;
  background: var(--cga-bg);
  color: var(--cga-txt);
  min-height: calc(100vh - 60px);
  text-align: left;
}

/* ---- En-tête ---- */
.cga-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}
/* main.css impose « h1 { text-align: center; padding: 15px } » : le titre se centrait au-dessus du sous-titre */
.cga-header h1 { margin: 0; padding: 0; text-align: left; font-size: 16pt; color: var(--main-bg-color); }
.cga-header h1 .fa { margin-right: 6px; }
.cga-sub { color: #888; font-size: 8.5pt; margin-top: 2px; }
.cga-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Boutons (charte .imp-btn / .prosp-btn) ---- */
.cga-btn {
  padding: 5px 14px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #f5f5f5;
  color: #333;
  cursor: pointer;
  font-size: 9pt;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.cga-btn:hover { background: #ececec; }
.cga-btn:disabled { opacity: .55; cursor: not-allowed; }
.cga-btn.cga-btn-primary { background: var(--main-bg-color); border-color: var(--main-bg-color); color: #fff; }
.cga-btn.cga-btn-primary:hover { filter: brightness(1.1); }
.cga-btn.cga-btn-warn { background: var(--cga-orange); border-color: var(--cga-orange); color: #fff; margin-top: 6px; }
.cga-btn.cga-btn-icon { padding: 4px 8px; }
.cga-btn-txt { display: none; }   /* libellé des boutons d'action : affiché sur mobile seulement */

/* ---- KPI ---- */
.cga-kpi-row { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.cga-kpi-card {
  flex: 1;
  min-width: 160px;
  background: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  display: flex;
  align-items: center;
  gap: 12px;
  border: 2px solid transparent;
  transition: box-shadow 0.2s, border-color 0.2s;
}
.cga-kpi-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.cga-kpi-clickable { cursor: pointer; }
.cga-kpi-active { border-color: var(--main-bg-color); }
.cga-kpi-objectif { flex: 2; min-width: 260px; }
.cga-kpi-icon {
  width: 42px; height: 42px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #fff; background: var(--main-bg-color);
}
.cga-ki-apointer { background: #ff9800; }
.cga-ki-ecart { background: #e53935; }
.cga-ki-marge { background: #8e1b1b; }
.cga-ki-pointee { background: #43a047; }
.cga-kpi-content { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.cga-kpi-value { font-size: 18pt; font-weight: 700; color: #222; line-height: 1.1; white-space: nowrap; }
.cga-kpi-label { font-size: 8.5pt; color: #888; font-weight: 500; margin-top: 2px; }
.cga-kpi-hint { font-size: 8pt; color: var(--cga-muted); }

/* ---- Barre de progression (objectif) ---- */
.cga-progress { height: 7px; background: #e8ebf2; border-radius: 99px; overflow: hidden; margin: 5px 0 3px; }
.cga-progress i { display: block; height: 100%; background: var(--cga-orange); border-radius: 99px; }
.cga-progress i.cga-progress-ok { background: var(--cga-green); }
.cga-progress-inline { display: inline-block; width: 80px; vertical-align: middle; margin: 0 6px 0 0; }

/* ---- Barre d'outils ---- */
.cga-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.cga-chip {
  padding: 4px 11px;
  border-radius: 99px;
  background: #fff;
  border: 1px solid var(--cga-line);
  font-size: 9pt;
  cursor: pointer;
  user-select: none;
}
.cga-chip b { margin-left: 4px; color: var(--cga-muted); font-weight: 600; }
.cga-chip.on { background: var(--main-bg-color); border-color: var(--main-bg-color); color: #fff; }
.cga-chip.on b { color: #fff; }
.page_cogekom_achats label.cga-toggle {
  width: auto; margin: 0; font-weight: normal;
  display: inline-flex; align-items: center; gap: 6px; font-size: 9pt;
}
.cga-toggle select { font-size: 9pt; padding: 2px 4px; }
.cga-search {
  flex: 1;
  min-width: 220px;
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 9.5pt;
}

/* ---- Barre de sélection ---- */
.cga-selbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  background: #fff8f0; border: 1px solid #f3c58f; border-radius: 8px;
  padding: 8px 12px; margin-bottom: 10px; font-size: 9.5pt;
  position: sticky; top: 0; z-index: 20;
}
.cga-selbar > span { flex: 1; }

/* ---- Tableau (surcharges obligatoires de main.css : thead th / th a, centrage, marges auto) ---- */
.cga-wrap { background: #fff; border: 1px solid var(--cga-line); border-radius: 8px; overflow: auto; }
.cga-table { width: 100%; border-collapse: collapse; margin: 0; font-size: 9.5pt; }
.cga-table thead th,
.cga-table thead th a {
  background: #f8f9fa;
  color: #444;
}
.cga-table thead th {
  position: sticky; top: 0; z-index: 2;
  text-align: left; font-size: 8.5pt; font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--cga-line);
  white-space: nowrap; cursor: pointer; user-select: none;
}
.cga-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid #edf0f6; vertical-align: top; }
.cga-table tbody tr:hover td { background: #fafbfe; }
.cga-table .cga-num { text-align: right; white-space: nowrap; }
.cga-table tfoot td { background: #f8f9fa; border-top: 1px solid var(--cga-line); }
.cga-arrow { font-size: 7pt; color: var(--cga-muted); }
.cga-col-check { width: 28px; text-align: center !important; }
.cga-row-sel td { background: #fff8f0; }
.cga-row-cur td { background: #fff8f0; font-weight: 600; }
.cga-produits { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #555; }
.cga-client { color: inherit; }
.cga-actions { white-space: nowrap; text-align: right !important; }
.cga-actions .cga-btn + .cga-btn { margin-left: 4px; }
.cga-empty { text-align: center !important; color: var(--cga-muted); padding: 22px !important; }
.cga-muted { color: var(--cga-muted); font-size: 8pt; }
.cga-warn-txt { color: var(--cga-orange); font-size: 8pt; font-weight: 600; }
.cga-pos { color: var(--cga-green); font-weight: 600; }
.cga-neg { color: var(--cga-red); font-weight: 600; }
.cga-zero { color: var(--cga-muted); }

/* ---- Badges ---- */
.cga-badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 8pt; white-space: nowrap; }
.cga-badge-a_pointer { background: #fdf0d5; color: #8a5a00; }
.cga-badge-pointee { background: #e0f4ea; color: #12673f; }
.cga-badge-brouillon { background: #e8ebf2; color: #4a5570; margin-left: 4px; }
.cga-badge-partielle { background: #e3eefc; color: #1f4e8c; }

/* Choix des lignes payées (une commande client peut avoir plusieurs fournisseurs).
   main.css impose « label { width: 30%; margin: 1%; font-weight: bold } » : surchargé ici. */
.cga-lignes-choix { border: 1px solid var(--cga-line); border-radius: 8px; max-height: 240px; overflow: auto; }
.cga-lc-cmd { background: #f8f9fa; font-size: 8.5pt; font-weight: 600; color: #555; padding: 5px 10px; border-bottom: 1px solid #edf0f6; }
.page_cogekom_achats label.cga-lc-ligne {
  width: auto; margin: 0; font-weight: normal;
  display: grid; grid-template-columns: 22px 120px 1fr auto auto; align-items: center; gap: 10px;
  padding: 6px 10px; border-bottom: 1px solid #edf0f6; font-size: 9.5pt; cursor: pointer;
}
.cga-lc-ligne:last-child { border-bottom: none; }
.cga-lc-ligne:hover { background: #fafbfe; }
.cga-lc-payee { color: var(--cga-muted); }
.cga-lc-ref { font-weight: 600; }
.cga-lc-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cga-lc-prix { white-space: nowrap; text-align: right; }
.cga-lc-etat { font-size: 8pt; white-space: nowrap; color: var(--cga-muted); }

.cga-showmore { text-align: center; padding: 10px; }
.cga-footer { margin-top: 12px; font-size: 8.5pt; color: var(--cga-muted); line-height: 1.5; }

/* ---- Fenêtres ---- */
.cga-modal {
  background: #fff;
  border-radius: 10px;
  width: 95%;
  max-width: 860px;
  max-height: 90vh;
  margin: 4vh auto 0;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  text-align: left;
  box-sizing: border-box;
}
.cga-modal-stats { max-width: 1000px; }
.cga-modal-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--cga-line);
}
.cga-modal-title { font-size: 12pt; font-weight: 600; color: var(--main-bg-color); }
.cga-modal-title a { color: inherit; }
.cga-modal-sub { font-size: 8.5pt; color: var(--cga-muted); margin-top: 2px; }
.cga-close { background: none; border: none; font-size: 16px; cursor: pointer; color: #666; padding: 2px 6px; }
.cga-modal-body { padding: 14px 18px; overflow: auto; flex: 1; }
.cga-modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--cga-line); }

.cga-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin-bottom: 14px; }
.cga-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cga-field-wide { grid-column: 1 / -1; }
.cga-field-label { font-size: 8.5pt; color: var(--cga-muted); font-weight: 600; }
.cga-field input,
.cga-field select,
.cga-field textarea {
  font: inherit; font-size: 10pt; padding: 6px 8px;
  border: 1px solid #ccc; border-radius: 6px; width: 100%; box-sizing: border-box;
}
.cga-field input.cga-montant { font-size: 12pt; font-weight: 600; }

/* Montant attendu (TTC, ce qui figure sur le relevé de carte) et écart en direct */
.cga-attendu {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px;
  background: #f0f7f6; border: 1px solid #cfe5e1; border-radius: 8px; padding: 8px 12px;
}
.cga-attendu-montant { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; flex: 1; }
.cga-attendu-montant b { font-size: 13pt; color: var(--main-bg-color); }
.cga-attendu-ecart { flex-basis: 100%; font-size: 9.5pt; }
.cga-tfoot-ht td { font-size: 8pt; color: var(--cga-muted); background: #fff !important; }

.cga-apercu { margin-bottom: 10px; }
.cga-apercu-title { font-size: 9pt; font-weight: 600; color: #555; text-transform: uppercase; letter-spacing: .4px; margin: 12px 0 6px; }
.cga-table-mini { border: 1px solid var(--cga-line); border-radius: 6px; }
.cga-table-mini thead th { position: static; cursor: default; }
.cga-hint { font-size: 8.5pt; color: var(--cga-muted); background: #f5f7fb; border-radius: 6px; padding: 8px 10px; margin-top: 8px; line-height: 1.45; }

.cga-alert { display: flex; gap: 10px; align-items: flex-start; border-radius: 8px; padding: 9px 12px; margin-top: 10px; font-size: 9.5pt; }
.cga-alert > .fa { margin-top: 2px; }
.cga-alert-ok { background: #e0f4ea; color: #12673f; }
.cga-alert-ok a { color: inherit; }
.cga-alert-warn { background: #fdf0d5; color: #8a5a00; }
.cga-alert-err { background: #fbe1e1; color: #9c2323; }

.cga-tabs { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.cga-tab { padding: 5px 12px; border: 1px solid #ccc; border-radius: 6px; background: #f5f5f5; cursor: pointer; font-size: 9pt; }
.cga-tab.on { background: var(--main-bg-color); border-color: var(--main-bg-color); color: #fff; }
.cga-spacer { flex: 1; }
.cga-stats-resume { font-size: 9.5pt; margin-bottom: 10px; }

/* ==================== TABLETTE ==================== */
@media (max-width: 992px) {
  .page_cogekom_achats { padding: 12px 12px 24px; }
  .cga-kpi-row { gap: 8px; }
  .cga-kpi-card { padding: 8px 10px; gap: 8px; min-width: 120px; }
  .cga-kpi-objectif { min-width: 100%; }
  .cga-kpi-icon { width: 32px; height: 32px; border-radius: 8px; font-size: 14px; }
  .cga-kpi-value { font-size: 14pt; }
  .cga-kpi-label { font-size: 7.5pt; }
}

/* ==================== MOBILE : tableau en cartes ==================== */
@media (max-width: 768px) {
  .cga-header-actions { width: 100%; }
  .cga-header-actions .cga-btn { flex: 1; justify-content: center; }
  .cga-kpi-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; }
  .cga-kpi-card { min-width: 0; padding: 4px 6px; gap: 5px; border-radius: 6px; }
  .cga-kpi-objectif { grid-column: 1 / -1; }
  .cga-kpi-icon { width: 22px; height: 22px; border-radius: 5px; font-size: 10px; }
  .cga-kpi-value { font-size: 10pt; }
  .cga-kpi-label { font-size: 6.5pt; }
  .cga-search { min-width: 0; width: 100%; flex-basis: 100%; }
  .cga-btn { min-height: 36px; }

  .cga-wrap { background: transparent; border: none; overflow: visible; }
  .cga-table thead { display: none; }
  .cga-table, .cga-table tbody, .cga-table tr, .cga-table td, .cga-table tfoot { display: block; width: 100%; box-sizing: border-box; }
  .cga-table tbody tr {
    background: #fff; border: 1px solid var(--cga-line); border-radius: 8px;
    margin-bottom: 8px; padding: 6px 10px;
  }
  .cga-table td { border: none; padding: 3px 0; display: flex; justify-content: space-between; gap: 10px; }
  .cga-table td[data-label]::before { content: attr(data-label); color: var(--cga-muted); font-size: 8pt; flex-shrink: 0; }
  .cga-table .cga-num { text-align: right; }
  .cga-col-check { width: 100%; text-align: left !important; }
  .cga-col-check input { width: 28px; height: 28px; }
  .cga-produits { max-width: none; white-space: normal; }
  /* Boutons d'action des cartes : cibles tactiles de 44 px, pleine largeur, avec libellé */
  .cga-actions { gap: 8px; padding-top: 8px !important; margin-top: 4px; border-top: 1px solid #edf0f6 !important; }
  .cga-actions .cga-btn + .cga-btn { margin-left: 0; }
  .cga-table .cga-actions .cga-btn.cga-btn-icon {
    flex: 1; justify-content: center; min-height: 44px; padding: 8px 10px; font-size: 10.5pt; gap: 8px;
  }
  .cga-actions .cga-btn.cga-btn-icon:first-child { background: var(--main-bg-color); border-color: var(--main-bg-color); color: #fff; }
  .cga-btn-txt { display: inline; }
  .cga-table tfoot tr { display: flex; justify-content: space-between; flex-wrap: wrap; padding: 6px 10px; }
  .cga-table tfoot td { display: inline-block; width: auto; background: none; border: none; }
  .cga-empty { display: block !important; }

  .cga-modal { width: 100%; max-width: none; max-height: 100vh; height: 100%; margin: 0; border-radius: 0; }
  .cga-form { grid-template-columns: 1fr; }
  .page_cogekom_achats label.cga-lc-ligne { grid-template-columns: 28px 1fr auto; min-height: 44px; }
  .cga-lc-ligne input { width: 22px; height: 22px; }
  .cga-lc-ligne input { grid-row: 1; grid-column: 1; }
  .cga-lc-ref { grid-row: 1; grid-column: 2; }
  .cga-lc-prix { grid-row: 1; grid-column: 3; }
  .cga-lc-label { grid-row: 2; grid-column: 2 / -1; white-space: normal; }
  .cga-lc-etat { grid-row: 3; grid-column: 2 / -1; white-space: normal; }
  .cga-lignes-choix { max-height: none; }
  .cga-table-mini { border: none; }
  .cga-modal-footer { flex-wrap: wrap; }
  .cga-modal-footer .cga-btn { flex: 1; justify-content: center; }
  .cga-progress-inline { width: 60px; }
}
