* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f6f8;
  color: #1f2933;
}

header {
  background: #16324f;
  color: white;
  padding: 14px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header strong {
  font-size: 18px;
}

nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  background: #16324f;
  color: white;
}

button.secondary {
  background: #64748b;
}

button.success {
  background: #15803d;
}

button.danger {
  background: #dc2626;
}

button.light {
  background: #e2e8f0;
  color: #0f172a;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 22px;
}

.card {
  background: white;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .07);
  margin-bottom: 18px;
}

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

.form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #475569;
}

input,
select {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 9px 11px;
  background: white;
}

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

th,
td {
  padding: 10px;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
  font-size: 14px;
}

th {
  background: #eef2f7;
  color: #334155;
}

.photo {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 9px;
  background: #e2e8f0;
}

.notice {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  background: #dbeafe;
  color: #1e3a8a;
}

.notice.error {
  background: #fee2e2;
  color: #991b1b;
}

.notice.success {
  background: #dcfce7;
  color: #166534;
}

.cards-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.id-card {
  width: 85.6mm;
  height: 53.98mm;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  background: linear-gradient(135deg, #16324f, #2563eb);
  border: 1px solid #16324f;
  page-break-inside: avoid;
}

.id-left {
  width: 31%;
  padding: 8px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 7px;
}

.id-left img.photo-id {
  width: 23mm;
  height: 27mm;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid white;
  background: #e2e8f0;
}

.id-qr {
  width: 18mm;
  height: 18mm;
  background: white;
  border-radius: 5px;
  padding: 2px;
}

.id-right {
  flex: 1;
  background: white;
  padding: 9px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.id-group {
  background: #16324f;
  color: white;
  text-align: center;
  border-radius: 5px;
  font-size: 9px;
  padding: 4px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 800;
}

.id-label {
  font-size: 8px;
  color: #64748b;
  text-transform: uppercase;
  margin-top: 5px;
}

.id-name {
  color: #16324f;
  font-size: 16px;
  font-weight: 900;
  line-height: 1.1;
}

.id-value {
  font-size: 12px;
  font-weight: 700;
}

.id-footer {
  font-size: 8px;
  color: #94a3b8;
  display: flex;
  justify-content: space-between;
  border-top: 1px solid #e2e8f0;
  padding-top: 4px;
}

#reader {
  width: 100%;
  max-width: 420px;
}

@media print {
  header,
  .no-print {
    display: none !important;
  }

  body {
    background: white;
  }

  main {
    max-width: none;
    padding: 0;
  }

  .card {
    box-shadow: none;
    margin: 0;
  }

  .cards-grid {
    gap: 8px;
  }
}

/* ===== Correctif impression cartes ID ===== */

.id-card,
.id-card *,
.cards-grid,
.cards-grid * {
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 8mm;
  }

  html,
  body {
    width: 210mm;
    min-height: 297mm;
    background: #ffffff !important;
  }

  main {
    padding: 0 !important;
    margin: 0 !important;
  }

  .card {
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  .cards-grid {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6mm !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #ffffff !important;
  }

  .id-card {
    width: 85.6mm !important;
    height: 53.98mm !important;
    min-width: 85.6mm !important;
    max-width: 85.6mm !important;
    min-height: 53.98mm !important;
    max-height: 53.98mm !important;
    border: 0.4mm solid #16324f !important;
    border-radius: 2.5mm !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: row !important;
    background: #16324f !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin: 0 !important;
  }

  .id-left {
    width: 27mm !important;
    min-width: 27mm !important;
    height: 53.98mm !important;
    background: #16324f !important;
    padding: 2.2mm !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 2mm !important;
  }

  .id-left img.photo-id,
  .photo-id {
    width: 22mm !important;
    height: 27mm !important;
    object-fit: cover !important;
    border-radius: 1.5mm !important;
    border: 0.6mm solid #ffffff !important;
    background: #e2e8f0 !important;
    display: block !important;
  }

  .id-qr {
    width: 18mm !important;
    height: 18mm !important;
    background: #ffffff !important;
    border-radius: 1.2mm !important;
    padding: 1mm !important;
    display: block !important;
  }

  .id-right {
    height: 53.98mm !important;
    flex: 1 !important;
    background: #ffffff !important;
    padding: 2.3mm !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
  }

  .id-group {
    background: #16324f !important;
    color: #ffffff !important;
    border-radius: 1.3mm !important;
    text-align: center !important;
    font-size: 7.5pt !important;
    line-height: 1.2 !important;
    padding: 1.2mm !important;
    font-weight: 800 !important;
  }

  .id-label {
    font-size: 5.8pt !important;
    line-height: 1.1 !important;
    color: #64748b !important;
    text-transform: uppercase !important;
    margin-top: 1.2mm !important;
  }

  .id-name {
    color: #16324f !important;
    font-size: 11pt !important;
    line-height: 1.05 !important;
    font-weight: 900 !important;
  }

  .id-value {
    color: #111827 !important;
    font-size: 8.5pt !important;
    line-height: 1.05 !important;
    font-weight: 700 !important;
  }

  .id-footer {
    font-size: 5.8pt !important;
    line-height: 1 !important;
    color: #94a3b8 !important;
    display: flex !important;
    justify-content: space-between !important;
    border-top: 0.25mm solid #e2e8f0 !important;
    padding-top: 1mm !important;
  }
}
