/**
 * FormForge — Conversational Mode (Typeform-style)
 * Full-screen, one question at a time with smooth animations.
 */

/* ── Container ──
 * The outer wrapper is a flex column that centers the active step in
 * the viewport. We keep min-height tied to the viewport so the form
 * feels like a focused canvas (Typeform-style) rather than a tall
 * scroll. Builder live preview overrides these in the
 * data-formforge-preview block below so the preview can sit inside its
 * iframe without needing 100vh.
 */
.ff-conversational {
    max-width: 100%;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    position: relative;
    background: #f8fafc;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    min-height: min(720px, 100vh);
}

.ff-conversational .formforge-form {
    position: relative;
    overflow: hidden;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
}

/* ── Progress Bar ── */
.ff-conv-progress-bar {
    position: sticky;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: #e2e8f0;
    z-index: 5;
    flex: 0 0 auto;
}

.ff-conv-progress-fill {
    height: 100%;
    background: #3B82F6;
    border-radius: 0 2px 2px 0;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    width: 0;
}

/* ── Each Step ──
 * Each step is positioned absolutely so transitions stack cleanly. The
 * active step gets `position: relative` so the parent flex container
 * can size to it. We pad lightly and let the inner `max-width: 640px`
 * box do the visual constraining — that's the Typeform-style focused
 * column.
 */
.ff-conv-step {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 24px 32px;
    box-sizing: border-box;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100%;
    opacity: 0;
    visibility: hidden;
    transform: translateY(40px);
    transition: opacity 0.4s ease, transform 0.4s ease, visibility 0s 0.4s;
    pointer-events: none;
}

.ff-conv-step.ff-conv-step--active {
    position: relative;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition: opacity 0.4s ease, transform 0.4s ease, visibility 0s 0s;
    pointer-events: auto;
    flex: 1 1 auto;
}

.ff-conv-step.ff-conv-step--prev {
    opacity: 0;
    transform: translateY(-40px);
}

/* ── Step Inner Content ──
 * 640px gives the "centered focused column" feel that Typeform uses —
 * wide enough for a paragraph of supporting copy or a horizontal name
 * group, narrow enough that text never spans the full viewport.
 */
.ff-conv-step-inner {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
}

/* ── Step Counter ──
 * The counter is injected inside each `.ff-conv-step-inner` so it sits
 * flush above the question (e.g. "1 / 4" → "What is your name?"). This
 * keeps the counter visually bound to the step content rather than
 * floating at the viewport corner.
 */
.ff-conv-counter {
    font-size: 13px;
    font-weight: 600;
    color: #64748b;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin: 0 0 12px;
    display: block;
}

/* ── Step Number ── */
.ff-conv-step-number {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: #3B82F6;
    margin-bottom: 12px;
}

.ff-conv-step-number span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: #EFF6FF;
    border-radius: 50%;
    font-size: 14px;
    font-weight: 700;
    color: #3B82F6;
}

.ff-conv-step-number svg {
    display: none;
}

/* ── Labels (Questions) ── */
.ff-conversational .formforge-label {
    font-size: 24px;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 20px;
    line-height: 1.35;
    display: block;
}

.ff-conversational .formforge-required {
    color: #3B82F6;
    margin-left: 2px;
}

.ff-conversational .formforge-description {
    font-size: 15px;
    color: #64748b;
    margin-top: 8px;
    margin-bottom: 0;
    line-height: 1.5;
}

/* ── Inputs ── */
.ff-conversational .formforge-input,
.ff-conversational .formforge-textarea,
.ff-conversational .formforge-select {
    width: 100%;
    font-size: 18px;
    padding: 16px 20px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    color: #0f172a;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
    -webkit-appearance: none;
}

.ff-conversational .formforge-input:focus,
.ff-conversational .formforge-textarea:focus,
.ff-conversational .formforge-select:focus {
    border-color: #3B82F6;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.ff-conversational .formforge-input::placeholder,
.ff-conversational .formforge-textarea::placeholder {
    color: #94a3b8;
}

.ff-conversational .formforge-textarea {
    min-height: 120px;
    resize: vertical;
}

.ff-conversational .formforge-color {
    width: 72px;
    min-width: 72px;
    height: 48px;
    padding: 4px;
    border-radius: 10px;
    -webkit-appearance: auto;
    appearance: auto;
}

.ff-conversational .formforge-color::-webkit-color-swatch-wrapper {
    padding: 0;
}

.ff-conversational .formforge-color::-webkit-color-swatch {
    border: 0;
    border-radius: 6px;
}

.ff-conversational .formforge-color::-moz-color-swatch {
    border: 0;
    border-radius: 6px;
}

/* ── Radio / Checkbox (card-style) ── */
.ff-conversational .formforge-radio-label,
.ff-conversational .formforge-checkbox-label {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 16px;
    padding: 14px 18px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #fff;
    color: #1e293b;
}

.ff-conversational .formforge-radio-label:hover,
.ff-conversational .formforge-checkbox-label:hover {
    border-color: #3B82F6;
    background: #EFF6FF;
}

.ff-conversational .formforge-radio-label input:checked + *,
.ff-conversational .formforge-checkbox-label input:checked + * {
    color: #3B82F6;
}

/* ── Name / Address groups ── */
.ff-conversational .formforge-name-group {
    display: flex;
    gap: 12px;
}

.ff-conversational .formforge-name-group .formforge-input {
    flex: 1;
}

.ff-conversational .formforge-address-row {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

/* ── Rating ── */
.ff-conversational .formforge-star {
    font-size: 32px;
    cursor: pointer;
    transition: color 0.15s ease, transform 0.15s ease;
}

.ff-conversational .formforge-star:hover {
    transform: scale(1.15);
}

/* ── Range ── */
.ff-conversational .formforge-range {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    background: #e2e8f0;
    border-radius: 3px;
    outline: none;
}

.ff-conversational .formforge-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    background: #3B82F6;
    border-radius: 50%;
    cursor: pointer;
}

.ff-conversational .formforge-range-value {
    display: inline-block;
    margin-top: 8px;
    font-size: 18px;
    font-weight: 600;
    color: #3B82F6;
}

/* ── File Upload ── */
.ff-conversational .formforge-file {
    font-size: 16px;
    padding: 14px;
    border: 2px dashed #e2e8f0;
    border-radius: 10px;
    width: 100%;
    box-sizing: border-box;
    background: #f8fafc;
    cursor: pointer;
}

.ff-conversational .formforge-file:hover {
    border-color: #3B82F6;
    background: #EFF6FF;
}

/* ── Heading / HTML / Divider ── */
.ff-conversational .formforge-heading {
    font-size: 28px;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 8px;
}

.ff-conversational .formforge-html {
    font-size: 16px;
    line-height: 1.6;
    color: #334155;
}

.ff-conversational .formforge-divider {
    border: none;
    border-top: 2px solid #e2e8f0;
    margin: 0;
}

/* ── Navigation Buttons ── */
.ff-conv-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 32px;
    flex-wrap: wrap;
}

.ff-conv-btn-next {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #3B82F6;
    color: #fff;
    border: none;
    padding: 14px 32px;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    line-height: 1;
}

.ff-conv-btn-next:hover {
    background: #2D74E8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.ff-conv-btn-next:active {
    transform: translateY(0);
}

.ff-conv-btn-back {
    background: none;
    border: none;
    color: #64748b;
    font-size: 14px;
    cursor: pointer;
    padding: 8px 4px;
    transition: color 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ff-conv-btn-back:hover {
    color: #3B82F6;
}

.ff-conv-hint {
    margin-left: auto;
    font-size: 14px;
    color: #94a3b8;
}

.ff-conv-hint kbd {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

/* ── Validation Error ── */
.ff-conv-error {
    color: #dc2626;
    font-size: 14px;
    margin-top: 8px;
    display: none;
    animation: ff-conv-shake 0.3s ease;
}

.ff-conv-error.ff-conv-error--visible {
    display: block;
}

@keyframes ff-conv-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

/* ── Submit step (final) ── */
.ff-conv-step--submit .ff-conv-step-inner {
    text-align: center;
}

.ff-conv-submit-title {
    font-size: 28px;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 8px;
}

.ff-conv-submit-desc {
    font-size: 16px;
    color: #64748b;
    margin-bottom: 32px;
}

.ff-conv-submit-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #3B82F6;
    color: #fff;
    border: none;
    padding: 16px 48px;
    border-radius: 50px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.ff-conv-submit-btn:hover {
    background: #2D74E8;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.35);
}

.ff-conv-submit-btn:active {
    transform: translateY(0);
}

/* ── Message (success/error after submit) ── */
.ff-conversational .formforge-message {
    max-width: 600px;
    margin: 0 auto;
    padding: 24px;
    text-align: center;
    font-size: 18px;
}

/* ── Hide standard elements in conversational mode ── */
.ff-conversational .formforge-submit-wrap,
.ff-conversational .formforge-step-nav,
.ff-conversational .formforge-progress {
    display: none !important;
}

/* Hide steps that aren't wrapped (the original formforge-step) */
.ff-conversational .formforge-step {
    display: block !important;
}

/* ── Mobile ── */
@media (max-width: 640px) {
    .ff-conversational {
        min-height: min(600px, 100vh);
        border-radius: 8px;
    }

    .ff-conv-step {
        padding: 12px 16px 24px;
    }

    .ff-conversational .formforge-label {
        font-size: 20px;
    }

    .ff-conversational .formforge-input,
    .ff-conversational .formforge-textarea,
    .ff-conversational .formforge-select {
        font-size: 16px;
        padding: 14px 16px;
    }

    .ff-conv-btn-next {
        padding: 12px 28px;
        font-size: 15px;
        width: 100%;
        justify-content: center;
    }

    .ff-conv-nav {
        flex-direction: column-reverse;
        gap: 8px;
    }

    .ff-conv-hint {
        display: none;
    }

    .ff-conv-counter {
        font-size: 12px;
        margin-bottom: 10px;
    }

    .ff-conversational .formforge-name-group {
        flex-direction: column;
        gap: 10px;
    }

    .ff-conversational .formforge-address-row {
        flex-direction: column;
        gap: 10px;
    }
}

/* ── Builder live preview ──
 * Inside the admin iframe we don't have a 100vh viewport, so we pin a
 * fixed min-height and let the iframe auto-resize to the step's actual
 * content. Counter stays inline (above the step) for visual parity
 * with the public frontend.
 */
.ff-conversational[data-formforge-preview="1"] {
    overflow: hidden;
    min-height: 460px;
}

.ff-conversational[data-formforge-preview="1"] .ff-conv-progress-bar {
    position: relative;
}

.ff-conversational[data-formforge-preview="1"] .ff-conv-counter {
    margin-bottom: 10px;
    font-size: 12px;
}

.ff-conversational[data-formforge-preview="1"] .ff-conv-step {
    padding: 12px 18px 28px;
    min-height: 360px;
}

.ff-conversational[data-formforge-preview="1"] .ff-conv-step-inner {
    max-width: 520px;
}

.ff-conversational[data-formforge-preview="1"] .formforge-label {
    font-size: 20px;
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    .ff-conv-step {
        transition: opacity 0.15s ease, visibility 0s;
        transform: none !important;
    }

    .ff-conv-step.ff-conv-step--prev {
        transform: none !important;
    }

    .ff-conv-progress-fill {
        transition: width 0.15s ease;
    }

    .ff-conv-error {
        animation: none;
    }
}
