/**
 * ============================================================
 * 🎨 FORMANT - FORM BUILDER STYLES
 * Inspiré du style fonctionnel + intégration thème
 * ============================================================
 */

/* ============================================================
   🏗️ STRUCTURE DE BASE (HAUTEUR STABLE)
   ============================================================ */

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--theme-background, #ffffff);
    color: var(--theme-text, #1e293b);
    font-family: var(--theme-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
    font-size: var(--theme-base-size, 16px);
}

/* Conteneur principal de l'app (prend tout l'espace restant) */
.formant-app {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0; /* Crucial pour le flex child */
}

/* ============================================================
   🧰 TOOLBAR
   ============================================================ */

#toolbar {
    flex-shrink: 0;
    background: var(--theme-surface, #f8fafc);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding: 12px 24px;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

/* Mode sombre : ajustement de la bordure */
body[data-mode="dark"] #toolbar {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.toolbar-info {
    color: var(--theme-text-secondary, #64748b);
    font-style: italic;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: var(--theme-border-radius, 0.5rem);
}

body[data-mode="dark"] .toolbar-info {
    background: rgba(255, 255, 255, 0.1);
}

#toolbar button {
    padding: 8px 16px;
    border: none;
    border-radius: var(--theme-border-radius, 0.5rem);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    background: var(--theme-primary, #2563eb);
    color: white;
}

#toolbar button:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

#toolbar button:active {
    transform: translateY(0);
}

/* ============================================================
   🧩 FORM BUILDER CONTAINER (CRUCIAL)
   ============================================================ */

#form-container {
    flex: 1;
    min-height: 0; /* CRUCIAL : permet au contenu de scroller */
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* Le builder interne doit prendre tout l'espace */
.form-builder,
.fb-container {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
}

/* ============================================================
   🎴 CARTES DES CHAMPS
   ============================================================ */

.fb-field {
    background: var(--theme-surface, #ffffff);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: var(--theme-border-radius, 0.5rem);
    margin-bottom: 16px;
    padding: 16px;
    transition: all 0.2s ease;
}

.fb-field:hover {
    border-color: var(--theme-primary, #2563eb);
}

body[data-mode="dark"] .fb-field {
    background: var(--theme-surface, #1e293b);
    border-color: rgba(255, 255, 255, 0.1);
}

.fb-field-label {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--theme-text, #1e293b);
}

.fb-field-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: calc(var(--theme-border-radius, 0.5rem) * 0.75);
    background: var(--theme-background, #ffffff);
    color: var(--theme-text, #1e293b);
    font-size: inherit;
}

.fb-field-input:focus {
    outline: none;
    border-color: var(--theme-primary, #2563eb);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

body[data-mode="dark"] .fb-field-input {
    background: var(--theme-background, #0f172a);
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--theme-text, #f1f5f9);
}

/* ============================================================
   🚫 ÉCRAN D'ERREUR (inspiré de ton style)
   ============================================================ */

.fb-error-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-family: sans-serif;
    text-align: center;
    background: var(--theme-background, #f8f9fa);
    color: var(--theme-text, #1e293b);
}

.fb-error-box {
    max-width: 400px;
    padding: 20px;
}

.fb-error-box h2 {
    margin-bottom: 10px;
    color: var(--theme-primary, #2563eb);
}

.fb-error-box p {
    color: var(--theme-text-secondary, #666);
}

body[data-mode="dark"] .fb-error-box p {
    color: var(--theme-text-secondary, #94a3b8);
}

/* ============================================================
   🔔 NOTIFICATIONS
   ============================================================ */

.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: var(--theme-border-radius, 0.5rem);
    background: var(--theme-primary, #2563eb);
    color: white;
    z-index: 10000;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideInRight 0.3s ease;
}

.notification-success {
    background: #10b981;
}

.notification-error {
    background: #ef4444;
}

.notification-info {
    background: var(--theme-primary, #2563eb);
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ============================================================
   🧪 ÉTAT DE CHARGEMENT
   ============================================================ */

.fb-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--theme-text-secondary, #64748b);
    font-size: 14px;
}

.fb-loading::before {
    content: '';
    width: 20px;
    height: 20px;
    margin-right: 10px;
    border: 2px solid var(--theme-primary, #2563eb);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   📱 RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
    #toolbar {
        padding: 12px;
        gap: 8px;
    }
    
    #toolbar button {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .fb-field {
        padding: 12px;
    }
}

/* ============================================================
   🎨 SURCHARGES MODE SOMBRE (via thème)
   ============================================================ */

/* Les variables CSS sont injectées dynamiquement */
/* Le mode sombre est géré via data-mode et les variables --theme-* */