/* ============================================================
   Composants réutilisables — CRM CAFA (verbatim maquette)
   ============================================================ */

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-family: var(--font); font-weight: 600; font-size: 13.5px; line-height: 1;
  padding: 0 14px; height: 38px; border-radius: var(--r-sm);
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s, color .12s, transform .04s;
  user-select: none;
}
.btn:active { transform: translateY(.5px); }
.btn .ic { width: 16px; height: 16px; flex: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { background: var(--primary-press); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--text-faint); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--neutral-bg); color: var(--text); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, white); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { height: 32px; font-size: 12.5px; padding: 0 11px; border-radius: var(--r-xs); }
.btn-icon { width: 38px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Badges de statut ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; line-height: 1;
  padding: 4px 9px 4px 8px; border-radius: var(--r-full); white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge-success { color: var(--success); background: var(--success-bg); }
.badge-warning { color: var(--warning); background: var(--warning-bg); }
.badge-danger  { color: var(--danger);  background: var(--danger-bg); }
.badge-info    { color: var(--info);    background: var(--info-bg); }
.badge-neutral { color: var(--neutral); background: var(--neutral-bg); }
.badge-primary { color: var(--primary); background: var(--primary-100); }
.badge-sq { border-radius: var(--r-xs); }

/* ---------- Cartes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
.card-pad { padding: var(--sp-5); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 15px; }

/* ---------- Utilitaire de troncature (valeurs longues : formation, NAF…) ---------- */
.is-truncate { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Pages de formulaire CRUD custom (réutilisable) ---------- */
.cafa-form-page { max-width: 640px; margin: 0 auto; padding: 28px; }
.cafa-back {
  display: inline-flex; align-items: center; gap: 5px; margin-bottom: 14px;
  font-size: 13px; font-weight: 600; color: var(--text-muted); text-decoration: none;
}
.cafa-back:hover { color: var(--primary); }
.cafa-form-page__title { font-size: 22px; font-weight: 700; }
.cafa-form-page__sub { margin: 4px 0 18px; font-size: 14px; }
.cafa-form { display: flex; flex-direction: column; gap: 16px; }
.cafa-form .field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.cafa-form__err { display: block; margin-top: 5px; font-size: 12.5px; color: var(--danger); }
.cafa-form__actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 6px; padding-top: 16px; border-top: 1px solid var(--border);
}

/* Suppression unitaire d'un préfixe NAF (× dans la chip) */
.cafa-naf-chip { display: inline-flex; align-items: center; gap: 4px; }
.cafa-naf-chip__del { display: inline; margin: 0; }
.cafa-naf-chip__del button {
  border: none; background: none; cursor: pointer; padding: 0 0 0 2px;
  color: var(--text-faint); font-size: 14px; line-height: 1;
}
.cafa-naf-chip__del button:hover { color: var(--danger); }

/* Bandeau flash de succès (après une action CRUD) */
.cafa-flash {
  display: flex; align-items: center; gap: 10px;
  max-width: 1320px; margin: 16px auto 0; padding: 11px 16px;
  background: var(--success-bg); border: 1px solid var(--success);
  border-radius: var(--r-lg); font-size: 13.5px; font-weight: 600; color: var(--text);
}
.cafa-flash > .ic { color: var(--success); flex: none; }

/* ---------- KPI ---------- */
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 16px 18px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden;
}
/* padding-right : laisse passer la pastille .kpi-ic (absolue) sans couper le libellé. */
.kpi-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; padding-right: 42px; line-height: 1.3; }
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1; }
.kpi-foot { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.kpi-up   { color: var(--success); }
.kpi-down { color: var(--danger); }
.kpi-ic { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border-radius: var(--r-sm); display: flex; align-items: center; justify-content: center; }

/* Jauge vers l'objectif (taux) + ligne de contexte (dénominateur). */
.kpi-gauge { height: 5px; border-radius: 99px; background: var(--score-track, var(--border)); overflow: hidden; }
.kpi-gauge__fill { height: 100%; border-radius: 99px; transition: width .5s cubic-bezier(.22,1,.36,1); }
.kpi-gauge__cap { font-size: 11px; color: var(--text-faint); margin-top: -4px; }
.kpi-sub { font-size: 11.5px; color: var(--text-muted); }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.input {
  height: 40px; padding: 0 12px; font-family: var(--font); font-size: 14px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface);
  color: var(--text); transition: border-color .12s, box-shadow .12s; width: 100%;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-100); }
.input.err { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }
.input-with-ic { position: relative; }
.input-with-ic .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-faint); pointer-events: none; }
.input-with-ic .input { padding-left: 34px; }
select.input { appearance: none; cursor: pointer; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235B6473' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }

/* ---------- Segmented ---------- */
.seg { display: inline-flex; background: var(--neutral-bg); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg button {
  border: none; background: transparent; font-family: var(--font); font-weight: 600; font-size: 12.5px;
  color: var(--text-muted); padding: 6px 12px; border-radius: var(--r-xs); cursor: pointer; transition: all .12s;
  display: inline-flex; align-items: center; gap: 6px;
}
.seg button.on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-xs); }
.seg button:hover:not(.on) { color: var(--text); }

/* ---------- Tables ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl thead th {
  text-align: left; font-size: 11.5px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em; padding: 11px 14px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.tbl tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr { transition: background .1s; cursor: pointer; }
.tbl tbody tr:hover { background: var(--primary-50); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Avatar ---------- */
.av { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%;
  background: var(--primary-100); color: var(--primary); font-weight: 700; flex: none; letter-spacing: -.01em; }

/* ---------- Drawer / slide-over ---------- */
.drawer-overlay { position: absolute; inset: 0; background: rgba(11,11,18,.32); z-index: 40; animation: cafa-overlay .15s ease; }
.drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: 460px; max-width: 90%;
  background: var(--surface); box-shadow: var(--shadow-lg); z-index: 41;
  display: flex; flex-direction: column; animation: cafa-slide-in .22s cubic-bezier(.22,1,.36,1);
}
/* `.drawer` a un display:flex explicite qui écraserait l'attribut [hidden] de
   l'user-agent : on rétablit le masquage tant que le tiroir n'est pas ouvert
   (sinon un panneau vide reste affiché en permanence sur tous les écrans). */
.drawer[hidden] { display: none; }
.drawer-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; background: var(--surface-2); }

/* ---------- Score gauge ---------- */
.score-bar-track { height: 8px; border-radius: 99px; background: var(--score-track); overflow: hidden; }
.score-bar-fill { height: 100%; border-radius: 99px; transition: width .5s cubic-bezier(.22,1,.36,1); }
.score-ring { transform: rotate(-90deg); }
.score-ring circle { fill: none; }
.score-pill { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 5px 10px; border-radius: var(--r-full); font-size: 13px; }

/* ---------- Tooltip-ish chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 4px 9px; border-radius: var(--r-full); background: var(--neutral-bg); color: var(--text-muted); }
.chip-on { background: var(--primary-100); color: var(--primary); }

/* ---------- Empty state ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 48px 24px; gap: 12px; color: var(--text-muted); }
.empty .ill { width: 56px; height: 56px; border-radius: var(--r-lg); background: var(--primary-50);
  display: flex; align-items: center; justify-content: center; color: var(--primary); }

/* ---------- Section title ---------- */
.sec-title { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); margin-bottom: 10px; }

/* ---------- Divider ---------- */
.hr { height: 1px; background: var(--border); border: none; margin: 0; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tabs button { border: none; background: transparent; font-family: var(--font); font-weight: 600; font-size: 13.5px;
  color: var(--text-muted); padding: 11px 14px; cursor: pointer; position: relative; transition: color .12s; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--primary); }
.tabs button.on::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; background: var(--primary); border-radius: 2px; }

/* ---------- Densité (tweak) ---------- */
[data-density="compact"] { font-size: 13px; }
[data-density="compact"] .tbl tbody td { padding: 8px 12px; }
[data-density="compact"] .tbl thead th { padding: 8px 12px; }
[data-density="compact"] .card-pad { padding: 16px; }
[data-density="compact"] .kpi { padding: 13px 15px; }
[data-density="compact"] .kpi-value { font-size: 26px; }
