/* ==========================================================================
   Styles globaux pour l'application Microentreprise
   ========================================================================== */

/* Variables CSS */
:root {
  --color-primary: #16a34a;
  --color-primary-dark: #15803d;
  --color-primary-light: #22c55e;
  --color-secondary: #3b82f6;
  --color-danger: #ef4444;
  --color-warning: #f59e0b;
  --color-success: #10b981;
  --color-gray-50: #f9fafb;
  --color-gray-100: #f3f4f6;
  --color-gray-200: #e5e7eb;
  --color-gray-300: #d1d5db;
  --color-gray-400: #9ca3af;
  --color-gray-500: #6b7280;
  --color-gray-600: #4b5563;
  --color-gray-700: #374151;
  --color-gray-800: #1f2937;
  --color-gray-900: #111827;
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --border-radius: 0.5rem;
  --border-radius-lg: 1rem;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

/* Reset et base */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  line-height: 1.6;
  color: var(--color-gray-900);
  background-color: var(--color-gray-50);
}

/* Focus visible pour accessibilité */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Liens */
a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Formulaires */
input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-gray-300);
  border-radius: var(--border-radius);
  background-color: white;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2);
  outline: none;
}

input:invalid, select:invalid, textarea:invalid {
  border-color: var(--color-danger);
}

/* Boutons */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: all 0.15s;
}

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

.btn-primary {
  background-color: var(--color-primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--color-primary-dark);
}

.btn-secondary {
  background-color: white;
  color: var(--color-gray-700);
  border: 1px solid var(--color-gray-300);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--color-gray-50);
}

/* Messages d'erreur */
.errorlist {
  list-style: none;
  padding: 0;
  margin: 0.25rem 0 0 0;
  color: var(--color-danger);
  font-size: 0.875rem;
}

.errorlist li {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.errorlist li::before {
  content: "⚠";
}

/* Alertes */
.alert {
  padding: 1rem;
  border-radius: var(--border-radius);
  margin-bottom: 1rem;
}

.alert-success {
  background-color: #d1fae5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}

.alert-warning {
  background-color: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
}

.alert-error {
  background-color: #fee2e2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.alert-info {
  background-color: #dbeafe;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

/* Cards */
.card {
  background: white;
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--color-gray-200);
}

th {
  font-weight: 600;
  background-color: var(--color-gray-50);
}

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

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

.animate-fade-in {
  animation: fadeIn 0.3s ease-out;
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* Loader */
.loader {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--color-gray-200);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Print styles */
@media print {
  body {
    background: white;
  }
  
  .no-print {
    display: none !important;
  }
  
  a[href]::after {
    content: " (" attr(href) ")";
  }
}

/* Responsive utilities */
.hide-mobile {
  display: none;
}

@media (min-width: 768px) {
  .hide-mobile {
    display: block;
  }
  
  .hide-desktop {
    display: none;
  }
}

/* Skip link pour accessibilité */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-primary);
  color: white;
  padding: 8px;
  z-index: 100;
}

.skip-link:focus {
  top: 0;
}

/* Scrollbar personnalisée */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--color-gray-100);
}

::-webkit-scrollbar-thumb {
  background: var(--color-gray-400);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-gray-500);
}

/* Selection */
::selection {
  background: var(--color-primary);
  color: white;
}

/* ==========================================================================
   Custom Checkbox - Style CARRÉ avec vert foncé
   ========================================================================== */

/* Variable pour le vert foncé */
:root {
  --color-checkbox-checked: #166534; /* Vert foncé */
}

/* Masquer la checkbox native et forcer le style carré */
input[type="checkbox"],
input[type="checkbox"].custom-checkbox {
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  appearance: none !important;
  width: 1.5rem !important;
  height: 1.5rem !important;
  min-width: 1.5rem !important;
  min-height: 1.5rem !important;
  border: 2px solid var(--color-gray-400) !important;
  border-radius: 3px !important; /* CARRÉ avec coins légèrement arrondis */
  background-color: white !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  position: relative !important;
  flex-shrink: 0 !important;
  display: inline-block !important;
  vertical-align: middle !important;
}

/* État hover */
input[type="checkbox"]:hover {
  border-color: var(--color-checkbox-checked) !important;
  background-color: #f0fdf4 !important; /* Léger vert de fond au hover */
}

/* État focus */
input[type="checkbox"]:focus {
  outline: none !important;
  border-color: var(--color-checkbox-checked) !important;
  box-shadow: 0 0 0 3px rgba(22, 101, 52, 0.25) !important;
}

/* État coché - fond VERT FONCÉ */
input[type="checkbox"]:checked {
  background-color: var(--color-checkbox-checked) !important;
  border-color: var(--color-checkbox-checked) !important;
}

/* Checkmark ✓ blanc bien visible */
input[type="checkbox"]:checked::after {
  content: '' !important;
  position: absolute !important;
  left: 6px !important;
  top: 2px !important;
  width: 6px !important;
  height: 12px !important;
  border: solid white !important;
  border-width: 0 2.5px 2.5px 0 !important;
  transform: rotate(45deg) !important;
}

/* État invalide/erreur */
input[type="checkbox"]:invalid,
input[type="checkbox"].error {
  border-color: var(--color-danger) !important;
}

/* Animation au clic */
input[type="checkbox"]:active {
  transform: scale(0.95) !important;
}

/* Style spécifique pour les checkboxes dans les formulaires */
.flex.items-start input[type="checkbox"],
.flex.items-center input[type="checkbox"] {
  margin-top: 2px !important;
}

/* ==========================================================================
   CHAMPS OBLIGATOIRES - BORDURE ROUGE
   ========================================================================== */

/* Label avec étoile rouge pour champs obligatoires */
label.required::after,
label[for] span.required,
.field-required label::after {
  content: " *";
  color: var(--color-danger);
  font-weight: bold;
}

/* Champs obligatoires - bordure rouge */
input[required],
select[required],
textarea[required] {
  border-color: #fca5a5 !important; /* Rouge clair */
}

input[required]:focus,
select[required]:focus,
textarea[required]:focus {
  border-color: var(--color-danger) !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2) !important;
}

/* Champs remplis correctement - bordure verte */
input[required]:valid:not(:placeholder-shown),
select[required]:valid:not([value=""]),
textarea[required]:valid:not(:placeholder-shown) {
  border-color: var(--color-success) !important;
}

/* Zone upload document obligatoire - cadre rouge */
.upload-zone.required,
.document-required {
  border: 2px dashed #fca5a5 !important;
  background-color: #fef2f2 !important;
}

.upload-zone.required:hover,
.document-required:hover {
  border-color: var(--color-danger) !important;
  background-color: #fee2e2 !important;
}

/* Label document obligatoire */
.label-required,
.document-label-required {
  color: var(--color-danger) !important;
  font-weight: 600 !important;
}

/* ==========================================================================
   CHECKBOXES - COULEUR UNIFORME (VERT FONCÉ)
   ========================================================================== */

/* Toutes les checkboxes avec la même couleur */
input[type="checkbox"]:checked {
  background-color: #166534 !important; /* Vert foncé uniforme */
  border-color: #166534 !important;
}

/* Checkbox obligatoire non cochée - bordure rouge */
input[type="checkbox"][required]:not(:checked) {
  border-color: #fca5a5 !important;
}

input[type="checkbox"][required]:not(:checked):hover {
  border-color: var(--color-danger) !important;
}

/* ==========================================================================
   ERREURS DE VALIDATION
   ========================================================================== */

/* Champ avec erreur */
.has-error input,
.has-error select,
.has-error textarea,
input.error,
select.error,
textarea.error {
  border-color: var(--color-danger) !important;
  background-color: #fef2f2 !important;
}

/* Message d'erreur sous le champ */
.error-message,
.field-error {
  color: var(--color-danger);
  font-size: 0.875rem;
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.error-message::before,
.field-error::before {
  content: "⚠";
}

/* ==========================================================================
   ALIGNEMENT DES CHAMPS DE FORMULAIRE
   ========================================================================== */

/* Tous les inputs, selects et textareas prennent toute la largeur */
form input[type="text"],
form input[type="email"],
form input[type="tel"],
form input[type="date"],
form input[type="number"],
form select,
form textarea {
  width: 100% !important;
  display: block !important;
}

/* Espacement uniforme entre label et input */
form label + input,
form label + select,
form label + textarea {
  margin-top: 0.25rem;
}

/* ==========================================================================
   BOUTONS RADIO TOGGLE - COULEUR UNIFORME (VERT FONCÉ)
   ========================================================================== */

/* Override des couleurs Tailwind pour les boutons radio toggle */
.peer:checked ~ div {
  background-color: #166534 !important;
  border-color: #166534 !important;
  color: white !important;
}

/* Style pour les boutons toggle au hover */
.peer ~ div:hover {
  border-color: #22c55e !important;
}

/* ==========================================================================
   RADIO BUTTONS CLASSIQUES - STYLE UNIFORME
   ========================================================================== */

input[type="radio"] {
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  appearance: none !important;
  width: 1.25rem !important;
  height: 1.25rem !important;
  border: 2px solid var(--color-gray-400) !important;
  border-radius: 50% !important;
  background-color: white !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  position: relative !important;
}

input[type="radio"]:checked {
  border-color: #166534 !important;
  background-color: #166534 !important;
}

input[type="radio"]:checked::after {
  content: '' !important;
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  width: 6px !important;
  height: 6px !important;
  border-radius: 50% !important;
  background-color: white !important;
}

input[type="radio"]:hover {
  border-color: #166534 !important;
}

input[type="radio"]:focus {
  outline: none !important;
  box-shadow: 0 0 0 3px rgba(22, 101, 52, 0.25) !important;
}

/* ==========================================================================
   CORRECTIF ULTIME SIGNATURE MOBILE - v19
   ========================================================================== */

/* Désactive toutes les interactions tactiles du navigateur (zoom, scroll, pull-to-refresh) */
#signature-container, #sigpad {
  touch-action: none !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
  /* Bloque l'effet élastique sur iOS */
  overscroll-behavior: none !important;
  /* Force le curseur */
  cursor: crosshair;
}

/* Évite le zoom si on tape vite - permet le scroll autour */
#signature-container {
  touch-action: pan-x pan-y;
}

/* Verrouillage strict sur le canvas lui-même */
canvas#sigpad {
  touch-action: none !important;
}
