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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
}

header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: white;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

header h1 {
  font-size: 1.3rem;
  font-weight: 600;
}

/* Navigation header */
.header-nav {
  display: flex;
  gap: 0.5rem;
}

.header-nav a {
  color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.1);
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.85rem;
  transition: background 0.2s, color 0.2s;
}

.header-nav a:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.header-nav a.active {
  background: rgba(255, 255, 255, 0.25);
  color: white;
  font-weight: 600;
}

.btn-admin {
  color: white;
  background: rgba(255, 255, 255, 0.15);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.85rem;
  transition: background 0.2s;
}

.btn-admin:hover {
  background: rgba(255, 255, 255, 0.25);
}

main {
  max-width: 800px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Steps */
.step {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.step.hidden {
  display: none;
}

.step h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: #16213e;
}

/* Search box */
.search-box {
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-box input:focus {
  border-color: #4361ee;
}

.dropdown-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 0 0 8px 8px;
  max-height: 250px;
  overflow-y: auto;
  z-index: 100;
  display: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.dropdown-results.show {
  display: block;
}

.dropdown-item {
  padding: 0.7rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.15s;
}

.dropdown-item:hover {
  background: #f0f4ff;
}

.dropdown-item .item-name {
  font-weight: 500;
  font-size: 0.9rem;
}

.dropdown-item .item-city {
  font-size: 0.8rem;
  color: #666;
}

/* Selected magasin */
.selected-magasin {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: #e8f5e9;
  border-radius: 8px;
  border: 1px solid #a5d6a7;
}

.selected-magasin.hidden {
  display: none;
}

.selected-magasin span {
  flex: 1;
  font-weight: 500;
}

/* Buttons */
.btn-primary {
  display: block;
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, #4361ee, #3a0ca3);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 1rem;
  transition: opacity 0.2s;
}

.btn-primary:hover {
  opacity: 0.9;
}

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

.btn-primary.hidden {
  display: none;
}

.btn-small {
  padding: 0.3rem 0.6rem;
  background: #e0e0e0;
  border: none;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-small:hover {
  background: #ccc;
}

/* Capture */
.capture-options {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.btn-capture {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: #f8f9fa;
  border: 2px dashed #ccc;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}

.btn-capture:hover {
  border-color: #4361ee;
  background: #f0f4ff;
}

#preview-container {
  text-align: center;
  margin-top: 1rem;
}

#preview-container.hidden {
  display: none;
}

#image-preview {
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* OCR Loading */
#ocr-loading {
  text-align: center;
  padding: 2rem;
}

#ocr-loading.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e0e0e0;
  border-top-color: #4361ee;
  border-radius: 50%;
  margin: 0 auto 1rem;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Form */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.3rem;
  font-size: 0.9rem;
}

.form-group input {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
}

.form-group input:focus {
  border-color: #4361ee;
}

.hint {
  color: #888;
  font-size: 0.8rem;
  margin-top: 0.25rem;
  display: block;
}

.info-text {
  background: #f8f9fa;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
}

.ocr-raw {
  background: #f8f9fa;
  padding: 0.75rem;
  border-radius: 6px;
  font-size: 0.75rem;
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  border: 1px solid #eee;
}

/* Lot blocks */
.lot-block {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  background: #fafbfc;
}

.lot-block.hidden {
  display: none;
}

.lot-block h3 {
  font-size: 0.95rem;
  color: #4361ee;
  margin-bottom: 0.75rem;
}

.btn-secondary {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: #f0f0f0;
  color: #333;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  margin-bottom: 1rem;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: #e0e0e0;
}

.btn-secondary.hidden {
  display: none;
}

/* Result */
.result-card {
  padding: 1.5rem;
  border-radius: 10px;
  margin-bottom: 1rem;
}

.result-found {
  background: #e8f5e9;
  border: 2px solid #4caf50;
}

.result-not-found {
  background: #ffebee;
  border: 2px solid #f44336;
}

.result-card h3 {
  margin-bottom: 0.5rem;
}

.result-card .result-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.result-details {
  margin-top: 0.75rem;
}

.result-details p {
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}

.result-details strong {
  display: inline-block;
  min-width: 120px;
}

/* ============ ADMIN ============ */
.admin-main {
  max-width: 1100px;
}

.admin-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.5rem;
  background: white;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.admin-tab {
  flex: 1;
  padding: 1rem;
  border: none;
  background: white;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  color: #666;
  transition: background 0.2s, color 0.2s;
  border-bottom: 3px solid transparent;
}

.admin-tab:hover {
  background: #f8f9fa;
}

.admin-tab.active {
  color: #4361ee;
  border-bottom-color: #4361ee;
  font-weight: 600;
}

.tab-count {
  display: inline-block;
  background: #e0e0e0;
  color: #666;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  font-size: 0.75rem;
  margin-left: 0.3rem;
}

.admin-tab.active .tab-count {
  background: #e8edff;
  color: #4361ee;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.export-buttons {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-export {
  padding: 0.5rem 0.9rem;
  background: #16213e;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-export:hover {
  opacity: 0.85;
}

.admin-stats {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat {
  flex: 1;
  background: white;
  border-radius: 10px;
  padding: 1.2rem;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.stat-number {
  display: block;
  font-size: 2rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.8rem;
  color: #666;
}

.stat.found .stat-number { color: #4caf50; }
.stat.not-found .stat-number { color: #f44336; }

.admin-filters {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.admin-filters input,
.admin-filters select {
  padding: 0.6rem 0.8rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
}

.admin-filters input {
  flex: 1;
}

.admin-filters input:focus,
.admin-filters select:focus {
  border-color: #4361ee;
}

.table-container {
  background: white;
  border-radius: 10px;
  overflow-x: auto;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

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

th {
  background: #f8f9fa;
  padding: 0.75rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  color: #666;
  text-align: left;
  border-bottom: 2px solid #e0e0e0;
  white-space: nowrap;
}

td {
  padding: 0.65rem 0.75rem;
  font-size: 0.85rem;
  border-bottom: 1px solid #f0f0f0;
}

.lot-cell {
  font-family: 'Courier New', monospace;
  font-weight: 600;
}

.badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success {
  background: #e8f5e9;
  color: #2e7d32;
}

.badge-danger {
  background: #ffebee;
  color: #c62828;
}

.btn-delete {
  padding: 0.3rem 0.6rem;
  background: #ffebee;
  color: #c62828;
  border: 1px solid #ef9a9a;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
}

.btn-delete:hover {
  background: #ffcdd2;
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: #999;
}

/* Admin actions */
.actions-cell {
  white-space: nowrap;
  display: flex;
  gap: 0.3rem;
}

.btn-review {
  padding: 0.3rem 0.6rem;
  background: #e3f2fd;
  color: #1565c0;
  border: 1px solid #90caf9;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
}

.btn-review:hover {
  background: #bbdefb;
}

/* ============ BULK SCAN ============ */
.bulk-upload-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  width: 100%;
  cursor: pointer;
}

.bulk-upload-zone.drag-over {
  border-color: #4361ee;
  background: #e8edff;
}

.file-preview-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.5rem;
  margin-top: 0.75rem;
  max-height: 300px;
  overflow-y: auto;
}

.file-preview-item {
  position: relative;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  overflow: hidden;
  background: white;
}

.file-preview-item img {
  width: 100%;
  height: 80px;
  object-fit: cover;
}

.file-preview-name {
  display: block;
  font-size: 0.65rem;
  padding: 0.2rem 0.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #666;
}

.file-preview-item button {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  padding: 0;
  font-size: 0.8rem;
  line-height: 1;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  color: white;
  border: none;
  cursor: pointer;
}

/* Progress bar */
.bulk-progress {
  margin-bottom: 1rem;
}

.progress-bar {
  width: 100%;
  height: 12px;
  background: #e0e0e0;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4361ee, #3a0ca3);
  border-radius: 6px;
  transition: width 0.3s ease;
}

#progress-text {
  font-size: 0.85rem;
  color: #666;
  text-align: center;
}

/* Bulk results */
.bulk-results-list {
  max-height: 500px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.bulk-result-row {
  display: flex;
  gap: 0.75rem;
  padding: 0.6rem;
  border-bottom: 1px solid #f0f0f0;
  align-items: center;
}

.bulk-result-img {
  flex-shrink: 0;
}

.bulk-result-img img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
}

.bulk-result-info {
  flex: 1;
  min-width: 0;
}

.bulk-result-file {
  display: block;
  font-size: 0.75rem;
  color: #888;
  margin-bottom: 0.25rem;
}

.bulk-lot-line {
  font-size: 0.85rem;
  margin-bottom: 0.15rem;
}

.spinner-small {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #e0e0e0;
  border-top-color: #4361ee;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 0.3rem;
}

/* ============ MODAL ============ */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: white;
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #eee;
}

.modal-header h3 {
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #999;
  padding: 0 0.3rem;
}

.modal-close:hover {
  color: #333;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid #eee;
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.modal-footer .btn-primary {
  width: auto;
  margin-top: 0;
  padding: 0.6rem 1.5rem;
}

.modal-footer .btn-secondary {
  margin-bottom: 0;
}

.review-image-container {
  text-align: center;
  margin-bottom: 1rem;
}

.review-image-container.hidden {
  display: none;
}

.review-image-container img {
  max-width: 100%;
  max-height: 250px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.review-ocr-lots {
  margin-top: 0.5rem;
}

.ocr-lot-option {
  padding: 0.5rem 0.75rem;
  background: #f0f4ff;
  border: 1px solid #c5cae9;
  border-radius: 6px;
  margin-bottom: 0.3rem;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
}

.ocr-lot-option:hover {
  background: #dde3ff;
}

/* ============ AUTHENTIFICATION ============ */

/* Boîte utilisateur dans l'en-tête */
.user-box {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}

.user-email {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.9);
}

.user-role {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.55);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.btn-logout {
  color: white;
  background: rgba(255, 255, 255, 0.12);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.8rem;
  transition: background 0.2s;
}

.btn-logout:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Page de connexion / accès refusé */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

.login-card {
  background: white;
  border-radius: 14px;
  padding: 2.5rem 2rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.login-card h1 {
  font-size: 1.4rem;
  color: #16213e;
  margin-bottom: 0.75rem;
}

.login-sub {
  color: #555;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.btn-microsoft {
  display: inline-block;
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, #4361ee, #3a0ca3);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-microsoft:hover {
  opacity: 0.9;
}

.btn-logout-link {
  display: inline-block;
  margin-top: 1rem;
  color: #888;
  font-size: 0.85rem;
  text-decoration: none;
}

.btn-logout-link:hover {
  color: #555;
  text-decoration: underline;
}

.login-warning {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 8px;
  padding: 1rem;
  text-align: left;
  font-size: 0.85rem;
  color: #6d4c00;
}

.login-warning p {
  margin-top: 0.5rem;
}

.login-warning code {
  background: rgba(0, 0, 0, 0.07);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

/* Champ de saisie invalide (format de lot incorrect) */
.form-group input.invalid {
  border-color: #f44336;
  background: #fff5f5;
}

/* ============ GESTION DES UTILISATEURS ============ */

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-success {
  background: #e8f5e9;
  border: 1px solid #a5d6a7;
  color: #2e7d32;
}

.alert-error {
  background: #ffebee;
  border: 1px solid #ef9a9a;
  color: #c62828;
}

.add-user-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.add-user-form input {
  flex: 1;
  min-width: 220px;
  padding: 0.7rem 1rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
}

.add-user-form input:focus {
  border-color: #4361ee;
}

.add-user-form .btn-primary {
  width: auto;
  margin-top: 0;
  flex-shrink: 0;
  padding: 0.7rem 1.5rem;
}

.badge-info {
  background: #e3f2fd;
  color: #1565c0;
}

.add-user-form .btn-delete,
td form {
  margin: 0;
}

/* Responsive */
@media (max-width: 600px) {
  header {
    flex-direction: column;
    gap: 0.5rem;
  }
  .header-nav {
    width: 100%;
    justify-content: center;
  }
  .user-box {
    width: 100%;
    justify-content: space-between;
  }
  .user-meta {
    align-items: flex-start;
  }
  .capture-options {
    flex-direction: column;
  }
  .admin-stats {
    flex-direction: column;
  }
  .admin-filters {
    flex-direction: column;
  }
  td, th {
    padding: 0.5rem;
    font-size: 0.75rem;
  }
  .file-preview-list {
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  }
  .modal-content {
    width: 95%;
  }
}
