/* =========================================================================
   Composants réutilisables : boutons, cartes, tableaux, formulaires, badges…
   ========================================================================= */

/* Boutons -------------------------------------------------------------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink-800);
  --btn-bd: var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 8px 14px;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.2;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { text-decoration: none; background: var(--surface-sunken); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

.btn--primary {
  --btn-bg: var(--brand-700);
  --btn-fg: #fff;
  --btn-bd: var(--brand-700);
  box-shadow: var(--shadow-xs);
}
.btn--primary:hover { background: var(--brand-800); border-color: var(--brand-800); }

.btn--danger { --btn-bg: var(--surface); --btn-fg: var(--danger-700); --btn-bd: #e6c7c4; }
.btn--danger:hover { background: var(--danger-100); }

.btn--ghost { --btn-bg: transparent; --btn-bd: transparent; }
.btn--ghost:hover { background: var(--surface-sunken); }

.btn--sm { padding: 5px 10px; font-size: var(--text-xs); }
.btn--lg { padding: 11px 20px; font-size: var(--text-base); }
.btn--block { width: 100%; }
.btn--icon { padding: 7px; }

/* Cartes -------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.card__title { font-size: var(--text-md); font-weight: 650; }
.card__body { padding: var(--space-5); }
.card__body--flush { padding: 0; }
.card__footer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Grille de statistiques -------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}
.stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.14s ease, transform 0.14s ease;
}
a.stat:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); text-decoration: none; }
.stat__label {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-sm); color: var(--ink-400); font-weight: 550;
}
.stat__label .icon { color: var(--ink-300); }
.stat__value { font-size: var(--text-2xl); font-weight: 680; color: var(--ink-900); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat__hint { font-size: var(--text-xs); color: var(--ink-300); }
.stat--positive .stat__value { color: var(--positive); }
.stat--negative .stat__value { color: var(--negative); }
.stat--warning .stat__value { color: var(--warning-700); }

/* Badges ------------------------------------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1.4;
}
.badge::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}
.badge--neutral { background: var(--surface-sunken); color: var(--ink-500); border-color: var(--border-strong); }
.badge--success { background: var(--success-100); color: var(--success-700); }
.badge--warning { background: var(--warning-100); color: var(--warning-700); }
.badge--danger { background: var(--danger-100); color: var(--danger-700); }
.badge--info { background: var(--info-100); color: var(--info-700); }
.badge--plain::before { display: none; }

/* Puce de comptage */
.count-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  font-size: 11px; font-weight: 700; line-height: 1;
  background: var(--brand-700); color: #fff; border-radius: var(--radius-pill);
}

/* Tableaux -------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table th {
  text-align: left;
  padding: 11px var(--space-4);
  font-size: var(--text-xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-400);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 12px var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color 0.1s ease; }
.table tbody tr:hover { background: var(--brand-050); }
.table tr.is-clickable { cursor: pointer; }
.table .u-right, .table th.u-right { text-align: right; }
.table__num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table--tight td { padding: 8px var(--space-4); }
.table__link { font-weight: 600; color: var(--ink-900); }
.table__link:hover { color: var(--brand-700); }
.row-unread td { background: var(--brand-050); }
.row-unread td:first-child { box-shadow: inset 3px 0 0 var(--brand-600); }

/* Formulaires ---------------------------------------------------- */
.form-section { margin-bottom: var(--space-6); }
.form-section__title {
  font-size: var(--text-sm);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-400);
  padding-bottom: var(--space-2);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4) var(--space-5);
}
.form-grid--single { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field--full { grid-column: 1 / -1; }
.field__label { font-size: var(--text-sm); font-weight: 600; color: var(--ink-700); }
.field__label .req { color: var(--danger-700); margin-left: 2px; }
.field__hint { font-size: var(--text-xs); color: var(--ink-400); }
.field__error { font-size: var(--text-xs); color: var(--danger-700); font-weight: 550; }

.input, .select, .textarea {
  width: 100%;
  padding: 9px 11px;
  font-size: var(--text-base);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-300); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand-600);
  box-shadow: 0 0 0 3px var(--brand-100);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-300); }
.textarea { resize: vertical; min-height: 84px; }
.field--error .input, .field--error .select, .field--error .textarea {
  border-color: var(--danger-700);
}
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group__suffix {
  display: inline-flex; align-items: center; padding: 0 12px;
  background: var(--surface-sunken); border: 1px solid var(--border-strong);
  border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: var(--text-sm); color: var(--ink-400); font-weight: 600;
}

.check {
  display: flex; align-items: flex-start; gap: var(--space-2);
  font-size: var(--text-base);
}
.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--brand-700); }

.form-actions {
  display: flex; align-items: center; gap: var(--space-3);
  padding-top: var(--space-5); margin-top: var(--space-5);
  border-top: 1px solid var(--border);
}
.form-actions--end { justify-content: flex-end; }

/* Alertes / messages flash ------------------------------------- */
.flash-stack {
  position: fixed; bottom: 20px; right: 20px; z-index: 65;
  display: flex; flex-direction: column; gap: var(--space-2);
  max-width: min(400px, calc(100vw - 32px));
}
@media (max-width: 520px) {
  .flash-stack { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}
.flash {
  display: flex; align-items: flex-start; gap: var(--space-2);
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--ink-400);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  animation: flash-in 0.2s ease;
}
@keyframes flash-in { from { opacity: 0; transform: translateY(8px); } }
.flash--success { border-left-color: var(--success-700); }
.flash--success .icon { color: var(--success-700); }
.flash--error { border-left-color: var(--danger-700); }
.flash--error .icon { color: var(--danger-700); }
.flash--warning { border-left-color: var(--warning-700); }
.flash--warning .icon { color: var(--warning-700); }
.flash--info .icon { color: var(--info-700); }
.flash__close { margin-left: auto; background: none; border: 0; cursor: pointer; color: var(--ink-300); padding: 2px; }
.flash__close:hover { color: var(--ink-700); }

.notice {
  display: flex; gap: var(--space-3); padding: var(--space-4);
  border-radius: var(--radius-md); font-size: var(--text-sm);
  background: var(--info-100); color: var(--info-700);
  border: 1px solid #cfe3ea;
}
.notice .icon { flex: none; margin-top: 1px; }
.notice--warning { background: var(--warning-100); color: var(--warning-700); border-color: #ecdcbf; }
.notice--danger { background: var(--danger-100); color: var(--danger-700); border-color: #ecccc8; }

/* États vides --------------------------------------------------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: var(--space-3); padding: var(--space-7) var(--space-5);
  color: var(--ink-400);
}
.empty-state__icon {
  display: flex; align-items: center; justify-content: center;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--surface-sunken); color: var(--ink-300);
}
.empty-state__title { font-size: var(--text-md); font-weight: 600; color: var(--ink-700); }
.empty-state__text { max-width: 42ch; font-size: var(--text-sm); }

/* Onglets ------------------------------------------------------ */
.tabs {
  display: flex; gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tabs__item {
  padding: 10px 14px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-400);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  text-decoration: none;
}
.tabs__item:hover { color: var(--ink-800); text-decoration: none; }
.tabs__item.is-active { color: var(--brand-700); border-bottom-color: var(--brand-700); }

/* Menu déroulant --------------------------------------------- */
.dropdown { position: relative; }
.dropdown__menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 40;
  min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  display: none;
}
.dropdown__menu.is-open { display: block; }
.dropdown__item {
  display: flex; align-items: center; gap: var(--space-2);
  width: 100%; padding: 8px 10px; border: 0; background: none;
  font-size: var(--text-sm); color: var(--ink-800); text-align: left;
  border-radius: var(--radius-sm); cursor: pointer; text-decoration: none;
}
.dropdown__item:hover { background: var(--surface-sunken); text-decoration: none; }
.dropdown__item--danger { color: var(--danger-700); }
.dropdown__sep { height: 1px; background: var(--border); margin: 5px 0; }

/* Modale ---------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(26, 29, 26, 0.42);
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
}
.modal {
  width: 100%; max-width: 460px;
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal__header { padding: var(--space-5); border-bottom: 1px solid var(--border); }
.modal__title { font-size: var(--text-lg); }
.modal__body { padding: var(--space-5); font-size: var(--text-sm); color: var(--ink-700); }
.modal__footer {
  display: flex; justify-content: flex-end; gap: var(--space-3);
  padding: var(--space-4) var(--space-5); background: var(--surface-2);
  border-top: 1px solid var(--border);
}

/* Pagination --------------------------------------------- */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); margin-top: var(--space-4);
  font-size: var(--text-sm); color: var(--ink-400);
}
.pagination__links { display: flex; gap: var(--space-2); }

/* Fil d'Ariane ----------------------------------------- */
.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: var(--text-sm); color: var(--ink-400); margin-bottom: var(--space-2);
}
.breadcrumb a { color: var(--ink-400); }
.breadcrumb a:hover { color: var(--brand-700); }
.breadcrumb .icon { color: var(--ink-300); }

/* Barre de filtres ------------------------------------- */
.filter-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); margin-bottom: var(--space-4);
}
.filter-bar .select { width: auto; min-width: 150px; max-width: 240px; flex: 0 1 auto; }
.filter-bar .input[type="date"] { width: auto; }
.search-field { position: relative; flex: 1 1 220px; min-width: 200px; }
.search-field .icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--ink-300); pointer-events: none;
}
.search-field .input { padding-left: 34px; }

/* Listes de définition ------------------------------ */
.def-list { display: grid; grid-template-columns: max-content 1fr; gap: 10px var(--space-4); font-size: var(--text-sm); }
.def-list dt { color: var(--ink-400); font-weight: 550; }
.def-list dd { color: var(--ink-800); font-weight: 500; }

/* Barre de progression ---------------------------- */
.progress { height: 6px; background: var(--surface-sunken); border-radius: var(--radius-pill); overflow: hidden; }
.progress__bar { height: 100%; background: var(--brand-600); border-radius: inherit; }
.progress__bar--full { background: var(--success-700); }
.progress__bar--warn { background: var(--warning-700); }

/* Avatar ---------------------------------------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand-100); color: var(--brand-800);
  font-size: var(--text-xs); font-weight: 700; flex: none;
}
.avatar--lg { width: 52px; height: 52px; font-size: var(--text-md); }

/* Séparateur de section ------------------------- */
.section-title {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-400); margin-bottom: var(--space-3);
}
