/**
 * OFAP Form Builder v2 - Public Form Styles
 * - Variantes de layout : card | minimal | inline | embedded
 * - Adaptatif via container queries (le formulaire s'adapte au CONTENEUR parent, pas au viewport)
 * - Support thème clair / sombre
 */

/* ============== VARIABLES + RESET ============== */
.ofap-form-wrapper {
    --ofap-primary: #ED1C25;
    --ofap-primary-hover: #c91820;
    --ofap-secondary: #2D2A4E;
    --ofap-secondary-hover: #ffe0cc;
    --ofap-accent: #22AF9E;
    --ofap-bg: #FFEBDE;
    --ofap-option-hover: #d4d3de;
    --ofap-option-bg-hover: #ffffff;
    --ofap-white: #ffffff;
    --ofap-gray-100: #f3f4f6;
    --ofap-gray-200: #e5e7eb;
    --ofap-gray-400: #9ca3af;
    --ofap-gray-500: #6b7280;
    --ofap-gray-700: #374151;
    --ofap-radius: 12px;
    --ofap-radius-lg: 20px;
    --ofap-shadow: 0 8px 32px rgba(45, 42, 78, 0.12);
    --ofap-transition: cubic-bezier(0.4, 0, 0.2, 1);
    --ofap-title-font: 'DM Sans', sans-serif;
    --ofap-body-font: 'DM Sans', sans-serif;
    --ofap-title-size: 24px;
    --ofap-title-weight: 600;
    --ofap-label-size: 13px;
    --ofap-input-size: 15px;
    /* Couleurs de surface (calculées selon le thème) */
    --ofap-surface: var(--ofap-white);
    --ofap-surface-soft: #fafbfc;
    --ofap-text: var(--ofap-secondary);
    --ofap-text-muted: var(--ofap-gray-500);
    --ofap-border: var(--ofap-gray-200);

    font-family: var(--ofap-body-font);
    line-height: 1.5;
    /* Active container queries sur le wrapper */
    container-type: inline-size;
    container-name: ofap;
}

.ofap-form-wrapper * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ============== THEME SOMBRE ============== */
.ofap-form-wrapper[data-theme="dark"] {
    --ofap-surface: #1f2937;
    --ofap-surface-soft: #2a3441;
    --ofap-text: #f3f4f6;
    --ofap-text-muted: #9ca3af;
    --ofap-border: #374151;
    --ofap-bg: #111827;
}

/* ============== CONTAINER : LAYOUT VARIANTS ============== */

/* Largeur du conteneur */
.ofap-form-wrapper[data-width="auto"]  .ofap-form-container { max-width: 520px; margin: 0 auto; }
.ofap-form-wrapper[data-width="full"]  .ofap-form-container { max-width: 100%; margin: 0; }
.ofap-form-wrapper[data-width="fixed"] .ofap-form-container { max-width: 520px; margin: 0 auto; }

/* Layout : CARD (défaut) */
.ofap-form-wrapper[data-layout="card"] .ofap-form-container {
    background: var(--ofap-surface);
    border-radius: var(--ofap-radius-lg);
    box-shadow: var(--ofap-shadow);
    overflow: hidden;
}

/* Layout : MINIMAL — pas de header coloré, bordure douce */
.ofap-form-wrapper[data-layout="minimal"] .ofap-form-container {
    background: var(--ofap-surface);
    border-radius: var(--ofap-radius);
    border: 1px solid var(--ofap-border);
    overflow: hidden;
}
.ofap-form-wrapper[data-layout="minimal"] .ofap-form-header { display: none; }

/* Layout : INLINE — sans aucun chrome, intégré au contenu */
.ofap-form-wrapper[data-layout="inline"] .ofap-form-container {
    background: transparent;
    box-shadow: none;
    border: none;
    border-radius: 0;
    padding: 0;
}
.ofap-form-wrapper[data-layout="inline"] .ofap-form-header { display: none; }
.ofap-form-wrapper[data-layout="inline"] .ofap-form-content { padding: 0; }
.ofap-form-wrapper[data-layout="inline"] .ofap-progress { padding: 0 0 16px; }

/* Layout : EMBEDDED — fond transparent qui hérite du parent */
.ofap-form-wrapper[data-layout="embedded"] .ofap-form-container {
    background: transparent;
    box-shadow: none;
    border-radius: 0;
}
.ofap-form-wrapper[data-layout="embedded"] .ofap-form-header { display: none; }

/* ============== HEADER (uniquement layout card) ============== */
.ofap-form-header {
    background: var(--ofap-primary);
    padding: 28px 32px;
    position: relative;
    overflow: hidden;
}
.ofap-form-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 200px;
    height: 200px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
}
.ofap-logo { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.ofap-logo-icon { width: 48px; height: 48px; color: var(--ofap-white); }
.ofap-logo-text { color: var(--ofap-white); font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.ofap-logo-subtitle { color: rgba(255, 255, 255, 0.9); font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; margin-top: 2px; }

/* ============== PROGRESS BAR ============== */
.ofap-progress { padding: 24px 32px 0; }
.ofap-progress-bar { height: 4px; background: var(--ofap-bg); border-radius: 2px; overflow: hidden; }
.ofap-progress-fill { height: 100%; background: var(--ofap-primary); border-radius: 2px; transition: width 0.5s var(--ofap-transition); }
.ofap-progress-steps { display: flex; justify-content: space-between; margin-top: 12px; }
.ofap-progress-step { display: flex; align-items: center; justify-content: center; }
.ofap-step-num { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; background: var(--ofap-bg); color: var(--ofap-text-muted); transition: all 0.3s ease; }
.ofap-progress-step.active .ofap-step-num { background: var(--ofap-primary); color: white; }
.ofap-progress-step.completed .ofap-step-num { background: var(--ofap-accent); color: white; }

/* ============== CONTENT ============== */
.ofap-form-content { padding: 32px; position: relative; min-height: 320px; }
.ofap-step { display: none; animation: fadeSlideIn 0.4s var(--ofap-transition); }
.ofap-step.active { display: block; }
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}
.ofap-form-wrapper[data-animation="fade"] .ofap-step { animation: fadeOnly 0.3s ease; }
@keyframes fadeOnly { from { opacity: 0; } to { opacity: 1; } }
.ofap-form-wrapper[data-animation="none"] .ofap-step { animation: none; }

.ofap-step-title { font-family: var(--ofap-title-font); font-size: var(--ofap-title-size); font-weight: var(--ofap-title-weight, 600); color: var(--ofap-text); margin-bottom: 8px; }
.ofap-step-subtitle { font-family: var(--ofap-body-font); color: var(--ofap-text-muted); font-size: 14px; margin-bottom: 24px; }

/* ============== FIELDS ============== */
.ofap-fields { margin-bottom: 8px; }
.ofap-field-group { margin-bottom: 20px; }
.ofap-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.ofap-field-row .ofap-field-group { margin-bottom: 0; }

.ofap-label { display: block; font-family: var(--ofap-body-font); font-size: var(--ofap-label-size); font-weight: 500; color: var(--ofap-text); margin-bottom: 8px; }

.ofap-input {
    width: 100%;
    padding: 14px 18px;
    font-family: var(--ofap-body-font);
    font-size: var(--ofap-input-size, 15px);
    color: var(--ofap-text);
    background: var(--ofap-surface-soft);
    border: 2px solid var(--ofap-border);
    border-radius: var(--ofap-radius);
    transition: all 0.3s ease;
}
.ofap-input:focus { outline: none; border-color: var(--ofap-primary); background: var(--ofap-surface); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ofap-primary) 12%, transparent); }
.ofap-input::placeholder { color: var(--ofap-gray-400); }

.ofap-textarea { min-height: 100px; resize: vertical; }

.ofap-phone-wrap { position: relative; }
.ofap-phone-prefix { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); color: var(--ofap-text-muted); font-size: 15px; font-weight: 500; }
.ofap-input.has-prefix { padding-left: 58px; }

/* ============== RADIO CARDS ============== */
.ofap-options-grid { display: grid; gap: 12px; }
.ofap-options-grid.ofap-options-horizontal { grid-template-columns: 1fr 1fr; }

.ofap-option-card { position: relative; }
.ofap-option-card input { position: absolute; opacity: 0; cursor: pointer; }

.ofap-option-label {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    background: var(--ofap-surface-soft);
    border: 2px solid var(--ofap-border);
    border-radius: var(--ofap-radius);
    cursor: pointer;
    transition: all 0.3s ease;
}
.ofap-option-label:hover { border-color: var(--ofap-option-hover); background: var(--ofap-option-bg-hover); }
.ofap-option-card input:checked + .ofap-option-label { border-color: var(--ofap-primary); background: color-mix(in srgb, var(--ofap-primary) 4%, transparent); }
.ofap-option-card input:focus-visible + .ofap-option-label { box-shadow: 0 0 0 3px color-mix(in srgb, var(--ofap-primary) 25%, transparent); }

.ofap-option-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: var(--ofap-bg); transition: all 0.3s ease; flex-shrink: 0; }
.ofap-option-card input:checked + .ofap-option-label .ofap-option-icon { background: var(--ofap-primary); }
.ofap-option-icon svg { width: 20px; height: 20px; stroke: var(--ofap-primary); stroke-width: 2; fill: none; }
.ofap-option-card input:checked + .ofap-option-label .ofap-option-icon svg { stroke: white; }

.ofap-option-text { flex: 1; min-width: 0; }
.ofap-option-title { font-weight: 500; color: var(--ofap-text); font-size: 14px; }
.ofap-option-desc { font-size: 12px; color: var(--ofap-text-muted); margin-top: 2px; }

.ofap-option-check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--ofap-border); display: flex; align-items: center; justify-content: center; transition: all 0.3s ease; flex-shrink: 0; }
.ofap-option-card input:checked + .ofap-option-label .ofap-option-check { border-color: var(--ofap-primary); background: var(--ofap-primary); }
.ofap-option-check svg { width: 12px; height: 12px; stroke: white; opacity: 0; transform: scale(0); transition: all 0.2s ease; }
.ofap-option-card input:checked + .ofap-option-label .ofap-option-check svg { opacity: 1; transform: scale(1); }

/* ============== RADIO + CHECKBOX simples ============== */
.ofap-radio-group, .ofap-checkbox-group { display: flex; flex-direction: column; gap: 10px; }
.ofap-radio, .ofap-checkbox { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; color: var(--ofap-gray-700); }
.ofap-radio input, .ofap-checkbox input { width: 18px; height: 18px; accent-color: var(--ofap-primary); }

/* ============== CONSENT FIELD (RGPD) ============== */
.ofap-consent-field {
    margin: 12px 0 4px;
    padding: 14px 16px;
    background: var(--ofap-surface-soft);
    border: 1px solid var(--ofap-border);
    border-radius: var(--ofap-radius);
    transition: border-color 0.2s ease;
}
.ofap-consent-field:hover { border-color: var(--ofap-option-hover); }
.ofap-consent-field.ofap-consent-required { border-left: 3px solid var(--ofap-primary); }

.ofap-consent-label {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    font-size: 13px;
    line-height: 1.5;
    color: var(--ofap-text);
    position: relative;
}

.ofap-consent-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.ofap-consent-checkmark {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border-radius: 5px;
    border: 2px solid var(--ofap-border);
    background: var(--ofap-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    margin-top: 1px;
}
.ofap-consent-checkmark svg { width: 12px; height: 12px; stroke: white; opacity: 0; transform: scale(0.5); transition: all 0.15s ease; }
.ofap-consent-label input:checked + .ofap-consent-checkmark { background: var(--ofap-primary); border-color: var(--ofap-primary); }
.ofap-consent-label input:checked + .ofap-consent-checkmark svg { opacity: 1; transform: scale(1); }
.ofap-consent-label input:focus-visible + .ofap-consent-checkmark { box-shadow: 0 0 0 3px color-mix(in srgb, var(--ofap-primary) 25%, transparent); }

.ofap-consent-text { flex: 1; }
.ofap-consent-text a { color: var(--ofap-primary); text-decoration: underline; text-underline-offset: 2px; }
.ofap-consent-text a:hover { color: var(--ofap-primary-hover); }
.ofap-consent-required-mark { color: var(--ofap-primary); font-weight: 700; margin-left: 2px; }

.ofap-consent-field.error { border-color: #ef4444; background: #fef2f2; }
.ofap-consent-field.error .ofap-consent-checkmark { border-color: #ef4444; }

/* ============== ACTIONS ============== */
.ofap-actions { display: flex; gap: 12px; margin-top: 28px; }

.ofap-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 24px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: var(--ofap-radius);
    cursor: pointer;
    transition: all 0.3s ease;
}
.ofap-btn svg { width: 18px; height: 18px; stroke-width: 2.5; }

.ofap-btn-primary {
    background: var(--ofap-primary);
    color: var(--ofap-white);
    box-shadow: 0 4px 14px color-mix(in srgb, var(--ofap-primary) 30%, transparent);
}
.ofap-btn-primary:hover { background: var(--ofap-primary-hover); transform: translateY(-1px); box-shadow: 0 6px 20px color-mix(in srgb, var(--ofap-primary) 35%, transparent); }
.ofap-btn-primary:disabled { opacity: 0.7; cursor: not-allowed; transform: none; }
.ofap-btn-primary svg { stroke: white; fill: none; }

.ofap-btn-secondary { background: var(--ofap-bg); color: var(--ofap-secondary); }
.ofap-btn-secondary:hover { background: var(--ofap-secondary-hover); }
.ofap-btn-secondary svg { stroke: var(--ofap-secondary); fill: none; }

/* ============== SUCCESS ============== */
.ofap-success-step { text-align: center; padding: 20px 0; }
.ofap-success-icon {
    width: 80px; height: 80px; border-radius: 50%;
    background: linear-gradient(135deg, var(--ofap-accent), color-mix(in srgb, var(--ofap-accent) 80%, white));
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 24px;
    animation: successPop 0.5s var(--ofap-transition);
}
@keyframes successPop {
    0%   { transform: scale(0); opacity: 0; }
    50%  { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}
.ofap-success-icon svg { width: 40px; height: 40px; stroke: white; }
.ofap-success-title { font-size: 26px; font-weight: 600; color: var(--ofap-text); margin-bottom: 12px; }
.ofap-success-message { color: var(--ofap-text-muted); font-size: 15px; line-height: 1.6; max-width: 320px; margin: 0 auto; }

/* ============== LAYOUT FIELDS ============== */
.ofap-field-heading { font-size: 18px; font-weight: 600; color: var(--ofap-text); margin-bottom: 8px; }
.ofap-field-paragraph { font-size: 14px; color: var(--ofap-text-muted); line-height: 1.6; }
.ofap-field-divider { border: none; border-top: 1px solid var(--ofap-border); margin: 16px 0; }

/* ============== ERROR + LOADING ============== */
.ofap-input.error { border-color: #ef4444; }
.ofap-error-msg { display: block; color: #ef4444; font-size: 12px; margin-top: 6px; }
.ofap-loading { display: inline-block; width: 18px; height: 18px; border: 2px solid rgba(255, 255, 255, 0.3); border-radius: 50%; border-top-color: white; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============== CONTAINER QUERIES (clé de l'adaptivité) ============== */

/* Conteneur < 480px : on resserre tout */
@container ofap (max-width: 480px) {
    .ofap-form-content { padding: 24px; }
    .ofap-form-header { padding: 24px; }
    .ofap-progress { padding: 20px 24px 0; }
    .ofap-field-row { grid-template-columns: 1fr; }
    .ofap-options-grid.ofap-options-horizontal { grid-template-columns: 1fr; }
    .ofap-step-title { font-size: calc(var(--ofap-title-size) - 2px); }
    .ofap-btn { padding: 14px 20px; font-size: 14px; }
    .ofap-logo-text { font-size: 24px; }
}

/* Conteneur < 360px : version ultra-compacte (sidebar étroite) */
@container ofap (max-width: 360px) {
    .ofap-form-content { padding: 16px; }
    .ofap-form-header { padding: 18px; }
    .ofap-progress { padding: 16px 18px 0; }
    .ofap-progress-steps { display: none; }
    .ofap-option-label { padding: 12px 14px; gap: 10px; }
    .ofap-option-icon { width: 32px; height: 32px; }
    .ofap-step-title { font-size: 18px; }
    .ofap-step-subtitle { font-size: 13px; margin-bottom: 18px; }
    .ofap-input { padding: 12px 14px; }
    .ofap-actions { flex-direction: column; }
    .ofap-btn { padding: 12px 16px; }
}

/* Fallback pour navigateurs qui ne supportent pas les container queries */
@supports not (container-type: inline-size) {
    @media (max-width: 560px) {
        .ofap-form-content { padding: 24px; }
        .ofap-form-header { padding: 24px; }
        .ofap-progress { padding: 20px 24px 0; }
        .ofap-field-row { grid-template-columns: 1fr; }
        .ofap-options-grid.ofap-options-horizontal { grid-template-columns: 1fr; }
        .ofap-btn { padding: 14px 20px; font-size: 14px; }
    }
}
