/* ===== RESET ET BASE ===== */
* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin: 0;
    padding: 20px;
    padding-bottom: 70px;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: #fff;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

h1 {
    text-align: center;
    color: #2d3748;
    margin: 0 0 30px 0;
    font-size: 2em;
    font-weight: 700;
}

/* ===== ALERTES ===== */
.alert {
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
    line-height: 1.6;
}

.alert-error {
    background-color: #fee;
    border: 1px solid #fcc;
    color: #c33;
}

.alert-success {
    background-color: #efe;
    border: 1px solid #cfc;
    color: #393;
}

.alert p {
    margin: 5px 0;
}

/* ===== TEXTE CONDITIONS ===== */
.terms-notice {
    text-align: center;
    color: #4a5568;
    font-size: 14px;
    margin: 20px auto;
    max-width: 500px;
    line-height: 1.6;
}

.terms-notice a {
    color: #667eea;
    text-decoration: underline;
    font-weight: 600;
    transition: color 0.2s ease;
}

.terms-notice a:hover {
    color: #764ba2;
}

/* ===== UPLOAD BOX ===== */
.terms-text {
    text-align: center;
    margin: 20px auto 10px;
    max-width: 500px;
    font-size: 13px;
    color: #2d3748;
    line-height: 1.6;
}

.terms-text a {
    color: #667eea;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

.terms-text a:hover {
    color: #764ba2;
    text-decoration: underline;
}

.upload-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 3px dashed #667eea;
    border-radius: 12px;
    padding: 50px 30px;
    max-width: 500px;
    margin: 50px auto;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
}

.upload-box:hover {
    border-color: #764ba2;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

.file-label {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    width: 100%;
    padding: 15px 25px;
    margin-bottom: 20px;
    background-color: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.file-label:hover {
    background-color: #f7fafc;
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15);
}

.file-label input[type="file"] {
    display: none;
}

.file-text {
    font-size: 15px;
    color: #4a5568;
    font-weight: 500;
}

.upload-btn {
    padding: 14px 30px;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.upload-btn:active {
    transform: translateY(0);
}

/* ===== INFO BOX ===== */
.info-box {
    margin-top: 30px;
    padding: 25px;
    background: #f7fafc;
    border-radius: 10px;
    border-left: 4px solid #667eea;
}

.info-box h3 {
    margin: 0 0 15px 0;
    color: #2d3748;
    font-size: 18px;
}

.info-box ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.info-box li {
    padding: 8px 0;
    color: #4a5568;
    font-size: 15px;
}

/* ===== TOOLBAR ===== */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
    padding: 15px;
    background: #f7fafc;
    border-radius: 10px;
}

.toolbar-secondary {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
    padding: 10px 15px;
    background: #edf2f7;
    border-radius: 8px;
}

.toolbar button,
.toolbar-secondary button,
.toolbar #exportForm button,
.toolbar-secondary #exportForm button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    color: #fff;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.toolbar button:hover,
.toolbar-secondary button:hover,
.toolbar #exportForm button:hover,
.toolbar-secondary #exportForm button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.toolbar button:active,
.toolbar-secondary button:active,
.toolbar #exportForm button:active,
.toolbar-secondary #exportForm button:active {
    transform: translateY(0);
}

/* Boutons standards (Texte, Signature, Zoom) */
.toolbar button:not(.btn-export):not(.btn-newpdf) {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.toolbar button:not(.btn-export):not(.btn-newpdf):hover {
    background: linear-gradient(135deg, #5568d3 0%, #653a8b 100%);
}

/* Bouton actif (mode dessin) */
.toolbar button.active {
    background: linear-gradient(135deg, #f6ad55 0%, #ed8936 100%) !important;
    box-shadow: 0 0 0 3px rgba(237, 137, 54, 0.3);
}

.toolbar button.active:hover {
    background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%) !important;
}

/* Export vert */
.btn-export {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%) !important;
}

.btn-export:hover {
    background: linear-gradient(135deg, #38a169 0%, #2f855a 100%) !important;
}

/* Nouveau PDF orange */
.btn-newpdf {
    background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%) !important;
}

.btn-newpdf:hover {
    background: linear-gradient(135deg, #dd6b20 0%, #c05621 100%) !important;
}

/* Labels dans la toolbar */
.toolbar label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #4a5568;
}

/* Bouton Image qui ressemble aux autres boutons */
.btn-image {
    display: inline-flex !important;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    color: #fff !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.btn-image:hover {
    background: linear-gradient(135deg, #5568d3 0%, #653a8b 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.btn-image:active {
    transform: translateY(0);
}

.toolbar label span {
    white-space: nowrap;
}

.toolbar input[type="color"] {
    width: 40px;
    height: 40px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    cursor: pointer;
}

.toolbar select {
    padding: 8px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    background: white;
    cursor: pointer;
    transition: border-color 0.2s;
}

.toolbar select:hover {
    border-color: #667eea;
}

/* ===== SEPARATOR ===== */
.separator {
    height: 2px;
    background: linear-gradient(90deg, transparent, #e2e8f0, transparent);
    margin: 20px 0;
    width: 100%;
}

/* ===== NAVIGATION BUTTONS ===== */
.nav-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin: 20px 0;
}

.nav-buttons button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.nav-buttons button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.nav-buttons button:active:not(:disabled) {
    transform: translateY(0);
}

.nav-buttons button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #cbd5e0;
}

.page-info {
    font-size: 15px;
    font-weight: 600;
    color: #4a5568;
    padding: 8px 16px;
    background: #f7fafc;
    border-radius: 6px;
}

.bottom-nav {
    margin-top: 20px;
}

/* ===== ÉDITEUR PDF ===== */
#editor {
    position: relative;
    margin: 20px auto;
    display: block;
    overflow: visible;
    max-width: 100%;
    touch-action: none;
    background: #f0f0f0;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    text-align: center;
}

#pdfCanvas {
    border: 1px solid #cbd5e0;
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

#drawCanvas {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 5;
    cursor: crosshair;
}

/* ===== ÉLÉMENTS TEXTE ET SIGNATURE ===== */
.text-box,
.signature,
.imported-image {
    position: absolute;
    padding: 4px 8px;
    border: 2px dashed #667eea;
    cursor: move;
    background: rgba(255, 255, 255, 0.9);
    text-align: left;
    user-select: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.text-box:hover,
.signature:hover,
.imported-image:hover {
    border-color: #764ba2;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.text-box {
    min-width: 50px;
    width: auto !important;
    height: auto !important;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 90%;
}

.selected-mobile {
    outline: 3px solid #ed8936 !important;
    outline-offset: 2px;
}

.dragging {
    opacity: 0.7;
    cursor: grabbing !important;
}

/* Masquer les boutons zoom sur mobile */
.desktop-only {
    display: inline-flex;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
}

/* ===== BOUTON SUPPRIMER ===== */
.delete-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #f56565;
    color: #fff;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    border-radius: 50%;
    cursor: pointer;
    z-index: 30;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    user-select: none;
    pointer-events: auto;
}

.delete-btn:hover {
    background: #c53030;
    transform: scale(1.1);
}

/* ===== POIGNÉE DE REDIMENSIONNEMENT ===== */
.resize-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: #667eea;
    cursor: nwse-resize;
    border-radius: 50%;
    z-index: 25;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.resize-handle:hover {
    background: #764ba2;
    transform: scale(1.15);
}

/* ===== MODAL SIGNATURE ===== */
.modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    padding: 0;
    border-radius: 12px;
    z-index: 1000;
    flex-direction: column;
    align-items: center;
    max-width: 90%;
    touch-action: none;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
    width: 100%;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px 12px 0 0;
    text-align: center;
}

.modal-header h3 {
    margin: 0;
    color: white;
    font-size: 18px;
    font-weight: 600;
}

#signatureCanvas {
    border: 2px solid #e2e8f0;
    cursor: crosshair;
    background: white;
    margin: 20px;
    border-radius: 6px;
}

.signature-buttons {
    display: flex;
    gap: 10px;
    padding: 20px;
    width: 100%;
    justify-content: center;
    background: #f7fafc;
    border-radius: 0 0 12px 12px;
}

.signature-buttons button {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.btn-validate {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
}

.btn-validate:hover {
    background: linear-gradient(135deg, #38a169 0%, #2f855a 100%);
    transform: translateY(-1px);
}

.btn-clear {
    background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%);
    color: white;
}

.btn-clear:hover {
    background: linear-gradient(135deg, #dd6b20 0%, #c05621 100%);
    transform: translateY(-1px);
}

.btn-cancel {
    background: #e2e8f0;
    color: #4a5568;
}

.btn-cancel:hover {
    background: #cbd5e0;
    transform: translateY(-1px);
}

/* ===== FOOTER FIXE ===== */
.footer-fixed {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 14px;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}
.footer-fixed a {
    color: #ffffff;
    text-decoration: none;
}
.footer-fixed a:hover {
    text-decoration: underline;
}

.footer-left {
    font-weight: 600;
}

.footer-right {
    font-weight: 500;
    transition: opacity 0.5s ease-in-out;
}

/* ===== RESPONSIVE MOBILE ===== */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        padding: 20px;
        border-radius: 8px;
    }

    h1 {
        font-size: 1.5em;
        margin-bottom: 20px;
    }

    .toolbar {
        flex-direction: column;
        gap: 8px;
        padding: 12px;
    }
    
    .toolbar-secondary {
        flex-direction: column;
        gap: 8px;
        padding: 10px;
    }

    .toolbar button,
    .toolbar-secondary button,
    .toolbar #exportForm button,
    .toolbar-secondary #exportForm button,
    .toolbar label {
        width: 100%;
        justify-content: center;
    }

    /* Boutons de navigation côte à côte sur mobile */
    .nav-buttons {
        flex-direction: row !important;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: space-between;
    }

    .nav-buttons button {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
        max-width: calc(50% - 4px);
    }
    
    .nav-buttons .page-info {
        flex: 1 1 100%;
        text-align: center;
        order: -1;
        margin-bottom: 5px;
    }

    #editor {
        width: 100%;
        max-width: 100%;
    }

    #pdfCanvas {
        width: 100% !important;
        height: auto !important;
    }

    .modal {
        width: 95%;
        max-width: 95%;
    }

    #signatureCanvas {
        margin: 15px;
    }

    .signature-buttons {
        flex-direction: column;
        padding: 15px;
    }

    .signature-buttons button {
        width: 100%;
    }

    .upload-box {
        padding: 30px 20px;
        margin: 30px auto;
    }

    .file-text {
        font-size: 14px;
        text-align: center;
    }
    
    .footer-fixed {
        flex-direction: column;
        gap: 5px;
        padding: 10px 15px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 15px;
    }

    h1 {
        font-size: 1.3em;
    }

    .toolbar button,
    .nav-buttons button {
        font-size: 13px;
        padding: 8px 14px;
    }

    .info-box {
        padding: 15px;
    }

    .info-box li {
        font-size: 14px;
    }
}

/* ===== GESTION DES PAGES ===== */
.modal-large {
    width: 90%;
    max-width: 1000px;
    max-height: 90vh;
}

.modal-large .page-manager-content {
    max-height: 60vh;
    overflow-y: auto;
    padding: 20px;
}

.modal-close {
    position: absolute;
    right: 15px;
    top: 15px;
    background: none;
    border: none;
    color: white;
    font-size: 30px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
}

.modal-close:hover {
    opacity: 0.7;
}

.pages-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.page-item {
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    padding: 15px;
    background: white;
    transition: all 0.2s;
}

.page-item:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.page-preview {
    position: relative;
    margin-bottom: 15px;
    text-align: center;
}

.page-preview-canvas {
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    max-width: 100%;
    height: auto;
}

.page-number {
    margin-top: 10px;
    font-weight: 600;
    color: #4a5568;
    font-size: 14px;
}

.rotation-indicator {
    position: absolute;
    top: 5px;
    right: 5px;
    background: #667eea;
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.page-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 5px;
}

.page-actions button {
    padding: 8px;
    font-size: 14px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    transition: all 0.2s;
}

.page-actions button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.page-actions button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-delete-page {
    background: linear-gradient(135deg, #f56565 0%, #c53030 100%) !important;
}

.btn-delete-page:hover {
    box-shadow: 0 4px 8px rgba(245, 101, 101, 0.3) !important;
}

.btn-page-manager {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%) !important;
}

.btn-page-manager:hover {
    background: linear-gradient(135deg, #38a169 0%, #2f855a 100%) !important;
}

@media (max-width: 768px) {
    .modal-large {
        width: 95%;
        max-height: 95vh;
    }
    
    .pages-list {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 15px;
    }
    
    .page-item {
        padding: 10px;
    }
    
    .page-actions {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    
    .page-actions button {
        padding: 10px;
        font-size: 16px;
    }
}
