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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    touch-action: manipulation; /* Améliore les performances tactiles */
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 10px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 15px 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

header h1 {
    color: #333;
    font-size: 1.5rem;
}

.file-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

#fileInput {
    padding: 8px;
    border: 2px dashed #ddd;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
}

#saveBtn {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
}

#saveBtn:hover {
    background: #45a049;
}

.editor-layout {
    display: flex;
    gap: 15px;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    flex-direction: row;
}

.toolbar {
    width: 280px;
    padding: 15px;
    background: #fafafa;
    border-right: 1px solid #eee;
    max-height: 80vh;
    overflow-y: auto;
    flex-shrink: 0;
}

.tool-section {
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.tool-section:last-child {
    border-bottom: none;
}

.tool-section h3 {
    margin-bottom: 12px;
    color: #333;
    font-size: 15px;
}

/* AJOUTÉ : Styles pour l'historique */
.history-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.history-btn {
    padding: 8px 12px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s;
    flex: 1;
}

.history-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.history-btn:not(:disabled):hover {
    background: #f0f0f0;
}

.tool-section small {
    color: #666;
    font-size: 11px;
}

.tool-btn, .apply-btn, .cancel-btn, .rotate-btn, .filter-btn, .reset-btn {
    padding: 8px 12px;
    margin: 4px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 13px;
    touch-action: manipulation;
}

.tool-btn:hover, .rotate-btn:hover, .filter-btn:hover {
    background: #f0f0f0;
}

.tool-btn.active {
    background: #2196F3;
    color: white;
    border-color: #2196F3;
}

.brush-controls {
    margin-top: 12px;
}

.brush-controls label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
}

.brush-controls input[type="color"] {
    width: 40px;
    height: 25px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

.brush-controls input[type="range"] {
    width: 100%;
    margin-top: 5px;
}

.rotation-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.adjustments-section .adjustment {
    margin-bottom: 12px;
}

.adjustment label {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
}

.adjustment input[type="range"] {
    width: 100%;
    margin-bottom: 3px;
}

.adjustment .value {
    font-weight: bold;
    color: #666;
    font-size: 12px;
}

/* AJOUTÉ : Grille pour les filtres */
.filters-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.apply-btn {
    background: #4CAF50;
    color: white;
    border-color: #4CAF50;
}

.cancel-btn {
    background: #f44336;
    color: white;
    border-color: #f44336;
}

.reset-btn {
    background: #ff9800;
    color: white;
    border-color: #ff9800;
    width: 100%;
    padding: 10px;
    font-weight: bold;
}

.zoom-controls button {
    min-width: 60px;
    font-size: 12px;
}
.canvas-container {
    flex: 1;
    padding: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    min-height: 60vh;
    overflow: auto;
    /* Centrer parfaitement */
    text-align: center;
    cursor: grab; /* Curseur pour indiquer qu'on peut déplacer */
}
.canvas-container.panning {
    cursor: grabbing;
}

#canvas {
    max-width: 100%;
    max-height: 70vh;
    border: 1px solid #ddd;
    cursor: crosshair;
    /* Désactive le scroll pour le dessin tactile */
    touch-action: none;
    /* Éviter la déformation */
    object-fit: contain;
    display: block;
    transform-origin: 0 0; /* Très important */
    /* IMPORTANT : Ne pas forcer de hauteur fixe */
    width: auto !important;
    height: auto !important;
}

.crop-box {
    position: absolute;
    border: 2px dashed #2196F3;
    background: rgba(33, 150, 243, 0.1);
    cursor: move;
}

.crop-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #2196F3;
    border: 2px solid white;
    border-radius: 50%;
}

.crop-handle.top-left {
    top: -7px;
    left: -7px;
    cursor: nw-resize;
}

.crop-handle.top-right {
    top: -7px;
    right: -7px;
    cursor: ne-resize;
}

.crop-handle.bottom-left {
    bottom: -7px;
    left: -7px;
    cursor: sw-resize;
}

.crop-handle.bottom-right {
    bottom: -7px;
    right: -7px;
    cursor: se-resize;
}

.filter-btn.active {
    background: #9C27B0;
    color: white;
    border-color: #9C27B0;
}

/* RESPONSIVE DESIGN */
@media (max-width: 768px) {
    .container {
        padding: 5px;
    }

    header {
        padding: 10px 15px;
        text-align: center;
    }

    header h1 {
        font-size: 1.3rem;
        width: 100%;
        margin-bottom: 10px;
    }

    .file-controls {
        width: 100%;
        justify-content: center;
    }

    .editor-layout {
        flex-direction: column;
        gap: 0;
    }

    .toolbar {
        width: 100%;
        max-height: none;
        order: 2;
        padding: 10px;
    }

    .canvas-container {
        order: 1;
        min-height: 50vh;
        padding: 10px;
    }

    #canvas {
        max-height: 50vh;
    }

    .tool-section {
        margin-bottom: 15px;
        padding-bottom: 10px;
    }

    .tool-section h3 {
        font-size: 14px;
        margin-bottom: 8px;
        display: none;
    }

    .history-controls {
        flex-direction: column;
        flex-direction: unset;
        gap: 5px;
    }

    .rotation-buttons {
        grid-template-columns: 1fr 1fr 1fr 1fr;
        gap: 5px;
    }

    .filters-grid {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 4px;
    }

    .crop-handle {
        width: 16px;
        height: 16px;
    }

    .crop-handle.top-left, .crop-handle.top-right,
    .crop-handle.bottom-left, .crop-handle.bottom-right {
        top: -8px;
        right: -8px;
        bottom: -8px;
        left: -8px;
    }
}

@media (max-width: 480px) {
    .toolbar {
        padding: 8px;
    }

    .tool-btn, .apply-btn, .cancel-btn, .rotate-btn, .filter-btn, .reset-btn {
        padding: 6px 8px;
        font-size: 12px;
        margin: 2px;
    }

    .brush-controls input[type="range"], .adjustment input[type="range"] {
        height: 20px;
    }

    .rotation-buttons {
        grid-template-columns: 1fr 1fr;
        gap: 4px;
    }

    .filters-grid {
        grid-template-columns: 1fr 1fr;
        gap: 3px;
    }
}

/* Amélioration pour les appareils tactiles */
@media (hover: none) and (pointer: coarse) {
    .tool-btn, .apply-btn, .cancel-btn, .rotate-btn, .filter-btn, .reset-btn {
        min-height: 44px; /* Taille minimum tactile recommandée */
        padding: 10px;
    }

    .crop-handle {
        width: 20px;
        height: 20px;
    }

    input[type="range"] {
        height: 30px;
    }
}
