/* ========================================================================
   Composants : boutons, cards, inputs, badges, KPI, modal, toast, table
   ======================================================================== */

/* --- Card --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);            /* +lift sur le canvas teinté */
  overflow: hidden;
}
.card-tinted { background: var(--bg-subtle); }   /* variante feutrée pour rails/sections internes */
.card-header {
  padding: var(--space-5) var(--space-6) var(--space-3);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4);
}
.card-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
}
.card-subtitle {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
}
.card-content { padding: var(--space-4) var(--space-6) var(--space-6); }
.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: flex-end; gap: var(--space-3);
}

/* --- Boutons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1.25;
  border: 1px solid transparent;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  white-space: nowrap;
  min-height: 36px;
}
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }

/* Vert FIXE (hors thème tenant) — actions d'acceptation : accepter une offre,
   une location. Le vert = « oui » universel, il ne suit jamais --primary. */
.btn-success {
  background: #16a34a;
  color: #ffffff;
  border-color: #16a34a;
}
.btn-success:hover:not(:disabled) { background: #15803d; border-color: #15803d; }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-muted); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger {
  background: #dc2626;
  color: var(--white);
  border-color: #dc2626;
}
.btn-danger:hover:not(:disabled) { background: #b91c1c; border-color: #b91c1c; }

.btn-sm { padding: var(--space-1) var(--space-3); min-height: 30px; font-size: var(--text-xs); }
.btn-lg { padding: var(--space-3) var(--space-6); min-height: 44px; font-size: var(--text-base); }

/* --- Inputs --- */
.input, .textarea, .select {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: var(--text-sm);
  line-height: 1.375;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  min-height: 36px;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.textarea { resize: vertical; min-height: 80px; padding: var(--space-3); }

.label {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field { display: flex; flex-direction: column; gap: 0; margin-bottom: var(--space-4); }
.field-hint { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--space-1); }
.field-error { font-size: var(--text-xs); color: #dc2626; margin-top: var(--space-1); }

/* --- Badge (statuts) --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: var(--weight-medium);
  line-height: 1.25;
  border: 1px solid transparent;
}
.badge-slate { background: var(--slate-50); color: var(--slate-700); border-color: var(--slate-200); }
.badge-sky { background: var(--sky-50); color: var(--sky-700); }
.badge-violet { background: var(--violet-50); color: var(--violet-700); }
.badge-amber { background: var(--amber-50); color: var(--amber-700); }
.badge-emerald { background: var(--emerald-50); color: var(--emerald-700); }
.badge-rose { background: var(--rose-50); color: var(--rose-700); }
.badge-pink { background: #fdf2f8; color: #be185d; border-color: #fbcfe8; }

/* Sélecteur de produit (fiche client → Cave → Ajouter) : recherche + tri prix */
.product-picker { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; background: var(--bg-card); }
.product-picker-bar { display: flex; gap: 8px; align-items: center; padding: 8px; border-bottom: 1px solid var(--border-subtle); background: var(--bg-subtle); }
.product-picker-search { flex: 1; display: flex; align-items: center; gap: 6px; padding: 0 10px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-full); min-height: 32px; }
.product-picker-search svg { width: 14px; height: 14px; color: var(--text-muted); flex-shrink: 0; }
.product-picker-search input { flex: 1; border: 0; background: transparent; outline: 0; font-size: 13px; color: var(--text-primary); min-width: 0; }
.product-picker-bar .btn { white-space: nowrap; }
.product-picker-list { max-height: 240px; overflow: auto; }
.product-picker-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 8px 12px; border: 0; border-bottom: 1px solid var(--border-subtle); background: transparent; cursor: pointer; font-size: 13px; color: var(--text-primary); }
.product-picker-item:hover { background: var(--bg-hover); }
.product-picker-item.is-selected { background: color-mix(in oklch, var(--primary) 10%, var(--bg-card)); box-shadow: inset 3px 0 0 var(--primary); }
.product-picker-name { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.product-picker-name small { color: var(--text-muted); font-size: 11px; }
.product-picker-price { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.product-picker-selected { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 13px; background: color-mix(in oklch, var(--primary) 8%, var(--bg-card)); border-top: 1px solid var(--border-subtle); }
.product-picker-selected svg { width: 16px; height: 16px; color: var(--primary); flex-shrink: 0; }
.product-picker-selected[hidden] { display: none; }

/* Filtres de la timeline Activité (fiche lead) */
.activity-filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.activity-filter { border: 1px solid var(--border); background: var(--bg-card); color: var(--text-muted); border-radius: var(--radius-full); padding: 5px 12px; font-size: 12px; cursor: pointer; }
.activity-filter:hover { color: var(--text-primary); background: var(--bg-hover); }
.activity-filter.is-active { border-color: var(--primary); color: var(--primary); background: color-mix(in oklch, var(--primary) 10%, transparent); font-weight: 600; }
.activity-link { color: var(--text-muted); margin-left: 4px; display: inline-flex; vertical-align: -1px; }
.activity-link svg { width: 12px; height: 12px; }
.activity-link:hover { color: var(--primary); }

/* Pills radio « Paiement » du modal d'ajout en cave */
.pay-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-full); cursor: pointer; font-size: 13px; }
.pay-pill.is-active { border-color: var(--primary); background: color-mix(in oklch, var(--primary) 10%, transparent); }
.badge-blue { background: var(--blue-50); color: var(--blue-700); }
.badge-green { background: var(--green-50); color: var(--green-700); }
.badge-yellow { background: var(--yellow-50); color: var(--yellow-700); }
.badge-red { background: var(--red-50); color: var(--red-700); }
.badge-pink { background: var(--pink-50); color: var(--pink-700); }
.badge-orange { background: var(--orange-50); color: var(--orange-700); }

/* Select statut teinté (tables leads + modal) — mêmes teintes que les badges */
.status-select {
  font-weight: var(--weight-medium);
  border-color: color-mix(in srgb, currentColor 30%, transparent);
}
.status-select.status-slate { background: var(--slate-50); color: var(--slate-700); }
.status-select.status-sky { background: var(--sky-50); color: var(--sky-700); }
.status-select.status-violet { background: var(--violet-50); color: var(--violet-700); }
.status-select.status-amber { background: var(--amber-50); color: var(--amber-700); }
.status-select.status-emerald { background: var(--emerald-50); color: var(--emerald-700); }
.status-select.status-rose { background: var(--rose-50); color: var(--rose-700); }
.status-select.status-blue { background: var(--blue-50); color: var(--blue-700); }
.status-select.status-green { background: var(--green-50); color: var(--green-700); }
.status-select.status-yellow { background: var(--yellow-50); color: var(--yellow-700); }
.status-select.status-red { background: var(--red-50); color: var(--red-700); }
.status-select.status-pink { background: var(--pink-50); color: var(--pink-700); }
.status-select.status-orange { background: var(--orange-50); color: var(--orange-700); }

/* --- KPI card (gradient Monday-style) --- */
.kpi {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-2xl);
  padding: var(--space-5);
  color: var(--white);
  box-shadow: var(--shadow-md);
  transition: transform var(--transition), box-shadow var(--transition);
}
.kpi:hover { transform: scale(1.015); box-shadow: var(--shadow-lg); }
.kpi::before {
  content: "";
  position: absolute; top: -24px; right: -24px;
  width: 96px; height: 96px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.1);
  filter: blur(24px);
}
.kpi-content { position: relative; }
.kpi-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--space-2);
}
.kpi-label {
  font-size: 11px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.85);
}
.kpi-icon {
  display: grid; place-items: center;
  width: 28px; height: 28px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.15);
}
.kpi-icon svg { width: 16px; height: 16px; color: var(--white); }
.kpi-value {
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  margin-top: var(--space-2);
  line-height: 1;
}
.kpi-subtitle {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.8);
  margin-top: var(--space-1);
}
/* Tendance vs période précédente — pastille blanche, texte vert/rouge */
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.92);
  font-size: 11px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0;
  vertical-align: middle;
}
.kpi-delta.is-up { color: #059669; }
.kpi-delta.is-down { color: #dc2626; }
.kpi-delta.is-flat { color: var(--slate-500, #64748b); }

/* Barre d'objectif mensuel (dashboard) */
.target-bar {
  position: relative;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  overflow: visible;
}
.target-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}
.target-bar-fill.is-reached { background: linear-gradient(to right, #10b981, #059669); }
.target-bar-fill.is-onpace  { background: linear-gradient(to right, #34d399, #10b981); }
.target-bar-fill.is-behind  { background: linear-gradient(to right, #f59e0b, #dc2626); }
.target-bar-pace {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 16px;
  background: var(--text-muted);
  border-radius: 1px;
  opacity: 0.6;
}
.kpi-blue { background: linear-gradient(to bottom right, #3b82f6, #2563eb); }
.kpi-green { background: linear-gradient(to bottom right, #10b981, #0d9488); }
.kpi-purple { background: linear-gradient(to bottom right, #8b5cf6, #4f46e5); }
.kpi-amber { background: linear-gradient(to bottom right, #f59e0b, #f97316); }
.kpi-pink { background: linear-gradient(to bottom right, #f43f5e, #db2777); }
.kpi-cyan { background: linear-gradient(to bottom right, #06b6d4, #0284c7); }

/* --- Table --- */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  /* Scroll horizontal sur petits écrans (tableau performance à 10 colonnes,
     leads…) — overflow:hidden coupait les colonnes sans recours. */
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--bg-card);
}
.table-wrap table { min-width: max-content; }
.table {
  width: 100%;
  font-size: var(--text-sm);
}
.table thead {
  background: color-mix(in oklch, var(--bg-muted) 60%, transparent);
}
.table th {
  padding: 10px var(--space-4);
  text-align: left;
  font-weight: var(--weight-medium);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  vertical-align: middle;
}
/* Zébrage : alternance blanc / teinte légère pour la lisibilité des listes */
.table tbody tr:nth-child(even) td { background: var(--bg-subtle); }
.table tbody tr:hover td { background: var(--bg-hover); }
.table td.right, .table th.right { text-align: right; }
.table td.center, .table th.center { text-align: center; }

/* --- Modal --- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: var(--z-modal-backdrop);
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
  animation: fade-in var(--transition-fast) ease-out;
}
.modal {
  background: var(--bg-card);
  border-radius: var(--radius-2xl);        /* +8px vs avant → look plus moderne */
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 500px;
  max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
  z-index: var(--z-modal);
  animation: modal-in var(--transition) ease-out;
  overflow: hidden;                        /* évite que les enfants débordent des coins arrondis */
}
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 960px; }
/* Fiche lead : assez large pour la rangée complète d'onglets (9, libellés
   toujours visibles) sur une seule ligne. */
.modal-lead { max-width: min(1560px, calc(100vw - 48px)); }
.modal-header {
  padding: var(--space-5) var(--space-6) var(--space-3);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
}
.modal-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.015em;
  min-width: 0;
}
.modal-close {
  flex-shrink: 0;
  display: grid; place-items: center;
  width: 36px; height: 36px;
  margin: -6px -8px -6px 0;
  border: 0; background: none; cursor: pointer;
  border-radius: var(--radius-full);
  color: var(--text-muted);
  -webkit-tap-highlight-color: transparent;
}
.modal-close:hover { background: var(--bg-muted); color: var(--text); }
.modal-close i, .modal-close svg { width: 18px; height: 18px; }
@media (max-width: 767px) {
  .modal-close { width: 44px; height: 44px; margin-right: -12px; }
}
.modal-body {
  padding: var(--space-5) var(--space-6);
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: flex-end;
  gap: var(--space-3);
}

@keyframes fade-in { from { opacity: 0 } to { opacity: 1 } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* --- Toast --- */
.toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex; flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  min-width: 280px; max-width: 380px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: var(--text-sm);
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: var(--space-3);
  animation: toast-in var(--transition) ease-out;
}
.toast-icon { flex-shrink: 0; margin-top: 1px; }
.toast-title { font-weight: var(--weight-semibold); }
.toast-body { color: var(--text-muted); font-size: var(--text-xs); margin-top: 2px; }
.toast-success { border-color: rgba(16, 185, 129, 0.3); }
.toast-success .toast-icon { color: #059669; }
.toast-error { border-color: rgba(239, 68, 68, 0.3); }
.toast-error .toast-icon { color: #dc2626; }
.toast-warning { border-color: rgba(245, 158, 11, 0.3); }
.toast-warning .toast-icon { color: #d97706; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: none; }
}

/* --- Status badge (avec pastille) --- */
.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: var(--weight-medium);
  background: var(--slate-50);
  color: var(--slate-700);
  border: 1px solid var(--slate-200);
}
.status-badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* --- Pagination --- */
.pagination {
  display: flex; align-items: center; gap: var(--space-2);
  justify-content: center;
  padding: var(--space-4);
}
.pagination button {
  min-width: 32px; height: 32px;
  padding: 0 var(--space-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: var(--text-sm);
}
.pagination button:hover:not(:disabled) { background: var(--bg-hover); }
.pagination button[aria-current="page"] {
  background: var(--primary); color: var(--primary-fg); border-color: var(--primary);
}

/* --- Mobile : anti-zoom iOS ---
   Sous 16px, iOS Safari zoome automatiquement au focus d'un champ (et ne
   revient pas). 16px sur tous les champs de saisie en mobile. */
@media (max-width: 767px) {
  .input, .select, .textarea, .dw-search input, .dw-char-range-input {
    font-size: 16px;
  }
}


/* --- Mobile : toasts pleine largeur (280-380px collés à droite sinon) --- */
@media (max-width: 640px) {
  .toast-container { left: var(--space-4); right: var(--space-4); }
  .toast { min-width: 0; max-width: none; width: 100%; }
}

/* Mode Intervenir (28/09) : bouton de la fiche lead */
.btn-intervene { color: #b91c1c; }
.btn-intervene:hover { color: #991b1b; border-color: #fca5a5; }

/* Robot d'appels (29/09) : petites cases cliquables + mini-bandeau flottant */
.robot-cells { margin-top: 12px; display: flex; gap: 4px; flex-wrap: wrap; }
.robot-cell {
  width: 16px; height: 10px; border-radius: 4px; border: none; padding: 0;
  cursor: pointer; transition: transform 0.12s, box-shadow 0.12s;
}
.robot-cell:hover { transform: scale(1.35); box-shadow: 0 0 0 2px var(--bg-card), 0 0 0 3px var(--primary); }
.robot-cell.is-current { box-shadow: 0 0 0 2px var(--bg-card), 0 0 0 3px var(--primary); }
.robot-dock {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  width: min(620px, calc(100vw - 32px));
  z-index: 9990;   /* au-dessus des fiches (modales) : Reprendre sans fermer la fiche */
}
.robot-dock[hidden] { display: none; }
.robot-dock-inner {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px 10px 16px;
  background: var(--bg-card);
  border: 2px solid var(--primary);
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.22);
}
.robot-dock-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; animation: robot-dot 1.4s ease-in-out infinite; }
@keyframes robot-dot { 50% { opacity: 0.35; } }
.robot-dock-btn { padding-left: 8px; padding-right: 8px; }
.robot-dock-btn svg { margin: 0; }

/* Œil « voir le mot de passe » (08/10) */
.pw-wrap { position: relative; }
.pw-wrap .input { width: 100%; padding-right: 44px !important; } /* !important : l'override client-zone a une spécificité supérieure */
.pw-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: 10px;
  background: transparent; color: var(--text-muted); cursor: pointer;
  transition: color .15s, background .15s;
}
.pw-toggle:hover { color: var(--text-primary); background: color-mix(in oklch, var(--text-primary) 6%, transparent); }
.pw-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
