/* Variables CSS */
:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #059669;
    --danger-color: #dc2626;
    --warning-color: #d97706;
    --light-gray: #f8fafc;
    --medium-gray: #e2e8f0;
    --dark-gray: #475569;
    --border-radius: 12px;
    --box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
}

/* Reset et base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: var(--dark-gray);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
    background: white;
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

header h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 10px;
    font-weight: 700;
}

header p {
    font-size: 1.2rem;
    color: var(--secondary-color);
}

/* Main content */
main {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 40px;
    margin-bottom: 20px;
}

/* Upload section */
.upload-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 40px;
}

.upload-zone {
    position: relative;
    border: 3px dashed var(--medium-gray);
    border-radius: var(--border-radius);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-zone:hover {
    border-color: var(--primary-color);
    background-color: var(--light-gray);
}

.upload-zone.dragover {
    border-color: var(--primary-color);
    background-color: #dbeafe;
    transform: scale(1.02);
}

.upload-content .upload-icon {
    font-size: 3rem;
    margin-bottom: 20px;
}

.upload-content h3 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 1.4rem;
}

.upload-content p {
    color: var(--secondary-color);
    font-size: 1rem;
}


/* Preview */
.preview {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: var(--border-radius);
    overflow: hidden;
}

.preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: var(--light-gray);
    image-rendering: crisp-edges;
    image-rendering: -webkit-optimize-contrast;
}

.edit-btn, .remove-btn {
    position: absolute;
    top: 10px;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: white;
}

.edit-btn {
    right: 60px;
    background: var(--primary-color);
}

.edit-btn:hover {
    background: #1d4ed8;
    transform: scale(1.1);
}

.remove-btn {
    right: 10px;
    background: var(--danger-color);
}

.remove-btn:hover {
    background: #b91c1c;
    transform: scale(1.1);
}

/* Modal d'édition simple */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: var(--border-radius);
    padding: 30px;
    max-width: 90vw;
    max-height: 90vh;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.modal-header h3 {
    color: var(--primary-color);
    margin-bottom: 5px;
}

.modal-subtitle {
    color: var(--secondary-color);
    font-size: 0.9rem;
    margin-bottom: 25px;
    display: block;
}

.modal-workspace {
    position: relative;
    display: inline-block;
    margin-bottom: 20px;
    border: 2px solid var(--medium-gray);
    border-radius: var(--border-radius);
    overflow: hidden;
}

#modal-canvas {
    display: block;
    background: white;
    max-width: 100%;
    height: auto;
    image-rendering: crisp-edges;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: pixelated;
}

.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.crop-selection {
    position: absolute;
    border: 2px dashed var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
    pointer-events: all;
    cursor: move;
    min-width: 50px;
    min-height: 50px;
    touch-action: none;
}

.crop-handle {
    position: absolute;
    width: 24px;
    height: 24px;
    background: var(--primary-color);
    border: 2px solid white;
    border-radius: 50%;
    margin: -12px;
    touch-action: none;
}

.crop-handle.nw { top: 0; left: 0; cursor: nw-resize; }
.crop-handle.ne { top: 0; right: 0; cursor: ne-resize; }
.crop-handle.sw { bottom: 0; left: 0; cursor: sw-resize; }
.crop-handle.se { bottom: 0; right: 0; cursor: se-resize; }

.modal-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 25px;
}

.modal-controls .btn-rotate {
    background: var(--medium-gray);
    border: none;
    border-radius: 8px;
    padding: 12px 16px;
    cursor: pointer;
    font-size: 1.5rem;
    transition: var(--transition);
    min-width: 60px;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dark-gray);
}

.modal-controls .btn-rotate:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
}

.modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

/* PDF Preview Modal */
.pdf-preview {
    max-width: 95vw;
    max-height: 95vh;
    width: auto;
}

.pdf-preview-workspace {
    display: flex;
    justify-content: center;
    margin-bottom: 25px;
    background: #f5f5f5;
    padding: 20px;
    border-radius: var(--border-radius);
}

#pdf-preview-canvas {
    max-width: 100%;
    max-height: 70vh;
    border: 1px solid var(--medium-gray);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background: white;
    image-rendering: crisp-edges;
    image-rendering: -webkit-optimize-contrast;
}

/* Processing section */
.processing-section {
    text-align: center;
    padding: 30px;
    background: var(--light-gray);
    border-radius: var(--border-radius);
    margin-bottom: 30px;
}

.processing-section h3 {
    color: var(--warning-color);
    margin-bottom: 20px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--medium-gray);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 15px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--success-color));
    width: 0%;
    transition: width 0.3s ease;
}

#processing-text {
    color: var(--secondary-color);
    font-size: 1rem;
}

/* Result section */
.result-section {
    margin-bottom: 30px;
}

.result-section h3 {
    color: var(--success-color);
    margin-bottom: 20px;
    text-align: center;
}

.result-preview {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

.result-card {
    text-align: center;
}

.result-card h4 {
    color: var(--dark-gray);
    margin-bottom: 15px;
    font-size: 1.2rem;
}

.result-card canvas {
    width: 100%;
    max-width: 300px;
    height: auto;
    border: 2px solid var(--medium-gray);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

/* Rotation controls */
.rotation-controls {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.btn-rotate {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-rotate:hover {
    background: #1d4ed8;
    transform: scale(1.1) rotate(15deg);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn-rotate:active {
    transform: scale(0.95) rotate(90deg);
}

.rotation-info {
    font-size: 0.85rem;
    color: var(--secondary-color);
    text-align: center;
    font-style: italic;
}

/* Actions */
.actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 40px;
    flex-wrap: wrap;
}

/* Buttons */
.btn-primary,
.btn-success,
.btn-secondary {
    padding: 15px 30px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 180px;
    justify-content: center;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #1d4ed8;
    transform: translateY(-2px);
}

.btn-primary:disabled {
    background: var(--medium-gray);
    color: var(--secondary-color);
    cursor: not-allowed;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: #047857;
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--medium-gray);
    color: var(--dark-gray);
}

.btn-secondary:hover {
    background: var(--secondary-color);
    color: white;
    transform: translateY(-2px);
}

/* Instructions */
.instructions {
    background: var(--light-gray);
    padding: 30px;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
}

.instructions h3 {
    color: var(--warning-color);
    margin-bottom: 20px;
    text-align: center;
}

.instructions ul {
    list-style: none;
    max-width: 600px;
    margin: 0 auto;
}

.instructions li {
    padding: 10px 0;
    padding-left: 30px;
    position: relative;
    color: var(--dark-gray);
}

.instructions li:before {
    content: '✓';
    position: absolute;
    left: 0;
    color: var(--success-color);
    font-weight: bold;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: var(--border-radius);
    color: var(--secondary-color);
}

/* Mobile breakpoints */

/* Très petits mobiles */
@media (max-width: 480px) {
    .container {
        padding: 10px;
    }
    
    header {
        padding: 20px;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    main {
        padding: 15px;
    }
    
    .upload-zone {
        padding: 30px 10px;
        min-height: 280px;
    }
    
    .upload-content .upload-icon {
        font-size: 3.5rem;
    }
    
    .upload-content h3 {
        font-size: 1.4rem;
    }
    
    .upload-content p {
        font-size: 1rem;
    }
    
    .camera-btn {
        padding: 10px 20px;
        font-size: 1rem;
    }
    
    .edit-btn, .remove-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    
    .edit-btn {
        right: 55px;
    }
}

/* Mobiles standards */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    main {
        padding: 25px;
    }
    
    .upload-section {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .result-preview {
        grid-template-columns: 1fr;
    }
    
    /* Modal mobile full-screen */
    .modal-content {
        max-width: 100vw;
        max-height: 100vh;
        width: 100vw;
        height: 100vh;
        margin: 0;
        border-radius: 0;
        padding: 15px;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .modal-workspace {
        max-width: 100%;
        overflow: hidden;
    }
    
    #modal-canvas {
        max-width: 95vw;
        max-height: 45vh;
        touch-action: none; /* Prévient le scroll lors du drag */
    }
    
    
    .modal-controls {
        gap: 20px;
        margin-bottom: 20px;
    }
    
    .modal-controls .btn-rotate {
        min-width: 70px;
        min-height: 70px;
        font-size: 1.8rem;
    }
    
    /* PDF Preview mobile */
    .pdf-preview {
        max-width: 100vw;
        max-height: 100vh;
        width: 100vw;
        height: 100vh;
        margin: 0;
        border-radius: 0;
        padding: 10px;
    }
    
    .pdf-preview-workspace {
        padding: 10px;
        margin-bottom: 15px;
    }
    
    #pdf-preview-canvas {
        max-height: 60vh;
    }
    
    .pdf-preview .modal-actions {
        flex-direction: column;
        gap: 15px;
    }
    
    .pdf-preview .modal-actions button {
        width: 100%;
        max-width: 300px;
        margin: 0 auto;
    }
    
    .actions {
        flex-direction: column;
        align-items: center;
    }
    
    .btn-primary,
    .btn-success,
    .btn-secondary {
        width: 100%;
        max-width: 280px;
    }
}

/* Tablettes */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: 20px;
    }
    
    .upload-section {
        grid-template-columns: 1fr 1fr;
        gap: 25px;
    }
    
    .modal-content {
        max-width: 85vw;
        max-height: 85vh;
        padding: 25px;
    }
    
    .modal-controls .btn-rotate {
        min-width: 55px;
        min-height: 55px;
    }
}

/* Amélioration pour tous les écrans tactiles */
@media (pointer: coarse) {
    .btn-primary, .btn-success, .btn-secondary {
        min-height: 48px;
        padding: 16px 32px;
    }
    
    .modal-controls .btn-rotate {
        min-width: 64px;
        min-height: 64px;
    }
    
    .edit-btn, .remove-btn {
        width: 48px;
        height: 48px;
    }
}

@media (max-width: 480px) {
    header {
        padding: 20px;
    }
    
    main {
        padding: 20px;
    }
    
    .upload-zone {
        padding: 40px 15px;
        min-height: 300px;
    }
    
    .upload-content .upload-icon {
        font-size: 4rem;
    }
    
    .upload-content h3 {
        font-size: 1.6rem;
        margin-bottom: 15px;
    }
    
    .upload-content p {
        font-size: 1.1rem;
        line-height: 1.4;
    }
    
    
    .instructions {
        padding: 20px;
    }
}

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

.processing-section {
    animation: pulse 2s ease-in-out infinite;
}

/* Accessibilité */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}