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

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Conteneur principal */
.app-shell {
    max-width: 960px;
    margin: 24px auto;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
    padding: 24px;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.app-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: #111827;
}

.app-subtitle {
    font-size: 0.9rem;
    color: #6b7280;
    margin-top: 4px;
}

.app-brand img {
    max-height: 120px;
    height: auto;
    width: auto;
}

.badge {
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 4px 10px;
    border-radius: 999px;
    background: #eff6ff;
    color: #1d4ed8;
}

/* Liste d'étapes */
.steps {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.step {
    display: flex;
    align-items: center;
    padding: 12px 12px;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
}

.step-main {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 12px;
}

.step-index {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
}

.step-index.done {
    background: #dcfce7;
    color: #166534;
}

.step-index.active {
    background: #1d4ed8;
    color: #ffffff;
}

.step-index.upcoming {
    background: #e5e7eb;
    color: #4b5563;
}

.step-texts {
    display: flex;
    flex-direction: column;
}

.step-title {
    font-size: 0.95rem;
    font-weight: 500;
    color: #111827;
}

.step-caption {
    font-size: 0.8rem;
    color: #6b7280;
    margin-top: 2px;
}

.step-action {
    margin-left: 12px;
}

.step-action a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
    background: #111827;
    color: #ffffff;
    border: none;
}

/* Footer */
.app-footer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.8rem;
    color: #6b7280;
}

.primary-action {
    margin-top: 4px;
}

.primary-action a {
    display: inline-flex;
    width: 100%;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border-radius: 999px;
    border: none;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    background: #1d4ed8;
    color: #ffffff;
}

/* Taille plus grande pour les boutons d'étapes dans le header */
.header-step-indicators .step-index {
    width: 52px;
    height: 52px;
    font-size: 1.1rem;
}

/* Titre de page */
.page-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: #111827;
    margin-bottom: 16px;
}

/* Message d'erreur */
.error-message {
    display: inline-block;
    margin-bottom: 16px;
    padding: 8px 12px;
    border-radius: 8px;
    background-color: #fef2f2;
    color: #b91c1c;
    font-size: 0.9rem;
}

/* Formulaire d'upload */
.upload-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border-radius: 12px;
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    margin-bottom: 20px;
}

.upload-field label {
    font-size: 0.9rem;
    font-weight: 500;
    color: #374151;
    display: block;
    margin-bottom: 4px;
}

.upload-field input[type="url"],
.upload-field input[type="text"],
.upload-field input[type="file"] {
    width: 100%;
    max-width: 100%;
    font-size: 0.9rem;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background-color: #ffffff;
}

.upload-field input[type="url"]:focus,
.upload-field input[type="text"]:focus,
.upload-field input[type="file"]:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 1px #2563eb33;
}

/* Bouton de validation */
.upload-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border-radius: 999px;
    border: none;
    background-color: #2563eb;
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
}

.upload-actions button:hover {
    background-color: #1d4ed8;
}

/* Bloc image actuelle + actions */
.current-image {
    margin-top: 20px;
    padding: 16px;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    background-color: #ffffff;
}

.current-image h2 {
    font-size: 1rem;
    font-weight: 600;
    color: #111827;
    margin-bottom: 8px;
}

.current-image img {
    display: block;
    max-width: 100%;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    margin-bottom: 8px;
}

.current-image a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 999px;
    border: none;
    background-color: #111827;
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    margin-top: 4px;
}

/* Bouton de réinitialisation */
.reset-form {
    margin-top: 10px;
}

.reset-form button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid #ef4444;
    background-color: #ffffff;
    color: #b91c1c;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
}

.reset-form button:hover {
    background-color: #fef2f2;
}

/* Bloc de choix du mode d'upload */
.upload-mode-switch {
    display: inline-flex;
    padding: 4px;
    border-radius: 999px;
    background-color: #e5e7eb;
    margin-bottom: 12px;
    gap: 4px;
}

.upload-mode-button {
    border: none;
    background: transparent;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #4b5563;
    cursor: pointer;
}

.upload-mode-button.active {
    background-color: #ffffff;
    color: #111827;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.15);
}

/* Conteneur des champs */
.upload-fields {
    margin-top: 8px;
}

/* On n'affiche qu'un des deux champs à la fois */
.upload-field-url,
.upload-field-file {
    display: none;
}

.upload-field-url.active,
.upload-field-file.active {
    display: block;
}

/* Conteneur de la zone de retouche (step2) */
.canvas-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}

/* Cadre autour du canvas */
.canvas-wrapper {
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    background: #111827;
    padding: 8px;
    display: inline-block;
    max-width: 100%;
}

/* Canvas plein dans son conteneur */
#edit-canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Formulaire / barre d'outils sous le canvas */
.canvas-tools {
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 0.85rem;
    color: #374151;
    margin-top: 8px;
}

/* Lignes de contrôles */
.canvas-tools-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.canvas-tools-row label {
    font-size: 0.85rem;
}

/* Variante empilée pour le bloc "fond" */
.canvas-tools-row--stacked {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.canvas-tools-subrow {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Check inline */
.checkbox-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Bouton secondaire (gomme, pipette, repositionnement) */
.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid #d1d5db;
    background-color: #ffffff;
    color: #374151;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
}

.btn-secondary:hover {
    background-color: #f3f4f6;
}

/* Input color dans la barre d'outils */
.canvas-tools input[type="color"] {
    padding: 0;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    width: 40px;
    height: 28px;
}

/* Slider de contraste */
#contrast-range {
    min-width: 180px;
}

/* Texte d'aide */
.helper-text {
    font-size: 0.8rem;
    color: #6b7280;
}

/* Lien de retour */
.back-link {
    margin-top: 16px;
    font-size: 0.85rem;
}

.back-link a {
    color: #1d4ed8;
    text-decoration: none;
}

.back-link a:hover {
    text-decoration: underline;
}

/* Prévisualisations côte à côte pour l'étape 3 */
.mosaic-previews {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 16px;
}

.mosaic-previews .current-image {
    flex: 1 1 0;
    min-width: 0;
}

.mosaic-preview-img {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Conteneur de la mosaïque avec overlay de chargement */
.mosaic-image-inner {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

.mosaic-loading {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.7);
}

.mosaic-loading::after {
    content: "";
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 3px solid #e5e7eb;
    border-top-color: #2563eb;
    animation: mosaic-spin 0.8s linear infinite;
}

@keyframes mosaic-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* Aide sous les labels des champs */
.field-help {
    display: inline-block;
    font-size: 0.8rem;
    color: #6b7280;
    margin: 0 0 4px 0;
}

/* Radios en ligne façon boutons */
.radio-inline {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-right: 12px;
    font-size: 0.85rem;
}

/* Description détaillée sous le libellé du mode */
.radio-with-description {
    flex-direction: column;
    align-items: flex-start;
    margin-top: 4px;
}

.radio-description {
    display: block;
    font-size: 0.8rem;
    color: #6b7280;
    margin-left: 18px;
}

/* Forcer les options (radios) à être réellement sur la même ligne */
.upload-field .radio-inline {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-right: 12px;
    vertical-align: middle;
}

/* Cas des options avec description (Standard / Précis) */
.upload-field .radio-inline.radio-with-description {
    flex-direction: row;
    align-items: center;
}

/* La description reste sur la même ligne que le titre */
.upload-field .radio-inline.radio-with-description .radio-description {
    display: inline;
    margin-left: 8px;
}

/* Adaptation mobile */
@media (max-width: 768px) {
    .app-shell {
        margin: 0;
        border-radius: 0;
        min-height: 100vh;
        padding: 16px;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .step {
        flex-direction: row;
        align-items: flex-start;
    }

    .mosaic-previews {
        flex-direction: column;
    }
}

@media (max-width: 640px) {
    .upload-form,
    .current-image {
        padding: 12px;
    }

    .canvas-wrapper {
        width: 100%;
    }
}

/* ===================================================================
   WORKSPACE LAYOUT (Split-screen Edit + Preview)
   =================================================================== */

.workspace-container {
    max-width: 100%;
    width: 100%;
}

.workspace-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-top: 24px;
}

.workspace-panel {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.panel-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #111827;
    margin: 0 0 16px 0;
    padding: 0 0 12px 0;
    border-bottom: 2px solid #e5e7eb;
    height: 52px;
    display: flex;
    align-items: center;
}

.panel-section {
    margin-top: 20px;
    padding-top: 0;
    border-top: none;
}

.section-subtitle {
    font-size: 0.95rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 12px;
}

/* Canvas container */
.canvas-container {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    height: 450px;
    margin: 0;
}

.canvas-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: #f9fafb;
    border-radius: 8px;
    padding: 16px;
    border: 2px dashed #d1d5db;
}

#edit-canvas {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    border-radius: 4px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Outils d'édition */
.canvas-tools {
    margin-top: 0;
    background: #f9fafb;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.canvas-tools-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.canvas-tools-row:last-child {
    margin-bottom: 0;
}

.canvas-tools-row label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    min-width: 80px;
}

.canvas-tools-row input[type="range"] {
    flex: 1;
    min-width: 120px;
}

.canvas-tools-row input[type="color"] {
    width: 50px;
    height: 32px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
}

.canvas-tools-row .btn-secondary {
    padding: 6px 14px;
    font-size: 0.85rem;
    white-space: nowrap;
}

.canvas-tools-row--stacked {
    flex-direction: column;
    align-items: flex-start;
}

.canvas-tools-subrow {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.checkbox-inline {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.875rem;
}

.helper-text {
    font-size: 0.8rem;
    color: #6b7280;
    margin-top: 12px;
    margin-bottom: 0;
}

/* Preview panel */
.mosaic-preview-container {
    width: 100%;
    height: 450px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: #f9fafb;
    border-radius: 8px;
    padding: 16px;
    position: relative;
    border: 2px dashed #d1d5db;
    margin: 0;
}

.mosaic-image-inner {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.mosaic-preview-img {
    display: block;
    max-width: 100%;
    max-height: 418px;
    width: auto;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.mosaic-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
}

.mosaic-loading::after {
    content: "";
    width: 40px;
    height: 40px;
    border: 4px solid #e5e7eb;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: mosaic-spin 0.8s linear infinite;
}

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

/* Contrôles mosaïque */
.mosaic-controls {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    align-items: flex-end;
    padding: 16px;
    background: #f9fafb;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.mosaic-controls .form-group {
    min-width: 0;
}

.mosaic-controls .form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 6px;
}

.mosaic-controls .form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #ffffff;
    font-size: 0.875rem;
    color: #111827;
}

.mosaic-controls .btn-secondary {
    padding: 8px 16px;
    font-size: 0.875rem;
    white-space: nowrap;
}

/* Actions du workspace */
.workspace-actions {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    align-items: center;
}

.workspace-actions .btn-secondary {
    padding: 10px 20px;
}

.workspace-actions .btn-primary {
    padding: 10px 24px;
    background: #2563eb;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.workspace-actions .btn-primary:hover {
    background: #1d4ed8;
}

/* Responsive workspace */
@media (max-width: 1024px) {
    .workspace-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .mosaic-controls {
        grid-template-columns: 1fr;
    }

    .mosaic-controls .btn-secondary {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .workspace-container .page-title {
        font-size: 1.2rem;
    }

    .workspace-panel {
        padding: 16px;
    }

    .canvas-container,
    .mosaic-preview-container {
        min-height: 300px;
    }

    .workspace-actions {
        flex-direction: column;
    }

    .workspace-actions .btn-secondary,
    .workspace-actions .btn-primary {
        width: 100%;
    }
}