:root {
  /* Couleurs principales */
  --primary-green: #4caf50;
  --primary-green-dark: #2e7d32;
  --primary-green-light: #81c784;

  /* Couleurs des légumes */
  --carrot-orange: #ff6b35;
  --eggplant-purple: #8e24aa;
  --corn-yellow: #ffc107;
  --tomato-red: #f44336;

  /* Couleurs neutres */
  --black: #1b1b1b;
  --white: #ffffff;
  --gray-light: #f5f5f5;
  --gray-medium: #e0e0e0;

  /* Variations pour l'interface */
  --background: #f8f9fa;
  --text-primary: #1b1b1b;
  --text-secondary: #666666;
  --border: #e0e0e0;

  /* États interactifs */
  --hover-green: #45a049;
  --focus-green: #388e3c;
}

/* Reset et base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(
    135deg,
    var(--primary-green-dark) 0%,
    var(--primary-green) 100%
  );
  min-height: 100vh;
  padding: 20px;
  color: var(--text-primary);
}

/* Header admin */
h1 {
  text-align: center;
  color: var(--white);
  font-size: 2.5rem;
  margin-bottom: 30px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  padding: 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 15px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: slideInDown 0.8s ease-out;
}

/* Sections */
section {
  background: var(--white);
  border-radius: 15px;
  padding: 30px;
  margin-bottom: 30px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
  animation: fadeInUp 0.8s ease-out;
  border-top: 4px solid var(--primary-green);
  position: relative;
  overflow: hidden;
}

section::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(
    90deg,
    var(--primary-green),
    var(--corn-yellow),
    var(--carrot-orange)
  );
}

section h2 {
  color: var(--primary-green-dark);
  font-size: 1.8rem;
  margin-bottom: 25px;
  padding-bottom: 15px;
  border-bottom: 2px solid var(--gray-light);
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

section h3 {
  color: var(--primary-green-dark);
  font-size: 1.3rem;
  margin: 25px 0 15px 0;
  padding: 10px 15px;
  background: linear-gradient(135deg, var(--gray-light), var(--gray-medium));
  border-radius: 8px;
  border-left: 4px solid var(--primary-green);
}

/* Formulaire admin */
#form-stock {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  align-items: end;
  background: linear-gradient(135deg, var(--background), var(--gray-light));
  padding: 25px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 30px;
}

/* Inputs admin */
input {
  padding: 15px 18px;
  border: 2px solid var(--gray-medium);
  border-radius: 10px;
  font-size: 1rem;
  transition: all 0.3s ease;
  background: var(--white);
  font-weight: 500;
  width: 100%;
}

input:focus {
  outline: none;
  border-color: var(--primary-green);
  box-shadow: 0 0 0 4px rgba(76, 175, 80, 0.1);
  transform: translateY(-2px);
}

input::placeholder {
  color: var(--text-secondary);
  font-weight: 400;
}

/* Boutons admin */
button {
  background: linear-gradient(
    135deg,
    var(--primary-green),
    var(--primary-green-dark)
  );
  color: var(--white);
  border: none;
  padding: 15px 25px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
  position: relative;
  overflow: hidden;
  min-height: 48px;
  touch-action: manipulation;
}

button::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s;
}

button:hover::before {
  left: 100%;
}

button:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 25px rgba(76, 175, 80, 0.4);
  background: linear-gradient(135deg, var(--hover-green), var(--focus-green));
}

button:active {
  transform: translateY(-1px);
}

/* Bouton supprimer */
.btn-supprimer {
  background: linear-gradient(135deg, var(--carrot-orange), var(--tomato-red));
  padding: 8px 15px;
  font-size: 0.9rem;
  border-radius: 6px;
  min-height: 40px;
}

.btn-supprimer:hover {
  background: linear-gradient(135deg, var(--tomato-red), #c62828);
  box-shadow: 0 6px 15px rgba(255, 107, 53, 0.4);
}

/* Container pour tables responsives */
.table-container {
  overflow-x: auto;
  margin: 20px 0;
  border-radius: 12px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

/* Tables admin */
table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 12px;
  overflow: hidden;
  background: var(--white);
  margin-top: 20px;
  min-width: 600px;
}

thead {
  background: linear-gradient(
    135deg,
    var(--primary-green-dark),
    var(--primary-green)
  );
  color: var(--white);
  position: relative;
}

thead::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary-green), var(--corn-yellow));
}

th {
  padding: 18px 15px;
  text-align: left;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.9rem;
  position: relative;
}

td {
  padding: 16px 15px;
  border-bottom: 1px solid var(--gray-light);
  font-weight: 500;
  transition: all 0.3s ease;
}

tbody tr {
  transition: all 0.3s ease;
  position: relative;
}

tbody tr:nth-child(even) {
  background: rgba(76, 175, 80, 0.03);
}

tbody tr:hover {
  background: rgba(76, 175, 80, 0.08);
  transform: scale(1.01);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

tbody tr:hover td {
  color: var(--primary-green-dark);
  font-weight: 600;
}

/* Table de préparation */
#table-preparation {
  border-top: 4px solid var(--corn-yellow);
}

#table-preparation thead {
  background: linear-gradient(135deg, var(--corn-yellow), var(--carrot-orange));
}

#table-preparation tbody tr:hover {
  background: rgba(255, 193, 7, 0.08);
}

/* Mise en évidence des actions */
td:last-child {
  text-align: center;
  font-weight: 600;
}

/* Animations */
@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-50px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(40px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* États vides */
tbody:empty::after {
  content: "Aucune donnée disponible";
  display: block;
  text-align: center;
  padding: 30px;
  color: var(--text-secondary);
  font-style: italic;
  font-size: 1.1rem;
  background: linear-gradient(135deg, var(--background), var(--gray-light));
  border-radius: 8px;
  margin: 10px;
}

/* Loading states */
.loading {
  opacity: 0.6;
  pointer-events: none;
  position: relative;
}

.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border: 3px solid var(--gray-light);
  border-top: 3px solid var(--primary-green);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Messages admin */
#admin-message {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 15px 20px;
  border-radius: 8px;
  font-weight: 600;
  z-index: 1000;
  max-width: 400px;
  opacity: 0;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* ========================================
   RESPONSIVE DESIGN ADMIN OPTIMISÉ
   ======================================== */

/* TABLET LANDSCAPE - 1024px et moins */
@media (max-width: 1024px) {
  body {
    padding: 18px;
  }

  h1 {
    font-size: 2.3rem;
    padding: 18px;
  }

  section {
    padding: 25px;
  }

  #form-stock {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 18px;
    padding: 22px;
  }
}

/* TABLET PORTRAIT - 768px et moins */
@media (max-width: 768px) {
  body {
    padding: 15px;
  }

  h1 {
    font-size: 2rem;
    padding: 15px;
    margin-bottom: 25px;
  }

  section {
    padding: 20px;
    margin-bottom: 25px;
  }

  section h2 {
    font-size: 1.6rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  section h3 {
    font-size: 1.2rem;
    padding: 8px 12px;
  }

  /* Formulaire responsive */
  #form-stock {
    grid-template-columns: 1fr;
    gap: 15px;
    padding: 20px;
  }

  input {
    padding: 14px 16px;
    font-size: 16px; /* Évite le zoom sur iOS */
  }

  button {
    padding: 14px 20px;
    font-size: 0.95rem;
    min-height: 48px;
  }

  /* Tables wrapper pour scroll horizontal */
  .table-container {
    margin: 15px -15px;
    border-radius: 0;
  }

  table {
    font-size: 0.85rem;
    min-width: 700px;
  }

  th,
  td {
    padding: 12px 8px;
  }

  th {
    font-size: 0.8rem;
  }

  .btn-supprimer {
    padding: 6px 10px;
    font-size: 0.8rem;
    min-height: 36px;
  }

  /* Messages responsives */
  #admin-message {
    top: 15px;
    right: 15px;
    left: 15px;
    max-width: none;
    padding: 12px 15px;
    font-size: 0.9rem;
  }
}

/* MOBILE LARGE - 480px et moins */
@media (max-width: 480px) {
  body {
    padding: 12px;
  }

  h1 {
    font-size: 1.6rem;
    padding: 12px;
    margin-bottom: 20px;
  }

  section {
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 12px;
  }

  section h2 {
    font-size: 1.4rem;
    margin-bottom: 20px;
  }

  section h3 {
    font-size: 1.1rem;
    margin: 20px 0 12px 0;
    padding: 8px 10px;
  }

  /* Formulaire très compact */
  #form-stock {
    padding: 15px;
    gap: 12px;
  }

  input {
    padding: 12px 15px;
    font-size: 16px;
  }

  input::placeholder {
    font-size: 0.9rem;
  }

  button {
    padding: 12px 18px;
    font-size: 0.9rem;
    letter-spacing: 0.5px;
  }

  /* Tables très compactes */
  .table-container {
    margin: 12px -12px;
  }

  table {
    font-size: 0.8rem;
    min-width: 600px;
  }

  th,
  td {
    padding: 10px 6px;
  }

  th {
    font-size: 0.75rem;
    letter-spacing: 0.5px;
  }

  .btn-supprimer {
    padding: 5px 8px;
    font-size: 0.75rem;
    min-height: 32px;
    border-radius: 4px;
  }

  /* Messages mobiles */
  #admin-message {
    top: 10px;
    right: 10px;
    left: 10px;
    padding: 10px 12px;
    font-size: 0.85rem;
  }
}

/* MOBILE EXTRA SMALL - 360px et moins */
@media (max-width: 360px) {
  body {
    padding: 10px;
  }

  h1 {
    font-size: 1.4rem;
    padding: 10px;
  }

  section {
    padding: 12px;
  }

  section h2 {
    font-size: 1.3rem;
  }

  #form-stock {
    padding: 12px;
    gap: 10px;
  }

  input {
    padding: 10px 12px;
  }

  button {
    padding: 10px 15px;
    font-size: 0.85rem;
  }

  table {
    min-width: 500px;
    font-size: 0.75rem;
  }

  th,
  td {
    padding: 8px 4px;
  }

  .btn-supprimer {
    padding: 4px 6px;
    font-size: 0.7rem;
    min-height: 28px;
  }
}

/* AMÉLIORATIONS TACTILES POUR MOBILE */
@media (max-width: 768px) {
  /* Désactiver les hovers sur tactile */
  @media (hover: none) {
    button:hover {
      transform: none;
      box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
    }

    .btn-supprimer:hover {
      transform: none;
      box-shadow: 0 3px 10px rgba(255, 107, 53, 0.3);
    }

    tbody tr:hover {
      transform: none;
      background: rgba(76, 175, 80, 0.05);
      box-shadow: none;
    }

    tbody tr:hover td {
      color: var(--text-primary);
      font-weight: 500;
    }

    input:focus {
      transform: none;
    }
  }

  /* Scroll plus fluide sur mobile */
  .table-container {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .table-container::-webkit-scrollbar {
    height: 6px;
  }

  .table-container::-webkit-scrollbar-track {
    background: var(--gray-light);
    border-radius: 3px;
  }

  .table-container::-webkit-scrollbar-thumb {
    background: var(--primary-green);
    border-radius: 3px;
  }
}

/* ORIENTATION LANDSCAPE SUR MOBILE */
@media (max-width: 768px) and (orientation: landscape) {
  h1 {
    font-size: 1.8rem;
    padding: 12px;
    margin-bottom: 20px;
  }

  section {
    padding: 18px;
  }

  #form-stock {
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
  }

  table {
    min-width: 800px;
  }
}

/* PRINT STYLES POUR ADMIN */
@media print {
  body {
    background: white !important;
    color: black !important;
    padding: 0;
  }

  h1 {
    background: none !important;
    color: black !important;
    text-shadow: none !important;
    border: 1px solid #ccc;
  }

  section {
    page-break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
    background: white !important;
  }

  section::before {
    display: none;
  }

  #form-stock,
  button,
  .btn-supprimer {
    display: none !important;
  }

  table {
    box-shadow: none;
    border: 1px solid #ccc;
  }

  thead {
    background: #f0f0f0 !important;
    color: black !important;
  }

  thead::after {
    display: none;
  }

  #admin-message {
    display: none !important;
  }
}

/* PRÉFÉRENCES D'ACCESSIBILITÉ */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  button:hover,
  input:focus,
  tbody tr:hover {
    transform: none !important;
  }

  button::before {
    display: none;
  }
}

/* DARK MODE POUR ADMIN */
@media (prefers-color-scheme: dark) {
  :root {
    --background: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --white: #2d2d2d;
    --gray-light: #3a3a3a;
    --gray-medium: #4a4a4a;
    --border: #555555;
  }

  body {
    background: linear-gradient(135deg, #0d1b0f 0%, #1a1a1a 100%);
  }

  section {
    background: var(--white);
    color: var(--text-primary);
  }

  input {
    background: var(--gray-light);
    color: var(--text-primary);
    border-color: var(--gray-medium);
  }

  input::placeholder {
    color: #999999;
  }

  table {
    background: var(--white);
  }

  tbody tr:nth-child(even) {
    background: rgba(76, 175, 80, 0.1);
  }

  tbody:empty::after {
    background: var(--gray-light);
    color: var(--text-secondary);
  }
}
