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

html, body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    height: 100vh;
    overflow: hidden;
    color: #333;
    padding: 20px 15px;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
    height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* En-tête */
.header {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    padding: 25px 20px;
    text-align: center;
    flex-shrink: 0;
    border-radius: 16px 16px 0 0;
}

.header h1 {
    font-size: 2em;
    margin-bottom: 5px;
    font-weight: 700;
}

.header p {
    font-size: 1em;
    opacity: 0.95;
}

/* Barre de progression */
.progress-container {
    background: #f8f9fa;
    padding: 15px 20px;
    border-bottom: 2px solid #e9ecef;
    flex-shrink: 0;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #1e3c72 0%, #2a5298 100%);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 10px;
}

.progress-text {
    text-align: center;
    font-size: 0.9em;
    color: #666;
    font-weight: 600;
}

/* Contenu principal - zone scrollable unique */
.content {
    padding: 30px 40px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

#contentArea .doc-step {
    display: none;
    animation: fadeIn 0.4s ease;
}

#contentArea .doc-step.active {
    display: block;
}

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

.doc-step h2 {
    color: #1e3c72;
    font-size: 1.8em;
    margin-bottom: 20px;
    border-bottom: 3px solid #2a5298;
    padding-bottom: 10px;
}

.doc-step h3 {
    color: #2a5298;
    font-size: 1.3em;
    margin-top: 20px;
    margin-bottom: 10px;
}

.doc-step p {
    line-height: 1.8;
    margin-bottom: 15px;
    color: #444;
}

.doc-step ul, .doc-step ol {
    margin-left: 25px;
    margin-bottom: 15px;
}

.doc-step li {
    margin-bottom: 10px;
    line-height: 1.7;
    color: #444;
}

.doc-step strong {
    color: #1e3c72;
    font-weight: 600;
}

.zone-box {
    background: #f8f9fa;
    border-left: 5px solid #2a5298;
    padding: 15px;
    margin: 15px 0;
    border-radius: 5px;
}

.zone-rouge { border-left-color: #dc3545; background: #ffe9eb; }
.zone-orange { border-left-color: #fd7e14; background: #fff3e0; }
.zone-vert { border-left-color: #28a745; background: #e8f5e9; }

.table-responsive {
    overflow-x: auto;
    margin: 20px 0;
}

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

.table-responsive th {
    background: #1e3c72;
    color: white;
    padding: 12px;
    text-align: left;
    font-weight: 600;
}

.table-responsive td {
    padding: 12px;
    border-bottom: 1px solid #e9ecef;
}

/* Récapitulatif des outils */
.tools-recap {
    background: #f8f9fa;
    padding: 20px;
    margin-top: 20px;
    border-radius: 8px;
}

.tools-recap h3 {
    color: #1e3c72;
    margin-bottom: 15px;
}

.tool-item {
    background: white;
    padding: 12px;
    margin-bottom: 10px;
    border-left: 4px solid #2a5298;
    border-radius: 4px;
}

.tool-name { font-weight: 600; color: #1e3c72; }
.tool-category { font-size: 0.9em; color: #666; margin-top: 3px; }

/* Pied de page fixe avec signature + navigation */
.footer {
    background: #f8f9fa;
    padding: 15px 20px;
    border-top: 2px solid #e9ecef;
    flex-shrink: 0;
}

.signature-section {
    margin-bottom: 15px;
}

.signature-section h3 {
    color: #1e3c72;
    margin-bottom: 15px;
    font-size: 1.3em;
}

.signature-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

.input-group {
    display: flex;
    flex-direction: column;
}

.input-group label {
    font-weight: 600;
    color: #333;
    margin-bottom: 6px;
    font-size: 0.95em;
}

.input-group input {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1em;
    transition: border-color 0.3s;
}

.input-group input:focus {
    outline: none;
    border-color: #2a5298;
    box-shadow: 0 0 5px rgba(42, 82, 152, 0.2);
}

.signature-canvas-container {
    border: 2px dashed #ccc;
    border-radius: 8px;
    padding: 10px;
    background: #fafbfc;
    margin-bottom: 10px;
}

.signature-canvas-container p {
    font-size: 0.85em;
    color: #666;
    margin-bottom: 8px;
    font-weight: 500;
}

#signaturePad {
    display: block;
    border: 1px solid #ccc;
    border-radius: 5px;
    cursor: crosshair;
    width: 100%;
    height: 120px;
    background: white;
    touch-action: none;
}

.signature-buttons {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 5px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-secondary { background: #6c757d; color: white; }
.btn-secondary:hover { background: #5a6268; }

/* Navigation fixe en bas */
.navigation {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
}

.scroll-hint {
    display: none;
    color: #888;
    font-size: 0.85em;
    text-align: center;
    flex: 1;
    animation: pulse 1.5s ease-in-out infinite;
}

.scroll-hint.visible {
    display: block;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.btn-primary {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #152a54 0%, #1f4070 100%);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(30, 60, 114, 0.3);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-success { background: #28a745; color: white; }

.btn-success:hover:not(:disabled) {
    background: #218838;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(40, 167, 69, 0.3);
}

.btn-success:disabled { opacity: 0.6; cursor: not-allowed; }

/* Modal de confirmation */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 30px;
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-content h2 { color: #1e3c72; margin-bottom: 15px; }
.modal-content p { color: #666; margin-bottom: 15px; line-height: 1.6; }

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.confirmation-check {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.confirmation-check input[type="checkbox"] {
    width: 20px; height: 20px;
    cursor: pointer;
}

.confirmation-check label {
    cursor: pointer;
    flex: 1;
    color: #333;
}

.confirmation-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    border-left: 5px solid #2a5298;
    margin-bottom: 15px;
}

.confirmation-section .confirmation-check { margin-bottom: 0; }
.confirmation-section .confirmation-check input[type="checkbox"] {
    width: 22px; height: 22px;
    accent-color: #2a5298;
}
.confirmation-section .confirmation-check label {
    font-size: 1em;
    font-weight: 500;
    color: #1e3c72;
    line-height: 1.5;
}

/* Responsive */
@media (max-width: 768px) {
    .header h1 { font-size: 1.5em; }
    .header { padding: 15px; }
    .content { padding: 20px; }
    .signature-inputs { grid-template-columns: 1fr; }
    .navigation { flex-direction: column; }
    .btn { width: 100%; text-align: center; }
    .doc-step h2 { font-size: 1.4em; }
    .doc-step h3 { font-size: 1.1em; }
    #signaturePad { height: 100px; }
    .scroll-hint { order: -1; width: 100%; }
}

@media (max-width: 768px) {
    html, body {
        padding: 10px 8px;
    }
    .container {
        height: calc(100vh - 20px);
        border-radius: 12px;
    }
    .header {
        border-radius: 12px 12px 0 0;
    }
}

/* Scrollbar personnalisée */
.content::-webkit-scrollbar { width: 8px; }
.content::-webkit-scrollbar-track { background: #f1f1f1; }
.content::-webkit-scrollbar-thumb { background: #888; border-radius: 10px; }
.content::-webkit-scrollbar-thumb:hover { background: #555; }

.success-message {
    display: none;
    background: #d4edda;
    color: #155724;
    padding: 12px;
    border-radius: 5px;
    margin-bottom: 10px;
    border-left: 4px solid #28a745;
}

.success-message.show {
    display: block;
    animation: slideDown 0.3s ease;
}

/* Écran d'accueil email */
.email-gate {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 40px;
    text-align: center;
}

.email-gate h2 { color: #1e3c72; margin-bottom: 10px; font-size: 1.5em; }
.email-gate p { color: #666; margin-bottom: 30px; }

.email-gate .input-group {
    max-width: 400px;
    width: 100%;
    margin: 0 auto 20px;
    text-align: left;
}

.email-gate .input-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #1e3c72;
}

.email-gate .input-group input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1em;
    transition: border-color 0.3s;
}

.email-gate .input-group input:focus {
    border-color: #2a5298;
    outline: none;
}

.email-error {
    color: #dc3545;
    margin-bottom: 15px;
    display: none;
    font-weight: 500;
}

.email-info {
    color: #856404;
    background: #fff3cd;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    display: none;
    border-left: 4px solid #ffc107;
    max-width: 400px;
}

.email-spinner {
    display: none;
    margin: 15px auto;
}

.email-spinner::after {
    content: '';
    display: inline-block;
    width: 24px; height: 24px;
    border: 3px solid #ddd;
    border-top-color: #2a5298;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.charter-content {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
}

.charter-content.visible {
    display: flex;
}

/* Message d'erreur backend */
.backend-error {
    display: none;
    background: #f8d7da;
    color: #721c24;
    padding: 12px;
    border-radius: 5px;
    margin-bottom: 10px;
    border-left: 4px solid #dc3545;
}

.backend-error.show {
    display: block;
}

/* Écran déjà signé */
.already-signed {
    display: none;
    flex: 1;
    flex-direction: column;
    padding: 30px;
    overflow: hidden;
}

.already-signed.visible {
    display: flex;
}

.already-signed-header {
    text-align: center;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.already-signed-header h2 {
    color: #28a745;
    font-size: 1.4em;
    margin-bottom: 8px;
}

.already-signed-header p {
    color: #666;
    font-size: 0.95em;
}

.pdf-viewer {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    min-height: 0;
}

.pdf-viewer iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.already-signed-actions {
    margin-top: 15px;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-shrink: 0;
}

/* Identité de la session : sur une charte, savoir sous quel compte on
   s'apprête à signer fait partie de la signature elle-même. */
.session-bar {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 8px 14px;
    background: #eef2f8;
    border-bottom: 1px solid #dde4ef;
    color: #1e3c72;
    font-size: 0.88em;
    flex-shrink: 0;
}

.session-bar.visible { display: flex; }

.session-bar button {
    background: none;
    border: none;
    color: #2a5298;
    text-decoration: underline;
    cursor: pointer;
    font-size: 1em;
    padding: 0;
}

.link-sent-icon { font-size: 2.6em; margin-bottom: 10px; }

/* --- Portail : liste des documents --- */
.portal {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
}

.portal.visible { display: flex; }

.portal-body {
    flex: 1;
    overflow-y: auto;
    padding: 30px 40px;
}

.portal-body > h2 { color: #1e3c72; font-size: 1.4em; margin-bottom: 6px; }
.portal-body > p { color: #666; margin-bottom: 24px; }

.doc-cards {
    display: grid;
    gap: 16px;
}

.doc-card {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 18px 20px;
    border: 1px solid #dde4ef;
    border-left: 5px solid #2a5298;
    border-radius: 10px;
    background: #fff;
}

.doc-card.status-signe { border-left-color: #28a745; }
.doc-card.status-a_signer,
.doc-card.status-nouvelle_version { border-left-color: #fd7e14; }

.doc-card-icon { font-size: 2em; flex-shrink: 0; }
.doc-card-main { flex: 1; min-width: 0; }
.doc-card-main h3 { color: #1e3c72; font-size: 1.15em; margin-bottom: 4px; }
.doc-card-meta { color: #666; font-size: 0.88em; margin-bottom: 8px; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.8em;
    font-weight: 600;
}

.badge-signe { background: #d4edda; color: #155724; }
.badge-a_signer { background: #fff3cd; color: #856404; }
.badge-nouvelle_version { background: #ffe5d0; color: #8a3c00; }
.badge-inconnu { background: #e9ecef; color: #495057; }

.doc-card-status { color: #555; font-size: 0.88em; margin-top: 6px; }
.doc-card-action { flex-shrink: 0; }

.back-link {
    background: none;
    border: none;
    color: #2a5298;
    text-decoration: underline;
    cursor: pointer;
    font-size: 1em;
    padding: 0;
}

/* Barre de session : bouton retour aligné à gauche */
.session-bar .back-link { margin-right: auto; }

.extra-input { grid-column: span 2; }

@media (max-width: 768px) {
    .portal-body { padding: 20px; }
    .doc-card { flex-direction: column; align-items: stretch; text-align: left; }
    .doc-card-icon { display: none; }
    .extra-input { grid-column: auto; }
}

/* --- PDF généré (html2pdf) ---
   Le PDF est construit à partir du MÊME content.html que l'écran : le texte
   signé est exactement le texte lu. Ces règles compactent la mise en page. */
.pdf-doc {
    background: white;
    color: #333;
    font-family: Arial, sans-serif;
    font-size: 10.5px;
    line-height: 1.45;
    width: 170mm;
}

.pdf-doc .pdf-head {
    text-align: center;
    padding: 18px 15px 22px;
    border-bottom: 3px solid #1e3c72;
}

.pdf-doc .pdf-head h1 { color: #1e3c72; margin: 0 0 4px; font-size: 24px; font-weight: bold; }
.pdf-doc .pdf-head .pdf-firm { color: #555; margin: 2px 0; font-size: 14px; font-weight: 600; }
.pdf-doc .pdf-head .pdf-sub { color: #888; margin: 2px 0; font-size: 10px; }

.pdf-doc .pdf-body { padding: 10px 18px; }

.pdf-doc .doc-step { display: block; }
.pdf-doc .doc-step h2 {
    color: #1e3c72;
    font-size: 13px;
    margin: 14px 0 6px;
    border-bottom: 2px solid #2a5298;
    padding-bottom: 4px;
    page-break-after: avoid;
}
.pdf-doc .doc-step h3 { color: #2a5298; font-size: 11px; margin: 10px 0 4px; page-break-after: avoid; }
.pdf-doc .doc-step p { text-align: justify; margin: 4px 0; line-height: 1.45; color: #333; }
.pdf-doc .doc-step ul, .pdf-doc .doc-step ol { margin: 4px 0 4px 18px; }
.pdf-doc .doc-step li { margin: 2px 0; line-height: 1.45; color: #333; page-break-inside: avoid; }
.pdf-doc .doc-step strong { color: #1e3c72; }
.pdf-doc .zone-box { padding: 8px 10px; margin: 8px 0; page-break-inside: avoid; }
.pdf-doc .tools-recap { padding: 8px 10px; margin-top: 8px; }
.pdf-doc .tools-recap h3 { margin-bottom: 6px; }
.pdf-doc .tool-item { padding: 5px 8px; margin-bottom: 4px; page-break-inside: avoid; }
.pdf-doc .table-responsive { overflow: visible; margin: 8px 0; }
.pdf-doc table { font-size: 9.5px; }
.pdf-doc tr { page-break-inside: avoid; }

.pdf-doc .pdf-sign {
    padding: 15px 18px;
    margin-top: 8px;
    border-top: 3px solid #1e3c72;
    page-break-inside: avoid;
}
.pdf-doc .pdf-sign h2 {
    color: #1e3c72;
    font-size: 14px;
    margin: 0 0 10px;
    border-bottom: 2px solid #2a5298;
    padding-bottom: 4px;
}
.pdf-doc .pdf-sign p { margin: 6px 0; }
.pdf-doc .pdf-sign img { max-width: 280px; height: auto; max-height: 110px; border: 1px solid #333; padding: 4px; }
.pdf-doc .pdf-engagement { margin-top: 15px; padding-top: 10px; border-top: 1px solid #ccc; font-size: 9px; text-align: justify; }
.pdf-doc .pdf-foot { padding: 6px 15px; border-top: 1px solid #e0e0e0; font-size: 8px; color: #999; text-align: center; }
