@font-face {
    font-family: 'Daniel';
    src: url('daniel/Daniel-Regular.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Daniel';
    src: url('daniel/Daniel-Bold.otf') format('opentype');
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: 'Daniel';
    src: url('daniel/Daniel-Black.otf') format('opentype');
    font-weight: 900;
    font-style: normal;
}

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

:root {
    --stone-50: #fafaf9;
    --stone-100: #f5f5f4;
    --stone-200: #e7e5e4;
    --stone-300: #d6d3d1;
    --stone-400: #a8a29e;
    --stone-500: #78716c;
    --stone-600: #57534e;
    --stone-700: #44403c;
    --stone-800: #292524;
    --stone-900: #1c1917;
    --stone-950: #0c0a09;
}

html {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    width: 100%;
    height: 100vh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: Arial, sans-serif;
    background: white;
}

/* Header (create page) */
.header {
    position: fixed;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    z-index: 30000;
    pointer-events: auto;
}

.logo {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.logo-icon {
    width: 36px;
    height: 36px;
    transform: rotate(-5deg);
}

@media (max-width: 767px) {
    .header {
        top: 14px;
        left: 14px;
        right: 14px;
    }

    .logo-icon {
        width: 32px;
        height: 32px;
    }
}

@media (max-width: 767px) {
    html, body {
        overflow: hidden;
        height: 100vh;
        max-height: 100vh;
        width: 100%;
        position: relative;
    }
}

.postcard-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    position: relative;
    flex-shrink: 0;
}


.flip-card {
    perspective: 1000px;
    opacity: 0;
    transform: translateY(100vh);
    transition: opacity 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94), transform 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    margin: 0 auto;
    z-index: 20000;
}

.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    will-change: transform;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.flip-card-inner.flipped {
    transform: rotateY(180deg);
}

/* Empêcher le clignotement des images scannées pendant l'animation flip */
.flip-card-inner:not(.flipped) .scanned-images-container,
.flip-card-inner.flipped .scanned-images-container {
    transform: translateZ(0) rotateY(0deg);
}

/* S'assurer que les éléments SVG et autres enfants respectent aussi backface-visibility */
.flip-card-front svg,
.flip-card-back svg,
.flip-card-front .sticker-peel-container,
.flip-card-back .sticker-peel-container,
.flip-card-front .lines-svg,
.flip-card-back .lines-svg {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(0);
}
    
    /* Forcer backface-visibility sur mobile pour éviter l'affichage des deux faces */
    .flip-card-front,
    .flip-card-back {
        -webkit-backface-visibility: hidden !important;
        backface-visibility: hidden !important;
    }
    
    .flip-card-front *,
    .flip-card-back * {
        -webkit-backface-visibility: hidden !important;
        backface-visibility: hidden !important;
    }

.flip-card-front,
.flip-card-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform-style: preserve-3d;
    overflow: visible;
    will-change: transform;
}

.flip-card-front {
    transform: rotateY(0deg) translateZ(1px);
    -webkit-transform: rotateY(0deg) translateZ(1px);
    z-index: 20000;
}

.flip-card-back {
    transform: rotateY(180deg) translateZ(1px);
    -webkit-transform: rotateY(180deg) translateZ(1px);
    z-index: 20000;
    cursor: pointer;
}

.flip-card-back.postcard::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url(kiwihug-zGZYQQVmXw0-unsplash.jpg);
    background-size: cover;
    background-position: center;
    opacity: 0.4;
    z-index: 0;
}

.flip-card-front.postcard::before,
.flip-card-back.postcard::before {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(0);
}

.flip-card-back .back-centered-image {
    position: absolute;
    top: 40px;
    left: 40px;
    right: 40px;
    bottom: 40px;
    width: calc(100% - 80px);
    height: calc(100% - 80px);
    object-fit: cover;
    z-index: 1;
    cursor: pointer;
    transition: opacity 0.2s ease;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(0);
}

.flip-card-back .back-centered-image:hover {
    opacity: 0.9;
}

/* Format A6 horizontal : 148mm x 105mm (ratio ~1.41:1) */
.postcard {
    background: #FFFFFD;
    box-shadow: 2px 3px 7px rgba(0, 0, 0, 0.12), 0px 4px 250px rgba(0, 0, 0, 0.05);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    z-index: 20000;
}

.flip-card-front.postcard::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url(kiwihug-zGZYQQVmXw0-unsplash.jpg);
    background-size: cover;
    background-position: center;
    opacity: 0.4;
    z-index: 0;
}

.text-boxes-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10; /* ⚠️ Au-dessus du container des images (z-index: 5) */
    z-index: 10;
    pointer-events: none;
    overflow: visible !important;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform-style: preserve-3d;
    transform: translateZ(0);
}

.text-box {
    position: absolute;
    min-width: 100px;
    min-height: 50px;
    padding: 10px;
    background: transparent;
    border: 1px dashed transparent;
    border-radius: 8px;
    cursor: text;
    pointer-events: all;
    word-wrap: break-word;
    z-index: 1; /* Sous le timbre */
    overflow-wrap: break-word;
    white-space: pre-wrap;
    overflow: visible !important;
    font-family: 'Daniel', 'Patrick Hand', cursive;
    font-weight: bold;
    font-size: 16px;
    color: #333;
    outline: none;
    resize: none;
    height: auto;
    transform-style: flat !important;
    /* isolation: isolate; */ /* ⚠️ RETIRÉ : créait un stacking context qui isolait le z-index */
}

/* Styles pour les textboxes variables (lecture seule) */
.text-box-variable {
    cursor: default !important;
    user-select: none !important;
}

.text-box-variable[contenteditable="false"] {
    cursor: default !important;
    user-select: none !important;
}

/* Les bordures et fonds ne s'affichent que si la classe .active est présente */
.text-box:focus:not(.active) {
    border-color: transparent;
    background: transparent;
}

/* Sur hover, afficher uniquement la bordure */
.text-box:hover:not(.active) {
    border-color: rgba(255, 0, 195, 0.7);
    background: transparent;
}

.text-box.active {
    border-color: rgba(255, 0, 195, 0.7) !important;
    background: rgba(255, 0, 195, 0.05) !important;
    z-index: 1000; /* ⚠️ Z-index de base, peut être augmenté par JavaScript via bringToFront() */
}

/* Style bleu pour textBox-2 uniquement */
#textBox-2:focus:not(.active) {
    border-color: transparent;
    background: transparent;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TEXTBOX VARIABLE - Type spécial pour les variables de publipostage
   ═══════════════════════════════════════════════════════════════════════════ */

#textBox-2:hover:not(.active) {
    border-color: rgba(0, 98, 255, 0.7);
    background: transparent;
}

#textBox-2.active {
    border-color: rgba(0, 98, 255, 0.7) !important;
    background: rgba(0, 98, 255, 0.05) !important;
}

/* Animation de clignotement pour les textbox au chargement */
@keyframes blinkBorderAndBg {
    0%, 100% {
        border-color: transparent;
        background-color: transparent;
    }
    50% {
        border-color: rgba(255, 0, 195, 0.7);
        background-color: rgba(255, 0, 195, 0.05);
    }
}

@keyframes blinkBorderAndBgBlue {
    0%, 100% {
        border-color: transparent;
        background-color: transparent;
    }
    50% {
        border-color: rgba(0, 98, 255, 0.7);
        background-color: rgba(0, 98, 255, 0.05);
    }
}

.text-box.blinking {
    animation: blinkBorderAndBg 2s ease-in-out;
    border-style: dashed !important;
}

#textBox-2.blinking {
    animation: blinkBorderAndBgBlue 2s ease-in-out;
    border-style: dashed !important;
}

.text-box:empty:not(:focus):before {
    content: attr(data-placeholder);
    color: #FF00C3;
    pointer-events: none;
    font-weight: 300;
    font-size: 1em;
}

/* Placeholder avec taille fixe pour textBox-1 */
#textBox-1:empty:not(:focus):before {
    font-size: 16px;
}

/* Placeholder bleu avec taille fixe pour textBox-2 (adresse) */
#textBox-2:empty:not(:focus):before {
    color: #0062FF;
    font-size: 16px;
}

/* Nouvelle approche : handles dans un container séparé */
.text-box-handles {
    position: fixed; /* ⚠️ FIXED au lieu d'absolute pour échapper au stacking context du parent */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 99999 !important; /* ⚠️ Z-index très élevé pour passer au-dessus de tout */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.text-box-handles.visible {
    opacity: 1;
    visibility: visible;
}

/* Handles pour les images (mêmes styles que les textbox) */
.image-handles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.text-box-handles .handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: white;
    border: 2px solid #FF00C3;
    pointer-events: all;
    z-index: 10000;
}

/* Handles bleus pour textBox-2 */
#textBox-2 ~ .text-box-handles[data-textbox-id="textBox-2"] .handle,
.text-box-handles[data-textbox-id="textBox-2"] .handle {
    border-color: #0062FF;
}

.text-box-handles .handle:hover:not(.handle-rotate) {
    background: rgba(255, 0, 195, 0.3);
    transform: scale(1.2);
}

/* Hover bleu pour les handles de textBox-2 */
.text-box-handles[data-textbox-id="textBox-2"] .handle:hover:not(.handle-rotate) {
    background: rgba(0, 98, 255, 0.3);
}

.text-box-handles .handle-right {
    width: 6px;
    height: 32px;
    border-radius: 3px;
}

.text-box-handles .handle-rotate {
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent !important;
    border: none !important;
}

.text-box-handles .handle-rotate:active {
    cursor: grabbing;
}

.text-box-handles .handle-rotate:hover {
    background: transparent !important;
}

.text-box-handles .handle-rotate svg {
    pointer-events: none;
    display: block;
}

/* Handles pour les images - Mêmes styles */
.image-handles .handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: white;
    border: 2px solid #FF00C3;
    pointer-events: all;
    z-index: 10000;
}

.image-handles .handle:hover:not(.handle-rotate) {
    background: rgba(255, 0, 195, 0.3);
    transform: scale(1.2);
}

.image-handles .handle-resize {
    width: 6px;
    height: 32px;
    border-radius: 3px;
}

.image-handles .handle-rotate {
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent !important;
    border: none !important;
}

.image-handles .handle-rotate:active {
    cursor: grabbing;
}

.image-handles .handle-rotate:hover {
    background: transparent !important;
}

.image-handles .handle-rotate svg {
    pointer-events: none;
    display: block;
}

.text-box-handles .bin-icon {
    position: absolute;
    width: 48px;
    height: 48px;
    left: -8px;
    top: -8px;
    cursor: pointer;
    pointer-events: all;
    z-index: 10000;
    transform: translate(-50%, -50%);
    transition: opacity 0.2s, visibility 0.2s;
}

.text-box-handles .bin-icon:hover {
    opacity: 0.8;
}

/* Bin icon pour les images - Même style */
.image-handles .bin-icon {
    position: absolute;
    width: 48px;
    height: 48px;
    left: -8px;
    top: -8px;
    cursor: pointer;
    pointer-events: all;
    z-index: 10000;
    transform: translate(-50%, -50%);
    transition: opacity 0.2s, visibility 0.2s;
}

.image-handles .bin-icon:hover {
    opacity: 0.8;
}

/* Bouton trash mobile pour les images */
.scanned-image-delete-mobile {
    outline: none !important;
    border: none !important;
    -webkit-tap-highlight-color: transparent;
}

.scanned-image-delete-mobile:focus {
    outline: none !important;
}

.scanned-image-delete-mobile:hover {
    opacity: 0.8 !important;
}

/* Barre d'outils de formatage */
.text-format-toolbar {
    position: fixed; /* ⚠️ FIXED au lieu d'absolute pour échapper au stacking context du parent */
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    z-index: 99998 !important; /* ⚠️ Z-index très élevé, juste sous les handles */
    padding: 6px 10px;
    gap: 12px;
    width: auto;
    min-height: 24px;
    background: white;
    border-radius: 16px;
    border: 1px solid var(--stone-100);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 10008; /* Au-dessus des boutons (z-index: 10) et du flip-button (z-index: 10006) */
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    box-sizing: border-box;
    overflow: visible;
}

.text-format-toolbar.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: all;
}

@media (max-width: 767px) {
    /* Sur mobile, la toolbar ne s'affiche que si la textbox correspondante est active */
    .text-format-toolbar.visible {
        opacity: 0 !important;
        visibility: hidden !important;
        display: none !important;
    }
    
    /* Afficher la toolbar uniquement si la textbox correspondante a la classe .active */
    .text-box.active ~ .text-format-toolbar.visible,
    .text-box.active + .text-format-toolbar.visible {
        opacity: 1 !important;
        visibility: visible !important;
        display: flex !important;
        transform: translateX(-50%) translateY(0) scale(1) !important;
    }
    
    /* Pour les toolbars avec data-textbox-id, vérifier que la textbox correspondante est active */
    .text-box.active[id] ~ .text-format-toolbar[data-textbox-id].visible,
    .text-box.active[id] + .text-format-toolbar[data-textbox-id].visible {
        opacity: 1 !important;
        visibility: visible !important;
        display: flex !important;
        transform: translateX(-50%) translateY(0) scale(1) !important;
    }
}

.text-format-toolbar .color-picker {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.text-format-toolbar .color-option {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: transform 0.2s;
    position: relative;
    box-shadow: 0 0 0 1px transparent;
}

.text-format-toolbar .color-option:hover {
    transform: scale(1.2);
}

.text-format-toolbar .color-option.active {
    box-shadow: 0 0 0 1px white;
}

.text-format-toolbar .color-option.active::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 50%;
    border: 1px solid white;
    pointer-events: none;
    z-index: 1;
}

.text-format-toolbar .color-option.active::after {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    border-radius: 50%;
    border: 2px solid var(--active-color, #000000);
    pointer-events: none;
    z-index: 0;
}

.text-format-toolbar .font-selector {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
    z-index: 10003;
}

.text-format-toolbar .font-selector:hover {
    background: #f5f5f5;
}

.text-format-toolbar .font-selector .chevron {
    width: 12px;
    height: 12px;
    color: var(--stone-600);
    flex-shrink: 0;
    transition: transform 0.2s;
}

.text-format-toolbar .font-selector:hover .chevron {
    color: var(--stone-700);
}


.text-format-toolbar .font-selector .font-name {
    font-family: inherit;
    font-weight: 600;
}

.text-format-toolbar .font-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    background: white;
    border: 1px solid var(--stone-200);
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10004;
    min-width: 150px;
    display: none;
    overflow: hidden;
    padding: 4px;
    flex-direction: column;
    gap: 4px;
}

.text-format-toolbar .font-dropdown.visible {
    display: flex;
}

.text-format-toolbar .font-option {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
    border-radius: 10px;
    margin: 0;
}

.text-format-toolbar .font-option:hover {
    background: var(--stone-100);
}

.text-format-toolbar .font-option.active {
    background: var(--stone-100);
    font-weight: 600;
}

.text-format-toolbar .font-size-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.text-format-toolbar .font-size-controls button {
    width: auto;
    height: 24px;
    border: none;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #333;
    transition: background 0.2s;
    flex-shrink: 0;
    padding: 0 2px;
    margin: 0;
}

.text-format-toolbar .font-size-controls button:hover {
    background: white;
}

.text-format-toolbar .font-size-display {
    min-width: 30px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    padding: 0 8px;
}

.variable-help-text {
    font-size: 11px;
    color: var(--stone-500);
    padding: 0 8px;
    white-space: nowrap;
    user-select: none;
    display: none; /* Masqué par défaut, affiché uniquement si CSV importé */
    position: absolute;
    z-index: 100009; /* Juste sous la toolbar (z-index: 10008) */
    pointer-events: none; /* Ne pas interférer avec les clics */
    text-align: center;
}

/* Modal pour sélectionner les variables */
.variable-selector-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.variable-selector-modal {
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.variable-selector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--stone-200);
}

.variable-selector-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--stone-900);
}

.variable-selector-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 0.2s;
}

.variable-selector-close:hover {
    background: var(--stone-100);
}

.variable-selector-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.variable-selector-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: white;
    border: 2px solid var(--stone-200);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 15px;
    font-weight: 500;
    color: var(--stone-900);
}

.variable-selector-item:hover {
    background: var(--stone-50);
    border-color: var(--stone-300);
    transform: translateY(-2px);
}

.variable-selector-item svg {
    flex-shrink: 0;
}

.lines-svg {
    position: absolute;
    bottom: 100px;
    right: 40px;
    width: 200px;
    height: 140px;
    z-index: 1;
    overflow: visible;
}

/* Sticker Peel Effect */
.sticker-peel-container {
    position: absolute;
    top: 25px;
    right: 7px;
    width: 131px;
    height: auto;
    z-index: 10005; /* Au-dessus des textes et images */
    cursor: pointer;
    transform: rotate(0deg);
    transform-origin: center;
    -webkit-tap-highlight-color: transparent;
    tap-highlight-color: transparent;
}

.sticker-filters {
    position: absolute;
    width: 0;
    height: 0;
    visibility: hidden;
}

.sticker-main {
    position: relative;
    clip-path: polygon(-10px -10px, calc(100% + 10px) -10px, calc(100% + 10px) calc(100% + 10px), -10px calc(100% + 10px));
    transition: clip-path 0.6s ease-out;
    filter: url(#stickerDropShadow);
    z-index: 10006;
}

.sticker-lighting {
    filter: url(#stickerPointLight);
}

.sticker-image {
    width: 131px;
    height: auto;
    display: block;
    transform: rotate(0deg);
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

.sticker-flap {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: calc(-100% - 20px);
    clip-path: polygon(-10px -10px, calc(100% + 10px) -10px, calc(100% + 10px) -10px, -10px -10px);
    transform: scaleY(-1);
    transition: all 0.6s ease-out;
    pointer-events: none;
    z-index: 10007;
}

.flap-lighting {
    filter: url(#stickerPointLightFlipped);
}

.flap-image {
    width: 131px;
    height: auto;
    display: block;
    transform: rotate(12deg);
    filter: url(#stickerExpandAndFill);
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

.sticker-peel-container:hover .sticker-main {
    clip-path: polygon(-10px 40%, calc(100% + 10px) 40%, calc(100% + 10px) calc(100% + 10px), -10px calc(100% + 10px));
}

.sticker-peel-container:hover .sticker-flap {
    clip-path: polygon(-10px -10px, calc(100% + 10px) -10px, calc(100% + 10px) 40%, -10px 40%);
    top: calc(-100% + 80% - 1px);
}

.sticker-peel-container:active .sticker-main {
    clip-path: polygon(-10px 40%, calc(100% + 10px) 40%, calc(100% + 10px) calc(100% + 10px), -10px calc(100% + 10px));
}

.sticker-peel-container:active .sticker-flap {
    clip-path: polygon(-10px -10px, calc(100% + 10px) -10px, calc(100% + 10px) 40%, -10px 40%);
    top: calc(-100% + 80% - 1px);
}

.frame-svg {
    position: absolute;
    top: 40px;
    right: 40px;
    width: 70px;
    height: auto;
    z-index: 1;
}

.vertical-line-svg {
    position: absolute;
    top: 15%;
    bottom: 15%;
    height: 70%;
    width: 1px;
    z-index: 1;
    overflow: hidden;
}

/* Desktop : positionnement avec espacement égal */
@media (min-width: 768px) {
    .vertical-line-svg {
        right: 280px; /* 40px (bord) + 200px (lignes pointillées) + 40px (espace) */
    }
}

/* Mobile : positionnement proportionnel */
@media (max-width: 767px) {
    .vertical-line-svg {
        right: calc(40px + 200px + 40px);
    }
}

/* Desktop : taille A6 fixe */
@media (min-width: 768px) {
    .flip-card {
        width: 595px;  /* ~148mm à 96dpi */
        height: 420px; /* ~105mm à 96dpi */
    }
    
    .postcard {
        width: 595px;
        height: 420px;
    }
}

/* Mobile : respecter le ratio A6 (148mm x 105mm = 1.41:1) et tout dans la largeur */
/* Desktop : 595px x 420px, donc ratio de scaling = (100vw - 32px) / 595 */
@media (max-width: 767px) {
    /* Masquer les handles de resize et rotation en mobile */
    .text-box-handles .handle-right,
    .text-box-handles .handle-rotate {
        display: none !important;
    }
    
    /* Masquer le bin-icon par défaut sur mobile */
    .text-box-handles .bin-icon {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }
    
    /* Afficher le bin-icon uniquement lorsque la textbox correspondante est active */
    /* Sur mobile, le handleContainer n'est visible que quand la textbox est active */
    /* Utiliser un sélecteur qui vérifie que la textbox active correspond au handleContainer */
    .text-box.active ~ .text-box-handles.visible .bin-icon {
        opacity: 1;
        visibility: visible;
        pointer-events: all;
    }
    
    /* Alternative avec :has() pour une meilleure compatibilité */
    .text-boxes-container:has(.text-box.active) .text-box-handles.visible .bin-icon {
        opacity: 1;
        visibility: visible;
        pointer-events: all;
    }
    
    /* Masquer le titre "Adresse postale" par défaut sur mobile */
    .address-title {
        opacity: 0 !important;
        visibility: hidden !important;
    }
    
    /* Afficher le titre "Adresse postale" uniquement lorsque la textbox-2 est active */
    /* Utiliser le sélecteur général de frère ~ qui fonctionne même si les éléments ne sont pas adjacents */
    .text-boxes-container:has(#textBox-2.active) .address-title {
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Fallback pour les navigateurs qui ne supportent pas :has() */
    #textBox-2.active ~ .address-title {
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Tooltip pour la toolbar de formatage en mobile */
    .postcard-container {
        position: relative;
        overflow: visible;
        justify-content: center;
        align-items: center;
    }
    
    .text-format-toolbar {
        position: fixed !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 8px 12px !important;
        gap: 10px !important;
        width: auto !important;
        min-width: fit-content !important;
        max-width: calc(100vw - 32px) !important;
        background: white !important;
        border-radius: 44px !important;
        border: 1px solid var(--stone-200) !important;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15) !important;
        z-index: 10010 !important;
        opacity: 0 !important;
        visibility: hidden !important;
        /* left, margin-left gérés par JavaScript */
        right: auto !important;
        bottom: -20px !important;
        top: auto !important;
        margin-right: 0 !important;
        transform: translateX(-50%) scale(0.96) !important;
        transition: opacity 0.2s ease-out !important, 
                    visibility 0.2s ease-out !important, 
                    transform 0.2s ease-out !important;
        pointer-events: none !important;
    }
    
    /* Sur mobile, la toolbar ne s'affiche que si la textbox correspondante est active */
    /* Par défaut, masquer toutes les toolbars sur mobile même si elles ont la classe .visible */
    .text-format-toolbar.visible {
        display: flex !important;
        opacity: 0 !important;
        visibility: hidden !important;
        transform: translateX(-50%) scale(0.96) !important;
        pointer-events: none !important;
    }
    
    /* Afficher uniquement la toolbar qui a la classe .toolbar-active (ajoutée quand la textbox est active) */
    .text-format-toolbar.visible.toolbar-active {
        display: flex !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: all !important;
        position: fixed !important;
        /* left et margin-left sont gérés par JavaScript pour permettre le centrage */
        right: auto !important;
        bottom: -20px !important;
        top: auto !important;
        transform: translateX(-50%) scale(1) !important;
        margin-right: 0 !important;
        border-radius: 44px !important;
        transition: opacity 0.2s ease-out !important, 
                    visibility 0.2s ease-out !important, 
                    transform 0.2s ease-out !important;
    }
    
    .postcard-container {
        padding: 16px 16px 80px 16px; /* Padding en bas pour laisser place aux boutons */
        gap: 12px;
        justify-content: center;
        align-items: center;
        height: 100vh;
        max-height: 100vh;
        overflow: visible; /* Permettre aux boutons fixed de s'afficher */
        position: relative;
    }
    
    /* S'assurer que les boutons fixed ne sont pas affectés par le container */
    .postcard-container > .bulk-import-button {
        position: fixed !important;
        z-index: 10020 !important;
        pointer-events: all !important;
    }
    
    .postcard-container > .card-navigation {
        display: none !important;
    }
    
    .flip-card {
        /* Ratio A6 : largeur/hauteur = 1.41 */
        width: calc(100vw - 32px);
        height: calc((100vw - 32px) / 1.41); /* Hauteur calculée pour respecter le ratio A6 */
        max-width: 100%;
        max-height: calc(100vh - 200px); /* Réserver l'espace pour les boutons */
        /* Améliorer l'animation flip sur mobile avec perspective optimisée */
        perspective: 1200px;
        -webkit-perspective: 1200px;
    }
    
    .flip-card-inner {
        transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
        -webkit-transition: -webkit-transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    /* S'assurer que backface-visibility fonctionne correctement sur mobile */
    .flip-card-front,
    .flip-card-back {
        -webkit-backface-visibility: hidden !important;
        backface-visibility: hidden !important;
        -webkit-transform-style: preserve-3d;
        transform-style: preserve-3d;
    }
    
    /* Forcer les enfants à respecter backface-visibility sans casser l'animation */
    .flip-card-front *,
    .flip-card-back * {
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    .postcard {
        width: 100%;
        height: 100%;
    }
    
    /* Lignes pointillées - proportionnel */
    /* Desktop: 200px width, bottom: 100px, right: 40px */
    .lines-svg {
        width: calc((100vw - 32px) * 200 / 595);
        height: calc((100vw - 32px) * 140 / 595);
        min-height: calc((100vw - 32px) * 140 / 595);
        bottom: calc((100vw - 32px) * 100 / 595);
        right: calc((100vw - 32px) * 40 / 595);
        overflow: visible;
    }
    
    /* Timbre - proportionnel */
    /* Desktop: 131px width, top: 25px, right: 7px */
    .sticker-peel-container {
        width: calc((100vw - 32px) * 131 / 595);
        top: calc((100vw - 32px) * 25 / 595);
        right: calc((100vw - 32px) * 7 / 595);
    }
    
    .sticker-image,
    .flap-image {
        width: calc((100vw - 32px) * 131 / 595);
    }
    
    /* Cadre - proportionnel */
    /* Desktop: 70px width, top: 40px, right: 40px */
    .frame-svg {
        width: calc((100vw - 32px) * 70 / 595);
        top: calc((100vw - 32px) * 40 / 595);
        right: calc((100vw - 32px) * 40 / 595);
    }
    
    /* Ligne verticale - proportionnel */
    /* Mobile: height: 70%, right: 280px */
    .vertical-line-svg {
        right: calc((100vw - 32px) * 280 / 595);
        top: 15%;
        bottom: 15%;
        height: 70%;
        transform: none;
    }
    
    /* Image face B - proportionnel */
    /* Desktop: top: 40px, left: 40px, right: 40px, bottom: 40px */
    .flip-card-back .back-centered-image {
        top: calc((100vw - 32px) * 40 / 595);
        left: calc((100vw - 32px) * 40 / 595);
        right: calc((100vw - 32px) * 40 / 595);
        bottom: calc((100vw - 32px) * 40 / 595);
        width: calc(100% - (100vw - 32px) * 80 / 595);
        height: calc(100% - (100vw - 32px) * 80 / 595);
    }
    
    /* Barre transparente fixe en bas */
    .postcard-container::after {
        content: '';
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 72px;
        background: transparent;
        z-index: 10007;
        pointer-events: none;
    }
    
    /* TAB BAR UNIQUE : Tous les boutons dans un seul container */
    .postcard-container > .buttons-container {
        position: fixed;
        bottom: 12px;
        left: 16px;
        right: 16px;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 8px; /* Léger espace entre les boutons blancs */
        padding: 0;
        background: transparent;
        margin: 0;
        flex-wrap: nowrap;
        box-sizing: border-box;
        pointer-events: all;
        z-index: 10005; /* Inférieur à text-options-popup (z-index: 10009) */
        max-width: calc(100% - 32px); /* Éviter le dépassement (16px left + 16px right) */
        overflow: hidden; /* Empêcher le dépassement visuel */
    }
    
    /* Bouton envoyer poussé à droite */
    .postcard-container > .buttons-container > .send-button {
        margin-left: auto;
    }
    
    /* Wrapper du bouton edit - masqué par défaut, affiché sur Face A par JS */
    .text-options-wrapper {
        position: relative;
        pointer-events: all;
    }
    
    /* Bouton flip - toujours visible */
    .flip-button {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        transform: none !important;
        width: 52px !important;
        height: 52px !important;
        min-width: 52px !important;
        max-width: 52px !important;
        padding: 12px !important;
        background: #FAFAF9 !important;
        border: 2px solid rgba(0, 0, 0, 0.02) !important;
        border-radius: 100px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;
        margin: 0 !important;
        pointer-events: all !important;
        cursor: pointer !important;
        font-size: 0 !important;
        line-height: 0 !important;
        flex-shrink: 0 !important;
        z-index: 1 !important;
        box-sizing: border-box !important;
    }
    
    /* Bouton text-options : style similaire mais display contrôlé par JavaScript */
    .text-options-button {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        transform: none !important;
        width: 52px !important;
        height: 52px !important;
        min-width: 52px !important;
        max-width: 52px !important;
        padding: 12px !important;
        background: #FAFAF9 !important;
        border: 2px solid rgba(0, 0, 0, 0.02) !important;
        border-radius: 100px !important;
        /* display contrôlé par JavaScript - pas de !important */
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;
        margin: 0 !important;
        pointer-events: all !important;
        cursor: pointer !important;
        font-size: 0 !important;
        line-height: 0 !important;
        flex-shrink: 0 !important;
        z-index: 1 !important;
        box-sizing: border-box !important;
    }
    
    /* Bouton face-b : style similaire mais display contrôlé par JavaScript */
    .face-b-button {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        transform: none !important;
        width: 52px !important;
        height: 52px !important;
        min-width: 52px !important;
        max-width: 52px !important;
        padding: 0 !important;
        background: #FAFAF9 !important;
        border: 2px solid rgba(0, 0, 0, 0.02) !important;
        border-radius: 100px !important;
        /* display contrôlé par JavaScript - pas de !important */
        display: flex;
        align-items: center !important;
        justify-content: center !important;
        gap: 0 !important;
        margin: 0 !important;
        pointer-events: all !important;
        cursor: pointer !important;
        font-size: 0 !important;
        line-height: 0 !important;
        flex-shrink: 0 !important;
        z-index: 1 !important;
        box-sizing: border-box !important;
    }
    
    /* Z-index pour le flip button */
    .flip-button {
        z-index: 10012 !important;
    }
    
    /* Z-index pour le text-options button */
    .text-options-button {
        z-index: 10013 !important;
    }
    
    /* Icônes des boutons circulaires - taille uniforme */
    .flip-button svg,
    .text-options-button svg,
    .face-b-button svg {
        width: 20px !important;
        height: 20px !important;
        color: var(--stone-700) !important;
        margin: 0 auto !important;
        padding: 0 !important;
        pointer-events: none !important;
        flex-shrink: 0 !important;
        display: block !important;
    }
    
    /* Cacher le texte dans tous les boutons circulaires */
    .flip-button-text {
        display: none !important;
    }
    
    /* Boutons Edit et Scan - cacher en mobile */
    .write-text-button,
    .scan-button,
    .add-variable-button {
        display: none !important;
    }
    
    /* Bouton face-b : laisser le JavaScript contrôler l'affichage (pas de !important sur display) */
    .face-b-button {
        /* Le display est contrôlé par JavaScript selon la face */
        /* Pas de display: flex !important ici pour permettre au JS de le cacher */
    }
    
    /* Bouton Envoyer - style différent (plus grand, arrondi, sombre) avec texte + icône */
    .buttons-container:last-child {
        width: auto;
        max-width: none;
    }
    
    .send-button {
        width: auto !important;
        min-width: auto !important;
        height: 52px !important;
        max-height: 52px !important;
        padding: 0 16px !important; /* Réduit de 20px à 16px pour mobile */
        background: var(--stone-800) !important;
        border: none !important;
        border-radius: 26px !important;
        position: relative !important;
        bottom: auto !important;
        right: auto !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px !important; /* Réduit de 8px à 6px pour mobile */
        font-size: 14px !important; /* Réduit de 15px à 14px pour mobile */
        line-height: 1 !important;
        flex-shrink: 1 !important; /* Permet au bouton de se rétrécir si nécessaire */
        box-sizing: border-box !important;
        max-width: 100%; /* Empêcher le dépassement */
    }
    
    .send-button svg {
        width: 16px !important;
        height: 16px !important;
        color: white !important;
        margin: 0 !important;
        flex-shrink: 0 !important;
    }
    
    /* Afficher le texte "Envoyer" */
    .send-button-text {
        display: inline !important;
        color: white !important;
        font-size: 14px !important; /* Réduit de 15px à 14px pour mobile */
        font-weight: 500 !important;
        font-family: Arial, sans-serif !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important; /* Le texte ne se rétrécit pas */
    }
}

.buttons-container {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
    max-width: 600px;
    opacity: 0;
    transition: opacity 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Desktop : positionnement absolu au-dessus */
@media (min-width: 768px) {
    .flip-button {
        position: absolute;
        bottom: calc(100% + 20px);
        left: 50%;
        transform: translateX(-50%);
        width: auto;
        min-width: 90px;
        height: 40px;
        padding: 0 8px;
        background: var(--stone-50);
        color: var(--stone-600);
        border: 1px solid var(--stone-100);
        border-radius: 100px;
        cursor: pointer;
        transition: all 0.3s;
        z-index: 10006; /* Au-dessus de tout */
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
    }
}

/* Desktop : styles du flip button */
@media (min-width: 768px) {
    .flip-button svg {
        width: 16px;
        height: 16px;
        flex-shrink: 0;
    }

    .flip-button-text {
        font-size: 14px;
        font-weight: 500;
        white-space: nowrap;
        display: inline-block;
    }

    .flip-button svg {
        display: inline-block;
    }

    .flip-button.rotating svg,
    .flip-button.rotating .flip-button-text {
        animation: rollVertical 0.3s ease;
    }

    .flip-button:hover {
        background: var(--stone-100);
    }

    .flip-button:active {
        background: var(--stone-300);
    }
}

@keyframes rollVertical {
    0% {
        transform: translateY(0) rotateX(0deg);
        opacity: 1;
    }
    50% {
        transform: translateY(-20px) rotateX(90deg);
        opacity: 0;
    }
    51% {
        transform: translateY(20px) rotateX(-90deg);
        opacity: 0;
    }
    100% {
        transform: translateY(0) rotateX(0deg);
        opacity: 1;
    }
}

.face-b-button,
.write-text-button,
.scan-button,
.add-variable-button {
    padding: 12px 20px;
    font-size: 15px;
    font-family: Arial, sans-serif;
    background: var(--stone-50);
    color: var(--stone-600);
    border: 1px solid var(--stone-100);
    border-radius: 100px;
    cursor: pointer;
    transition: background 0.3s, opacity 0.25s ease;
    z-index: 10;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    position: relative;
    height: 44px;
    line-height: 1;
    min-width: fit-content;
    flex-shrink: 0;
    opacity: 1;
}

.face-b-button svg,
.write-text-button svg,
.scan-button svg,
.add-variable-button svg {
    /* display: block; */
    flex-shrink: 0;
    margin: 0;
    vertical-align: middle;
}


.face-b-button,
.write-text-button,
.scan-button,
.add-variable-button {
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.face-b-button:hover,
.write-text-button:hover,
.scan-button:hover,
.add-variable-button:hover {
    background: var(--stone-200);
}

.face-b-button:active,
.write-text-button:active,
.scan-button:active,
.add-variable-button:active {
    background: var(--stone-300);
}

/* Desktop : styles spécifiques pour les boutons */
@media (min-width: 768px) {
    .face-b-button,
    .write-text-button,
    .scan-button,
    .add-variable-button {
        background: var(--stone-50);
        border: 1px solid var(--stone-100);
        padding-left: 16px;
        padding-right: 16px;
    }
    
    .face-b-button:hover,
    .write-text-button:hover,
    .scan-button:hover,
    .add-variable-button:hover {
        background: var(--stone-100);
    }
}

/* Wrapper pour les options de texte avec popup */
.text-options-wrapper {
    position: relative;
}

/* Bouton principal avec icône de stylo */
.text-options-button {
    width: 48px;
    height: 48px;
    min-width: 48px;
    padding: 0;
    background: white;
    border: 1px solid var(--stone-300);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10011;
    position: relative;
}

.text-options-button svg {
    width: 20px;
    height: 20px;
    color: var(--stone-700);
}

.text-options-button:hover {
    background: var(--stone-100);
}

.text-options-button:active {
    background: var(--stone-200);
}

/* Popup avec les deux options */
.text-options-popup {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 8px;
    display: none;
    flex-direction: column;
    gap: 4px;
    min-width: 180px;
    z-index: 10012;
    white-space: nowrap;
}

.text-options-popup.visible {
    display: flex;
}

/* Flèche pointant vers le bouton */
.text-options-popup::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid white;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

/* Mobile : ajuster le positionnement de la popup */
@media (max-width: 767px) {
    .text-options-popup {
        position: fixed;
        bottom: 12px; /* Au même niveau Y que les boutons de la navbar */
        left: 16px; /* Aligné à gauche avec le padding de la tab bar */
        transform: none;
        border-radius: 24px;
        padding: 10px;
        gap: 8px;
        width: 170px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
        z-index: 10014; /* Au-dessus de tous les boutons (max: 10013) */
    }
    
    .text-options-popup::after {
        display: none; /* Pas de flèche en mobile */
    }
}

/* Options dans la popup */
.text-option-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--stone-100);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 14px;
    font-family: Arial, sans-serif;
    color: var(--stone-700);
    text-align: left;
    width: 100%;
}

.text-option-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--stone-700);
}

.text-option-item:hover {
    background: var(--stone-200);
}

.text-option-item:active {
    background: var(--stone-300);
}

/* Mobile : styles spécifiques pour les options de la popup */
@media (max-width: 767px) {
    .text-option-item {
        padding: 14px 12px; /* Plus de padding top/bottom, moins de padding left/right */
        background: var(--stone-100);
        border-radius: 100px;
        font-weight: 500;
        color: #5B5B5B;
        width: auto;
    }
    
    .text-option-item svg {
        color: #5B5B5B;
        stroke-width: 2;
    }
    
    .text-option-item:hover {
        background: var(--stone-200);
    }
    
    .text-option-item:active {
        background: var(--stone-300);
    }
}

/* Desktop : afficher les boutons séparés normalement */
@media (min-width: 768px) {
    .text-options-wrapper {
        display: none !important;
    }
    
    .text-options-button {
        display: none !important;
    }
    
    .write-text-button,
    .scan-button,
    .add-variable-button {
        display: flex;
    }
}

/* Mobile : cacher les boutons séparés et afficher le bouton unique */
@media (max-width: 767px) {
    .text-options-wrapper {
        display: block;
    }
    
    .write-text-button,
    .scan-button,
    .add-variable-button {
        display: none !important;
    }
}

/* Bouton Envoyer */
.send-button {
    padding: 0 20px;
    font-size: 15px;
    font-family: Arial, sans-serif;
    background: var(--stone-900);
    color: var(--stone-100);
    border: none;
    border-radius: 100px;
    cursor: pointer;
    transition: background 0.3s;
    z-index: 100;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 52px;
    max-height: 52px;
    line-height: 1;
    min-width: fit-content;
    flex-shrink: 0;
    position: fixed;
    bottom: 20px;
    right: 20px;
    box-sizing: border-box;
}

.send-button svg {
    flex-shrink: 0;
    margin: 0;
    vertical-align: middle;
    width: 16px;
    height: 16px;
}

.send-button:hover {
    background: var(--stone-800);
}

.send-button:active {
    background: var(--stone-700);
}

/* État de chargement du bouton Envoyer */
.send-button.loading {
    background: rgb(231, 229, 228) !important; /* stone-200 */
    color: rgb(120, 113, 108) !important; /* stone-500 */
    cursor: not-allowed;
}

/* Mobile : texte "Envoi..." en stone-500 */
@media (max-width: 767px) {
    .send-button.loading {
        color: rgb(120, 113, 108) !important; /* stone-500 */
    }
    
    .send-button.loading .send-button-text {
        color: rgb(120, 113, 108) !important; /* stone-500 */
    }
}

/* Desktop : garantir la hauteur de 52px */
@media (min-width: 768px) {
    .send-button {
        height: 52px !important;
        max-height: 52px !important;
        padding: 0 20px !important;
        box-sizing: border-box !important;
    }
}

/* Animation du spinner */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.send-spinner {
    animation: spin 1s linear infinite;
    stroke-dasharray: 40;
    stroke-dashoffset: 20;
    width: 16px !important;
    height: 16px !important;
}

.send-spinner circle {
    stroke: rgb(120, 113, 108); /* stone-500 */
}

/* S'assurer que le spinner garde la bonne taille en état de chargement */
.send-button.loading .send-spinner {
    width: 16px !important;
    height: 16px !important;
}



/* Modal Styles */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.25);
    z-index: 30000; /* Au-dessus de la carte postale (z-index: 20000) */
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal-content {
    background: var(--stone-50);
    border: 1px solid var(--stone-200);
    border-radius: 32px;
    width: 100%;
    max-width: 500px; /* Taille par défaut (pour scan modal) */
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    padding: 20px;
}

/* Modal de choix d'image : plus large */
#modalOverlay .modal-content {
    max-width: 1000px;
    height: 700px;
    max-height: 700px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#modalOverlay .modal-title {
    margin-bottom: 16px;
    flex-shrink: 0;
}

#modalOverlay .drop-zone {
    flex-shrink: 0;
}

#modalOverlay .search-bar-container {
    flex-shrink: 0;
    margin-bottom: 16px;
}

#modalOverlay .postcards-container {
    flex: 1;
    min-height: 0;
}

.modal-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 10px;
}

.scan-icon-container {
    flex-shrink: 0;
    margin-bottom: 12px;
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.modal-close:hover {
    background: #f0f0f0;
}

.modal-title {
    padding: 0;
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: #333;
    text-align: center;
}

/* Barre de recherche dans le modal */
.search-bar-container {
    position: relative;
    margin: 0;
}

.search-bar-container .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--stone-400);
    pointer-events: none;
}

.search-bar-container .search-input {
    width: 100%;
    padding: 10px 40px 10px 40px;
    border: 1px solid var(--stone-300);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: white;
    transition: all 0.2s;
}

.search-bar-container .search-input:focus {
    outline: none;
    border-color: var(--stone-500);
    box-shadow: 0 0 0 3px rgba(120, 113, 108, 0.1);
}

.search-bar-container .search-input::placeholder {
    color: var(--stone-400);
}

.clear-search-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--stone-200);
    border: none;
    border-radius: 4px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
}

.clear-search-btn:hover {
    background: var(--stone-300);
}

.clear-search-btn svg {
    color: var(--stone-600);
}

/* Zone de drag & drop */
.drop-zone {
    margin: 0 0 16px 0;
    border: 1px dashed var(--stone-300);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: var(--stone-100);
}

.drop-zone:hover {
    border-color: var(--stone-400);
    background: var(--stone-100);
}

.drop-zone.drag-over {
    border-color: var(--stone-600);
    background: var(--stone-100);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.drop-zone-content svg {
    color: var(--stone-500);
}

.drop-zone-content p {
    margin: 0;
    color: var(--stone-500);
    font-size: 14px;
}

.drop-zone-text-mobile {
    display: none;
}

.drop-zone-text-desktop {
    display: block;
}

@media (max-width: 768px) {
    .drop-zone-text-mobile {
        display: block;
        font-size: 13px;
    }
    
    .drop-zone-text-desktop {
        display: none;
    }

    .drop-zone-content {
        gap: 6px;
    }
}

.drop-zone-content p strong {
    color: var(--stone-700);
    font-weight: 600;
}

.drop-zone-ratio {
    font-size: 12px !important;
    color: var(--stone-400) !important;
    font-style: italic;
}

/* Barre de recherche */
.search-container {
    margin: 20px 30px;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    border: 1px solid var(--stone-200);
    border-radius: 12px;
}

.search-icon {
    position: absolute;
    left: 16px;
    color: var(--stone-500);
    pointer-events: none;
}

.search-input {
    flex: 1;
    padding: 12px 16px 12px 48px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-family: Arial, sans-serif;
    background: white;
    color: #333;
    width: 100%;
}

.search-input::placeholder {
    color: var(--stone-400);
}

.search-input:focus {
    outline: none;
}

/* Résultats Unsplash */
.unsplash-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    padding: 20px 30px 30px;
}

.unsplash-image {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.unsplash-image:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.loading,
.error {
    padding: 40px;
    text-align: center;
    color: #666;
    font-size: 16px;
}

.error {
    color: #d32f2f;
}

/* Container pour les images scannées */
.scanned-images-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5; /* ⚠️ Sous le container des textbox (z-index: 10) */
    z-index: 5;
    pointer-events: none;
    overflow: visible !important;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform-style: preserve-3d;
    transform: translateZ(0);
}

.scanned-image {
    position: absolute;
    cursor: move;
    pointer-events: all;
    z-index: 10; /* ⚠️ Au-dessus des textbox (z-index: 1) mais sous les toolbars (10014+) */
    overflow: visible;
    border-radius: 8px;
    transform: translateZ(0);
    transform-style: flat;
    /* isolation: isolate; */ /* ⚠️ RETIRÉ : créait un stacking context qui isolait le z-index */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.scanned-image.selected {
    background: rgba(255, 0, 195, 0.05);
    z-index: 1000 !important; /* ⚠️ Au-dessus de tout pour manipulation */
}

.scanned-image img {
    display: block;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    border-radius: 8px;
    border: 1px dashed transparent;
    transition: border 0.3s ease;
    pointer-events: none;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

.scanned-image.selected img {
    border: 1px dashed rgba(255, 0, 195, 0.7);
}

.scanned-image.processing img {
    border: none;
}

.scanned-image-delete {
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 10010;
    pointer-events: none;
    border: none !important;
    /* Dimensions par défaut */
    width: 32px;
    height: 32px;
    position: absolute;
    top: -16px;
    left: -16px;
}

/* Style bulle pour le bouton delete en desktop */
@media (min-width: 768px) {
    .scanned-image-delete {
        background: white;
        border-radius: 50%;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        padding: 6px;
        display: flex !important;
        align-items: center;
        justify-content: center;
        object-fit: contain;
    }
    
    .scanned-image-delete:hover {
        transform: scale(1.15) !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    }
    
    .scanned-image-delete:active {
        transform: scale(1.05) !important;
    }
}

.scanned-image.selected .scanned-image-delete {
    opacity: 1;
    pointer-events: all;
    z-index: 1001 !important; /* ⚠️ Au-dessus de l'image sélectionnée */
}

.scanned-image.processing .scanned-image-delete {
    opacity: 0 !important;
    pointer-events: none !important;
}

.image-resize-handle {
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 10010;
    pointer-events: none;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    /* Dimensions par défaut */
    width: 20px;
    height: 20px;
    position: absolute;
    bottom: -10px;
    right: -10px;
}

/* Style bulle pour les handles en desktop */
@media (min-width: 768px) {
    .image-resize-handle {
        background: white;
        border: 2px solid #FF00C3;
        border-radius: 50%;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
        cursor: nwse-resize;
    }
    
    .image-resize-handle:hover {
        transform: scale(1.2);
        box-shadow: 0 3px 10px rgba(255, 0, 195, 0.3);
    }
    
    .image-resize-handle::before {
        content: '';
        position: absolute;
        width: 4px;
        height: 4px;
        background: #FF00C3;
        border-radius: 50%;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
}

.scanned-image.selected .image-resize-handle {
    opacity: 1;
    pointer-events: all;
    z-index: 1001 !important; /* ⚠️ Au-dessus de l'image sélectionnée */
}

.scanned-image.processing .image-resize-handle {
    opacity: 0 !important;
    pointer-events: none !important;
}

.image-rotate-handle {
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 10010;
    pointer-events: none;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    /* Dimensions par défaut */
    width: 20px;
    height: 20px;
    position: absolute;
    top: -10px;
    right: -10px;
}

/* Style bulle pour le handle de rotation en desktop */
@media (min-width: 768px) {
    .image-rotate-handle {
        background: white;
        border: 2px solid #FF00C3;
        border-radius: 50%;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
        cursor: grab;
    }
    
    .image-rotate-handle:active {
        cursor: grabbing;
    }
    
    .image-rotate-handle:hover {
        transform: scale(1.2);
        box-shadow: 0 3px 10px rgba(255, 0, 195, 0.3);
    }
    
    .image-rotate-handle::before {
        content: '↻';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        font-size: 10px;
        color: #FF00C3;
        font-weight: bold;
    }
}

.scanned-image.selected .image-rotate-handle {
    opacity: 1;
    pointer-events: all;
    z-index: 1001 !important; /* ⚠️ Au-dessus de l'image sélectionnée */
}

.scanned-image.processing .image-rotate-handle {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Masquer les handles desktop en mobile, mais garder le bouton trash */
@media (max-width: 767px) {
    .scanned-image.selected .image-resize-handle,
    .scanned-image.selected .image-rotate-handle {
        display: none !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
    
    /* Masquer la toolbar desktop */
    .scanned-image .image-toolbar {
        display: none !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
    
    /* Garder le bouton trash visible en mobile */
    .scanned-image.selected .scanned-image-delete {
        opacity: 1 !important;
        pointer-events: all !important;
        display: block !important;
    }
    
    /* Toolbar mobile personnalisée - Juste en dessous de la carte */
    .mobile-image-toolbar,
    #mobileImageToolbar {
        position: fixed !important;
        bottom: -16px !important; /* Remontée de 5px */
        left: 50% !important;
        transform: translateX(-50%) translateY(10px) !important;
        background: white !important;
        border-radius: 100px !important;
        border: 1px solid var(--stone-100) !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
        padding: 5px !important;
        height: 42px !important;
        display: flex !important;
        gap: 4px !important;
        align-items: center !important;
        z-index: 30001 !important; /* Au-dessus de la carte */
        opacity: 0;
        pointer-events: none;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease !important;
    }
    
    .mobile-image-toolbar.visible {
        opacity: 1 !important;
        pointer-events: all !important;
        visibility: visible !important;
        transform: translateX(-50%) translateY(0) !important;
    }
    
    .mobile-toolbar-btn {
        width: 32px;
        height: 32px;
        background: var(--stone-100);
        border: none;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: background 0.2s, transform 0.1s;
        flex-shrink: 0;
        padding: 0;
    }
    
    .mobile-toolbar-btn svg {
        width: auto;
        height: auto;
        display: block;
    }
    
    .mobile-toolbar-btn:active {
        background: var(--stone-200);
        transform: scale(0.95);
    }
    
    .mobile-toolbar-separator {
        width: 1px;
        height: 24px;
        background: var(--stone-200);
        flex-shrink: 0;
    }
}

/* Le handle de rotation est géré en JavaScript, mais on peut aussi ajouter un style CSS si nécessaire */

.image-toolbar {
    display: none !important; /* ⚠️ Toolbar désactivée en desktop */
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10010;
    pointer-events: none !important;
}

.scanned-image.selected .image-toolbar {
    display: none !important; /* ⚠️ Toolbar désactivée même quand sélectionnée */
    opacity: 0 !important;
    pointer-events: none !important;
}

.scanned-image.processing .image-toolbar {
    opacity: 0 !important;
    pointer-events: none;
}

.eraser-canvas {
    user-select: none;
    -webkit-user-select: none;
}

.eraser-cursor {
    transition: none;
    will-change: transform;
}

/* Overlay de traitement avec effet de reflet */
.processing-shimmer {
    position: absolute;
    top: 0;
    left: -100%;
    width: 150%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.3) 20%,
        rgba(255, 255, 255, 0.8) 40%,
        rgba(255, 255, 255, 1) 50%,
        rgba(255, 255, 255, 0.8) 60%,
        rgba(255, 255, 255, 0.3) 80%,
        transparent 100%
    );
    animation: shimmer 1.2s infinite;
    transform: skewX(-25deg);
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.6);
    filter: blur(2px);
}

@keyframes shimmer {
    0% {
        left: -150%;
    }
    100% {
        left: 100%;
    }
}

.scanned-image.processing {
    overflow: visible;
    position: relative;
}

.scanned-image.processing::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    animation: pulse 2s infinite;
    z-index: 9;
    pointer-events: none;
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.1;
    }
    50% {
        opacity: 0.3;
    }
}

.processing-message {
    /* Les styles sont maintenant définis inline dans le JavaScript pour un positionnement précis */
}

.scanned-image.processing {
    overflow: visible;
}

@keyframes spin {
    0% {
        transform: translate(-50%, -50%) rotate(0deg);
    }
    100% {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

.scanned-image.processing img {
    position: relative !important;
    overflow: hidden !important;
}

.scanned-image.processing {
    position: relative;
}

/* Styles pour le modal de scan */
.scan-description {
    text-align: center;
    margin-bottom: 25px;
    padding: 15px;
    background: rgba(255, 0, 195, 0.05);
    border-radius: 12px;
    border: 1px solid rgba(255, 0, 195, 0.1);
}

.scan-description p {
    color: #57534e;
    font-size: 14px;
    line-height: 1.6;
    margin: 0;
}

.scan-image-container {
    margin-bottom: 12px;
    margin-left: auto;
    margin-right: auto;
    width: fit-content;
    height: fit-content;
    max-width: 100%;
    position: relative;
    border-radius: 18px;
    overflow: hidden;
    display: block;
}

.scan-image-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 2px solid rgba(0, 0, 0, 0.08);
    border-radius: 18px;
    pointer-events: none;
    z-index: 1;
}

.scan-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    padding: 20px;
}

.scan-image-loader {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 18px;
    z-index: 2;
}

.scan-image-loader .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--stone-200);
    border-top-color: var(--stone-700);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.scan-text-image {
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: 350px;
    margin: 0;
    display: block;
    box-sizing: border-box;
    object-fit: contain;
}

.scan-instructions {
    text-align: left;
    margin-bottom: 12px;
    color: #666;
}

.scan-camera-button {
    width: 100%;
    padding: 15px;
    background: #FF00C3;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    margin-top: 8px;
    display: block;
    text-align: center;
    font-weight: 600;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.scan-camera-button:hover {
    background: #e600b3;
}

#qrcode-wrapper {
    display: none;
    flex-direction: column;
    align-items: center;
    background: white;
    border-radius: 18px;
    padding: 24px;
    width: fit-content;
    margin: 0 auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    position: relative;
}

#qrcode-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 18px;
    pointer-events: none;
    z-index: 1;
}

#qrcode {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto 16px;
    background: white;
    padding: 0;
    width: fit-content;
    position: relative;
    z-index: 0;
}

.scan-status {
    text-align: center;
    margin: 0;
    padding: 8px 12px;
    color: var(--stone-700);
    background: var(--stone-100);
    border-radius: 12px;
    font-size: 14px;
    width: fit-content;
    position: relative;
    z-index: 0;
}

.scan-content-area {
    margin-bottom: 16px;
}

.scan-start-button {
    width: 100%;
    padding: 16px 24px;
    background: var(--stone-800);
    color: var(--stone-100);
    border: none;
    border-radius: 100px;
    font-size: 16px;
    font-weight: 600;
    font-family: Arial, sans-serif;
    cursor: pointer;
    transition: background 0.3s;
    margin-top: 16px;
}

.scan-start-button:hover {
    background: var(--stone-700);
}

.scan-start-button:active {
    background: var(--stone-900);
}

/* Masquer le bouton "Commencer" sur mobile */
#mobileScanSection .scan-start-button {
    display: none;
}

/* Message de remerciement */
.thank-you-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 0; /* Sous la carte (qui a z-index: 1) */
    transition: none; /* Pas d'animation */
}


.thank-you-message.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto; /* Activer les interactions quand visible */
}

.thank-you-text {
    font-size: 18px;
    font-weight: bold;
    color: var(--stone-800);
    text-align: center;
    margin: 0;
    font-family: 'Daniel', 'Patrick Hand', cursive;
}

.create-new-card-button {
    padding: 12px 24px;
    background: var(--stone-800);
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 500;
    font-family: Arial, sans-serif;
    cursor: pointer;
    transition: background 0.3s ease;
}

.create-new-card-button:hover {
    background: var(--stone-900);
}

.create-new-card-button:active {
    background: var(--stone-700);
}

/* Responsive pour le message de remerciement */
@media (max-width: 767px) {
    .thank-you-text {
        font-size: 16px;
    }
    
    .create-new-card-button {
        padding: 10px 20px;
        font-size: 14px;
    }
}

/* Animation bottom sheet */
@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from {
        transform: translateY(0);
    }
    to {
        transform: translateY(100%);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

@keyframes zoomIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes zoomOut {
    from {
        transform: scale(1);
        opacity: 1;
    }
    to {
        transform: scale(0.9);
        opacity: 0;
    }
}

/* Animations pour l'overlay (mobile et desktop) */
.modal-overlay.show {
    animation: fadeIn 0.3s ease-out forwards;
}

.modal-overlay.hide {
    animation: fadeOut 0.3s ease-out forwards;
}

/* Animation zoom pour le contenu en desktop */
@media (min-width: 769px) {
    .modal-overlay.show .modal-content {
        animation: zoomIn 0.3s ease-out forwards;
    }
    
    .modal-overlay.hide .modal-content {
        animation: zoomOut 0.3s ease-out forwards;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }
    
    .modal-content {
        max-width: 100%;
        margin: 0;
        border-radius: 32px 32px 0 0;
        max-height: 90vh;
        position: relative;
        padding: 16px 20px 20px 20px;
        opacity: 1 !important;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        will-change: transform;
    }
    
    /* État initial : modal caché en bas */
    .modal-overlay:not(.show) .modal-content {
        transform: translateY(100%);
    }
    
    /* Animation d'ouverture */
    .modal-overlay.show .modal-content {
        animation: slideUp 0.3s ease-out forwards;
        opacity: 1 !important;
    }
    
    /* Animation de fermeture */
    .modal-overlay.hide .modal-content {
        animation: slideDown 0.3s ease-out forwards;
        opacity: 1 !important;
    }
    
    /* S'assurer que le contenu mobile est en flexbox pour garder les boutons visibles */
    #mobileScanSection {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }
    
    /* Réduire la taille de l'image pour laisser de la place aux boutons */
    #mobileScanSection .scan-image-container {
        max-height: 40vh;
        overflow: hidden;
        flex-shrink: 0;
    }
    
    #mobileScanSection .scan-image-container img {
        max-height: 40vh;
        width: auto;
        height: auto;
        object-fit: contain;
    }
    
    /* Garder les instructions et le bouton toujours visibles */
    #mobileScanSection .scan-instructions {
        flex-shrink: 0;
        margin-bottom: 12px;
    }
    
    #mobileScanSection .scan-camera-button {
        flex-shrink: 0;
        margin-top: auto;
        margin-bottom: 0;
    }
    
    .modal-handle {
        width: 40px;
        height: 4px;
        background: var(--stone-300);
        border-radius: 100px;
        margin: 0 auto;
        cursor: pointer;
        transition: background 0.2s;
    }
    
    .modal-handle:hover {
        background: var(--stone-400);
    }
    
    .scan-camera-button {
        background: #2C2C2C;
        color: white;
        border-radius: 100px;
        padding: 16px 24px;
        font-size: 16px;
        font-weight: 600;
        margin-top: 16px;
    }
    
    .scan-camera-button:hover {
        background: #1a1a1a;
    }
    
    .unsplash-results {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 10px;
    }
    
    .unsplash-image {
        height: 100px;
    }
    
    /* Handles plus grands en mobile pour faciliter l'utilisation */
    .image-resize-handle {
        width: 20px !important;
        height: 20px !important;
        bottom: -6px !important;
        right: -6px !important;
    }
    
    .image-rotate-handle {
        width: 20px !important;
        height: 20px !important;
        top: -6px !important;
        right: -6px !important;
    }
    
    .scanned-image-delete {
        width: 48px !important; /* ⚠️ Même taille que bin-icon des textbox */
        height: 48px !important;
        top: -24px !important; /* Ajusté pour centrer avec 48px */
        left: -24px !important;
    }
}

/* Styles pour le side sheet de paywall Stripe */
.side-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 30000;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.side-sheet-overlay.show {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

/* Desktop : pas d'overlay, juste pointer-events pour fermer */
@media (min-width: 768px) {
    .side-sheet-overlay {
        background: transparent;
        pointer-events: none;
    }
    
    .side-sheet-overlay.show {
        pointer-events: auto;
    }
}

/* Desktop : popup en bas à droite */
.side-sheet {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 100%;
    max-width: 420px;
    height: auto;
    max-height: calc(100vh - 40px);
    background: var(--stone-50);
    border: 1px solid var(--stone-200);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    border-radius: 32px;
    z-index: 30001;
    display: flex;
    flex-direction: column;
    transform: translateY(calc(100% + 20px)) scale(0.95);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.side-sheet-overlay.show .side-sheet {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* Mobile : bottom sheet */
@media (max-width: 767px) {
    .side-sheet-overlay {
        align-items: flex-end;
        justify-content: center;
    }
    
    .side-sheet {
        bottom: 0;
        right: 0;
        left: 0;
        max-width: 100%;
        height: auto;
        max-height: 90vh;
        border-radius: 32px 32px 0 0;
        transform: translateY(100%);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
        position: relative;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .side-sheet-overlay.show .side-sheet {
        transform: translateY(0);
    }
    
    /* Handle pour le swipe down sur mobile (générique, masquée pour CSV plus bas) */
    .side-sheet .modal-handle {
        width: 40px;
        height: 4px;
        background: var(--stone-300);
        border-radius: 100px;
        margin: 12px auto 16px auto;
        cursor: pointer;
        transition: background 0.2s;
        position: relative;
        z-index: 1;
    }
    
    .side-sheet .modal-handle:hover {
        background: var(--stone-400);
    }
}

.side-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--stone-200);
    position: relative;
    background: var(--stone-50);
    z-index: 10;
    flex-shrink: 0;
}

.side-sheet-close {
    position: absolute;
    top: 24px;
    right: 20px;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--stone-300);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: color 0.2s;
    z-index: 100;
    font-weight: 200;
}

/* Bouton de fermeture pour le side sheet CSV */
#csvImportSideSheet .side-sheet-close {
    top: 24px;
    right: 20px;
}

/* Masquer la handle uniquement dans le side sheet de publipostage CSV */
#csvImportSideSheet .modal-handle {
    display: none;
}

/* Bouton de fermeture pour la modal d'écriture manuscrite (desktop uniquement) */
.modal-close-desktop {
    position: absolute;
    top: 24px;
    right: 20px;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--stone-300);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: color 0.2s;
    z-index: 100;
    font-weight: 200;
}

.modal-close-desktop:hover {
    color: var(--stone-500);
}

/* Masquer les handles et afficher les boutons de fermeture en desktop pour les popups de paiement et d'écriture manuscrite */
@media (min-width: 768px) {
    #paywallSideSheet .modal-handle {
        display: none;
    }
    
    #scanModalOverlay .modal-handle {
        display: none;
    }
    
    /* Afficher les boutons de fermeture uniquement en desktop */
    .modal-close-desktop,
    #paywallModalClose {
        display: flex;
    }
}

.side-sheet-close:hover {
    color: var(--stone-500);
}

.paywall-content {
    padding: 0 24px 16px 24px;
    flex: 0 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    background: var(--stone-50);
    /* Améliorer le scroll tactile sur mobile */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
}

@media (min-width: 768px) {
    .paywall-content {
        margin-top: 24px;
    }
}

.paywall-header-section {
    margin-bottom: 24px;
}

.paywall-icon-wrapper {
    margin-bottom: 16px;
}

.paywall-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--stone-900);
    margin: 0 0 8px 0;
    line-height: 1.3;
}

.paywall-subtitle {
    font-size: 14px;
    color: var(--stone-500);
    margin: 0;
    line-height: 1.4;
}

.paywall-separator {
    width: calc(100% + 48px);
    height: 1px;
    background: var(--stone-200);
    margin: 24px -24px;
    box-sizing: border-box;
}

.paywall-price-detail {
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--stone-50);
    border-radius: 8px;
    border: 1px solid var(--stone-100);
}

.paywall-price-detail-text {
    font-size: 14px;
    color: var(--stone-600);
    font-weight: 500;
}

.paywall-price-section {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 24px;
}

.paywall-price-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.paywall-price-calculation {
    font-size: 14px;
    color: var(--stone-400);
    margin-top: 8px;
}

.paywall-price-amount {
    font-size: 20px;
    font-weight: 700;
    color: var(--stone-900);
}

.paywall-price-note {
    font-size: 14px;
    color: var(--stone-400);
}

.paywall-description {
    font-size: 16px;
    color: var(--stone-600);
    margin-bottom: 24px;
    line-height: 1.5;
    text-align: left;
}

.paywall-price {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 32px;
    padding: 24px;
    background: var(--stone-100);
    border-radius: 16px;
    text-align: center;
}

.price-amount {
    font-size: 48px;
    font-weight: 700;
    color: var(--stone-900);
    line-height: 1;
    margin-bottom: 8px;
}

.price-label {
    font-size: 14px;
    color: var(--stone-600);
}

.paywall-buttons-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

.paywall-button {
    width: 100%;
    padding: 16px 24px;
    background: #000;
    color: white;
    border: none;
    border-radius: 999px;
    font-size: 16px;
    font-weight: 500;
    font-family: Arial, sans-serif;
    cursor: pointer;
    transition: background 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
}

.paywall-button:hover {
    background: var(--stone-900);
}

.paywall-button:active {
    background: var(--stone-950);
}

.paywall-button:disabled {
    background: var(--stone-300);
    cursor: not-allowed;
}

.paywall-button-apple-pay {
    background: #000;
    color: white;
}

.paywall-button-apple-pay:hover {
    background: #1a1a1a;
}

.paywall-button-apple-pay:active {
    background: #2a2a2a;
}

/* 
 * Le bouton Apple Pay est géré dynamiquement par JavaScript
 * Il s'affiche sur tous les appareils Apple (Mac + iPhone/iPad) si Apple Pay est disponible
 * Par défaut il est masqué, le JS le rend visible quand Apple Pay est détecté
 */

.paywall-security-note {
    font-size: 11px;
    color: var(--stone-500);
    text-align: center;
    margin: 0;
    line-height: 1.4;
    font-family: Arial, sans-serif;
}

.paywall-error {
    color: #d32f2f;
    font-size: 14px;
    margin-top: 16px;
    padding: 12px;
    background: rgba(211, 47, 47, 0.1);
    border-radius: 8px;
}

.paywall-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-top: 16px;
}

.paywall-loading p {
    color: var(--stone-600);
    font-size: 14px;
    margin: 0;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--stone-200);
    border-top-color: var(--stone-600);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Styles pour le popup de choix de prix libre */
.price-popup-overlay {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 30001;
    pointer-events: none;
}

.price-popup {
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    padding: 24px;
    min-width: 320px;
    max-width: 400px;
    pointer-events: all;
    animation: slideUpPopup 0.3s ease-out;
}

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

.price-popup-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--stone-600);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
    padding: 0;
    line-height: 1;
}

.price-popup-close:hover {
    background: var(--stone-100);
}

.price-popup-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--stone-900);
    margin: 0 0 8px 0;
    padding-right: 32px;
}

.price-popup-description {
    font-size: 14px;
    color: var(--stone-600);
    margin: 0 0 20px 0;
}

.price-input-container {
    margin-bottom: 20px;
}

.price-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--stone-700);
    margin-bottom: 8px;
}

.price-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--stone-300);
    border-radius: 8px;
    font-size: 18px;
    font-weight: 600;
    color: var(--stone-900);
    text-align: center;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.price-input:focus {
    outline: none;
    border-color: #635BFF;
}

.price-slider-container {
    margin-bottom: 20px;
}

.price-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--stone-200);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    margin-bottom: 8px;
}

.price-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #635BFF;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

.price-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.price-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #635BFF;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

.price-slider::-moz-range-thumb:hover {
    transform: scale(1.1);
}

.price-slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--stone-500);
}

.price-display {
    text-align: center;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--stone-100);
    border-radius: 12px;
}

.price-display-amount {
    font-size: 32px;
    font-weight: 700;
    color: var(--stone-900);
}

.price-popup-button {
    width: 100%;
    padding: 16px 24px;
    background: #635BFF;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    font-family: Arial, sans-serif;
    cursor: pointer;
    transition: background 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.price-popup-button:hover {
    background: #5851EA;
}

.price-popup-button:active {
    background: #4C45D1;
}

.price-popup-button:disabled {
    background: var(--stone-300);
    cursor: not-allowed;
}

.price-popup-error {
    margin-top: 12px;
    padding: 12px;
    background: rgba(239, 68, 68, 0.1);
    color: rgb(220, 38, 38);
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
}

/* Mobile : ajuster le popup */
@media (max-width: 767px) {
    .price-popup-overlay {
        bottom: 80px; /* Au-dessus des boutons */
        right: 16px;
        left: 16px;
    }
    
    .price-popup {
        min-width: auto;
        width: 100%;
        max-width: none;
    }
}

/* Styles pour le code promo */
.promo-code-container {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    width: 100%;
}

.promo-code-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--stone-300);
    border-radius: 8px;
    font-size: 14px;
    font-family: Arial, sans-serif;
    transition: border-color 0.2s;
}

.promo-code-input:focus {
    outline: none;
    border-color: #635BFF;
}

.promo-code-button {
    padding: 12px 20px;
    background: var(--stone-200);
    color: var(--stone-700);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    font-family: Arial, sans-serif;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.promo-code-button:hover {
    background: var(--stone-300);
}

.promo-code-button:active {
    background: var(--stone-400);
}

.promo-code-message {
    margin-bottom: 16px;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
}

.promo-code-message.success {
    background: rgba(34, 197, 94, 0.1);
    color: rgb(22, 163, 74);
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.promo-code-message.error {
    background: rgba(239, 68, 68, 0.1);
    color: rgb(220, 38, 38);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.price-amount.discounted {
    color: #10b981;
    text-decoration: line-through;
}

.price-amount.free {
    color: #10b981;
    font-size: 36px;
}

/* Styles pour le bouton Publipostage */
.bulk-import-button {
    position: fixed !important;
    bottom: 20px;
    left: 20px;
    padding: 12px 20px;
    background: var(--stone-50);
    color: var(--stone-700);
    border: 1px solid var(--stone-100);
    border-radius: 100px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    font-family: Arial, sans-serif;
    box-shadow: none !important;
    transition: opacity 0.5s ease-in, background 0.3s;
    z-index: 10008;
    pointer-events: all !important;
    opacity: 0; /* Masquer initialement pour éviter le clignotement */
}

.bulk-import-button:hover {
    background: var(--stone-200);
}

.bulk-import-button:active {
    background: var(--stone-300);
}

/* Desktop : styles spécifiques pour le bouton publipostage */
@media (min-width: 768px) {
    .bulk-import-button:hover {
        background: var(--stone-100);
    }
}

.bulk-import-button svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Styles pour la navigation entre cartes */
.card-navigation {
    position: fixed !important;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
    background: white;
    padding: 4px;
    border-radius: 100px;
    box-shadow: none !important;
    transition: opacity 0.4s ease-out;
    z-index: 10009;
    pointer-events: all !important;
    visibility: visible !important;
    opacity: 1 !important;
    height: 44px;
    min-height: 44px;
    max-height: 44px;
    box-sizing: border-box;
}

.nav-button {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    padding: 0;
}

.nav-button:hover {
    background: var(--stone-100);
}

.nav-button:active {
    background: var(--stone-200);
}

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

.nav-button svg {
    width: 16px;
    height: 16px;
    color: var(--stone-700);
}

.nav-counter {
    font-size: 14px;
    font-weight: 500;
    color: var(--stone-700);
    font-family: Arial, sans-serif;
    min-width: 50px;
    text-align: center;
}

/* Styles pour l'import CSV - Side sheet en bas à gauche */
.side-sheet-left {
    right: auto !important;
    left: 20px !important;
}

@media (max-width: 767px) {
    .side-sheet-left {
        left: 0 !important;
        right: 0 !important;
    }
}

.csv-import-content {
    padding: 0 24px 8px 24px;
    flex: 0 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    background: var(--stone-50);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    /* Transition gérée en JavaScript pour éviter les conflits */
}

@media (min-width: 768px) {
    .csv-import-content {
        margin-top: 24px;
    }
}

.csv-import-header-section {
    margin-bottom: 24px;
}

.csv-import-icon-wrapper {
    margin-bottom: 16px;
}

.csv-import-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--stone-900);
    margin: 0 0 8px 0;
    line-height: 1.3;
}

.csv-import-subtitle {
    font-size: 14px;
    color: var(--stone-500);
    margin: 0;
    line-height: 1.4;
}

.csv-import-separator {
    width: calc(100% + 48px);
    height: 1px;
    background: var(--stone-200);
    margin: 24px -24px;
    box-sizing: border-box;
}

.csv-download-template-button {
    width: 100%;
    margin: 8px 0 20px 0;
    padding: 0;
    background: transparent;
    color: var(--stone-700);
    border: none;
    font-size: 14px;
    font-weight: 500;
    font-family: Arial, sans-serif;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-start;
    text-align: left;
}

.csv-download-template-button:hover {
    background: transparent;
    border: none;
    color: var(--stone-900);
}

.csv-download-template-button:active {
    background: transparent;
    border: none;
}

.csv-download-template-button svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.csv-drop-zone {
    margin: 0 0 20px 0;
}

.csv-preview {
    margin: 0 0 20px 0;
    padding: 0;
    background: transparent;
    border-radius: 0;
    border: none;
}

/* Tabs pour choisir entre CSV et Saisie manuelle */
.bulk-method-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 24px;
    padding: 6px;
    background: var(--stone-100);
    border-radius: 12px;
    position: relative;
}

/* Indicateur de fond animé */
.bulk-method-tabs::before {
    content: '';
    position: absolute;
    top: 6px;
    bottom: 6px;
    left: 6px;
    width: calc(50% - 9px);
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08),
                0 1px 2px rgba(0, 0, 0, 0.06);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
}

/* Position de l'indicateur selon l'onglet actif */
.bulk-method-tabs[data-active="manual"]::before {
    transform: translateX(calc(100% + 6px));
}

.bulk-tab-button {
    flex: 1;
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--stone-500);
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 2;
    font-family: Arial, sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.bulk-tab-button svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.bulk-tab-button:hover {
    color: var(--stone-700);
}

.bulk-tab-button.active {
    color: var(--stone-800);
}

/* Animations pour smart animate - transitions gérées en JavaScript */

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

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

/* Formulaire de saisie manuelle */
.manual-address-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 16px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--stone-700);
}

.form-group input {
    padding: 10px 12px;
    border: 1px solid var(--stone-200);
    border-radius: 8px;
    font-size: 14px;
    font-family: Arial, sans-serif;
    color: var(--stone-900);
    background: white;
    transition: all 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--stone-400);
    box-shadow: 0 0 0 3px rgba(87, 83, 78, 0.1);
}

.form-group input::placeholder {
    color: var(--stone-400);
}

.form-group-half {
    flex: 1;
    margin-bottom: 0;
}

.form-group-small {
    flex: 0 0 120px;
    margin-bottom: 0;
}

.form-group-large {
    flex: 1;
    margin-bottom: 0;
}

.add-address-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--stone-900);
    color: white;
    border: none;
    border-radius: 100px;
    font-size: 14px;
    font-weight: 500;
    font-family: Arial, sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}

.add-address-button:hover {
    background: var(--stone-800);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.add-address-button:active {
    transform: translateY(0);
}

.add-address-button svg {
    width: 16px;
    height: 16px;
}


/* Section de gestion des adresses */
.manage-addresses-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.manage-address-card {
    background: white;
    border: 1px solid var(--stone-200);
    border-radius: 12px;
    padding: 10px 12px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.manage-address-card:hover {
    border-color: var(--stone-300);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.manage-address-compact {
    display: flex;
    align-items: center;
    gap: 12px;
}

.manage-address-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--stone-700);
    color: var(--stone-100);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.manage-address-info-compact {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.manage-address-name-line {
    font-size: 14px;
    font-weight: 400;
    color: var(--stone-700);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.manage-address-full-line {
    font-size: 13px;
    font-weight: 400;
    color: var(--stone-400);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.manage-address-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.manage-address-edit,
.manage-address-delete {
    padding: 6px;
    border: 1px solid var(--stone-200);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.manage-address-edit {
    background: var(--stone-50);
    color: var(--stone-500);
    border-color: var(--stone-200);
}

.manage-address-edit:hover {
    background: var(--stone-100);
    border-color: var(--stone-300);
    color: var(--stone-700);
}

.manage-address-delete {
    background: #fef2f2;
    color: #ef4444;
    border-color: #fecaca;
}

.manage-address-delete:hover {
    background: #fee2e2;
    border-color: #ef4444;
    color: #dc2626;
}

.manage-address-edit svg,
.manage-address-delete svg {
    width: 16px;
    height: 16px;
}

/* Formulaire d'édition dans la carte */
.manage-address-edit-form {
    margin-top: 16px;
    padding-top: 20px;
    border-top: 1px solid var(--stone-200);
    display: none;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.manage-address-edit-form.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.manage-address-edit-form .form-row {
    display: flex;
    gap: 12px;
}

.manage-address-edit-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.manage-address-edit-form .form-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--stone-400);
}

.manage-address-edit-form .edit-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--stone-200);
    border-radius: 8px;
    font-size: 14px;
    font-family: Arial, sans-serif;
    color: var(--stone-900);
    background: white;
    transition: all 0.2s;
    box-sizing: border-box;
}

.manage-address-edit-form .edit-input:focus {
    outline: none;
    border-color: var(--stone-400);
    box-shadow: 0 0 0 3px rgba(87, 83, 78, 0.1);
}

.manage-address-edit-form .edit-input::placeholder {
    color: var(--stone-400);
}

.manage-edit-actions {
    display: flex;
    flex-direction: row-reverse;
    gap: 8px;
    margin-top: 16px;
}

.manage-edit-save,
.manage-edit-cancel {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.2s;
}

.manage-edit-save {
    background: var(--stone-900);
    color: white;
}

.manage-edit-save:hover {
    background: var(--stone-800);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.manage-edit-save:active {
    transform: translateY(0);
}

.manage-edit-cancel {
    background: white;
    color: var(--stone-700);
    border: 1px solid var(--stone-200);
}

.manage-edit-cancel:hover {
    background: var(--stone-50);
    border-color: var(--stone-300);
}

@media (max-width: 767px) {
    .manage-address-edit-form .form-row {
        flex-direction: column;
        gap: 0;
    }
}

/* Vue de gestion avec bouton ajouter */
.bulk-manage-view {
    margin-bottom: 20px;
}

.bulk-manage-header-with-icon {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
}

.bulk-manage-icon-wrapper {
    flex-shrink: 0;
}

.bulk-manage-icon-wrapper svg {
    width: 56px;
    height: 56px;
}

.bulk-manage-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--stone-900);
    text-align: center;
    flex: 1;
}

/* Bouton ajouter destinataires en format carte */
.bulk-add-recipients-card {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    background: white;
    border: 1px dashed var(--stone-300);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    color: var(--stone-600);
    cursor: pointer;
    transition: all 0.2s;
}

.bulk-add-recipients-card:hover {
    border-color: var(--stone-400);
    background: var(--stone-50);
    color: var(--stone-900);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.bulk-add-recipients-card svg {
    width: 18px;
    height: 18px;
}

/* Choix de méthode d'ajout */
.bulk-add-method-choice {
    margin-bottom: 20px;
    padding: 16px;
    background: var(--stone-50);
    border-radius: 8px;
    border: 1px solid var(--stone-200);
}

.bulk-add-method-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--stone-900);
    margin: 0 0 12px 0;
}

.bulk-add-method-buttons {
    display: flex;
    gap: 12px;
}

.bulk-method-choice-button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px;
    background: white;
    border: 2px solid var(--stone-200);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--stone-700);
    cursor: pointer;
    transition: all 0.3s ease;
}

.bulk-method-choice-button:hover {
    border-color: var(--stone-400);
    background: var(--stone-50);
    color: var(--stone-900);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.bulk-method-choice-button svg {
    width: 24px;
    height: 24px;
}

@media (max-width: 767px) {
    .manage-address-compact {
        gap: 8px;
    }
    
    .manage-address-info-compact {
        font-size: 13px;
    }
    
    .manage-address-name-line {
        font-size: 13px;
    }
    
    .manage-address-full-line {
        font-size: 12px;
    }
    
    .bulk-add-method-buttons {
        flex-direction: column;
    }
}

@media (max-width: 767px) {
    .form-row {
        flex-direction: column;
        gap: 16px;
    }
    
    .form-group-small {
        flex: 1;
    }
    
    .bulk-tab-button {
        font-size: 13px;
        padding: 8px 10px;
        gap: 6px;
    }
    
    .bulk-tab-button svg {
        width: 14px;
        height: 14px;
    }
    
    .bulk-method-tabs {
        padding: 4px;
        gap: 4px;
    }
    
    .bulk-method-tabs::before {
        top: 4px;
        bottom: 4px;
        left: 4px;
        width: calc(50% - 6px);
    }
    
    .bulk-method-tabs[data-active="manual"]::before {
        transform: translateX(calc(100% + 4px));
    }
    
    .manual-addresses-items {
        max-height: 250px;
    }
}


#csvPreviewContent {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 16px;
    padding: 12px;
    background: white;
    border-radius: 8px;
    border: 1px solid var(--stone-200);
}

.csv-preview-item {
    padding: 8px 12px;
    margin-bottom: 8px;
    background: var(--stone-50);
    border-radius: 6px;
    font-size: 13px;
    color: var(--stone-700);
    font-family: Arial, sans-serif;
    border-left: none;
}

.csv-preview-item:last-child {
    margin-bottom: 0;
}

.csv-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 16px;
}

.csv-cancel-button,
.csv-import-button {
    padding: 14px 0;
    border: none;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 500;
    font-family: Arial, sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1 1 0;
    text-align: center;
}

.csv-cancel-button {
    background: var(--stone-200);
    color: var(--stone-700);
}

.csv-cancel-button:hover {
    background: var(--stone-300);
}

.csv-import-button {
    background: var(--stone-800);
    color: white;
}

.csv-import-button:hover {
    background: var(--stone-900);
}

.csv-error {
    margin: 0;
    padding: 16px;
    background: rgba(239, 68, 68, 0.1);
    color: rgb(220, 38, 38);
    border-radius: 8px;
    border: 1px solid rgba(239, 68, 68, 0.2);
    font-size: 14px;
}

/* Mobile : masquer les boutons card-navigation et Envoi groupé */
@media (max-width: 767px) {
    .bulk-import-button {
        display: none !important;
    }
    
    .card-navigation {
        display: none !important;
    }
    
    .nav-button {
        width: 28px;
        height: 28px;
    }
    
    .nav-button svg {
        width: 14px;
        height: 14px;
    }
    
    .nav-counter {
        font-size: 13px;
        min-width: 50px;
    }
    
    /* S'assurer que les boutons ne sont pas masqués par le container */
    .postcard-container > .bulk-import-button,
    .postcard-container > .card-navigation {
        position: fixed !important;
        z-index: 10020 !important;
    }
    
    .postcard-container > .card-navigation {
        z-index: 10021 !important;
    }
}

/* Desktop : aligner la hauteur du bouton publipostage et de la navigation sur le bouton Envoyer */
@media (min-width: 768px) {
    .bulk-import-button {
        height: 52px !important;
        max-height: 52px !important;
        padding: 0 20px !important;
        box-sizing: border-box !important;
    }

    .card-navigation {
        padding: 4px;
        box-sizing: border-box;
        background: white;
        height: 44px;
        min-height: 44px;
        max-height: 44px;
    }

    .nav-button {
        width: 32px;
        height: 32px;
    }
    
    .nav-button svg {
        width: 16px;
        height: 16px;
    }
    
    .nav-counter {
        font-size: 14px;
        min-width: 50px;
    }
}

/* Styles pour la barre de progression du publipostage */
/* Barre de progression pour le publipostage (sous la carte) */
.bulk-progress-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    padding: 0;
    background: transparent;
}

.bulk-progress-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: white;
    padding: 20px 24px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 300px;
}

.bulk-progress-message {
    color: #57534e;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    margin: 0;
    padding: 0;
    white-space: nowrap;
}

.bulk-progress-bar-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    justify-content: center;
}

.bulk-progress-title {
    display: none;
}

.bulk-progress-warning {
    display: none;
}

.bulk-progress-bar-container {
    width: 200px;
    height: 4px;
    background: var(--stone-200);
    border-radius: 2px;
    overflow: hidden;
}

.bulk-progress-bar {
    height: 100%;
    background: var(--stone-800);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

.bulk-progress-text {
    font-size: 12px;
    color: var(--stone-600);
    font-weight: 500;
    font-family: Arial, sans-serif;
    white-space: nowrap;
}

/* Responsive pour mobile */
@media (max-width: 767px) {
    .bulk-progress-container {
        bottom: 80px;
    }
    
    .bulk-progress-content {
        padding: 16px 20px;
        gap: 12px;
        min-width: auto;
        max-width: 90vw;
    }
    
    .bulk-progress-message {
        font-size: 12px;
        white-space: normal;
        text-align: center;
    }
    
    .bulk-progress-bar-wrapper {
        gap: 10px;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .bulk-progress-bar-container {
        width: 150px;
        height: 3px;
    }
    
    .bulk-progress-text {
        font-size: 11px;
    }
}

/* Styles pour la case de formulaire de paiement (style Luma) */
.payment-form-container {
    background: white;
    border: 1px solid var(--stone-200);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-bottom: 0;
    overflow: hidden;
    transition: box-shadow 0.2s ease;
    padding: 20px;
}

.payment-form-container:focus-within {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: var(--stone-300);
}

.payment-form-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--stone-100);
    background: var(--stone-50);
}

.payment-form-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--stone-900);
    margin: 0;
    font-family: Arial, sans-serif;
}

.payment-form-body {
    padding: 0;
}

.payment-field {
    margin-bottom: 20px;
}

.payment-field:last-child {
    margin-bottom: 24px;
}

.payment-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--stone-700);
    margin-bottom: 8px;
    font-family: Arial, sans-serif;
}

.payment-input {
    width: 100%;
    padding: 8px 16px;
    font-size: 16px;
    font-family: Arial, sans-serif;
    color: var(--stone-900);
    background: white;
    border: 1px solid var(--stone-200);
    border-radius: 12px;
    transition: all 0.2s ease;
    box-sizing: border-box;
    height: 40px;
    text-align: left;
}

.payment-input:focus {
    outline: none;
    border-color: var(--stone-500);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.payment-input::placeholder {
    color: var(--stone-400);
}

.payment-input.error {
    border-color: #dc2626;
    color: #dc2626;
}

.payment-input.error::placeholder {
    color: #dc2626;
    opacity: 0.7;
}

.stripe-card-wrapper {
    padding: 9px 16px 0 16px;
    background: white;
    border: 1px solid var(--stone-200);
    border-radius: 12px;
    transition: all 0.2s ease;
    position: relative;
    pointer-events: auto;
    height: 40px;
    overflow: hidden;
    display: flex;
    align-items: center;
    line-height: 1;
    margin: 0;
}

.stripe-card-wrapper:focus-within {
    border-color: var(--stone-500);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.stripe-card-wrapper.error {
    border-color: #dc2626;
}

.stripe-card-wrapper.error .StripeElement {
    color: #dc2626 !important;
}

.stripe-card-wrapper.error iframe {
    color: #dc2626 !important;
}

/* Style pour les éléments Stripe Card Element */
.stripe-card-wrapper .StripeElement {
    width: 100%;
    display: flex;
    align-items: center;
    height: 100%;
    min-height: 20px;
    line-height: 1;
}

.stripe-card-wrapper .StripeElement--focus {
    outline: none;
}

/* S'assurer que les iframes Stripe sont interactives et centrées verticalement */
.stripe-card-wrapper iframe {
    pointer-events: auto !important;
    z-index: 1;
    width: 100% !important;
    height: 20px !important;
    min-height: 20px !important;
    max-height: 20px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    vertical-align: middle !important;
    display: block !important;
}

/* S'assurer que le wrapper n'interfère pas avec les interactions */
.stripe-card-wrapper * {
    pointer-events: auto;
}

/* Centrer le contenu Stripe verticalement */
.stripe-card-wrapper > * {
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
    height: 100% !important;
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MODAL DE SÉLECTION DE VARIABLES
   ═══════════════════════════════════════════════════════════════════════════ */

/* Overlay du modal */
.side-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 100000;
    display: none;
    justify-content: flex-end;
    align-items: flex-end;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.side-sheet-overlay.show {
    display: flex;
    opacity: 1;
}

/* Side sheet pour les variables (slider depuis la droite) */
.variable-selection-side-sheet,
.side-sheet.side-sheet-right {
    background: white;
    width: 100%;
    max-width: 400px;
    height: auto;
    max-height: 90vh;
    border-top-left-radius: 24px;
    border-bottom-left-radius: 24px;
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.1);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    position: relative;
}

.side-sheet-overlay.show .side-sheet {
    transform: translateX(0);
}

/* Handle du modal (barre en haut) */
.modal-handle {
    width: 40px;
    height: 4px;
    background: var(--stone-300);
    border-radius: 2px;
    margin: 12px auto 0;
    flex-shrink: 0;
}

/* Bouton de fermeture */
.side-sheet-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--stone-100);
    color: var(--stone-600);
    font-size: 24px;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    z-index: 10;
}

.side-sheet-close:hover {
    background: var(--stone-200);
}

/* Contenu du modal */
.variable-selection-content {
    padding: 24px;
    flex-grow: 0;
    overflow-y: auto;
}

.variable-selection-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--stone-900);
    margin-bottom: 8px;
    margin-top: 8px;
}

.variable-selection-subtitle {
    font-size: 15px;
    color: var(--stone-600);
    margin-bottom: 24px;
}

/* Container des options */
.variable-options-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Option de variable */
.variable-option-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-radius: 12px;
    background: var(--stone-50);
    border: 1px solid var(--stone-200);
    color: var(--stone-800);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.variable-option-item:hover {
    background: var(--stone-100);
    border-color: var(--stone-300);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.variable-option-item svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    flex-shrink: 0;
}

/* Responsive pour mobile */
@media (max-width: 767px) {
    .variable-selection-side-sheet,
    .side-sheet.side-sheet-right {
        width: 100%;
        max-width: 100%;
        height: auto;
        max-height: 80vh;
        border-top-left-radius: 24px;
        border-top-right-radius: 24px;
        border-bottom-left-radius: 0;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
        transform: translateY(100%);
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }
    
    .side-sheet-overlay.show .variable-selection-side-sheet,
    .side-sheet-overlay.show .side-sheet.side-sheet-right {
        transform: translateY(0);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   DROPDOWN POUR VARIABLES
   ═══════════════════════════════════════════════════════════════════════════ */

.add-variable-wrapper {
    position: relative;
    display: inline-block;
    z-index: 10; /* Même z-index que les autres boutons (write-text-button, scan-button) */
}

.variable-dropdown {
    position: fixed !important;
    top: auto !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    min-width: 140px;
    background: white !important;
    border: 1px solid var(--stone-200) !important;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    z-index: 1000000 !important;
    overflow: hidden;
    display: flex !important;
    flex-direction: column;
    gap: 0;
    pointer-events: none;
}

.add-variable-wrapper.active .variable-dropdown {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0);
    pointer-events: auto !important;
}

.variable-dropdown-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border: none;
    color: var(--stone-700);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
    text-align: left;
    white-space: nowrap;
    width: 100%;
    justify-content: flex-start;
}

.variable-dropdown-item:first-child {
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

.variable-dropdown-item:last-child {
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
}

.variable-dropdown-item:hover {
    background: var(--stone-50);
}

.variable-dropdown-item:active {
    background: var(--stone-100);
}

.variable-dropdown-item span {
    flex-grow: 1;
    color: #FF00C3;
    font-weight: 500;
}

.variable-dropdown-item span::before,
.variable-dropdown-item span::after {
    color: #FF00C3;
    font-weight: 500;
}

.variable-dropdown-item span::before {
    content: "{";
    margin-right: 2px;
}

.variable-dropdown-item span::after {
    content: "}";
    margin-left: 2px;
}

/* Mobile : ajuster la dropdown */
@media (max-width: 767px) {
    .variable-dropdown {
        left: auto;
        right: 0;
        min-width: 140px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MODAL CARTES POSTALES SUPABASE
   ═══════════════════════════════════════════════════════════════════════════ */

.postcards-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    gap: 16px;
}

.postcards-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--stone-200);
    border-top-color: var(--stone-600);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.postcards-loading p {
    font-size: 14px;
    color: var(--stone-600);
}

.postcards-error {
    padding: 16px;
    margin: 0 24px 16px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #dc2626;
    font-size: 14px;
    line-height: 1.5;
}

.postcards-container {
    display: flex;
    gap: 24px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.postcards-sidebar {
    flex-shrink: 0;
    width: 200px;
    padding: 0 0 30px 0;
    overflow-y: auto;
    max-height: 100%;
}

.sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--stone-700);
    margin: 0 0 16px 0;
    padding: 0;
}

.tags-list {
    display: flex;
    flex-direction: column;
    gap: 0px;
}

.tag-button {
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: var(--stone-700);
    border-radius: 6px;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
}

.tag-button:hover {
    background: var(--stone-50);
}

.tag-button.active {
    background: var(--stone-200);
}

.postcards-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 0 0 30px 0;
    overflow-y: auto;
    overflow-x: hidden;
    align-items: start;
    grid-auto-rows: min-content;
    min-height: 0;
    max-height: 100%;
    border-radius: 8px;
}

.postcard-item {
    position: relative;
    aspect-ratio: 3/2;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--stone-100);
    background: var(--stone-100);
    width: 100%;
    min-height: 0;
    display: flex;
}

.postcard-item:hover {
    border-color: var(--stone-700);
}

.postcard-item.selected {
    border-color: var(--stone-900);
    box-shadow: 0 0 0 2px var(--stone-900);
}

.postcard-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.postcard-item-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.4), transparent);
    color: white;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
}

/* Responsive mobile */
@media (max-width: 768px) {
    #modalOverlay .modal-content {
        max-width: 100%;
        height: 90vh;
        max-height: 90vh;
        padding: 16px 16px 20px 16px;
    }

    #modalOverlay .modal-title {
        font-size: 16px;
        font-weight: 400;
        margin-bottom: 12px;
        text-align: center;
        padding-right: 0;
    }

    .modal-close {
        top: 16px;
        right: 16px;
        width: 28px;
        height: 28px;
        font-size: 24px;
    }
    
    .postcards-container {
        flex-direction: column;
        gap: 16px;
        height: 100%;
    }

    .postcards-sidebar {
        width: 100%;
        padding: 0;
        border-right: none;
        border-bottom: none;
        height: auto;
        max-height: 120px;
        flex-shrink: 0;
    }

    .sidebar-title {
        display: none;
    }

    .tags-list {
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 6px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: var(--stone-300) transparent;
    }
    
    .tags-list::-webkit-scrollbar {
        height: 4px;
    }
    
    .tags-list::-webkit-scrollbar-track {
        background: transparent;
    }
    
    .tags-list::-webkit-scrollbar-thumb {
        background-color: var(--stone-300);
        border-radius: 2px;
    }

    .tag-button {
        padding: 6px 12px;
        font-size: 12px;
        flex-shrink: 0;
        white-space: nowrap;
    }
    
    .postcards-grid {
        flex: 1;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 0 0 16px 0;
        overflow-y: auto;
        align-items: start;
        grid-auto-rows: 1fr;
        border-radius: 8px;
    }

    .postcard-item {
        position: relative;
        width: 100%;
        padding-bottom: 66.666%;
        display: block;
        overflow: hidden;
        height: 0;
    }

    .postcard-item.selected {
        border-color: var(--stone-900);
        box-shadow: 0 0 0 1px var(--stone-900);
    }

    .postcard-item img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
    }

    .postcard-item-name {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1;
        pointer-events: none;
    }
    
    .postcards-loading {
        padding: 24px 16px;
    }
    
    .postcards-error {
        margin: 0 16px 12px;
    }
}


