/* ==========================================================================
   Composants : boutons, champs, panneaux, tableaux, badges, modale, toasts
   ========================================================================== */

/* --- Boutons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 38px; padding: 0 var(--s-4);
  font: 500 var(--t-sm)/1 var(--f-ui); letter-spacing: .01em;
  border: 1px solid var(--encre); border-radius: var(--r-champ);
  background: var(--encre); color: var(--blanc); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--encre-3); border-color: var(--encre-3); }
.btn--primaire { background: var(--rouge); border-color: var(--rouge); }
.btn--primaire:hover { background: var(--rouge-fonce); border-color: var(--rouge-fonce); }
.btn--ligne { background: var(--blanc); color: var(--encre); border-color: var(--trait-fort); }
.btn--ligne:hover { background: var(--surface); border-color: var(--encre); }
.btn--texte { background: none; border-color: transparent; color: var(--ardoise); padding: 0 var(--s-2); }
.btn--texte:hover { background: var(--surface); color: var(--encre); border-color: transparent; }
.btn--danger { background: var(--blanc); color: var(--rouge); border-color: #E7B9B7; }
.btn--danger:hover { background: var(--rouge-voile); border-color: var(--rouge); }
.btn--sm { height: 30px; padding: 0 var(--s-3); font-size: var(--t-xs); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }

/* --- Champs ------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span, .field-label { font-size: var(--t-sm); color: var(--ardoise); }
.field .req { color: var(--rouge); }
.field small { color: var(--brume); font-size: var(--t-xs); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=search], input[type=url], input[type=tel], select, textarea {
  width: 100%; min-height: 38px; padding: 8px 10px;
  font: 400 var(--t-base) var(--f-ui); color: var(--encre);
  background: var(--blanc); border: 1px solid var(--trait-fort); border-radius: var(--r-champ);
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--encre); box-shadow: var(--focus); }
input.is-invalid, select.is-invalid, textarea.is-invalid { border-color: var(--rouge); background: var(--rouge-voile); }
.hint-ok { color: var(--vert) !important; }
.hint-ko { color: var(--rouge) !important; }
.checkbox { display: flex; gap: var(--s-2); align-items: flex-start; font-size: var(--t-sm); cursor: pointer; }
.checkbox input { margin-top: 3px; accent-color: var(--rouge); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4) var(--s-4); }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-section { grid-column: 1 / -1; padding-top: var(--s-3); border-top: 1px solid var(--trait); font-weight: 500; font-size: var(--t-sm); }
.form-error { grid-column: 1 / -1; padding: var(--s-3); background: var(--rouge-voile); color: var(--rouge-fonce); font-size: var(--t-sm); border-left: 2px solid var(--rouge); }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.toolbar { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; margin-bottom: var(--s-4); }
.toolbar input[type=search] { width: 260px; }
.toolbar select { width: auto; min-width: 160px; }
.segmented { display: inline-flex; border: 1px solid var(--trait-fort); border-radius: var(--r-champ); overflow: hidden; background: var(--blanc); }
.segmented button { border: 0; background: none; padding: 0 var(--s-4); height: 36px; font: 400 var(--t-sm) var(--f-ui); color: var(--ardoise); cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--trait); }
.segmented button[aria-pressed="true"] { background: var(--encre); color: var(--blanc); }

/* --- Panneaux ------------------------------------------------------------ */
.panel { background: var(--blanc); border: 1px solid var(--trait); border-radius: var(--r-carte); }
.panel__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--trait); }
.panel__head h2 { font-size: var(--t-md); font-family: var(--f-ui); font-weight: 500; }
.panel__body { padding: var(--s-5); }
.panel__body--flush { padding: 0; }

/* Liste de définitions (fiches) */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-2) var(--s-5); margin: 0; font-size: var(--t-sm); }
.dl dt { color: var(--ardoise); }
.dl dd { margin: 0; overflow-wrap: anywhere; }

/* Chiffres clés */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); background: var(--blanc); border: 1px solid var(--trait); border-radius: var(--r-carte); }
.figure { padding: var(--s-4) var(--s-5); }
.figure + .figure { border-left: 1px solid var(--trait); }
.figure__label { font-size: var(--t-sm); color: var(--ardoise); }
.figure__value { font-family: var(--f-titre); font-size: var(--t-xl); line-height: 1.2; margin-top: 2px; font-variant-numeric: lining-nums tabular-nums; }
.figure__note { font-size: var(--t-xs); color: var(--brume); }
.figure--alerte .figure__value { color: var(--rouge); }
@media (max-width: 760px) { .figure + .figure { border-left: 0; border-top: 1px solid var(--trait); } }

/* --- Tableaux ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.table th {
  text-align: left; font-weight: 500; color: var(--ardoise); white-space: nowrap;
  padding: 10px var(--s-4); border-bottom: 1px solid var(--trait-fort); background: var(--blanc); position: sticky; top: 0;
}
.table td { padding: 11px var(--s-4); border-bottom: 1px solid var(--trait); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.is-link { cursor: pointer; }
.table tr.is-link:hover td { background: #FAFAFB; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .muted, .muted { color: var(--brume); }
.table .strong { font-weight: 500; }
.table tr.is-off td { color: var(--brume); }

.pagination { display: flex; align-items: center; justify-content: space-between; padding: var(--s-3) var(--s-4); border-top: 1px solid var(--trait); font-size: var(--t-sm); color: var(--ardoise); }

/* --- Badges -------------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; font-size: var(--t-xs); line-height: 1.5; border-radius: var(--r-pill); background: var(--surface); color: var(--ardoise); border: 1px solid var(--trait); white-space: nowrap; }
.badge--gagne { background: var(--vert-voile); color: var(--vert); border-color: #CFE3D8; }
.badge--perdu { background: var(--surface); color: var(--brume); }
.badge--alerte { background: var(--rouge-voile); color: var(--rouge-fonce); border-color: #F0CFCD; }
.badge--ambre { background: var(--ambre-voile); color: var(--ambre); border-color: #EFDFC0; }
.badge--encre { background: var(--encre); color: var(--blanc); border-color: var(--encre); }

.star { display: inline-block; width: 10px; height: 10px; background: var(--rouge); flex: none;
  clip-path: polygon(50% 0, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0 50%, 40% 40%); }

.avatar { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--encre); color: var(--blanc); font-size: 10px; font-weight: 500; letter-spacing: .03em; flex: none; }
.avatar--vide { background: var(--blanc); color: var(--brume); border: 1px dashed var(--trait-fort); }

/* --- États vides ------------------------------------------------------- */
.empty { padding: var(--s-7) var(--s-5); text-align: center; color: var(--ardoise); }
.empty h3 { font-family: var(--f-titre); font-size: var(--t-lg); color: var(--encre); margin-bottom: var(--s-2); font-weight: 500; }
.empty p { margin: 0 auto var(--s-4); }
.loading { padding: var(--s-6); color: var(--brume); font-size: var(--t-sm); }

/* --- Listes simples ---------------------------------------------------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--trait); }
.list > li:last-child { border-bottom: 0; }
.list__main { flex: 1; min-width: 0; }
.list__title { font-size: var(--t-sm); font-weight: 500; }
.list__meta { font-size: var(--t-xs); color: var(--ardoise); }
.list__note { font-size: var(--t-sm); color: var(--ardoise); margin-top: 2px; white-space: pre-line; }

/* --- Barre de progression --------------------------------------------- */
.progress { height: 6px; background: var(--trait); border-radius: var(--r-pill); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--encre); }

/* --- Modale -------------------------------------------------------------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: var(--s-4); background: rgba(3, 4, 8, .48); animation: fade .15s ease; }
.modal { width: min(640px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--blanc); border-radius: var(--r-carte); box-shadow: var(--ombre-modale); animation: rise .18s ease; }
.modal--large { width: min(920px, 100%); }
.modal--small { width: min(440px, 100%); }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--trait); }
.modal__head h2 { font-size: var(--t-lg); }
.modal__close { border: 0; background: none; font-size: 26px; line-height: 1; color: var(--brume); cursor: pointer; padding: 0 4px; }
.modal__close:hover { color: var(--encre); }
.modal__body { padding: var(--s-5); overflow-y: auto; }
.modal__foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-4) var(--s-5); border-top: 1px solid var(--trait); background: #FBFBFC; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* --- Toasts ------------------------------------------------------------- */
.toasts { position: fixed; right: var(--s-5); bottom: var(--s-5); z-index: 200; display: flex; flex-direction: column; gap: var(--s-2); }
.toast { min-width: 260px; max-width: 420px; padding: var(--s-3) var(--s-4); background: var(--encre); color: var(--blanc); font-size: var(--t-sm); border-radius: var(--r-champ); border-left: 3px solid var(--vert); animation: rise .18s ease; }
.toast--erreur { border-left-color: var(--rouge); }

/* Suggestions (annuaire Sirene) */
.suggestions { border: 1px solid var(--trait); border-radius: var(--r-champ); max-height: 240px; overflow-y: auto; }
.suggestions button { display: block; width: 100%; text-align: left; padding: var(--s-2) var(--s-3); border: 0; border-bottom: 1px solid var(--trait); background: var(--blanc); font: inherit; font-size: var(--t-sm); cursor: pointer; }
.suggestions button:hover { background: var(--surface); }
.suggestions button:last-child { border-bottom: 0; }
.modal form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
