/* ==========================================================================
   AFRISANTE — Composants UI
   ========================================================================== */

/* ==========================================================================
   BOUTONS
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  font-weight: 600;
  font-size: var(--text-base);
  border-radius: var(--radius-md);
  transition: all var(--transition);
  cursor: pointer;
  border: 2px solid transparent;
  white-space: nowrap;
  user-select: none;
  position: relative;
  overflow: hidden;
}

.btn:active { transform: translateY(1px); }

.btn-sm { padding: var(--space-2) var(--space-4); font-size: var(--text-sm); }
.btn-lg { padding: var(--space-4) var(--space-8); font-size: var(--text-lg); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: var(--white);
  box-shadow: var(--shadow-md);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-primary);
  color: white;
}

.btn-secondary {
  background: linear-gradient(135deg, var(--secondary), var(--secondary-dark));
  color: var(--white);
  box-shadow: var(--shadow-md);
}
.btn-secondary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-secondary);
  color: white;
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline:hover {
  background: var(--primary);
  color: white;
}

.btn-ghost {
  background: var(--gray-100);
  color: var(--gray-700);
}
.btn-ghost:hover { background: var(--gray-200); }

.btn-danger {
  background: var(--danger);
  color: var(--white);
}
.btn-danger:hover { background: #DC2626; color: white; }

.btn-block { width: 100%; }

.btn-icon {
  padding: var(--space-3);
  aspect-ratio: 1;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

/* Effet ripple */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.3), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}
.btn:active::after { opacity: 1; }

/* ==========================================================================
   CARDS
   ========================================================================== */

.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: all var(--transition);
  border: 1px solid var(--gray-200);
}

.card-hover:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-xl);
  border-color: var(--primary-100);
}

.card-body { padding: var(--space-6); }
.card-header {
  padding: var(--space-6);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-footer {
  padding: var(--space-4) var(--space-6);
  background: var(--gray-50);
  border-top: 1px solid var(--gray-200);
}

.card-title {
  font-size: var(--text-xl);
  margin-bottom: var(--space-2);
}

.card-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-4);
  background: var(--primary-50);
  color: var(--primary);
  font-size: 28px;
}
.card-icon.icon-secondary { background: var(--secondary-50); color: var(--secondary); }
.card-icon.icon-accent { background: #FEF3C7; color: var(--accent); }
.card-icon.icon-danger { background: #FEE2E2; color: var(--danger); }

/* ==========================================================================
   FORMS
   ========================================================================== */

.form-group {
  margin-bottom: var(--space-5);
}

.form-label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: 500;
  font-size: var(--text-sm);
  color: var(--gray-700);
}
.form-label.required::after {
  content: ' *';
  color: var(--danger);
}

.form-control {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  color: var(--gray-900);
  background: var(--white);
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  font-family: inherit;
}

.form-control:hover { border-color: var(--gray-300); }
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10, 110, 189, 0.1);
}
.form-control.is-invalid {
  border-color: var(--danger);
}
.form-control.is-invalid:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-error {
  margin-top: var(--space-1);
  font-size: var(--text-sm);
  color: var(--danger);
}

.form-help {
  margin-top: var(--space-1);
  font-size: var(--text-sm);
  color: var(--gray-500);
}

textarea.form-control {
  min-height: 100px;
  resize: vertical;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236B7280' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.5rem;
}

.form-check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
  margin-top: 2px;
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group .form-control {
  padding-left: 3rem;
}

.input-group-icon {
  position: absolute;
  left: 1rem;
  color: var(--gray-400);
  pointer-events: none;
}

/* ==========================================================================
   BADGES
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  line-height: 1.5;
}

.badge-primary { background: var(--primary-50); color: var(--primary-dark); }
.badge-secondary { background: var(--secondary-50); color: var(--secondary-dark); }
.badge-success { background: #D1FAE5; color: #065F46; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-danger { background: #FEE2E2; color: #991B1B; }
.badge-gray { background: var(--gray-100); color: var(--gray-700); }

/* Badges urgence */
.badge-urgency {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 700;
  border-radius: var(--radius-full);
  color: white;
}
.badge-urgency-1 { background: var(--urgency-1); }
.badge-urgency-2 { background: var(--urgency-2); }
.badge-urgency-3 { background: var(--urgency-3); }
.badge-urgency-4 { background: var(--urgency-4); }
.badge-urgency-5 { background: var(--urgency-5); animation: pulse-danger 1.5s infinite; }

/* ==========================================================================
   ALERTES
   ========================================================================== */

.alert {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  border-left: 4px solid;
  animation: slideInDown 400ms ease;
}

.alert-success { background: #ECFDF5; color: #065F46; border-color: var(--success); }
.alert-warning { background: #FFFBEB; color: #92400E; border-color: var(--warning); }
.alert-danger { background: #FEF2F2; color: #991B1B; border-color: var(--danger); }
.alert-info { background: #EFF6FF; color: #1E40AF; border-color: var(--info); }

.alert-icon { flex-shrink: 0; font-size: 24px; margin-top: 2px; }

/* ==========================================================================
   AVATARS
   ========================================================================== */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: var(--white);
  font-weight: 600;
  font-size: var(--text-sm);
  overflow: hidden;
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 32px; height: 32px; font-size: var(--text-xs); }
.avatar-lg { width: 64px; height: 64px; font-size: var(--text-xl); }
.avatar-xl { width: 96px; height: 96px; font-size: var(--text-3xl); }

/* ==========================================================================
   NAVIGATION
   ========================================================================== */

.navbar {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  transition: all var(--transition);
}

.navbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  height: 72px;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--text-xl);
  color: var(--gray-900);
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.navbar-brand:hover { color: var(--primary); }
@media (max-width: 480px) {
  .navbar-brand { font-size: var(--text-base); gap: var(--space-2); }
  .navbar-logo { width: 36px; height: 36px; font-size: var(--text-base); }
}

.navbar-logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: var(--text-lg);
  box-shadow: var(--shadow-primary);
  overflow: hidden;
}

.navbar-menu {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  list-style: none;
}

@media (max-width: 900px) {
  .navbar-menu { display: none; }
  .navbar-menu.open {
    display: flex;
    position: fixed;
    top: 72px;
    left: 0;
    right: 0;
    background: white;
    padding: var(--space-6);
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-4);
    box-shadow: var(--shadow-lg);
    border-top: 1px solid var(--gray-200);
    animation: slideInDown 300ms ease;
  }
}

.nav-link {
  color: var(--gray-700);
  font-weight: 500;
  transition: color var(--transition-fast);
  position: relative;
  padding: var(--space-2) 0;
}
.nav-link:hover, .nav-link.active { color: var(--primary); }
.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary);
  border-radius: 2px;
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.menu-toggle {
  display: none;
  padding: var(--space-2);
  color: var(--gray-700);
}
@media (max-width: 900px) {
  .menu-toggle { display: flex; }
}

/* ==========================================================================
   FOOTER
   ========================================================================== */

.footer {
  background: var(--gray-900);
  color: var(--gray-400);
  padding-block: var(--space-16) var(--space-8);
  margin-top: auto;
}

.footer-grid {
  display: grid;
  grid-template-columns: 2fr repeat(3, 1fr);
  gap: var(--space-12);
  margin-bottom: var(--space-12);
}
@media (max-width: 900px) {
  .footer-grid { grid-template-columns: 1fr 1fr; gap: var(--space-8); }
}
@media (max-width: 500px) {
  .footer-grid { grid-template-columns: 1fr; }
}

.footer h4 {
  color: white;
  margin-bottom: var(--space-4);
  font-size: var(--text-base);
}

.footer ul { list-style: none; }
.footer li { margin-bottom: var(--space-2); }
.footer a { color: var(--gray-400); transition: color var(--transition-fast); }
.footer a:hover { color: white; }

.footer-bottom {
  padding-top: var(--space-6);
  border-top: 1px solid var(--gray-800);
  text-align: center;
  font-size: var(--text-sm);
}

/* ==========================================================================
   TABLES
   ========================================================================== */

.table-wrapper {
  overflow-x: auto;
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

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

.table th {
  text-align: left;
  padding: var(--space-4) var(--space-5);
  background: var(--gray-50);
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-200);
}

.table td {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-800);
}

.table tbody tr { transition: background var(--transition-fast); }
.table tbody tr:hover { background: var(--gray-50); }
.table tbody tr:last-child td { border-bottom: none; }

/* ==========================================================================
   STEPPER
   ========================================================================== */

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-bottom: var(--space-8);
}

.step {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--gray-400);
  font-weight: 500;
}

.step-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gray-200);
  color: var(--gray-600);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  transition: all var(--transition);
}

.step.active .step-circle {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  box-shadow: var(--shadow-primary);
}
.step.active { color: var(--gray-900); }

.step.done .step-circle {
  background: var(--secondary);
  color: white;
}

.step-divider {
  flex: 1;
  max-width: 60px;
  height: 2px;
  background: var(--gray-200);
  border-radius: 1px;
}

/* ==========================================================================
   LOADER
   ========================================================================== */

.loader {
  width: 40px;
  height: 40px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.loader-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}

/* ==========================================================================
   TOAST
   ========================================================================== */

.toast-container {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.toast {
  min-width: 300px;
  max-width: 400px;
  padding: var(--space-4);
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  border-left: 4px solid var(--primary);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  animation: slideInRight 300ms ease;
}

.toast-success { border-left-color: var(--success); }
.toast-danger { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }

/* ==========================================================================
   EMPTY STATE
   ========================================================================== */

.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.empty-state-icon {
  width: 96px;
  height: 96px;
  margin: 0 auto var(--space-4);
  background: var(--gray-100);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  font-size: 40px;
}

.empty-state-title {
  font-size: var(--text-xl);
  margin-bottom: var(--space-2);
}

.empty-state-text {
  color: var(--gray-500);
  margin-bottom: var(--space-4);
}

/* ==========================================================================
   MODAL
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.5);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal-backdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  background: white;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2xl);
  z-index: var(--z-modal);
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition);
  overflow: hidden;
}
.modal.open { opacity: 1; transform: translate(-50%, -50%) scale(1); pointer-events: auto; }

/* ==========================================================================
   RESPONSIVE MOBILE — Correctifs globaux
   ========================================================================== */
@media (max-width: 768px) {
  /* Grids inline 2 colonnes forcées → 1 colonne en mobile */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:repeat(2,1fr)"],
  [style*="grid-template-columns: repeat(2, 1fr)"] {
    grid-template-columns: 1fr !important;
  }

  /* Dashboard header : titre + bouton action qui se place en-dessous en mobile */
  .dashboard-header {
    flex-direction: column;
    align-items: stretch !important;
    gap: var(--space-3);
  }
  .dashboard-header > a,
  .dashboard-header > button,
  .dashboard-header > .btn,
  .dashboard-header .action-bar {
    width: 100%;
    justify-content: center;
  }

  /* Cartes avec padding horizontal excessif */
  .card-body { padding: var(--space-4) !important; }

  /* Formulaires : tous les inputs full-width sur mobile */
  .form-control, .form-select { width: 100%; }

  /* Tables qui débordent : scroll horizontal */
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 100%; }

  /* Stepper : réduire la taille sur petit écran */
  .stepper { gap: var(--space-2); font-size: var(--text-sm); }
  .stepper .step-divider { display: none; }

  /* Masquer padding excessif des containers de page */
  main, .page-content, .content-area {
    padding-inline: var(--space-3) !important;
  }
}

/* Très petits écrans < 420px */
@media (max-width: 420px) {
  h1, .dashboard-title { font-size: var(--text-2xl) !important; }
  .card-body { padding: var(--space-3) !important; }
}
