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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f0f2f5;
    padding: 20px;
    line-height: 1.6;
    color: #1a1a1b;
}

h1, h2, h3, .document-title {
    font-family: 'Outfit', sans-serif;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
}

.form-section {
    flex: 1;
    min-width: 300px;
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.form-section h2 {
    margin-bottom: 20px;
    color: #333;
    font-size: 24px;
}

/* --- Sélecteur de type de document --- */
.type-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.type-selector button {
    flex: 1;
    min-width: 140px;
    padding: 10px 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    background: #fafafa;
    color: #555;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.type-selector button.active {
    border-color: #1a5eb8;
    background: #1a5eb8;
    color: white;
}

/* --- Sélecteur de mode (attestation) --- */
.mode-selector {
    display: flex;
    gap: 8px;
}

.mode-selector button {
    flex: 1;
    padding: 8px 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    background: #fafafa;
    color: #555;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-selector button.active {
    border-color: #f5a623;
    background: #f5a623;
    color: white;
}

/* --- Bandeau de message (remplace les alert()) --- */
.form-banner {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 18px;
    font-size: 14px;
    font-weight: 600;
}

.form-banner.error {
    background: #fdecea;
    color: #b3261e;
    border: 1px solid #f5c6c2;
}

.form-banner.success {
    background: #e6f4ea;
    color: #1e7e34;
    border: 1px solid #b7e1c1;
}

.form-banner.info {
    background: #eef4fc;
    color: #1a5eb8;
    border: 1px solid #c9dcf3;
}

.form-banner-text {
    display: block;
}

.form-banner-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.btn-banner-action {
    padding: 6px 14px;
    border-radius: 4px;
    border: none;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    background: #1a5eb8;
    color: #fff;
}

.btn-banner-action--ghost {
    background: transparent;
    color: #555;
    border: 1px solid #ccc;
}

.field-hint {
    font-size: 12.5px;
    color: #888;
    margin-top: 6px;
}

.field-error {
    color: #b3261e;
    font-size: 12.5px;
    margin-top: 6px;
    font-weight: 600;
}

.field-invalid {
    border-color: #b3261e !important;
}

.radio-row {
    display: flex;
    gap: 20px;
    padding: 6px 0;
}

.radio-inline {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: normal;
    color: #333;
}

.radio-inline input {
    width: auto;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #555;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.form-group textarea {
    resize: vertical;
}

/* --- Constructeur de stagiaires (mode nominatif) --- */
.stagiaires-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.stagiaire-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.stagiaire-row input {
    flex: 1;
}

.btn-remove-stagiaire {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 4px;
    background: #fdecea;
    color: #b3261e;
    font-size: 14px;
    cursor: pointer;
}

.btn-remove-stagiaire:hover {
    background: #f5c6c2;
}

.btn-add-row {
    padding: 8px 14px;
    border: 2px dashed #1a5eb8;
    border-radius: 4px;
    background: white;
    color: #1a5eb8;
    font-weight: 600;
    cursor: pointer;
}

.btn-add-row:hover {
    background: #eef4fc;
}

.signature-container {
    border: 2px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    background: white;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#signatureCanvas {
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: crosshair;
    background: white;
    display: block;
    max-width: 100%;
    height: auto;
    touch-action: none;
}

.btn-clear {
    margin-top: 10px;
    padding: 8px 16px;
    background: #ff6b6b;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.btn-clear:hover {
    background: #ff5252;
}

.form-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 30px;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, #4CAF50 0%, #388E3C 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #45a049 0%, #2e7d32 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(33, 150, 243, 0.3);
}

.btn-secondary:hover:not(:disabled) {
    background: linear-gradient(135deg, #0b7dda 0%, #1565C0 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(33, 150, 243, 0.4);
}

.btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.document-section {
    flex: 1;
    min-width: 300px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.document-a4 {
    width: 210mm;
    min-height: 297mm;
    background: white;
    padding: 15mm 20mm;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    border: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    position: relative;
}

.document-header {
    text-align: center;
    margin-bottom: 20px;
}

.header-image {
    width: 100%;
    max-width: 100%;
    height: auto;
    display: block;
}

.logo {
    max-width: 200px;
    height: auto;
}

.document-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.doc-type-badge {
    align-self: center;
    padding: 4px 16px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
    color: white;
}

.badge-livraison  { background: #2196F3; }
.badge-recette    { background: #4CAF50; }
.badge-formation  { background: #f5a623; }

.document-title {
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 30px;
    color: #333;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.document-text {
    text-align: justify;
    font-size: 14.5px;
    line-height: 1.8;
    margin-bottom: 25px;
    flex: 1;
    color: #333;
}

.section-container {
    margin: 20px 0;
}

.section-title {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a1b;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.equipment-list {
    background: #fdfdfd;
    padding: 15px 20px;
    border-radius: 6px;
    border-left: 4px solid #4CAF50;
    margin: 15px 0;
    page-break-inside: avoid;
}

.equipment-list p {
    margin-bottom: 5px !important;
}

.recette-status {
    background: #fdfdfd;
    padding: 12px 16px;
    border-radius: 6px;
    border-left: 4px solid #4CAF50;
}

.document-text p {
    margin-bottom: 12px;
    text-indent: 0;
}

.emis-par-line {
    font-style: italic;
    color: #555;
    font-size: 13.5px;
}

.field {
    border-bottom: 2px solid #333;
    padding: 0 5px;
    min-width: 150px;
    display: inline-block;
    font-weight: bold;
}

.document-date {
    text-align: right;
    margin: 25px 0 20px 0;
    font-size: 14px;
}

.signature-section {
    margin-top: 50px;
    margin-bottom: 30px;
    page-break-inside: avoid;
}

.signatures-container {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 60px;
    margin-top: 30px;
}

.signature-client {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.signature-xnova {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
}

.signature-label {
    font-weight: bold;
    margin-bottom: 15px;
    font-size: 14px;
    text-align: left;
}

.signature-xnova .signature-label {
    text-align: right;
}

.signature-display {
    display: inline-block;
    padding: 0;
    background: transparent;
    border: none;
}

#signatureDisplay {
    display: block;
    border: none;
    background: white;
}

.cachet-display {
    display: inline-block;
    padding: 0;
}

.cachet {
    max-width: 150px;
    height: auto;
    display: block;
}

/* --- Bloc QR de vérification --- */
.qr-block {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px dashed #ddd;
    display: flex;
    align-items: center;
    gap: 14px;
}

.qr-canvas-container {
    width: 90px;
    height: 90px;
    flex-shrink: 0;
}

.qr-canvas-container img,
.qr-canvas-container canvas {
    display: block;
    width: 90px;
    height: 90px;
}

.qr-caption {
    font-size: 11px;
    color: #888;
    line-height: 1.5;
}

.qr-reference {
    font-family: 'Courier New', monospace;
    font-weight: 700;
    color: #555;
}

.document-footer {
    text-align: center;
    margin-top: auto;
    padding-top: 20px;
}

.footer-image {
    width: 100%;
    max-width: 100%;
    height: auto;
    display: block;
}

@media print {
    body {
        background: white;
        padding: 0;
    }

    .form-section,
    .form-actions {
        display: none;
    }

    .document-a4 {
        box-shadow: none;
        border: none;
        margin: 0;
        padding: 20mm;
    }
}

@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }

    .document-a4 {
        width: 100%;
        min-height: auto;
    }

    .signatures-container {
        flex-direction: column;
        gap: 30px;
    }

    .signature-xnova {
        text-align: left;
    }

    .type-selector button {
        min-width: 100px;
        font-size: 12px;
    }
}
