/* ============================================================
   Composants réutilisables — cartes, boutons, champs,
   toasts, modales, chargement, badges. Esthétique iOS :
   remplissages doux, coins continus, retour tactile.
   ============================================================ */

/* ---------- Cartes / sections ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card > h2 {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Boutons ----------
   Trois niveaux : rempli (action principale), gris teinté
   (secondaire), rouge teinté (destructif). Retour tactile
   par légère réduction d'échelle. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 11px 22px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
  transition:
    background var(--dur) var(--ease),
    transform var(--dur-fast) var(--ease),
    box-shadow var(--dur) var(--ease),
    opacity var(--dur) var(--ease);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}

/* Micro-interaction : le bouton se soulève au survol, s'enfonce au clic. */
.btn:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
  box-shadow: var(--shadow-sm);
  transition-duration: 60ms;
}

/* Action principale du hero : plus généreuse. */
.btn--lg {
  min-height: 54px;
  padding: 15px 32px;
  font-size: var(--text-base);
  border-radius: var(--radius-sm);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Le liseré interne garantit une forme lisible même quand le bouton
   repose sur une surface de même teinte (rangées de liste). */
.btn--ghost {
  background: var(--surface-2);
  color: var(--tint);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.btn--ghost:hover {
  background: var(--accent-soft);
}

.btn--ghost:focus-visible {
  box-shadow: var(--focus-ring);
}

.btn--danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.btn--danger:hover {
  background: var(--danger-bg);
  color: var(--danger-hover);
}

.btn--sm {
  min-height: 36px;
  padding: 6px 14px;
  font-size: 0.9rem;
  border-radius: 10px;
}

.btn--block {
  width: 100%;
}

/* État occupé (requête en cours) */
.btn.is-busy {
  position: relative;
  color: transparent;
}

.btn.is-busy::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent-ink);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn--ghost.is-busy::after {
  border-color: var(--tint);
  border-top-color: transparent;
}

.btn--danger.is-busy::after {
  border-color: var(--danger);
  border-top-color: transparent;
}

/* ---------- Formulaires ----------
   Champs « inset » iOS : fond gris doux, pas de bordure au
   repos, anneau accent au focus. */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  font-weight: 600;
  font-size: 0.92rem;
}

.field .hint {
  font-size: 0.82rem;
  color: var(--muted);
}

input[type="text"],
input[type="tel"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="number"],
select,
textarea {
  min-height: 46px;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  letter-spacing: inherit;
  background: var(--surface-2);
  color: var(--ink);
  width: 100%;
  transition:
    border-color 0.2s var(--ease),
    box-shadow 0.2s var(--ease),
    background 0.2s var(--ease);
}

textarea {
  resize: vertical;
  min-height: 76px;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: var(--focus-ring);
}

input[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.form-row .field {
  flex: 1;
  min-width: 160px;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

.badge--success {
  background: var(--success-bg);
  color: var(--success);
}

.badge--danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge--info {
  background: var(--info-bg);
  color: var(--info);
}

.badge--warn {
  background: var(--warn-bg);
  color: var(--warn);
}

/* ---------- Bannière d'information ---------- */
.banner {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-size: 0.95rem;
  border: none;
}

/* Les bandeaux sont posés directement sur le fond de page (animé) :
   leur teinte translucide est composée sur une base opaque, sinon le
   dégradé transparaîtrait sous le texte. */
.banner--warn {
  background-color: var(--surface);
  background-image: linear-gradient(var(--warn-bg), var(--warn-bg));
  color: var(--warn);
}

.banner--error {
  background-color: var(--surface);
  background-image: linear-gradient(var(--danger-bg), var(--danger-bg));
  color: var(--danger);
}

/* ---------- Toasts — verre dépoli iOS ---------- */
.toast-region {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(400px, calc(100vw - 24px));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--frost);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: var(--shadow-modal);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
  animation: toast-in 0.35s var(--ease);
}

.toast--success {
  color: var(--success);
}

.toast--error {
  color: var(--danger);
}

.toast--info {
  color: var(--info);
}

.toast__close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 2px;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ---------- Modale — feuille iOS ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fade-in 0.25s var(--ease);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-modal);
  width: min(500px, 100%);
  max-height: min(85vh, 720px);
  overflow-y: auto;
  padding: 24px;
  animation: modal-in 0.3s var(--ease);
}

.modal h2 {
  font-size: 1.25rem;
  margin-bottom: 16px;
}

.modal__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  flex-wrap: wrap;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ---------- Chargement global ---------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 70;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--space-12) var(--space-4);
  overflow: hidden;
}

/* Silhouette de la page : mêmes proportions que le contenu réel,
   donc aucun saut visuel au moment du remplacement. */
.squelette {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

.squelette__logo {
  width: 68px;
  height: 84px;
  border-radius: var(--radius-sm);
}

.squelette__titre {
  width: min(280px, 70%);
  height: 40px;
  border-radius: var(--radius-sm);
}

.squelette__ligne {
  width: min(220px, 60%);
  height: 16px;
}

.squelette__pilule {
  width: 180px;
  height: 38px;
  border-radius: 999px;
}

.squelette__bouton {
  width: 220px;
  height: 54px;
  border-radius: var(--radius-sm);
}

.squelette__carte {
  width: 100%;
  margin-top: var(--space-8);
  padding: var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.squelette__court {
  width: 40%;
}

.squelette__grille {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Skeletons ----------
   Une silhouette du contenu à venir plutôt qu'un spinner : l'attente
   paraît plus courte et la mise en page ne bouge pas à l'arrivée. */

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  animation: skeleton-balaye 1.4s infinite;
}

@keyframes skeleton-balaye {
  to {
    transform: translateX(100%);
  }
}

.skeleton--ligne {
  height: 14px;
  margin-bottom: var(--space-2);
}

.skeleton--tuile {
  height: 44px;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton::after {
    animation: none;
  }
}

/* ---------- État vide ---------- */
.empty-state {
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: none;
}

/* ---------- Tableaux ---------- */
.table-wrap {
  overflow-x: auto;
}

table.data {
  width: 100%;
  border-collapse: collapse;
}

table.data th,
table.data td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

table.data th {
  background: var(--surface-2);
  font-weight: 700;
  font-size: 0.9rem;
}
