/* ==================== BONNES AFFAIRES (veille marché IA) ==================== */
/* Charte du projet : header h1 16pt couleur principale, KPI cartes blanches + icône 42px,
   tableau thead #f8f9fa sticky (surcharges main.css obligatoires : thead th ET thead th a,
   text-align left des td — main.css centre les tables). Préfixe ba-. */
.page_bonnes_affaires {
  --ba-line: #e3e6ea;
  --ba-muted: #6b7280;
  --ba-green: #2e7d52;
  --ba-red: #c0392b;
  --ba-orange: #e67e22;
  padding: 18px 22px 30px;
  background: #f5f6f8;
  min-height: calc(100vh - 60px);
  text-align: left;
  color: #22272e;
}

/* ---- Header ---- */
.ba-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}
.ba-header h1 { margin: 0; font-size: 16pt; color: var(--main-bg-color); text-align: left; }
.ba-header h1 .fa { margin-right: 6px; }
.ba-sub { color: #888; font-size: 8.5pt; margin-top: 2px; }
.ba-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Boutons (charte .imp-btn / .prosp-btn) ---- */
.page_bonnes_affaires .ba-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;
  text-decoration: none;
  line-height: 1.4;
}
.page_bonnes_affaires .ba-btn:hover { background: #ececec; }
.page_bonnes_affaires .ba-btn:disabled { opacity: .55; cursor: not-allowed; }
.page_bonnes_affaires .ba-btn-primary { background: var(--main-bg-color); border-color: var(--main-bg-color); color: #fff; }
.page_bonnes_affaires .ba-btn-primary:hover { filter: brightness(1.1); background: var(--main-bg-color); }
.page_bonnes_affaires .ba-btn-success { background: var(--ba-green); border-color: var(--ba-green); color: #fff; }
.page_bonnes_affaires .ba-btn-success:hover { background: #256742; }
.page_bonnes_affaires .ba-btn-danger { background: #fff; border-color: #e9b4ae; color: var(--ba-red); }
.page_bonnes_affaires .ba-btn-danger:hover { background: #fdecea; }

/* ---- Bandeaux ---- */
.ba-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 9pt;
  margin-bottom: 8px;
}
.ba-banner-run { background: #e8f4fd; border: 1px solid #b6dcf5; color: #1565c0; }
.ba-banner-warn { background: #fff8e1; border: 1px solid #ffe08a; color: #8a6d00; }

/* ---- KPI ---- */
.ba-kpi-row { display: flex; gap: 12px; margin: 6px 0 16px; flex-wrap: wrap; }
.ba-kpi-card {
  flex: 1;
  min-width: 150px;
  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;
}
.ba-kpi-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.ba-kpi-clickable { cursor: pointer; }
.ba-kpi-active { border-color: var(--main-bg-color); }
.ba-kpi-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
}
.ba-kpi-content { display: flex; flex-direction: column; min-width: 0; }
.ba-kpi-value { font-size: 18pt; font-weight: 700; color: #222; line-height: 1.1; white-space: nowrap; }
.ba-kpi-value-small { font-size: 11pt; }
.ba-kpi-label { font-size: 8.5pt; color: #888; font-weight: 500; margin-top: 2px; }
.ba-ki-good { background: #43a047; }
.ba-ki-new  { background: #fb8c00; }
.ba-ki-save { background: #00897b; }
.ba-ki-all  { background: #5c6bc0; }
.ba-ki-time { background: #8d6e63; }

/* ---- Toolbar ---- */
.ba-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 11px; }
.ba-chip {
  border: 1px solid var(--ba-line);
  background: #fff;
  border-radius: 20px;
  padding: 6px 13px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.ba-chip.on { background: var(--main-bg-color); border-color: var(--main-bg-color); color: #fff; }
.ba-select, .ba-rech {
  padding: 6px 10px;
  border: 1px solid var(--ba-line);
  border-radius: 20px;
  font-size: 12px;
  background: #fff;
}
.ba-rech { margin-left: auto; min-width: 240px; }
.ba-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; user-select: none; }

/* ---- Liste + panneau ---- */
.ba-layout { display: flex; gap: 14px; align-items: flex-start; }
.ba-layout > .ba-wrap { flex: 1; min-width: 0; }
.ba-wrap {
  overflow-x: auto;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}
.ba-table { width: 100%; border-collapse: collapse; font-size: 9pt; margin: 0; }
.ba-table thead th,
.ba-table thead th a {
  background: #f8f9fa;
  color: #555;
}
.ba-table thead th {
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 8.5pt;
  border-bottom: 2px solid #e0e0e0;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  z-index: 2;
}
.ba-table thead th:hover { background: #eef; }
.ba-arrow { font-size: 8pt; color: var(--main-bg-color); }
.ba-table td { padding: 7px 10px; vertical-align: top; text-align: left; }
.ba-table tbody tr { border-bottom: 1px solid #f0f0f0; cursor: pointer; }
.ba-table tbody tr:hover { background: rgba(38, 154, 142, 0.06); }
.ba-row-sel, .ba-table tbody tr.ba-row-sel:hover { background: #e0f2f1; }
.ba-row-good td:first-child { box-shadow: inset 3px 0 0 #43a047; }
.ba-row-off { opacity: .55; }
.ba-table .ba-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ba-fam { color: var(--ba-muted); white-space: nowrap; }
.ba-offre { min-width: 220px; }
.ba-offre-titre { display: block; font-weight: 600; color: #222; }
.ba-offre-site { display: block; font-size: 8pt; color: var(--ba-muted); }
/* Liens directs vers la fiche du site marchand (nouvel onglet) */
.ba-offre-site-lien { color: var(--main-bg-color); text-decoration: none; font-weight: 600; }
.ba-offre-site-lien:hover { text-decoration: underline; }
.ba-offre-site-lien .fa { font-size: 7pt; margin-left: 2px; }
.ba-good-icon { color: #43a047; margin-right: 3px; }
.ba-barre { display: block; font-size: 8pt; color: #999; text-decoration: line-through; }
.ba-date { color: var(--ba-muted); white-space: nowrap; font-size: 8.5pt; }
.ba-empty { text-align: center !important; color: var(--ba-muted); padding: 24px !important; cursor: default; }

.ba-ecart-bon { color: var(--ba-green); font-weight: 700; }
.ba-ecart-moyen { color: #8a6d00; }
.ba-ecart-mauvais { color: var(--ba-red); }
.ba-ecart-nc { color: #aaa; }

.ba-score {
  display: inline-block;
  min-width: 28px;
  padding: 2px 7px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 8.5pt;
  text-align: center;
}
.ba-score-bon { background: #e8f5e9; color: var(--ba-green); }
.ba-score-moyen { background: #fff8e1; color: #8a6d00; }
.ba-score-bas { background: #fdecea; color: var(--ba-red); }
.ba-score-nc { background: #f1f3f5; color: #9aa0a6; }

.ba-statut {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 8pt;
  font-weight: 700;
  white-space: nowrap;
}
.ba-statut-nouvelle { background: #fff3e0; color: #e65100; }
.ba-statut-vue { background: #f1f3f5; color: #6b7280; }
.ba-statut-retenue { background: #e8f5e9; color: var(--ba-green); }
.ba-statut-ecartee { background: #fdecea; color: var(--ba-red); }

/* ---- Panneau détail ---- */
.ba-panel {
  /* Largeur proportionnelle à l'écran (demande utilisateur : 440 px était trop étroit pour lire
     le comparatif critère par critère) : 45 % de la zone, entre 520 et 760 px */
  width: clamp(520px, 45%, 760px);
  flex-shrink: 0;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  position: sticky;
  top: 60px;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
}
.ba-panel-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--ba-line);
}
.ba-panel-title { flex: 1; min-width: 0; }
.ba-panel-title a { font-weight: 700; font-size: 10.5pt; color: var(--main-bg-color); text-decoration: none; }
.ba-panel-title a:hover { text-decoration: underline; }
.ba-panel-title a .fa { font-size: 8pt; }
.ba-panel-sub { font-size: 8.5pt; color: var(--ba-muted); margin-top: 2px; }
.ba-panel-close, .ba-panel-back { border: none; background: none; font-size: 15px; color: var(--ba-muted); cursor: pointer; padding: 2px 6px; }
.ba-panel-close:hover { color: var(--ba-red); }
.ba-panel-back { display: none; }
.ba-panel-body { overflow-y: auto; padding: 12px 14px 16px; }

.ba-prix-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.ba-prix-main, .ba-ecart-box {
  flex: 1;
  min-width: 110px;
  border: 1px solid var(--ba-line);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
}
.ba-prix-val { font-size: 15pt; font-weight: 700; color: #222; }
.ba-prix-lbl, .ba-ecart-lbl { font-size: 7.5pt; color: var(--ba-muted); }
.ba-ecart-val { font-size: 13pt; font-weight: 700; }

.ba-section { margin-top: 14px; }
.ba-section h3 {
  margin: 0 0 6px;
  font-size: 9pt;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--ba-muted);
  text-align: left;
}
.ba-section h3 .fa { margin-right: 4px; color: var(--main-bg-color); }
.ba-verdict { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ba-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 8pt;
  font-weight: 600;
}
.ba-badge-ok { background: #e8f5e9; color: var(--ba-green); }
.ba-badge-ko { background: #fdecea; color: var(--ba-red); }
.ba-badge-score { background: #e3f2fd; color: #1565c0; }
.ba-badge-warn { background: #fff8e1; color: #8a6d00; }
.ba-justif { width: 100%; margin: 6px 0 2px; font-size: 9pt; line-height: 1.45; color: #333; }
.ba-comp { width: 100%; border-collapse: collapse; font-size: 8.5pt; margin: 6px 0 0; }
.ba-comp td { padding: 4px 6px; border-bottom: 1px solid #f0f0f0; text-align: left; vertical-align: top; }
.ba-comp-head td { font-weight: 600; color: var(--ba-muted); background: #f8f9fa; }
.ba-comp-crit { font-weight: 600; white-space: nowrap; }
.ba-cmp { font-size: 7.5pt; font-weight: 700; padding: 1px 6px; border-radius: 10px; white-space: nowrap; }
.ba-cmp-superieur { background: #e8f5e9; color: var(--ba-green); }
.ba-cmp-equivalent { background: #e3f2fd; color: #1565c0; }
.ba-cmp-inferieur { background: #fdecea; color: var(--ba-red); }
.ba-cmp-inconnu { background: #f1f3f5; color: #9aa0a6; }
.ba-muted { width: 100%; font-size: 8.5pt; color: var(--ba-muted); margin-top: 4px; line-height: 1.45; }
.ba-carac { display: flex; gap: 8px; font-size: 9pt; padding: 3px 0; border-bottom: 1px dashed #eee; }
.ba-carac-lbl { color: var(--ba-muted); min-width: 110px; }
.ba-note { font-size: 8.5pt; color: #8a6d00; margin-top: 6px; }
.ba-ref {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 9pt;
  padding: 4px 0;
  border-bottom: 1px dashed #eee;
}
.ba-ref a { color: #22272e; text-decoration: none; }
.ba-ref a:hover { color: var(--main-bg-color); text-decoration: underline; }
.ba-ref-prix { white-space: nowrap; color: var(--ba-muted); font-variant-numeric: tabular-nums; }
.ba-histo { display: flex; justify-content: space-between; font-size: 9pt; padding: 2px 0; }
.ba-statut-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }

/* ---- Historique des veilles ---- */
.ba-runs { margin-top: 18px; }
.ba-runs-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--ba-muted);
  cursor: pointer;
  user-select: none;
  margin: 0 0 8px;
  text-align: left;
}
.ba-runs-table tbody tr { cursor: default; }
.ba-runs-fam { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Responsive ---- */
@media (max-width: 1200px) {
  .ba-panel { width: 50%; }
}
@media (max-width: 992px) {
  .ba-kpi-row { gap: 8px; }
  .ba-kpi-card { padding: 8px 10px; gap: 8px; min-width: 120px; }
  .ba-kpi-icon { width: 32px; height: 32px; border-radius: 8px; font-size: 14px; }
  .ba-kpi-value { font-size: 14pt; }
  .ba-kpi-value-small { font-size: 9pt; }
  .ba-kpi-label { font-size: 7.5pt; }
  /* Panneau détail en plein écran par-dessus la liste */
  body.ba-mobile-panel-open .ba-panel {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: none;
    border-radius: 0;
    z-index: 300;
  }
  body.ba-mobile-panel-open .ba-panel-head { background: var(--main-bg-color); }
  body.ba-mobile-panel-open .ba-panel-back { display: block; color: #fff; }
  body.ba-mobile-panel-open .ba-panel-close { display: none; }
  body.ba-mobile-panel-open .ba-panel-title a,
  body.ba-mobile-panel-open .ba-panel-sub { color: #fff; }
  .ba-layout-detail .ba-panel { display: flex; }
  body:not(.ba-mobile-panel-open) .ba-panel { display: none; }
  .ba-rech { margin-left: 0; min-width: 0; flex: 1; }
}
@media (max-width: 768px) {
  .page_bonnes_affaires { padding: 12px 10px 24px; }
  .ba-kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
  .ba-kpi-card { padding: 4px 6px; gap: 4px; border-radius: 6px; min-width: 0; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
  .ba-kpi-icon { width: 22px; height: 22px; border-radius: 5px; font-size: 10px; }
  .ba-kpi-value { font-size: 10pt; }
  .ba-kpi-value-small { font-size: 7.5pt; white-space: normal; }
  .ba-kpi-label { font-size: 6.5pt; }
  .ba-hide-mobile { display: none; }
  .page_bonnes_affaires .ba-btn { min-height: 44px; }
  .ba-chip { padding: 10px 13px; }

  /* G3 : colonnes au-delà de « Offre » atteignables par défilement interne
     (.ba-wrap overflow-x:auto) mais sans affordance visuelle. */
  .ba-wrap { position: relative; }
  .ba-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 14px;
    border-radius: 0 10px 10px 0;
    background: linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.12));
    pointer-events: none;
  }
}

/* Base de comparaison des écarts (référence de même gamme ou moyenne de la famille) */
.ba-base { font-size: 8.5pt; color: var(--ba-muted); margin: -2px 0 6px; }
.ba-base .fa { color: var(--main-bg-color); margin-right: 4px; }
.ba-base a { color: var(--main-bg-color); }
/* Prix non relevé par le serveur (vu dans un extrait de recherche) */
.ba-averifier { display: block; font-size: 7.5pt; font-weight: 700; color: #c77700; }
.ba-base-alerte { color: #c77700; }
.ba-base-alerte .fa { color: #c77700; }

/* ---- Menu contextuel d'une ligne (clic droit / appui long) : statut de l'offre ---- */
.ba-ctx {
  position: fixed;
  z-index: 400;
  width: 220px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  padding: 6px 0;
  animation: navDropdownFadeIn 0.12s ease;
  text-align: left;
}
.ba-ctx-titre {
  padding: 4px 12px 6px;
  font-size: 8pt;
  color: var(--ba-muted, #6b7280);
  border-bottom: 1px solid #eee;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.page_bonnes_affaires .ba-ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 12px;
  border: none;
  background: none;
  font-size: 9pt;
  color: #333;
  cursor: pointer;
  text-align: left;
}
.page_bonnes_affaires .ba-ctx-item:hover:not(:disabled) { background: #e0f2f1; color: var(--main-bg-color); }
.page_bonnes_affaires .ba-ctx-item .fa { width: 16px; text-align: center; color: var(--main-bg-color); }
.page_bonnes_affaires .ba-ctx-item:disabled { cursor: default; opacity: 1; }
.ba-ctx-actif { font-weight: 700; }
.ba-ctx-coche { margin-left: auto; }
.ba-row-menu, .ba-table tbody tr.ba-row-menu:hover { background: #e0f2f1; }

/* Bonne affaire POTENTIELLE : prix et disponibilité non vérifiés (jamais notifiée) */
.ba-pot-icon { color: #c77700; margin-right: 3px; }
.ba-pot-banner { margin-bottom: 10px; }
.ba-chip-nb {
  display: inline-block;
  min-width: 16px;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 8px;
  background: #fff3e0;
  color: #c77700;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}
.ba-chip.on .ba-chip-nb { background: rgba(255,255,255,0.3); color: #fff; }
