/* =============================================
   CSS COMMUN
   ============================================= */
:root {
  --bg: #fff;
  --fg: #111;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --ok: #059669;
  --warn: #b45309;
  --err: #b91c1c;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 16px;
  line-height: 1.5;
}

/* =============================================
   PAGE DE CONNEXION
   ============================================= */
.login-page {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  background: #f5f7fa !important;
}

.login-page > div {
  width: 100%;
  max-width: 500px;
  text-align: center;
}

.login-page .card {
  padding: 40px 30px;
  border-radius: 16px;
  background: white;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  border: 1px solid #e5e7eb;
}

.login-page .card h2 {
  font-size: 2rem;
  margin-bottom: 24px;
  color: #1a1a1a;
  font-weight: 700;
}

.login-page .error {
  font-size: 1.1rem;
  color: var(--err);
  margin-bottom: 20px;
  padding: 12px;
  background: #fef2f2;
  border-radius: 10px;
  border: 1px solid #fecaca;
  text-align: left;
}

.login-page label {
  display: block;
  text-align: left;
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: #1a1a1a;
}

.login-page input[type="password"] {
  width: 100%;
  padding: 16px;
  font-size: 1.3rem;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  margin-bottom: 24px;
  transition: border 0.2s;
  font-family: inherit;
}

.login-page input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.login-page button[type="submit"] {
  width: 100%;
  padding: 16px 24px;
  font-size: 1.2rem;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: white;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  margin-top: 10px;
}

.login-page button[type="submit"]:hover {
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}

.login-page button[type="submit"]:active {
  transform: scale(0.98);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* =============================================
   PAGE PRINCIPALE
   ============================================= */
header {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

header h1 {
  margin: 0;
  font-size: 1.25rem;
}

nav a {
  text-decoration: none;
  color: var(--accent);
  margin-right: 12px;
}

.container {
  padding: 16px;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
}

label {
  display: block;
  margin: 8px 0 4px;
  color: var(--fg);
  font-weight: 500;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-family: inherit;
  font-size: 1rem;
}

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

/* FORMULAIRE "AJOUTER UN PRODUIT" */
.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.form-inline label {
  display: flex;
  flex-direction: column;
  min-width: 150px;
  margin: 0;
  gap: 6px;
}

.form-inline label span {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
}

.form-inline input[type="text"],
.form-inline input[type="number"],
.form-inline select,
.form-inline textarea {
  width: 100%;
  min-width: 120px;
  max-width: 250px;
  padding: 10px;
  font-size: 1rem;
}

.form-inline textarea {
  min-height: 50px;
  max-width: 300px;
}

.form-inline button {
  margin-bottom: 0;
  align-self: flex-end;
  min-width: 120px;
}

/* FILTRES */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  align-items: center;
}

.filter-buttons {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.filters select {
  min-width: 150px;
}

/* TABLEAU */
.table-container {
  overflow-x: auto;
  margin-top: 16px;
}

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

.table th,
.table td {
  padding: 10px 8px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--line);
}

.table th {
  background: #f9fafb;
  font-weight: 600;
}

.table tr:last-child td {
  border-bottom: none;
}

.col-fournisseur { min-width: 100px; }
.col-produit { min-width: 150px; }
.col-photo { min-width: 220px; }
.col-categorie { min-width: 120px; }
.col-conditionnement { min-width: 100px; }
.col-stock { min-width: 80px; }
.col-a-commander { min-width: 80px; }

/* IMAGES */
.photo-cell > div:first-child {
  display: flex !important;
  flex-wrap: nowrap !important;
  gap: 16px !important;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
}

.thumb {
  width: 90px !important;
  height: 90px !important;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  margin-bottom: 5px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.2s, box-shadow 0.2s;
}

.thumb:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.table textarea.inline-edit {
  min-height: 120px !important;
  height: auto !important;
  resize: vertical;
  font-size: 1rem;
}

.photo-cell > div:first-child > div {
  display: inline-block;
  vertical-align: top;
  margin: 0;
  flex: 0 0 auto;
}

/* POPUP POUR LES PHOTOS */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  justify-content: center;
  align-items: center;
}

.modal-content {
  max-width: 90%;
  max-height: 90%;
  display: block;
  margin: auto;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.close-btn {
  position: absolute;
  top: 20px;
  right: 30px;
  color: white;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.5);
  width: 45px;
  height: 45px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background 0.2s;
}

.close-btn:hover {
  background: rgba(255, 0, 0, 0.7);
}

/* AUTRES STYLES */
.inline-edit {
  width: 100%;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  transition: border 0.2s;
}

.inline-edit:focus {
  background: #fff;
  border-color: var(--line);
  outline: none;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.photo-upload-btn {
  padding: 6px 10px;
  font-size: 0.875rem;
  background: #f3f4f6;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  display: inline-block;
  margin: 4px 0;
}

.photo-upload-btn:hover {
  background: #e5e7eb;
}

.file-input-hidden {
  display: none;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.actions button {
  margin: 0;
  padding: 8px 10px;
  width: 100%;
  border-radius: 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.875rem;
}

.actions button:last-child {
  border-bottom: none;
}

.notice {
  color: var(--ok);
  padding: 10px;
  background: #d1fae5;
  border-radius: 8px;
  margin-bottom: 16px;
}

.error {
  color: var(--err);
  padding: 10px;
  background: #fee2e2;
  border-radius: 8px;
  margin-bottom: 16px;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  border: 1px solid var(--line);
  color: var(--muted);
}

/* BOUTONS NEUMORPHISME */
button,
.btn,
input[type="button"],
input[type="submit"],
input[type="reset"] {
  border: none !important;
  border-radius: 12px !important;
  padding: 10px 16px !important;
  font-weight: 600 !important;
  color: white !important;
  cursor: pointer !important;
  transition: all 0.2s !important;
  box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2),
              -5px -5px 10px rgba(255, 255, 255, 0.5) !important;
  display: inline-block !important;
  text-decoration: none !important;
  font: inherit !important;
  text-align: center;
}

button:active,
.btn:active,
input[type="button"]:active,
input[type="submit"]:active,
input[type="reset"]:active {
  box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.2),
              inset -2px -2px 5px rgba(255, 255, 255, 0.5) !important;
}

.actions button,
button.small,
button[style*="padding:2px 6px"] {
  padding: 6px 8px !important;
  font-size: 0.8125rem !important;
  border-radius: 8px !important;
}

button[type="submit"]:not(.btn-outline):not(.actions > button),
.form-inline button[type="submit"] {
  background: linear-gradient(145deg, #4a90e2, #357abd) !important;
}

.btn-outline {
  background: linear-gradient(145deg, #95a5a6, #7f8c8d) !important;
  color: white !important;
}

.actions button[type="submit"] {
  background: linear-gradient(145deg, #2ecc71, #27ae60) !important;
}

button[onclick*="add_to_cart"] {
  background: linear-gradient(145deg, #3498db, #2980b9) !important;
}

button[onclick*="delete_product"],
button[onclick*="delete_photo"],
button[onclick*="delete_photo2"] {
  background: linear-gradient(145deg, #e74c3c, #c0392b) !important;
}

/* RESPONSIVE */
@media (max-width: 1024px) {
  .form-inline {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .form-inline label {
    width: 100%;
    min-width: auto;
  }

  .form-inline input[type="text"],
  .form-inline input[type="number"],
  .form-inline select,
  .form-inline textarea {
    max-width: 100%;
  }

  .form-inline button {
    width: 100%;
    align-self: center;
  }

  .filter-buttons {
    width: 100%;
    margin-left: 0;
  }

  .filter-buttons .btn {
    flex: 1;
  }

  .col-photo {
    min-width: 220px !important;
  }

  .login-page .card {
    padding: 30px 20px;
  }

  .login-page .card h2 {
    font-size: 1.75rem;
  }

  .login-page label {
    font-size: 1.1rem;
  }

  .login-page input[type="password"] {
    font-size: 1.2rem;
    padding: 14px;
  }

  .login-page button[type="submit"] {
    font-size: 1.1rem;
    padding: 14px 20px;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 12px;
  }

  header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .filters {
    flex-direction: column;
    gap: 10px;
  }

  .filters select {
    width: 100%;
  }

  .table textarea.inline-edit {
    min-height: 160px !important;
  }

  .col-photo {
    min-width: 200px !important;
  }

  .photo-cell > div:first-child {
    gap: 8px !important;
  }

  .thumb {
    width: 80px !important;
    height: 80px !important;
  }
}