body {
  font-family: 'Cairo', sans-serif;
  background: #f9fafb;
  margin: 0;
  padding: 0;
  color: #111827;
}

header {
  background: #2563eb;
  color: white;
  padding: 15px;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 600;
}

.add-btn {
  background: #2563eb;
  color: white;
  padding: 10px 18px;
  margin: 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  justify-content: center;
  align-items: center;
  padding: 10px;
}

.modal-content {
  background: white;
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: #2563eb;
}

.close {
  cursor: pointer;
  font-size: 1.4rem;
  color: #ef4444;
}

form {
  display: grid;
  gap: 12px;
}

.input-group {
  display: flex;
  align-items: center;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 5px 8px;
}

.input-group i {
  color: #2563eb;
  margin-right: 6px;
  font-size: 0.85rem;
}

.input-group input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.85rem;
  padding: 5px;
}

.submit-btn {
  background: #2563eb;
  color: white;
  border: none;
  padding: 10px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}

.submit-btn:hover {
  background: #1d4ed8;
}

/* Cards Produits */
.produits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 15px;
  padding: 20px;
}

.produit-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: transform 0.2s;
}

.produit-card:hover {
  transform: translateY(-2px);
}

.produit-img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
  background: #f3f4f6;
  flex-shrink: 0;
}

.produit-info {
  flex: 1;
}

.produit-info h4 {
  margin: 0;
  font-size: 0.95rem;
  color: #111827;
}

.produit-meta {
  font-size: 0.8rem;
  color: #374151;
}

.actions {
  margin-top: 5px;
}

.actions button {
  padding: 3px 7px;
  font-size: 0.7rem;
  border-radius: 6px;
  border: none;
  color: white;
  cursor: pointer;
  margin-right: 4px;
}

.edit-btn {
  background: #10b981;
}

.edit-btn:hover {
  background: #059669;
}

.delete-btn {
  background: #ef4444;
}

.delete-btn:hover {
  background: #dc2626;
}

.input-small input {
  width: 60px;
  min-width: 60px;
  max-width: 80px;
  text-align: center;
}

/* Bouton champs avancés */
.toggle-advanced {
  background: #e5e7eb;
  border: none;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
  margin-bottom: 10px;
}

.advanced-fields {
  display: none;
}

/* Form Rows (2 colonnes) */
.form-row {
  display: flex;
  gap: 10px;
}

.form-row .input-group {
  flex: 1;
  min-width: 0;
}

/* QR Reader */
#qr-reader {
  width: 100%;
  max-width: 320px;
  margin: 10px auto;
  border: 2px solid #2563eb;
  border-radius: 8px;
  display: none;
}

#qr-reader__scan_region video {
  border-radius: 6px;
}

.scan-btn {
  background: #10b981;
  color: #fff;
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  margin: 5px auto;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: 0.3s;
}

.scan-btn:hover {
  background: #059669;
  transform: scale(1.05);
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  min-width: 250px;
  position: relative;
}

.search-box input {
  flex: 1;
  border: none;
  outline: none;
  padding: 10px;
  font-size: 14px;
  border-radius: 8px;
}

.search-box input:focus {
  border-color: #2563eb;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
  outline: none;
}

.search-box::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: #888;
}

/* Statistiques Produits */
.search-stats-row {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 15px;
  width: 100%;
  max-width: 1250px;
  margin: 20px auto;
  padding: 0 10px;
  box-sizing: border-box;
  flex-wrap: wrap;
}

.stats-inline {
  display: flex;
  align-items: stretch;
  flex: 3;
  gap: 10px;
  justify-content: space-between;
}

.stat-card {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  border-radius: 10px;
  padding: 10px 15px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
  color: #fff;
  min-width: 140px;
  min-height: 60px;
  transition: transform 0.3s;
}

.stat-card:hover {
  transform: translateY(-4px);
}

.stat-card i {
  font-size: 1.5rem;
}

.stat-card h4 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: bold;
}

.stat-card p {
  margin: 0;
  font-size: 0.8rem;
}

/* DataTables */
body.table-mode {
  margin: 0;
  padding: 0;
  height: 100vh;
  background: #f1f5f9;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.table-mode header {
  position: sticky;
  top: 0;
  z-index: 1000;
  flex-shrink: 0;
}

body.table-mode .search-stats-row {
  flex-shrink: 0;
  padding: 10px;
}

body.table-mode #produitsGrid {
  flex: 1;
  width: 100%;
  overflow: auto;
  margin: 0;
  padding: 0;
  display: block;
}

body.table-mode .dataTables_wrapper {
  width: 100% !important;
  height: 100%;
  margin: 0;
  padding: 0;
  box-shadow: none;
  border-radius: 0;
  background: transparent;
  overflow: auto;
}

body.table-mode .dataTables_length,
body.table-mode .dataTables_filter {
  margin-bottom: 10px;
}

body.table-mode .dataTables_scroll {
  height: calc(100% - 50px); /* Adjust for length/filter/buttons height */
  overflow: auto;
}

body.table-mode .dataTables_scrollBody {
  overflow-x: auto !important;
  overflow-y: auto !important;
  height: 100% !important;
}

body.table-mode table.dataTable {
  width: 100% !important;
  min-width: 1300px;
  border-collapse: collapse;
  font-size: 13.5px;
  text-align: center;
}

body.table-mode .dataTables_scrollHeadInner,
body.table-mode .dataTables_scrollBody table {
  width: 100% !important;
  min-width: 1350px !important;
}

.dataTables_wrapper {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  background: #fff;
  padding: 10px 20px;
}

.dataTables_wrapper .dt-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
  margin-bottom: 10px;
}

.dataTables_wrapper .dataTables_filter {
  float: right !important;
  margin-bottom: 10px;
}

.dataTables_wrapper .dataTables_filter input {
  border-radius: 8px;
  border: 1px solid #ccc;
  padding: 6px 10px;
  font-size: 14px;
  transition: 0.3s;
}

.dataTables_wrapper .dataTables_filter input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 4px rgba(37, 99, 235, 0.3);
  outline: none;
}

.dataTables_wrapper .dataTables_paginate,
.dataTables_wrapper .dataTables_info {
  margin-top: 10px !important;
  font-size: 13px;
}

table.dataTable {
  width: 100% !important;
  min-width: 1350px !important;
  border-collapse: collapse;
  font-size: 13.5px;
  text-align: center;
  background: white;
}

table.dataTable tbody tr:hover {
  background: #f1f5ff !important;
  transition: 0.2s;
}

table.dataTable thead th {
  background: linear-gradient(90deg, #2563eb, #1e40af);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  padding: 10px;
}

table.dataTable tbody td {
  padding: 8px 6px;
  border-bottom: 1px solid #f1f5f9;
}

table.dataTable tbody tr:nth-child(even) {
  background: #f9fafb;
}

table.dataTable tfoot th {
  background: #f8fafc !important;
  font-weight: bold;
  color: #1e293b;
  padding: 10px;
  border-top: 2px solid #e2e8f0;
}

.btn-export {
  background: #2563eb !important;
  color: #fff !important;
  border: none !important;
  border-radius: 6px !important;
  padding: 7px 14px !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  transition: 0.2s;
}

.btn-export:hover {
  background: #1e40af !important;
  transform: scale(1.03);
}

/* Barcode Section */
#barcodeSection {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

#barcodeSection .modal-content {
  background: #fff;
  padding: 20px 30px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  min-width: 300px;
  max-width: 600px;
  text-align: center;
  animation: zoomIn 0.2s ease;
}

@keyframes zoomIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

#barcodeSection .close-btn {
  position: absolute;
  top: 15px;
  right: 20px;
  font-size: 22px;
  color: #444;
  cursor: pointer;
}

/* Barcode Table */
#barcodeTable {
  width: 100%;
  border-collapse: collapse;
  font-family: "Cairo", sans-serif;
  font-size: 14px;
  margin-top: 10px;
}

#barcodeTable th {
  background: #2563eb;
  color: #fff;
  text-align: center;
  padding: 8px;
}

#barcodeTable td {
  padding: 6px 8px;
  text-align: center;
  border-bottom: 1px solid #ddd;
}

#barcodeTable tr:nth-child(even) {
  background: #f3f4f6;
}

#barcodeTable tr:hover {
  background: #e0f2fe;
}

/* Boutons personnalisés */
.btn-action {
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
  color: white;
  transition: 0.3s;
}

.btn-edit {
  background-color: #3b82f6;
}

.btn-edit:hover {
  background-color: #1d4ed8;
}

.btn-delete {
  background-color: #ef4444;
}

.btn-delete:hover {
  background-color: #b91c1c;
}

.editable {
  background: #fff;
  border-radius: 4px;
}

.editable:focus {
  outline: 2px solid #60a5fa;
  background-color: #eef6ff;
}

.btn-filter {
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: 0.2s;
  font-size: 14px;
}

.btn-filter:hover {
  background: #e5e7eb;
}

.btn-filter.active {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

/* Bouton Code-barres */
.btn-barcode {
  background: #10b981;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  margin-top: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.3s;
}

.btn-barcode:hover {
  background: #059669;
}

.btn-add {
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  margin-left: 8px;
  cursor: pointer;
  font-weight: 600;
}

.btn-add:hover {
  background: #1d4ed8;
}

/* Couleurs */
.bg-blue {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

.bg-green {
  background: linear-gradient(135deg, #059669, #047857);
}

.bg-orange {
  background: linear-gradient(135deg, #f59e0b, #d97706);
}

.bg-purple {
  background: linear-gradient(135deg, #7c3aed, #5b21b6);
}

/* Responsive */
@media (max-width: 1024px) {
  .stats-row {
    flex-wrap: wrap;
    justify-content: center;
  }
  .stat-card {
    flex: 1 1 45%;
  }
  table.dataTable {
    min-width: 1000px !important;
  }
}

@media (max-width: 992px) {
  .search-stats-row {
    flex-wrap: wrap;
  }
  .search-box {
    flex: 1 1 100%;
    margin-bottom: 10px;
  }
  .stats-inline {
    flex: 1 1 100%;
    flex-wrap: wrap;
  }
  .stat-card {
    flex: 1 1 48%;
  }
}

@media (max-width: 768px) {
  .dataTables_wrapper {
    width: 98%;
    padding: 10px;
  }
  .dataTables_wrapper .dt-buttons {
    justify-content: center;
    flex-wrap: wrap;
  }
  .dataTables_filter {
    float: none !important;
    text-align: center;
  }
  body.table-mode #produitsGrid {
    height: auto;
  }
}

@media (max-width: 600px) {
  .modal-content {
    max-width: 95%;
    padding: 15px;
  }
  .search-box {
    max-width: 100%;
    padding: 0 8px;
  }
  .search-box input {
    font-size: 13px;
    padding: 7px 10px 7px 30px;
    height: 32px;
  }
  .form-row {
    flex-direction: row;
  }
  .form-row .input-group input {
    font-size: 0.8rem;
    padding: 4px;
  }
  .input-group i {
    font-size: 0.75rem;
  }
  .stat-card {
    flex: 1 1 100%;
  }
}

@media (max-width: 480px) {
  .stat-card {
    flex: 1 1 100%;
  }
}