/* ============================================
   Styles communs à toutes les pages
   ============================================ */

/* Base */
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  padding: 0 20px;
  background: #f5f5f5;
}

.page {
  max-width: 1200px;
  margin: 20px auto;
  background: #ffffff;
  padding: 24px 28px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border-radius: 8px;
}

/* Typographie */
h1, h2, h3 {
  margin-top: 0;
  color: #222;
}

h1 {
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
}

h2 {
  font-size: 1.3rem;
  margin-top: 2rem;
  border-bottom: 1px solid #ddd;
  padding-bottom: 0.25rem;
}

p {
  line-height: 1.5;
  margin-top: 0.4rem;
  margin-bottom: 0.4rem;
}

small {
  display: block;
  color: #666;
  font-size: 0.8rem;
  margin-top: 2px;
}

/* Boutons de scan */
.btn-scan {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-scan:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-scan-large {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
  border: none;
  padding: 16px 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 600;
  transition: transform 0.2s, box-shadow 0.2s;
  width: 100%;
  max-width: 300px;
}

.btn-scan-large:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}

.btn-scan-large.btn-secondary {
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
}

/* Modale de scan */
.scan-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.scan-modal-content {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 1000px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

/* Modal fullscreen sur mobile */
@media (max-width: 768px) {
  .scan-modal {
    padding: 0;
  }
  
  .scan-modal-content {
    max-width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }
  
  .scan-modal-body {
    flex: 1;
    overflow-y: auto;
  }
}

/* Layout pour les résultats du scan */
.scan-result-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.scan-result-image-container {
  flex: 1;
  max-width: 50%;
  position: relative;
  overflow: hidden;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #f5f5f5;
}

.scan-result-form-container {
  flex: 1;
}

/* Image avec effet zoom au survol (desktop uniquement) */
.scan-result-image {
  width: 100%;
  border-radius: 8px;
  transition: transform 0.3s ease;
  cursor: zoom-in;
  display: block;
}

/* Zoom au survol sur desktop */
@media (min-width: 769px) {
  .scan-result-image:hover {
    transform: scale(2);
    transform-origin: center center;
  }
  
  /* Permettre de se déplacer dans l'image zoomée */
  .scan-result-image-container:hover .scan-result-image {
    cursor: move;
  }
}

/* Layout en colonne sur mobile */
@media (max-width: 768px) {
  .scan-result-layout {
    flex-direction: column;
  }
  
  .scan-result-image-container {
    max-width: 100%;
    width: 100%;
  }
  
  .scan-result-form-container {
    width: 100%;
  }
  
  .scan-result-image {
    cursor: default;
  }
}

/* Styles pour la caméra */
#camera-container {
  text-align: center;
}

#camera-video {
  max-width: 100%;
  max-height: 70vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  display: block;
  margin: 0 auto;
}

#camera-overlay {
  border-radius: 8px;
  pointer-events: none;
}

/* Mobile: caméra plus grande */
@media (max-width: 768px) {
  #camera-video {
    max-height: 60vh;
  }
}

.scan-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid #e5e7eb;
}

.scan-modal-header h2 {
  margin: 0;
  border: none;
  padding: 0;
  font-size: 1.5rem;
}

.scan-modal-close {
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: #6b7280;
  padding: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.scan-modal-close:hover {
  background: #f3f4f6;
}

.scan-modal-body {
  padding: 24px;
}

.scan-upload-area {
  text-align: center;
  padding: 40px 20px;
  border: 2px dashed #d1d5db;
  border-radius: 8px;
  background: #f9fafb;
}

.scan-preview-container {
  margin-bottom: 20px;
  text-align: center;
}

#scan-canvas {
  max-width: 100%;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
}

.scan-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}

.scan-results {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.scan-results h3 {
  margin-top: 0;
  color: #15803d;
}

.scan-result-item {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid #dcfce7;
}

.scan-result-item:last-child {
  border-bottom: none;
}

.scan-result-item label {
  font-weight: 600;
  color: #374151;
}

.scan-result-item span {
  color: #15803d;
  font-weight: 600;
}

.spinner {
  border: 4px solid #f3f4f6;
  border-top: 4px solid #3b82f6;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 0 auto;
}

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

/* Caméra en direct */
#camera-container {
  max-width: 800px;
  margin: 0 auto;
}

#camera-video {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  background: #000;
}

#camera-overlay {
  pointer-events: none;
}

/* Responsive: caméra sur mobile */
@media (max-width: 768px) {
  #camera-video {
    max-height: 50vh;
  }
}

.text-right {
  text-align: right !important;
}

.text-muted {
  color: #666;
  font-size: 0.85rem;
}

/* Navigation desktop */
.nav-links {
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid #e5e7eb;
}

.nav-links a {
  color: #2563eb;
  text-decoration: none;
  margin-right: 20px;
  font-weight: 500;
}

.nav-links a:hover {
  text-decoration: underline;
}

.nav-links a.active {
  font-weight: 700;
}

#user-email-display {
  font-size: 0.85rem;
  color: #6b7280;
  margin-left: auto;
}

.desktop-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid #e5e7eb;
}

.desktop-nav a {
  color: #2563eb;
  text-decoration: none;
  font-weight: 500;
  margin-right: 20px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;;
}

.desktop-nav a:hover {
  text-decoration: underline;
}

.desktop-nav a.active {
  font-weight: 700;
}

/* Header avec titre et sélecteur d'année */
.header-section {
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
  gap: 10px;
}

.year-selector-wrapper {
  display: flex;
  width: 200px;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.year-selector-wrapper label {
  font-weight: 600;
}

/* Formulaires */
.field-group {
  margin-bottom: 12px;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="file"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.95rem;
  box-sizing: border-box;
}

input[type="number"] {
  text-align: right;
}

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

/* Grilles */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* Sections */
.section-box {
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 16px;
  background: #fafafa;
}

/* Boutons */
.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
  margin-bottom: 10px;
}

button {
  border: none;
  border-radius: 4px;
  padding: 8px 14px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary {
  background: #2563eb;
  color: white;
}

.btn-secondary {
  background: #e5e7eb;
  color: #111827;
}

.btn-danger {
  background: #dc2626;
  color: white;
}

.btn-success {
  background: #16a34a;
  color: white;
}

.btn-warning {
  background: #f59e0b;
  color: white;
}

.btn-primary:hover {
  background: #1d4ed8;
}

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

.btn-danger:hover {
  background: #b91c1c;
}

.btn-success:hover {
  background: #15803d;
}

.btn-warning:hover {
  background: #d97706;
}

.btn-small {
  padding: 4px 10px;
  font-size: 0.85rem;
}

.logout-btn {
  background: #ef4444;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
}

.logout-btn:hover {
  background: #dc2626;
}

/* Alertes */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
}

.alert-info {
  background: #dbeafe;
  color: #1e40af;
  border-left: 4px solid #2563eb;
}

.alert-success {
  background: #dcfce7;
  color: #166534;
  border-left: 4px solid #16a34a;
}

.alert-warning {
  background: #fef3c7;
  color: #92400e;
  border-left: 4px solid #f59e0b;
}

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

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

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid #e5e7eb;
}

th {
  background: #f9fafb;
  font-weight: 600;
  position: sticky;
  top: 0;
}

tr:hover {
  background: #f9fafb;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Modales */
.modal {
  display: none !important;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  overflow: auto;
}

.modal[style*="display: block"] {
  display: block !important;
}

.modal-content {
  background: white;
  margin: 40px auto;
  padding: 24px;
  border-radius: 8px;
  max-width: 600px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h2 {
  margin: 0;
  border: none;
}

.close-modal {
  font-size: 1.5rem;
  cursor: pointer;
  color: #666;
}

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

/* Navigation mobile */
.mobile-nav {
  display: none;
}

.user-email-mobile {
  display: none;
}

/* Responsive */
@media (max-width: 768px) {
  body {
    padding: 0;
    padding-bottom: 70px;
  }

  .page {
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
  }

  .desktop-nav {
    display: none;
  }

  .user-email-mobile {
    display: block;
    font-size: 0.85rem;
    color: #6b7280;
    padding: 12px 16px;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    margin: -24px -28px 16px -28px;
  }

  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    padding: 8px 0;
  }

  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    text-decoration: none;
    color: #6b7280;
    background: none;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
  }

  .mobile-nav-item.active {
    color: #2563eb;
  }

  .mobile-nav-item:active {
    background: #f3f4f6;
  }

  .mobile-nav-icon {
    font-size: 1.5rem;
    margin-bottom: 2px;
  }

  .mobile-nav-label {
    font-size: 0.7rem;
    font-weight: 500;
  }

  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }

  table {
    font-size: 0.85rem;
  }

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

  h1 {
    font-size: 1.3rem;
  }
}
