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

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

.header {
  background: linear-gradient(135deg, #1e3a5f, #2563eb);
  color: #fff;
  padding: 24px 20px;
  text-align: center;
}
.header h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.header .sub { opacity: 0.85; font-size: 14px; }

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  padding: 28px 24px;
  margin-bottom: 20px;
}

.card h2 {
  font-size: 18px;
  color: #1e3a5f;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid #e5e7eb;
}

/* Steps */
.step { display: none; }
.step.active { display: block; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  color: #374151;
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="date"] {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 15px;
  transition: border-color 0.2s;
  outline: none;
}
.form-group input:focus {
  border-color: #2563eb;
}
.form-group .hint {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 4px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 500px) {
  .form-row { grid-template-columns: 1fr; }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  border: none;
  transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { background: #93c5fd; cursor: not-allowed; }
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-secondary { background: #e5e7eb; color: #374151; }
.btn-secondary:hover { background: #d1d5db; }

.btn-group {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
}

/* Alerts */
.alert {
  padding: 14px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  display: none;
}
.alert.show { display: block; }
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alert-info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }

/* Declaration content */
.declaration-content {
  background: #fafafa;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 20px;
  font-size: 14px;
  line-height: 1.7;
  max-height: 500px;
  overflow-y: auto;
}
.declaration-content h3 {
  font-size: 16px;
  text-align: center;
  text-transform: uppercase;
  margin-bottom: 4px;
  color: #1e3a5f;
}
.declaration-content h4 {
  font-size: 14px;
  text-align: center;
  font-weight: normal;
  margin-bottom: 20px;
  color: #4b5563;
}
.declaration-content .point {
  margin: 14px 0;
  padding-left: 24px;
  text-indent: -24px;
  text-align: justify;
}
.declaration-content .conclusion {
  margin-top: 20px;
  font-style: italic;
  text-align: justify;
}
.declaration-content .footnotes {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid #d1d5db;
  font-size: 12px;
  color: #6b7280;
}
.declaration-content .footnotes p {
  margin: 3px 0;
}

/* Signature pad */
.signature-section {
  margin-top: 20px;
  padding: 16px;
  background: #fafafa;
  border-radius: 8px;
}
.signature-section h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  color: #374151;
}
#sigCanvas {
  width: 100%;
  height: 140px;
  border: 2px dashed #d1d5db;
  border-radius: 8px;
  cursor: crosshair;
  background: #fff;
  touch-action: none;
}
#sigCanvas.signed { border-color: #22c55e; border-style: solid; }
.sig-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
}
.sig-hint {
  font-size: 12px;
  color: #9ca3af;
  text-align: center;
  margin-top: 6px;
}

/* Checkbox confirmation */
.confirm-check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 20px;
  padding: 16px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  cursor: pointer;
}
.confirm-check input { margin-top: 3px; flex-shrink: 0; }
.confirm-check span { font-size: 14px; color: #1e40af; }

/* Loading overlay */
.loading {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}
.loading.show { display: flex; }
.loading-box {
  background: #fff;
  border-radius: 12px;
  padding: 32px 40px;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,0.2);
}
.spinner {
  width: 40px; height: 40px;
  border: 4px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Success screen */
.success-icon {
  width: 64px; height: 64px;
  background: #dcfce7;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 32px;
  color: #16a34a;
}

/* Footer */
.footer {
  text-align: center;
  color: #9ca3af;
  font-size: 12px;
  margin-top: 24px;
  padding-bottom: 16px;
}

/* Existing signature info */
.existing-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  margin-bottom: 16px;
}
.existing-info .icon { font-size: 24px; }
.existing-info .text { font-size: 14px; color: #92400e; }
.existing-info .text strong { display: block; margin-bottom: 2px; }

/* Collaborator selector */
.form-group select {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 15px;
  background: #fff;
  outline: none;
}
.form-group select:focus { border-color: #2563eb; }

/* Collaborator info panel */
.identite-box {
  padding: 10px 14px;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-weight: 600;
  color: #1f2937;
}
.identite-box .identite-email {
  display: block;
  font-weight: normal;
  font-size: 13px;
  color: #6b7280;
  margin-top: 2px;
}
.collab-panel {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
  display: none;
}
.collab-panel.show { display: block; }
.collab-panel .collab-name { font-weight: 600; font-size: 16px; color: #0c4a6e; }
.collab-panel .collab-meta { font-size: 13px; color: #0369a1; margin-top: 4px; }

/* Dossiers list */
.dossier-list-wrap {
  background: #fafafa;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-bottom: 20px;
  display: none;
}
.dossier-list-wrap.show { display: block; }
.dossier-list-header {
  padding: 10px 16px;
  border-bottom: 1px solid #e5e7eb;
  font-weight: 600;
  font-size: 13px;
  color: #374151;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dossier-list {
  max-height: 220px;
  overflow-y: auto;
}
.dossier-item {
  padding: 9px 16px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.dossier-item:last-child { border-bottom: none; }
.dossier-item .d-main { flex: 1; min-width: 0; }
.dossier-item .d-nom { font-weight: 500; color: #1f2937; }
.dossier-item .d-code { font-size: 11px; color: #6b7280; }
.dossier-item .d-cac { font-size: 12px; color: #6b7280; text-align: right; white-space: nowrap; }
.dossier-item.sans-info { background: #fef3c7; }
.dossier-item.sans-info .d-nom::after {
  content: " (info manquante)";
  color: #b45309;
  font-weight: normal;
  font-size: 11px;
}
.dossier-item .d-actions { display: flex; gap: 6px; align-items: center; }
.dossier-vide { padding: 14px 16px; font-size: 13px; color: #6b7280; font-style: italic; }
.badge-ajoute {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  color: #1d4ed8;
  background: #dbeafe;
  border-radius: 10px;
  padding: 1px 8px;
  margin-left: 6px;
  vertical-align: 1px;
}

/* Mini boutons (liste des dossiers) */
.btn-mini {
  padding: 3px 10px;
  font-size: 11px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  cursor: pointer;
  white-space: nowrap;
}
.btn-mini:hover { border-color: #93c5fd; background: #eff6ff; }
.btn-mini.btn-retirer:hover { border-color: #dc2626; color: #dc2626; background: #fef2f2; }
.btn-mini-primary { border-color: #2563eb; background: #2563eb; color: #fff; font-weight: 600; }
.btn-mini-primary:hover { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }

/* Panneau ajout / complétion de dossier */
.panneau-dossier {
  display: none;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
}
.panneau-dossier.show { display: block; }
.panneau-dossier .panneau-titre {
  font-weight: 600;
  font-size: 14px;
  color: #374151;
  margin-bottom: 12px;
}
.resultats-recherche {
  max-height: 180px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-bottom: 14px;
}
.resultats-recherche:empty { display: none; }
.resultat-item {
  padding: 8px 12px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.resultat-item:last-child { border-bottom: none; }
.resultat-item:hover { background: #eff6ff; }
.resultat-item .r-nom { font-weight: 500; color: #1f2937; }
.resultat-item .r-detail { font-size: 11px; color: #6b7280; white-space: nowrap; }
.resultat-vide { padding: 10px 12px; font-size: 12px; color: #6b7280; font-style: italic; }

/* Category checkboxes */
.category-section { margin: 20px 0 16px; }
.category-section > label.section-label {
  display: block;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
  color: #374151;
}
.category-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.category-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.category-item:hover { border-color: #93c5fd; }
.category-item.selected { border-color: #2563eb; background: #eff6ff; }
.category-item input { margin-top: 3px; flex-shrink: 0; }
.category-item .cat-title { font-weight: 600; font-size: 14px; display: block; }
.category-item .cat-desc { font-size: 12px; color: #6b7280; }
