/* ==========================================================================
   components.css — Composants réutilisables
   Boutons, cartes, formulaires, badges, nav, modale, tableaux, alertes…
   ========================================================================== */

/* --------------------------------------------------------------------------
   Boutons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-base);
  font-weight: 500;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--lime);
  color: var(--encre);
}

.btn-primary:hover:not(:disabled) {
  background: #c7d22c;
}

.btn-secondary {
  background: var(--teal);
  color: var(--blanc);
}

.btn-secondary:hover:not(:disabled) {
  background: #185270;
}

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

.btn-danger:hover:not(:disabled) {
  background: #a5311f;
}

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--encre);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--teal);
  color: var(--teal);
}

.btn-sm {
  padding: var(--space-xs) var(--space-md);
  font-size: var(--font-size-sm);
}

.btn-block {
  width: 100%;
}

/* --------------------------------------------------------------------------
   Icônes (Lucide, SVG inline)
   -------------------------------------------------------------------------- */
.icon {
  display: inline-block;
  vertical-align: -0.15em;
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Actions de ligne (tableau produits)
   -------------------------------------------------------------------------- */
.row-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: var(--font-size-lg);
  line-height: 1;
}

.btn-icon:hover {
  background: rgba(192, 57, 43, 0.1);
}

/* --------------------------------------------------------------------------
   Cartes
   -------------------------------------------------------------------------- */
.card {
  background: var(--blanc);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-md);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-sm);
}

/* --------------------------------------------------------------------------
   Badges
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 2px var(--space-sm);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-weight: 500;
  background: var(--bg-light);
  color: var(--encre);
  border: 1px solid var(--border);
}

/* --------------------------------------------------------------------------
   Formulaires
   -------------------------------------------------------------------------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
}

label {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--encre);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--blanc);
  color: var(--encre);
  font-size: var(--font-size-base);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(31, 100, 129, 0.15);
}

.textarea {
  resize: vertical;
  min-height: 80px;
}

/* --------------------------------------------------------------------------
   Navigation
   -------------------------------------------------------------------------- */
.nav {
  background: var(--teal);
  color: var(--blanc);
  box-shadow: var(--shadow-sm);
}

.nav-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin-inline: auto;
  padding: var(--space-sm) var(--space-md);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-weight: 700;
  color: var(--blanc);
}

.nav-brand img {
  height: 32px;
  width: auto;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  color: var(--blanc);
  font-weight: 500;
  opacity: 0.85;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.nav-item:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

.nav-item.active {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
  box-shadow: inset 0 -2px 0 var(--lime);
}

.nav-toggle {
  display: none;
  color: var(--blanc);
  font-size: var(--font-size-lg);
  padding: var(--space-xs);
}

@media (max-width: 768px) {
  .nav-toggle {
    display: block;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    background: var(--teal);
    padding: var(--space-sm);
    box-shadow: var(--shadow-md);
  }

  .nav-links.open {
    display: flex;
  }

  .nav-container {
    position: relative;
  }
}

/* --------------------------------------------------------------------------
   Compteur du panier (badge dans la nav)
   -------------------------------------------------------------------------- */
.cart-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 var(--space-xs);
  border-radius: 999px;
  background: var(--lime);
  color: var(--encre);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

/* --------------------------------------------------------------------------
   Modale
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 34, 40, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  z-index: 1000;
}

.modal {
  background: var(--blanc);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

/* --------------------------------------------------------------------------
   Tableaux
   -------------------------------------------------------------------------- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--blanc);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table th,
.table td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  background: var(--bg-light);
  font-weight: 700;
  font-size: var(--font-size-sm);
  color: var(--encre);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.table tbody tr:nth-child(even) {
  background: var(--bg-light);
}

.table tbody tr:hover {
  background: rgba(31, 100, 129, 0.06);
}

/* Transforme le tableau en cartes empilées sous 640px */
@media (max-width: 640px) {
  .table-responsive thead {
    display: none;
  }

  .table-responsive,
  .table-responsive tbody,
  .table-responsive tr,
  .table-responsive td {
    display: block;
    width: 100%;
  }

  .table-responsive tr {
    margin-bottom: var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
  }

  .table-responsive td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    text-align: right;
  }

  .table-responsive td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--muted);
    text-align: left;
  }
}

/* --------------------------------------------------------------------------
   Barre de stock (jauge de niveau)
   -------------------------------------------------------------------------- */
.stock-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.stock-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.2s ease;
}

.stock-bar-fill.stock-high {
  background: var(--success);
}

.stock-bar-fill.stock-medium {
  background: var(--warning);
}

.stock-bar-fill.stock-low {
  background: var(--danger);
}

.stock-bar-fill.stock-empty {
  background: var(--muted);
}

/* --------------------------------------------------------------------------
   Alertes
   -------------------------------------------------------------------------- */
.alert {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: var(--font-size-sm);
}

.alert-warning {
  background: rgba(230, 168, 23, 0.12);
  border-color: var(--warning);
  color: #8a5e0d;
}

.alert-danger {
  background: rgba(192, 57, 43, 0.1);
  border-color: var(--danger);
  color: var(--danger);
}

.alert[hidden] {
  display: none;
}

/* --------------------------------------------------------------------------
   Filtres par catégorie (pills)
   -------------------------------------------------------------------------- */
.pill-filter {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-md);
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--blanc);
  color: var(--encre);
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.pill-filter:hover {
  border-color: var(--teal);
}

.pill-filter.active {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--blanc);
}

/* --------------------------------------------------------------------------
   Barre flottante (retrait.html)
   -------------------------------------------------------------------------- */
.floating-bar {
  position: fixed;
  bottom: var(--space-md);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  background: var(--encre);
  color: var(--blanc);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  z-index: 100;
}

/* --------------------------------------------------------------------------
   État vide
   -------------------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-2xl) var(--space-md);
  color: var(--muted);
  text-align: center;
}

.empty-state h3 {
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Filtres (conteneur des pills)
   -------------------------------------------------------------------------- */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

/* --------------------------------------------------------------------------
   Bandeau de compteurs (stats)
   -------------------------------------------------------------------------- */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-md);
}

.stat-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-sm);
}

.stat-icon {
  font-size: var(--font-size-xl);
}

.stat-value {
  font-size: var(--font-size-lg);
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  font-size: var(--font-size-sm);
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Grille de cartes produit
   -------------------------------------------------------------------------- */
.product-grid {
  display: grid;
  gap: var(--space-md);
  grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 900px) {
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .product-grid {
    grid-template-columns: 1fr;
  }
}

.product-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.product-card-name {
  font-weight: 700;
}

.product-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.product-card-category {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--font-size-sm);
  color: var(--muted);
}

.product-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-light);
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-image-sm {
  width: 50%;
  margin-inline: auto;
}

.product-thumb {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

/* --------------------------------------------------------------------------
   Édition inline de la quantité (produits.html)
   -------------------------------------------------------------------------- */
.qty-inline {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.qty-inline .input {
  width: 70px;
}

.qty-display {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: none;
  border: none;
  cursor: pointer;
  min-width: 120px;
}

.qty-display .stock-bar {
  width: 60px;
}

.product-image-placeholder {
  font-size: 40px;
}

/* --------------------------------------------------------------------------
   Sélecteur de quantité
   -------------------------------------------------------------------------- */
.qty-selector {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.qty-selector button {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--blanc);
  font-weight: 700;
  font-size: var(--font-size-lg);
  line-height: 1;
}

.qty-selector button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.qty-value {
  min-width: 20px;
  text-align: center;
  font-weight: 700;
}

/* --------------------------------------------------------------------------
   Barre de recherche
   -------------------------------------------------------------------------- */
.search-bar {
  max-width: 360px;
}

/* --------------------------------------------------------------------------
   Panier
   -------------------------------------------------------------------------- */
.cart-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.cart-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.cart-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.cart-item-name {
  font-weight: 500;
  flex: 1 1 160px;
}

.cart-item-subtotal {
  min-width: 80px;
  text-align: right;
  font-weight: 700;
}

.cart-total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: var(--font-size-lg);
  padding-top: var(--space-md);
  margin-top: var(--space-md);
  border-top: 1px solid var(--border);
}

/* --------------------------------------------------------------------------
   Page de connexion
   -------------------------------------------------------------------------- */
.login-page {
  min-height: 100vh;
  background: var(--teal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}

.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  text-align: center;
}

.login-logo {
  width: 72px;
  height: auto;
  margin-inline: auto;
}

.login-card form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   Classes utilitaires
   -------------------------------------------------------------------------- */
.text-center {
  text-align: center;
}

.text-muted {
  color: var(--muted);
}

.text-sm {
  font-size: var(--font-size-sm);
}

.text-lg {
  font-size: var(--font-size-lg);
}

.font-bold {
  font-weight: 700;
}

.font-medium {
  font-weight: 500;
}

.mt-xs { margin-top: var(--space-xs); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }

.mb-xs { margin-bottom: var(--space-xs); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }
