/* ==========================================================================
   FundFox Multi-Step Form — Mobile-First Styles
   Uses Bricks Builder CSS custom properties for colors & typography.
   ========================================================================== */

/* ---------- Reset & Base ---------- */
.ff-form-wrapper *,
.ff-form-wrapper *::before,
.ff-form-wrapper *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.ff-form-wrapper {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    position: relative;
    overflow: visible;
}

.ff-form-wrapper.ff-animating {
    overflow: hidden;
}

.ff-form {
    position: relative;
    transition: height 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- Progress Bar ---------- */
.ff-progress-bar {
    width: 100%;
    height: 4px;
    background: var(--color-2-l-2, #e0e0e0);
    margin-bottom: 2rem;
    overflow: hidden;
}

.ff-progress-fill {
    height: 100%;
    background: var(--color-1, #2563eb);
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: width;
}

/* ---------- Step Container ---------- */
.ff-step {
    position: relative;
    will-change: transform, opacity;
}

/* Step header — holds the back link above the title */
.ff-step-header {
    margin-bottom: 0.75rem;
}

/* Subtle back link — understated text button, sits top-left */
.ff-back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: none;
    border: none;
    padding: 0.25rem 0;
    font-size: calc(var(--text-b-s, 0.875rem) * 0.9);
    font-weight: 400;
    color: var(--color-2, #6b7280);
    cursor: pointer;
    transition: color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.ff-back-link:hover {
    color: var(--color-4, #1a1a2e);
}

.ff-back-link svg {
    display: block;
    flex-shrink: 0;
}

.ff-step-title {
    text-align: center;
    margin-bottom: 0.5rem;
    color: var(--color-4, #1a1a2e);
    font-weight: 700;
}

.ff-step-subtitle {
    text-align: center;
    font-size: var(--text-b-s);
    color: var(--color-2, #6b7280);
    margin-bottom: 1.5rem;
    font-weight: 400;
}

.ff-step-title + .ff-options-grid,
.ff-step-title + .ff-form-fields,
.ff-step-title + .ff-company-search-wrapper {
    margin-top: 1.5rem;
}

.ff-step-subtitle + .ff-options-grid {
    margin-top: 0;
}

/* ---------- Step Animations ---------- */
@keyframes ffSlideInRight {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes ffSlideOutLeft {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(-40px);
    }
}

@keyframes ffSlideInLeft {
    from {
        opacity: 0;
        transform: translateX(-40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes ffSlideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(40px);
    }
}

@keyframes ffFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.ff-step--entering-forward {
    animation: ffSlideInRight 0.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    position: relative;
    z-index: 2;
}

.ff-step--leaving-forward {
    animation: ffSlideOutLeft 0.3s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1;
}

.ff-step--entering-back {
    animation: ffSlideInLeft 0.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    position: relative;
    z-index: 2;
}

.ff-step--leaving-back {
    animation: ffSlideOutRight 0.3s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1;
}

/* ---------- Options Grid ---------- */
.ff-options-grid {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: 1fr;
    margin-bottom: 1.5rem;
}

.ff-options-grid--2col {
    grid-template-columns: 1fr 1fr;
}

/* ---------- Option Card ---------- */
.ff-option-card {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-3, #ffffff);
    border: 1px solid var(--color-2-l-2, #e5e7eb);
    padding: 1rem 0.75rem;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.25s ease, transform 0.2s ease, box-shadow 0.25s ease;
    min-height: 56px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.ff-option-card:hover {
    border-color: var(--color-1-l-1, #60a5fa);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.ff-option-card:active {
    transform: scale(0.97);
}

/* Hide native radio */
.ff-option-card input[type="radio"] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.ff-option-label {
    font-size: var(--text-b-s);
    font-weight: 400;
    color: var(--color-4, #1a1a2e);
    line-height: 1.3;
    transition: color 0.2s ease, font-weight 0.2s ease;
}

/* Checked state */
.ff-option-card:has(input:checked) {
    border-color: var(--color-1, #2563eb);
    background: var(--color-1-l-2, #eff6ff);
    transform: scale(1.02);
}

.ff-option-card:has(input:checked) .ff-option-label {
    color: var(--color-1, #2563eb);
    font-weight: 700;
}

/* Checked dot indicator */
.ff-option-card:has(input:checked)::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 8px;
    width: 12px;
    height: 12px;
    background: var(--color-1, #2563eb);
    border-radius: 50%;
    animation: ffFadeIn 0.2s ease;
}

/* Full-width card for odd last items */
.ff-option-card--full {
    grid-column: 1 / -1;
}

/* ---------- Form Fields ---------- */
.ff-form-fields {
    margin-bottom: 1.5rem;
}

.ff-field {
    margin-bottom: 1rem;
}

.ff-field-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 0;
}

.ff-label {
    display: block;
    font-size: var(--text-b-s);
    font-weight: 700;
    color: var(--color-4, #1a1a2e);
    margin-bottom: 0.35rem;
}

.ff-input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: var(--text-body);
    font-weight: 400;
    color: var(--color-4, #1a1a2e);
    background: var(--color-3, #ffffff);
    border: 1px solid var(--color-2-l-2, #e5e7eb);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.ff-input:focus {
    border-color: var(--color-1, #2563eb);
    box-shadow: 0 0 0 3px var(--color-1-l-2, rgba(37, 99, 235, 0.15));
}

.ff-input::placeholder {
    color: var(--color-2-l-1, #9ca3af);
}

/* ---------- Consent Checkbox ---------- */
.ff-consent {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    margin-bottom: 1.5rem;
    cursor: pointer;
    font-size: var(--text-b-s);
    color: var(--color-2, #6b7280);
    line-height: 1.4;
    font-weight: 400;
}

.ff-consent input[type="checkbox"] {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: var(--color-1, #2563eb);
    cursor: pointer;
}

/* ---------- Buttons ---------- */
.ff-button-group {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.75rem;
    align-items: stretch;
}

.ff-button-group--single {
    grid-template-columns: 1fr;
}

.ff-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.85rem 1.5rem;
    font-size: var(--text-body);
    font-weight: 700;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.2s ease, opacity 0.2s ease, transform 0.15s ease, border-color 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    text-decoration: none;
    line-height: 1.2;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.ff-btn:active {
    transform: scale(0.97);
}

.ff-btn--primary {
    background: var(--color-1, #2563eb);
    color: var(--color-3, #ffffff);
    border-color: var(--color-1, #2563eb);
}

.ff-btn--primary:hover:not(:disabled) {
    background: var(--color-1-l-0, #1d4ed8);
}

.ff-btn--primary:disabled {
    background: var(--color-2-l-1, #9ca3af);
    border-color: var(--color-2-l-1, #9ca3af);
    cursor: not-allowed;
    opacity: 0.7;
}

/* Back button — square icon */
.ff-btn--back {
    background: var(--color-3, #ffffff);
    color: var(--color-4, #1a1a2e);
    border-color: var(--color-2-l-2, #e5e7eb);
    width: 48px;
    min-width: 48px;
    padding: 0;
    aspect-ratio: 1;
    flex-shrink: 0;
}

.ff-btn--back:hover {
    background: var(--color-2-l-2, #f3f4f6);
    border-color: var(--color-2-l-1, #d1d5db);
}

.ff-btn--back svg {
    display: block;
    width: 20px;
    height: 20px;
}

.ff-btn--text {
    background: none;
    border: none;
    color: var(--color-1, #2563eb);
    font-size: var(--text-b-s);
    padding: 0.25rem 0;
    font-weight: 400;
    text-decoration: underline;
    cursor: pointer;
}

.ff-btn--text:hover {
    color: var(--color-1-l-0, #1d4ed8);
}

/* ---------- Company Search ---------- */
.ff-company-search-wrapper {
    position: relative;
    margin-bottom: 1.5rem;
}

.ff-search-input-wrapper {
    position: relative;
}

.ff-search-spinner {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
}

.ff-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-2-l-2, #e5e7eb);
    border-top-color: var(--color-1, #2563eb);
    border-radius: 50%;
    animation: ffSpin 0.6s linear infinite;
}

@keyframes ffSpin {
    to { transform: rotate(360deg); }
}

.ff-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--color-3, #ffffff);
    border: 1px solid var(--color-2-l-2, #e5e7eb);
    border-top: none;
    max-height: 280px;
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.ff-search-result-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--color-2-l-2, #f3f4f6);
    transition: background 0.15s ease;
    animation: ffFadeIn 0.2s ease both;
}

.ff-search-result-item:hover {
    background: var(--color-1-l-2, #eff6ff);
}

.ff-search-result-item:last-child {
    border-bottom: none;
}

.ff-search-result-name {
    font-weight: 700;
    font-size: var(--text-b-s);
    color: var(--color-4, #1a1a2e);
}

.ff-search-result-meta {
    font-size: calc(var(--text-b-s) * 0.85);
    color: var(--color-2, #6b7280);
    margin-top: 2px;
}

.ff-search-no-results {
    padding: 1rem;
    text-align: center;
    color: var(--color-2, #6b7280);
    font-size: var(--text-b-s);
}

/* Stagger animation for search results */
.ff-search-result-item:nth-child(1) { animation-delay: 0s; }
.ff-search-result-item:nth-child(2) { animation-delay: 0.03s; }
.ff-search-result-item:nth-child(3) { animation-delay: 0.06s; }
.ff-search-result-item:nth-child(4) { animation-delay: 0.09s; }
.ff-search-result-item:nth-child(5) { animation-delay: 0.12s; }
.ff-search-result-item:nth-child(6) { animation-delay: 0.15s; }
.ff-search-result-item:nth-child(7) { animation-delay: 0.18s; }
.ff-search-result-item:nth-child(8) { animation-delay: 0.21s; }

/* ---------- Selected Company Card ---------- */
.ff-company-card {
    background: var(--color-1-l-2, #eff6ff);
    border: 1px solid var(--color-1, #2563eb);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.ff-company-name {
    font-weight: 700;
    color: var(--color-4, #1a1a2e);
    margin-bottom: 0.35rem;
}

.ff-company-meta {
    display: flex;
    gap: 1rem;
    font-size: var(--text-b-s);
    color: var(--color-2, #6b7280);
    margin-bottom: 0.35rem;
    flex-wrap: wrap;
}

.ff-company-address {
    font-size: var(--text-b-s);
    color: var(--color-2, #6b7280);
    margin-bottom: 0.5rem;
    font-weight: 400;
}

/* ---------- Error / Loading States ---------- */
.ff-field-error {
    font-size: calc(var(--text-b-s) * 0.9);
    color: #dc2626;
    margin-top: 0.25rem;
}

.ff-input--error {
    border-color: #dc2626;
}

.ff-input--error:focus {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.ff-form-error {
    background: #fef2f2;
    border-left: 4px solid #dc2626;
    color: #991b1b;
    padding: 1rem;
    font-size: var(--text-b-s);
    margin-bottom: 1rem;
}

.ff-form-loading {
    opacity: 0.6;
    pointer-events: none;
}

/* ---------- Responsive: Tablet (768px+) ---------- */
@media (min-width: 768px) {
    .ff-form-wrapper {
        padding: 2rem 1.5rem;
    }

    .ff-field-row {
        grid-template-columns: 1fr 1fr;
    }

    .ff-progress-bar {
        height: 5px;
    }

    .ff-option-card {
        padding: 1.15rem 1rem;
        min-height: 60px;
    }
}

/* ---------- Responsive: Desktop (1024px+) ---------- */
@media (min-width: 1024px) {
    .ff-form-wrapper {
        padding: 2.5rem 2rem;
    }

    .ff-options-grid {
        gap: 1rem;
    }

    .ff-option-card {
        padding: 1.25rem 1.25rem;
    }

    .ff-option-card:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    }

    .ff-option-card:has(input:checked) {
        transform: scale(1.03);
    }
}
