/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary-color: #667eea;
    --primary-dark: #4f46e5;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #e67e22;
    --light-bg: #f0f2f5;
    --white: #ffffff;
    --border-color: #e0e0e0;
    --text-primary: #333333;
    --text-secondary: #666666;
    --shadow-sm: 0 2px 10px rgba(0,0,0,0.1);
    --shadow-md: 0 5px 15px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.2);
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 50px;
    --transition: all 0.3s ease;
}

/* Scrollbar personnalisée - Webkit */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 10px; }
::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #a1a1a1; }

/* Scrollbar - Firefox */
html {
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f1f1f1;
}

body { 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    background: var(--light-bg); 
    line-height: 1.6; 
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
}

/* Focus visible pour l'accessibilité */
:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* Sélection */
::selection {
    background: var(--primary-color);
    color: #fff;
}

/* ============================================
   LAYOUT
   ============================================ */
.app-container { 
    display: flex; 
    min-height: 100vh;
    min-height: 100dvh;
}

.side-panel { 
    width: 480px; 
    min-width: 480px; 
    background: var(--white); 
    padding: 25px; 
    box-shadow: var(--shadow-sm); 
    overflow-y: auto; 
    max-height: 100vh;
    max-height: 100dvh;
    position: sticky; 
    top: 0; 
}

.app-title { 
    font-size: 24px; 
    margin-bottom: 0; 
    color: var(--text-primary); 
}

.preview-panel { 
    flex: 1; 
    padding: 25px; 
    background: #e0e0e0; 
    display: flex; 
    align-items: flex-start;
    justify-content: center; 
    overflow: auto; 
}

.preview-container { 
    background: var(--white); 
    width: 100%;
    max-width: 850px;
    min-height: 500px;
    box-shadow: var(--shadow-lg); 
    border-radius: 5px; 
    overflow: auto;
    position: sticky;
    top: 25px;
}

.preview-iframe { 
    width: 794px;
    min-height: 1123px;
    border: none;
    display: block;
    margin: 0 auto;
}
/* ============================================
   FORM SECTIONS
   ============================================ */
.form-section { 
    display: none; 
    animation: fadeIn 0.3s ease; 
}
.form-section.active { 
    display: block; 
}

@keyframes fadeIn { 
    from { opacity: 0; transform: translateY(10px); } 
    to { opacity: 1; transform: translateY(0); } 
}

.section-title { font-size: 18px; margin-bottom: 8px; }
.section-subtitle { color: var(--text-secondary); margin-bottom: 15px; font-size: 13px; }

/* ============================================
   FORMS
   ============================================ */
.form-fieldset { 
    border: 2px solid var(--border-color); 
    border-radius: var(--radius-md); 
    padding: 18px; 
    margin-bottom: 20px;
    background: var(--white);
    transition: var(--transition);
}

.form-fieldset:hover {
    border-color: #c0c0c0;
}

.form-fieldset legend { 
    font-weight: 600; 
    font-size: 14px; 
    padding: 0 8px; 
    color: var(--text-primary);
}

.form-group { margin-bottom: 15px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

label { 
    display: block; 
    margin-bottom: 4px; 
    font-weight: 600; 
    font-size: 13px; 
    color: var(--text-secondary);
}

/* Astérisque pour champs requis - avec support multi-navigateur */
label.required::after,
label:has(+ input[required])::after {
    content: ' *';
    color: var(--danger-color);
}

input, textarea, select { 
    width: 100%; 
    padding: 10px 12px;
    border: 2px solid var(--border-color); 
    border-radius: var(--radius-sm); 
    font-size: 13px; 
    font-family: inherit;
    transition: var(--transition);
    background: var(--white);
    color: var(--text-primary);
}

input:focus, textarea:focus, select:focus { 
    outline: none; 
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

/* Placeholder */
input::placeholder, textarea::placeholder {
    color: #bbb;
    font-style: italic;
    opacity: 1; /* Firefox */
}

textarea { min-height: 80px; resize: vertical; line-height: 1.5; }

/* Select personnalisé */
select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 35px;
}

/* ============================================
   DYNAMIC SECTIONS
   ============================================ */
.dynamic-section { 
    border: 2px solid var(--border-color); 
    border-radius: var(--radius-md); 
    padding: 20px 15px 15px; 
    margin-bottom: 10px; 
    position: relative; 
    animation: slideIn 0.3s ease;
    background: #fafafa;
}

@keyframes slideIn { 
    from { opacity: 0; transform: translateX(-20px); } 
    to { opacity: 1; transform: translateX(0); } 
}

.dynamic-section:hover {
    border-color: #c0c0c0;
}

.remove-btn { 
    position: absolute; 
    top: 8px; 
    right: 8px; 
    background: var(--danger-color); 
    color: white; 
    border: none; 
    border-radius: 50%; 
    width: 26px; 
    height: 26px; 
    cursor: pointer; 
    font-size: 16px; 
    z-index: 2;
    display: flex; 
    align-items: center; 
    justify-content: center;
    transition: var(--transition);
    line-height: 1;
}

.remove-btn:hover { 
    background: #c82333;
    transform: scale(1.1);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn { 
    padding: 10px 20px; 
    border: none; 
    border-radius: var(--radius-sm); 
    font-size: 14px; 
    font-weight: 600; 
    cursor: pointer; 
    transition: var(--transition); 
    display: inline-flex; 
    align-items: center; 
    justify-content: center; 
    gap: 6px;
    text-decoration: none;
    line-height: 1.4;
}

.btn:hover { 
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn:active {
    transform: translateY(0);
}

/* Bouton désactivé */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-primary { background: var(--primary-color); color: white; width: 100%; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary-color); color: white; }
.btn-secondary:hover { background: #5a6268; }
.btn-add { background: var(--success-color); color: white; width: 100%; margin-bottom: 8px; }
.btn-add:hover { background: #218838; }

.button-group { 
    display: flex; 
    gap: 10px; 
    margin-top: 20px;
    flex-wrap: wrap;
}
.button-group .btn { flex: 1; min-width: 140px; }

/* ============================================
   TOP BAR
   ============================================ */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.top-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background: var(--white);
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-icon:hover {
    background: #f0f4ff;
    border-color: var(--primary-color);
}

.lang-select {
    padding: 6px 12px;
    border: 2px solid var(--border-color);
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    background: var(--white);
    transition: var(--transition);
}

.lang-select:focus {
    border-color: var(--primary-color);
}

/* ============================================
   BOUTON IA
   ============================================ */
.btn-ai {
    margin-top: 8px;
    padding: 8px 16px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-ai:hover {
    opacity: 0.9;
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-ai:active {
    transform: scale(1);
}

/* ============================================
   DRAG HANDLE
   ============================================ */
.drag-handle {
    position: absolute;
    top: 8px;
    left: 8px;
    cursor: grab;
    font-size: 16px;
    color: #999;
    z-index: 2;
    padding: 4px 8px;
    user-select: none;
    -webkit-user-select: none;
}
.drag-handle:hover {
    color: var(--primary-color);
}
.drag-handle:active {
    cursor: grabbing;
}
.sortable-ghost {
    opacity: 0.4;
    background: #f0f4ff;
    border-style: dashed;
}
.sortable-chosen {
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

/* ============================================
   NOTIFICATION TOAST
   ============================================ */
.notification-toast {
    font-size: 14px;
}

/* ============================================
   MODE SOMBRE
   ============================================ */
body.dark-mode {
    --light-bg: #1a1a2e;
    --white: #16213e;
    --border-color: #2a2a4a;
    --text-primary: #e0e0ff;
    --text-secondary: #a0a0c0;
}
body.dark-mode .side-panel {
    background: #16213e;
    color: #e0e0ff;
}
body.dark-mode input,
body.dark-mode textarea,
body.dark-mode select {
    background: #1a1a3a;
    color: #e0e0ff;
    border-color: #2a2a5a;
}
body.dark-mode input::placeholder,
body.dark-mode textarea::placeholder {
    color: #555;
}
body.dark-mode input:focus,
body.dark-mode textarea:focus,
body.dark-mode select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}
body.dark-mode .preview-panel {
    background: #0f0f23;
}
body.dark-mode .btn-icon {
    background: #1a1a3a;
    border-color: #2a2a5a;
    color: #e0e0ff;
}
body.dark-mode .dynamic-section {
    border-color: #2a2a5a;
    background: #1a1a35;
}
body.dark-mode .form-fieldset {
    background: #16213e;
}
body.dark-mode .form-fieldset legend {
    color: #e0e0ff;
}
body.dark-mode select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a0a0c0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
}

/* Scrollbar dark mode - Webkit */
body.dark-mode ::-webkit-scrollbar-track { background: #1a1a35; }
body.dark-mode ::-webkit-scrollbar-thumb { background: #3a3a5a; }

/* Scrollbar dark mode - Firefox */
body.dark-mode {
    scrollbar-color: #3a3a5a #1a1a35;
}

/* ============================================
   IMPRESSION
   ============================================ */
@media print { 
    .side-panel, #paymentModal, .notification-toast { 
        display: none !important; 
    } 
    .preview-panel { 
        padding: 0 !important; 
        background: white !important; 
    } 
    .preview-container { 
        box-shadow: none !important; 
        width: 100% !important;
        border-radius: 0 !important;
        position: static !important;
    }
    body {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Écran moyen */
@media (max-width: 1200px) { 
    .side-panel {
        width: 420px;
        min-width: 420px;
    }
}

/* Tablette */
@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
    }
    
    .side-panel {
        width: 100% !important;
        min-width: 100% !important;
        max-height: none !important;
        position: static !important;
        padding: 20px !important;
    }
    
    .preview-panel {
        padding: 15px !important;
    }
    
    .preview-container {
        width: 100% !important;
        min-height: auto !important;
        position: static !important;
        overflow: auto !important;
    }
    
    .preview-iframe {
        width: 100% !important;
        height: auto !important;
        min-height: 500px !important;
        transform: none !important;
    }

}

/* Mobile */
@media (max-width: 767px) {
    .side-panel {
        padding: 12px !important;
    }
    
    .app-title {
        font-size: 20px !important;
    }
    
    .form-row {
        grid-template-columns: 1fr !important;
    }
    
    .button-group {
        flex-direction: column !important;
    }
    .button-group .btn {
        min-width: 100% !important;
    }
    
    .btn {
        padding: 12px 16px !important;
        font-size: 14px !important;
    }
    
    .preview-container {
        width: 100% !important;
        overflow: auto !important;
    }
    
    .preview-iframe {
        width: 100% !important;
        height: auto !important;
        min-height: 400px !important;
        transform: none !important;
    }

    
    #paymentModal > div {
        padding: 20px 15px !important;
        max-width: 95% !important;
    }
    
    #modalPrice {
        font-size: 28px !important;
    }
    
    #modelPriceBar {
        flex-direction: column !important;
        gap: 8px !important;
        text-align: center !important;
    }
    
    .top-bar {
        flex-direction: column !important;
        align-items: flex-start !important;
    }
}

/* Petit mobile */
@media (max-width: 480px) {
    .side-panel {
        padding: 10px !important;
    }
    
    .app-title {
        font-size: 18px !important;
    }
    
    .form-fieldset {
        padding: 12px !important;
    }
    
    .dynamic-section {
        padding: 15px 10px 10px !important;
    }
    
    .btn-icon {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    
    .preview-iframe {
        width: 100% !important;
        height: auto !important;
        min-height: 350px !important;
        transform: none !important;
    }
}

/* ============================================
   LOADER / SPINNER GLOBAL
   ============================================ */
@keyframes spin { 
    to { transform: rotate(360deg); } 
}

/* ============================================
   ANIMATION PULSE (pour loader paiement)
   ============================================ */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}