/* ============================================================
   AgroGest — components.css : bibliothèque de composants (§10.5)
   Nomenclature BEM. Rayon boutons 8px, cartes 12px.
   ============================================================ */

/* ---------- Boutons (4 variantes) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--sp-2);
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-btn);
  font-weight: 600; font-size: var(--fs-sm);
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn--primary { background: var(--color-primary); color: var(--text-on-primary); box-shadow: var(--shadow-sm); }
.btn--primary:hover:not(:disabled) { background: var(--color-primary-h); box-shadow: var(--shadow-md); }

.btn--secondary {
  background: var(--surface-1); color: var(--text-1);
  border-color: var(--border);
}
.btn--secondary:hover:not(:disabled) { border-color: var(--color-primary); color: var(--color-primary); }

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

.btn--danger { background: var(--color-danger); color: #fff; }
.btn--danger:hover:not(:disabled) { filter: brightness(1.08); }

.btn--block { width: 100%; }
.btn--sm { padding: 5px 10px; font-size: 13px; }

/* Spinner intégré au bouton (état chargement) */
.btn__spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255, 255, 255, .4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Champs de formulaire ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }

.field__label {
  font-size: var(--fs-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-2);
}
.field__label--required::after { content: " *"; color: var(--color-danger); }

.field__input, .field__select, .field__textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.field__input:focus, .field__select:focus, .field__textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--tint-primary);
}
.field__input--error { border-color: var(--color-danger) !important; }

.field__error { font-size: 12px; color: var(--color-danger); min-height: 16px; }
.field__hint  { font-size: 12px; color: var(--text-2); }

/* Jauge de robustesse du mot de passe (§9.2) */
.pw-meter { display: flex; gap: 4px; margin-top: 4px; }
.pw-meter__bar {
  height: 4px; flex: 1; border-radius: 2px;
  background: var(--border);
  transition: background var(--t-med);
}
.pw-meter__bar--weak   { background: var(--color-danger); }
.pw-meter__bar--medium { background: var(--color-warning); }
.pw-meter__bar--strong { background: var(--color-success); }

/* ---------- Cartes ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--sp-5);
}
.card__title {
  font-size: var(--fs-h2); margin-bottom: var(--sp-4);
  display: flex; align-items: center; gap: var(--sp-2);
}
.card__title i { color: var(--color-primary); }

/* Carte KPI du tableau de bord (§5.1) */
.kpi {
  position: relative;
  display: flex; flex-direction: column; gap: 6px;
  padding: var(--sp-5);
  transition: box-shadow var(--t-fast), transform var(--t-fast), border-color var(--t-fast);
}
.kpi:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--border-strong); }
.kpi__label {
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-3); font-weight: 600;
  display: flex; align-items: center; gap: var(--sp-2);
}
.kpi__icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: grid; place-items: center; font-size: 16px;
  background: var(--tint-primary); color: var(--color-primary);
  margin-bottom: var(--sp-1);
}
.kpi__icon--success { background: var(--tint-success); color: var(--color-success); }
.kpi__icon--warning { background: var(--tint-warning); color: var(--color-warning); }
.kpi__icon--danger  { background: var(--tint-danger);  color: var(--color-danger); }
.kpi__icon--info    { background: var(--tint-info);    color: var(--color-info); }
.kpi__icon--accent  { background: var(--color-accent-soft); color: var(--color-accent); }
.kpi__value { font-size: var(--fs-kpi); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1.1; color: var(--text-1); }
.kpi__delta { font-size: var(--fs-xs); font-weight: 600; }
.kpi__delta--up   { color: var(--color-success); }
.kpi__delta--down { color: var(--color-danger); }

/* ---------- Badges teintés 12 % (§10.5) ---------- */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px; font-weight: 500;
}
.badge--success { background: var(--tint-success); color: var(--color-success); }
.badge--warning { background: var(--tint-warning); color: var(--color-warning); }
.badge--danger  { background: var(--tint-danger);  color: var(--color-danger); }
.badge--info    { background: var(--tint-info);    color: var(--color-info); }
.badge--neutral { background: var(--tint-neutral); color: var(--text-2); }
.badge i { font-size: 10px; margin-right: 4px; }

/* ---------- Tables ----------
   Le tableau garde une largeur naturelle (par le contenu de ses colonnes) ;
   quand elle dépasse celle du conteneur, .table-wrap défile horizontalement
   au lieu de laisser les colonnes s'écraser illisiblement. */
.table-wrap { overflow-x: auto; overflow-y: hidden; max-width: 100%; border-radius: var(--radius-card); border: 1px solid var(--border); background: var(--surface-1); box-shadow: var(--shadow-card); }

.table { width: 100%; min-width: max-content; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: var(--fs-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
.table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); white-space: nowrap; }
/* Colonnes qu'on veut au contraire laisser s'enrouler (texte libre long :
   description, adresse, notes…) — ajouter la classe sur le th/td concerné. */
.table th.col--wrap, .table td.col--wrap { white-space: normal; overflow-wrap: anywhere; min-width: 200px; }
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--t-fast); cursor: default; }
.table tbody tr:hover { background: var(--tint-primary); }
.table td--num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Modale et slide-over (§10.5) ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(16, 21, 19, .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn var(--t-med);
}
@keyframes fadeIn { from { opacity: 0; } }

.modal {
  background: var(--surface-1);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  padding: var(--sp-5);
}
.modal__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--sp-4); }
.modal__close  { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-2); line-height: 1; }
.modal__footer { display: flex; justify-content: flex-end; gap: var(--sp-3); margin-top: var(--sp-5); flex-wrap: wrap; }

.slideover {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(480px, 100vw);
  background: var(--surface-1);
  box-shadow: var(--shadow-pop);
  z-index: 101;
  padding: var(--sp-5);
  overflow-y: auto;
  animation: slideIn var(--t-med);
}
@keyframes slideIn { from { transform: translateX(100%); } }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; bottom: var(--sp-5); right: var(--sp-5);
  display: flex; flex-direction: column; gap: var(--sp-2);
  z-index: 200;
}
.toast {
  display: flex; align-items: center; gap: var(--sp-3);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 4px solid var(--color-info);
  border-radius: var(--radius-btn);
  box-shadow: var(--shadow-pop);
  padding: 12px 16px;
  min-width: min(280px, 100%); max-width: min(400px, 100%);
  animation: toastIn var(--t-med);
}
@media (max-width: 480px) {
  .toasts { left: var(--sp-3); right: var(--sp-3); bottom: var(--sp-3); }
  .toast { width: 100%; }
}
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } }
.toast--success { border-left-color: var(--color-success); }
.toast--error   { border-left-color: var(--color-danger); }
.toast--warning { border-left-color: var(--color-warning); }

/* ---------- État vide (§10.5) ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-7) var(--sp-5);
  text-align: center;
  color: var(--text-2);
}
.empty__icon  { font-size: 40px; opacity: .6; }
.empty__title { font-weight: 600; color: var(--text-1); }

/* ---------- Squelettes de chargement ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--bg-page) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-btn);
  min-height: 16px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; gap: var(--sp-2); justify-content: flex-end; flex-wrap: wrap; row-gap: var(--sp-2); padding: var(--sp-3) 0; }
.pagination__info { color: var(--text-2); font-size: 13px; margin-right: auto; }

/* ---------- Icônes Font Awesome (auto-hébergées) ---------- */
.empty__icon { font-size: 36px; opacity: .55; color: var(--color-primary); }
.sidebar__link-icon { font-size: 17px; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar__brand-logo { font-size: 22px; width: 28px; text-align: center; flex-shrink: 0; }
.btn .fa-solid, .btn .fa-regular { font-size: 13px; }

/* ============ Centre de notifications (topbar) ============ */
.notif { position: relative; flex-shrink: 0; }
.notif__btn {
  position: relative; background: none; border: none; cursor: pointer;
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 18px; display: grid; place-items: center;
  transition: background var(--t-fast), color var(--t-fast);
}
.notif__btn:hover { background: var(--surface-2); color: var(--text-1); }
.notif__badge {
  position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px;
  padding: 0 5px; border-radius: 9px; background: var(--color-danger);
  color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
.notif__panel {
  position: absolute; right: 0; top: calc(100% + 8px); width: min(360px, 90vw);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg); z-index: 50;
  overflow: hidden;
}
@media (max-width: 480px) {
  /* Ancré au viewport plutôt qu'à la petite icône : évite qu'il ne
     déborde hors écran quand la topbar est resserrée sur mobile. */
  .notif__panel {
    position: fixed; top: calc(var(--topbar-h) + 8px);
    left: var(--sp-3); right: var(--sp-3); width: auto;
  }
}
.notif__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border);
}
.notif__list { max-height: 60vh; overflow-y: auto; }
.notif__empty { padding: var(--sp-5); text-align: center; }
.notif__item {
  display: flex; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background var(--t-fast);
}
.notif__item:hover { background: var(--surface-2); }
.notif__item--unread { background: color-mix(in srgb, var(--color-primary) 6%, transparent); }
.notif__item-icon { flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; font-size: 14px; }
.notif__item-icon--info { background: color-mix(in srgb, var(--color-info) 18%, transparent); color: var(--color-info); }
.notif__item-icon--warning { background: color-mix(in srgb, var(--color-warning) 18%, transparent); color: var(--color-warning); }
.notif__item-icon--critical { background: color-mix(in srgb, var(--color-danger) 18%, transparent); color: var(--color-danger); }
.notif__item-body { flex: 1; min-width: 0; }
.notif__item-title { font-weight: 600; font-size: 13px; }
.notif__item-msg { font-size: 12px; color: var(--text-2); }
.notif__item-time { font-size: 11px; color: var(--text-3); margin-top: 2px; }

.topbar__icon {
  background: none; border: none; cursor: pointer; width: 40px; height: 40px;
  border-radius: var(--radius-sm); color: var(--text-2); font-size: 18px;
  display: grid; place-items: center; transition: background var(--t-fast), color var(--t-fast);
  flex-shrink: 0;
}
.topbar__icon:hover { background: var(--surface-2); color: var(--text-1); }

/* ============ Galerie de cartes (bétail) ============ */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--sp-4); }
.animal-card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: var(--sp-4); cursor: pointer;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.animal-card:hover { border-color: var(--color-primary); box-shadow: var(--shadow-sm); }
.animal-card__tag { font-weight: 700; font-size: 15px; }
.animal-card__meta { font-size: 13px; color: var(--text-2); margin: var(--sp-1) 0; }

/* ============ Kanban (tâches) ============ */
.kanban { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); align-items: start; }
.kanban__col {
  background: var(--surface-2); border-radius: var(--radius-md); padding: var(--sp-3);
  min-height: 120px;
}
.kanban__col-head { font-weight: 600; padding: var(--sp-2) var(--sp-2) var(--sp-3); display: flex; justify-content: space-between; }
.kanban__col--over { outline: 2px dashed var(--color-primary); outline-offset: -2px; }
.kanban__card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-left: 3px solid var(--text-3);
  border-radius: var(--radius-sm); padding: var(--sp-3); margin-bottom: var(--sp-2);
  cursor: grab; font-size: 13px;
}
.kanban__card[draggable="true"]:active { cursor: grabbing; }
.kanban__card--high { border-left-color: var(--color-danger); }
.kanban__card--medium { border-left-color: var(--color-warning); }
.kanban__card--low { border-left-color: var(--color-info); }
.kanban__card-title { font-weight: 600; margin-bottom: var(--sp-1); }
.kanban__card-meta { font-size: 11px; color: var(--text-2); }
.kanban__card--overdue .kanban__card-meta { color: var(--color-danger); font-weight: 600; }
@media (max-width: 768px) { .kanban { grid-template-columns: 1fr; } }

/* ============ Dossiers GED ============ */
.folder-tabs { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.folder-tab {
  padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-1); cursor: pointer;
  font-size: 13px; transition: all var(--t-fast);
}
.folder-tab--active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ============ Onglets (fiches à onglets) ============ */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.tab {
  padding: var(--sp-3) var(--sp-4); background: none; border: none; cursor: pointer;
  font-size: 14px; color: var(--text-2); border-bottom: 2px solid transparent;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.tab:hover { color: var(--text-1); }
.tab--active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }

/* ============ Groupe de boutons ============ */
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn[aria-pressed="true"] { background: var(--color-primary); color: #fff; }

/* ============ Ligne historique (carnet, entretiens) ============ */
.timeline-item {
  display: flex; gap: var(--sp-3); padding: var(--sp-3) 0; border-bottom: 1px solid var(--border);
}
.timeline-item__date { flex-shrink: 0; width: 90px; font-size: 12px; color: var(--text-2); }
.timeline-item__body { flex: 1; }
.timeline-item__title { font-weight: 600; font-size: 13px; }
.timeline-item__meta { font-size: 12px; color: var(--text-2); }

/* ---------- Suggestions IA (dashboard §6.4) ---------- */
.suggestion {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 12px 14px; margin-bottom: var(--sp-2);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-1);
  text-decoration: none; transition: background var(--t-fast), transform var(--t-fast);
}
.suggestion:hover { background: var(--surface-3); transform: translateX(2px); text-decoration: none; }
.suggestion__badge {
  flex-shrink: 0; font-size: var(--fs-xs); font-weight: 600;
  padding: 4px 10px; border-radius: var(--radius-pill);
  background: var(--tint-accent, var(--color-accent-soft)); color: var(--color-accent);
  white-space: nowrap;
}
.suggestion__msg { flex: 1; font-size: var(--fs-sm); line-height: 1.4; }
.suggestion__arrow { color: var(--text-3); font-size: 12px; }

/* ---------- Boutons de déplacement des cartes kanban ---------- */
.kanban__card-actions {
  display: flex; justify-content: space-between; gap: var(--sp-2);
  margin-top: var(--sp-2); padding-top: var(--sp-2);
  border-top: 1px solid var(--border);
}
.kanban__move {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-2); cursor: pointer;
  width: 30px; height: 26px; border-radius: var(--radius-sm);
  display: grid; place-items: center; font-size: 12px;
  transition: background var(--t-fast), color var(--t-fast);
}
.kanban__move:hover { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
