/* ==========================================================================
   QALIS NOVA — Historique commercial (exports Odoo)
   ========================================================================== */

.history-root {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.hist-kpis {
  margin-bottom: 0;
}

.hist-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.hist-toolbar .erp-search {
  width: min(320px, 100%);
}

.hist-chips {
  margin-bottom: 14px;
}

/* Aide à l'export et compte rendu d'import -------------------------------- */
.hist-help,
.hist-report,
.hist-takeaways {
  margin-bottom: 18px;
  padding: 16px 18px;
  border-radius: 12px;
  background: var(--qn-blue-soft, #eaf1f9);
  box-shadow: inset 0 0 0 1px rgba(47, 91, 143, 0.16);
}

.hist-help-intro {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.hist-help-intro i {
  font-size: 18px;
  color: var(--qn-blue, #2f5b8f);
}

.hist-help-intro p {
  margin: 0;
}

.hist-help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.hist-help-grid h4 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--text-primary);
}

.hist-help-grid p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.hist-report {
  background: #e8f6ef;
  box-shadow: inset 0 0 0 1px rgba(15, 122, 82, 0.2);
}

.hist-report.has-errors {
  background: #fdf4e3;
  box-shadow: inset 0 0 0 1px rgba(138, 90, 0, 0.22);
}

.hist-report-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13.5px;
}

.hist-report ul {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  line-height: 1.7;
}

.hist-report li i {
  color: #0f7a52;
}

.hist-report li.is-error,
.hist-report li.is-error i {
  color: #b42318;
}

/* Synthèse ---------------------------------------------------------------- */
.hist-takeaways {
  background: var(--qn-gold-soft, #fbf3e3);
  box-shadow: inset 0 0 0 1px rgba(196, 138, 38, 0.25);
}

.hist-takeaways h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--text-primary);
}

.hist-takeaways h4 i {
  color: var(--qn-gold, #c48a26);
}

.hist-takeaways ul {
  margin: 0;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-secondary);
}

.hist-takeaways strong {
  color: var(--text-primary);
}

.hist-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.hist-card {
  min-width: 0;
  padding: 16px 18px;
  border-radius: 12px;
  background: var(--qn-surface-raised, #fff);
  box-shadow: var(--shadow-xs), inset 0 0 0 1px var(--border-color);
}

.hist-card h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--text-primary);
}

.hist-card h4 > i {
  color: var(--qn-blue, #2f5b8f);
}

.hist-note {
  margin: 10px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-muted);
}

.hist-none {
  margin: 0;
  font-size: 13px;
}

/* Barres horizontales : tranches de montant, poids des clients */
.hist-brackets {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hist-bracket {
  display: grid;
  grid-template-columns: minmax(110px, 150px) minmax(60px, 1fr) 48px;
  grid-template-areas:
    "label bar rate"
    "meta meta meta";
  align-items: center;
  column-gap: 10px;
  row-gap: 2px;
  font-size: 13px;
}

.hist-bracket-label { grid-area: label; color: var(--text-primary); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-bar { grid-area: bar; }
.hist-bracket-rate { grid-area: rate; text-align: right; font-weight: 700; }
.hist-bracket-meta { grid-area: meta; font-size: 11.5px; }

.hist-bar {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: #eef1f5;
  overflow: hidden;
}

.hist-bar > span {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #2f5b8f, #4c7cb6);
}

.hist-bracket.is-weak .hist-bar > span {
  background: linear-gradient(90deg, #c48a26, #e0a94a);
}

.hist-bracket.is-weak .hist-bracket-rate {
  color: #8a5a00;
}

.hist-share {
  cursor: pointer;
  border-radius: 8px;
}

.hist-share:hover .hist-bracket-label {
  color: var(--qn-blue, #2f5b8f);
  text-decoration: underline;
}

/* Barres verticales : CA par mois */
.hist-months {
  display: flex;
  align-items: stretch;
  gap: 6px;
  height: 190px;
}

.hist-month {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.hist-month-value {
  font-size: 10.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.hist-month-bar {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 34px;
  border-radius: 6px 6px 2px 2px;
  background: #f1f3f6;
}

.hist-month-bar > span {
  position: absolute;
  inset: auto 0 0 0;
  border-radius: inherit;
  background: linear-gradient(180deg, #4c7cb6, #1f3a5f);
}

.hist-month-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 11px;
  line-height: 1.15;
  color: var(--text-secondary);
}

.hist-month-label small {
  font-size: 9.5px;
  color: var(--text-muted);
}

/* Listes courtes */
.hist-list {
  display: flex;
  flex-direction: column;
}

.hist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 6px;
  border-top: 1px solid var(--border-color);
  font-size: 13px;
  cursor: pointer;
}

.hist-row:first-child {
  border-top: 0;
}

.hist-row:hover {
  background: var(--bg-card-hover, #fafbfc);
}

.hist-row > div:first-child {
  min-width: 0;
}

.hist-row .erp-muted {
  display: block;
  font-size: 11.5px;
}

.hist-row-end {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.hist-age {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}

.hist-age--fresh { color: #0f7a52; background: #e8f6ef; }
.hist-age--warm  { color: #8a5a00; background: #fdf4e3; }
.hist-age--cold  { color: #b42318; background: #fdeeec; }

/* Points de contrôle */
.hist-alerts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hist-alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.hist-alert i {
  font-size: 16px;
  line-height: 1.3;
}

.hist-alert strong {
  color: var(--text-primary);
}

.hist-alert .btn {
  margin-left: 6px;
  padding: 3px 10px;
}

.hist-alert--high   { background: #fdeeec; }
.hist-alert--high i { color: #b42318; }
.hist-alert--medium   { background: #fdf4e3; }
.hist-alert--medium i { color: #8a5a00; }
.hist-alert--low   { background: #f1f3f6; }
.hist-alert--low i { color: #566074; }

/* Tableaux ---------------------------------------------------------------- */
.hist-table td {
  vertical-align: middle;
}

.hist-table tfoot td {
  font-size: 12.5px;
  color: var(--text-secondary);
  border-top: 2px solid var(--border-color);
}

.hist-flag {
  color: #c48a26;
  font-size: 14px;
  vertical-align: -2px;
}

.hist-cancelled td {
  opacity: 0.55;
}

.hist-highlight td {
  background: var(--qn-gold-soft, #fbf3e3) !important;
  transition: background 0.3s ease;
}

/* Fiche client (modale) */
.hist-modal {
  width: min(560px, calc(100vw - 32px));
}

#modal-history-client [hidden] {
  display: none !important;
}

.hist-modal .form-group + .form-group {
  margin-top: 16px;
}

.hist-client-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.hist-client-stats div {
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f6f8fb;
}

.hist-client-stats span {
  font-size: 11px;
  color: var(--text-muted);
}

.hist-client-stats strong {
  font-size: 13.5px;
  color: var(--text-primary);
}

.hist-client-flags {
  margin: 0 0 14px;
  padding: 10px 12px 10px 28px;
  border-radius: 10px;
  font-size: 12.5px;
  color: #8a5a00;
  background: #fdf4e3;
}

.hist-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

@media (max-width: 1100px) {
  .hist-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .hist-months {
    height: 150px;
  }

  .hist-month-value {
    display: none;
  }

  .hist-client-stats {
    grid-template-columns: minmax(0, 1fr);
  }
}

.hist-prices-note {
  margin: 0 0 12px;
}
