/**
 * Add Listing — multi-step wizard + modern layout (child theme).
 * Scoped with body.ml-child-add-listing-modern on the WP Job Manager submission page.
 */

body.ml-child-add-listing-modern {
    --ml-al-add-olive: #4f5a3e;
    --ml-al-add-olive-soft: rgba(79, 90, 62, 0.12);
    --ml-al-add-olive-muted: #6b7a54;
    --ml-al-add-surface: #fafbf8;
    --ml-al-add-card: #ffffff;
    --ml-al-add-radius: 16px;
    --ml-al-add-shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
    --ml-al-add-error: #c0392b;
    --ml-al-wizard-max: 680px;
}

/* Page background */
body.ml-child-add-listing-modern.add-listing-form .add-listing-step,
body.ml-child-add-listing-modern.add-listing-form #c27-site-wrapper > .add-listing-step {
    background: linear-gradient(180deg, #f4f5f2 0%, #eceee9 100%);
    min-height: 100vh;
}

body.ml-child-add-listing-modern .add-listing-step .i-section {
    padding-top: 1.25rem;
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
}

body.ml-child-add-listing-modern .add-listing-step .section-title h2 {
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #2d3328;
}

body.ml-child-wizard-active .ml-child-wizard-page-title h2 {
    font-size: clamp(1.35rem, 4vw, 1.75rem);
    text-align: center;
    margin-bottom: 0.25rem;
}

/* Top progress bar (synced with wizard) */
#ml-child-add-listing-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    z-index: 9998;
    pointer-events: none;
    background: rgba(79, 90, 62, 0.12);
}

#ml-child-add-listing-progress .ml-child-add-listing-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--ml-al-add-olive), var(--ml-al-add-olive-muted));
    border-radius: 0 3px 3px 0;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 12px rgba(79, 90, 62, 0.35);
}

/* Hide legacy scroll nav when wizard is active */
body.ml-child-wizard-active .add-listing-nav {
    display: none !important;
}

/* Collapse legacy multi-section layout until the wizard is ready */
body.ml-child-add-listing-modern.add-listing-form:not(.ml-child-wizard-active):not(.ml-child-wizard-fallback) #submit-job-form .form-section-wrapper .pf-head,
body.ml-child-add-listing-modern.add-listing-form:not(.ml-child-wizard-active):not(.ml-child-wizard-fallback) .add-listing-nav {
    visibility: hidden;
}

body.ml-child-wizard-active #submit-job-form .form-section-wrapper:not(.ml-child-wizard-section-active):not(.form-footer) {
    display: none !important;
}

body.ml-child-wizard-active #submit-job-form .form-section-wrapper.ml-child-wizard-section-active {
    display: block !important;
}

body.ml-child-wizard-active #submit-job-form .form-section-wrapper:not(.form-footer) .form-section {
    margin-bottom: 0 !important;
}

/* Stop parent theme scroll-spy opacity/scale transitions (main flicker source) */
body.ml-child-wizard-active #submit-job-form .form-section {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
}

body.ml-child-wizard-active #submit-job-form .form-section-wrapper.active .form-section {
    box-shadow: var(--ml-al-add-shadow) !important;
}

body.ml-child-wizard-active.add-listing-form {
    scroll-behavior: auto;
}

body.ml-child-wizard-active #submit-job-form {
    overflow: visible;
}

body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-step-visible {
    overflow: visible;
}

/* Wizard chrome (header + bottom nav) */
.ml-child-wizard-chrome {
    width: min(100%, var(--ml-al-wizard-max));
    margin: 0 auto 1.25rem;
    padding: 0 1rem;
}

.ml-child-wizard-header {
    text-align: center;
    margin-bottom: 1rem;
}

.ml-child-wizard-progress-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #5a6352;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.ml-child-wizard-percent {
    color: var(--ml-al-add-olive);
}

.ml-child-wizard-progress-track {
    height: 6px;
    border-radius: 999px;
    background: var(--ml-al-add-olive-soft);
    overflow: hidden;
    margin-bottom: 1.25rem;
}

.ml-child-wizard-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--ml-al-add-olive), var(--ml-al-add-olive-muted));
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.ml-child-wizard-section-label {
    margin: 0 0 0.35rem;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ml-al-add-olive-muted);
}

.ml-child-wizard-section-label:empty {
    display: none;
}

.ml-child-wizard-field-title {
    margin: 0 0 0.5rem;
    font-size: clamp(1.35rem, 4.5vw, 1.75rem);
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.02em;
    color: #2d3328;
}

.ml-child-wizard-field-desc {
    margin: 0;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: #6b7264;
}

.ml-child-wizard-field-desc:empty {
    display: none;
}

/* Wizard navigation */
.ml-child-wizard-nav {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.75rem;
    width: min(100%, var(--ml-al-wizard-max));
    margin: 1.5rem auto 0;
    padding: 0 1rem;
}

.ml-child-wizard-nav.ml-child-wizard-nav--has-skip {
    grid-template-columns: auto 1fr auto;
}

.ml-child-wizard-back {
    grid-column: 1;
}

.ml-child-wizard-next {
    grid-column: 2;
}

.ml-child-wizard-nav.ml-child-wizard-nav--has-skip .ml-child-wizard-next {
    grid-column: 2;
}

.ml-child-wizard-skip {
    grid-column: 3;
    display: none;
}

.ml-child-wizard-nav button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 48px;
    padding: 0.75rem 1.25rem !important;
    font-size: 0.9375rem !important;
    font-weight: 600 !important;
    border-radius: 12px !important;
    transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.ml-child-wizard-back {
    background: #fff !important;
    color: #3d4634 !important;
    border: 1px solid #dfe3d8 !important;
}

.ml-child-wizard-back:hover:not(:disabled) {
    border-color: rgba(79, 90, 62, 0.35) !important;
    transform: translateY(-1px);
}

.ml-child-wizard-back:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.ml-child-wizard-next {
    background: var(--ml-al-add-olive) !important;
    color: #fff !important;
    border: none !important;
    box-shadow: 0 6px 20px rgba(79, 90, 62, 0.28);
}

.ml-child-wizard-next:hover {
    background: #5a6748 !important;
    transform: translateY(-1px);
    box-shadow: 0 10px 28px rgba(79, 90, 62, 0.32);
}

.ml-child-wizard-skip {
    background: #fff !important;
    color: #5a6352 !important;
    border: 1px solid #dfe3d8 !important;
    box-shadow: none !important;
    min-width: 4.5rem;
    padding-left: 1rem !important;
    padding-right: 1rem !important;
}

.ml-child-wizard-skip:hover {
    color: #3d4634 !important;
    border-color: rgba(79, 90, 62, 0.35) !important;
    background: #fafbf8 !important;
    transform: translateY(-1px);
}

.ml-child-wizard-nav button i {
    font-size: 1.125rem;
    line-height: 1;
}

/* Form wizard step visibility */
body.ml-child-wizard-active #submit-job-form .form-section-wrapper .pf-head {
    display: none !important;
}

body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-step-hidden,
body.ml-child-wizard-active #submit-job-form .form-section-wrapper.form-footer.ml-child-wizard-step-hidden {
    display: none !important;
}

body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-step-visible,
body.ml-child-wizard-active #submit-job-form .form-section-wrapper.form-footer.ml-child-wizard-step-visible {
    display: block !important;
}

/* Override parent theme: all sections visible at once */
body.ml-child-wizard-active #submit-job-form .form-section-wrapper .form-section {
    opacity: 1 !important;
    transform: none !important;
    visibility: visible !important;
}

body.ml-child-wizard-active #submit-job-form .form-section-wrapper:not(.form-footer) {
    background: transparent;
    border: none;
    box-shadow: none;
    margin-bottom: 0 !important;
}

body.ml-child-wizard-active #submit-job-form .form-section-wrapper:not(.form-footer) .form-section {
    background: transparent;
    border: none;
    box-shadow: none;
}

body.ml-child-wizard-active #submit-job-form .form-section-wrapper:not(.form-footer) .pf-body {
    padding: 0;
}

/* Single-step field card */
body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-step-visible {
    width: min(100%, var(--ml-al-wizard-max));
    margin: 0 auto;
    padding: 1.5rem;
    background: var(--ml-al-add-card);
    border-radius: var(--ml-al-add-radius);
    border: 1px solid var(--ml-al-add-olive-soft);
    box-shadow: var(--ml-al-add-shadow);
    animation: ml-child-wizard-step-in 0.35s ease;
}

body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-step-visible .field-head > label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-step-visible .field-head .description {
    display: none;
}

body.ml-child-wizard-active #submit-job-form .form-group .field > input,
body.ml-child-wizard-active #submit-job-form .form-group .field > textarea,
body.ml-child-wizard-active #submit-job-form .form-group .field > select {
    font-size: 1.0625rem;
    padding: 0.85rem 0;
}

body.ml-child-wizard-active #submit-job-form .form-group .field > input:focus,
body.ml-child-wizard-active #submit-job-form .form-group .field > textarea:focus {
    border-bottom-color: var(--ml-al-add-olive) !important;
}

/* Validation */
.ml-child-wizard-error {
    margin: 0.75rem 0 0;
    padding: 0.65rem 0.85rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ml-al-add-error);
    background: rgba(192, 57, 43, 0.08);
    border-radius: 8px;
    border-left: 3px solid var(--ml-al-add-error);
}

@keyframes ml-child-wizard-shake {
    0%,
    100% {
        transform: translateX(0);
    }
    20%,
    60% {
        transform: translateX(-6px);
    }
    40%,
    80% {
        transform: translateX(6px);
    }
}

body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-shake {
    animation: ml-child-wizard-shake 0.42s ease;
}

@media (prefers-reduced-motion: reduce) {
    body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-shake {
        animation: none;
    }
}

body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-invalid .field > input.invalid,
body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-invalid .field > select.invalid,
body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-invalid .field > textarea.invalid,
body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-invalid .address-field.invalid {
    border-bottom-color: var(--ml-al-add-error) !important;
}

@keyframes ml-child-wizard-step-in {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .ml-child-wizard-progress-fill,
    #ml-child-add-listing-progress .ml-child-add-listing-progress-fill,
    body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-step-visible {
        animation: none;
        transition: none;
    }
}

/* Review / submit step */
body.ml-child-wizard-active #submit-job-form .form-section-wrapper.form-footer.ml-child-wizard-step-visible {
    width: min(100%, var(--ml-al-wizard-max));
    margin: 0 auto;
}

body.ml-child-wizard-active #submit-job-form .form-section-wrapper.form-footer .form-section {
    background: var(--ml-al-add-card);
    border-radius: var(--ml-al-add-radius);
    border: 1px solid var(--ml-al-add-olive-soft);
    box-shadow: var(--ml-al-add-shadow);
}

body.ml-child-wizard-active #submit-job-form .form-section-wrapper.form-footer .pf-body {
    padding: 1.5rem;
}

body.ml-child-wizard-active .ml-child-wizard-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    margin-top: 0;
    padding-top: 0.75rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, rgba(244, 245, 242, 0) 0%, rgba(244, 245, 242, 0.96) 28%, #eceee9 100%);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

body.ml-child-wizard-active .add-listing-step .i-section {
    padding-bottom: calc(6.5rem + env(safe-area-inset-bottom, 0px));
}

/* Legacy full-form polish (non-wizard fallback + review buttons) */
body.ml-child-add-listing-modern #submit-job-form .form-section {
    width: min(100%, 720px);
    margin-left: auto;
    margin-right: auto;
    float: none;
    background: var(--ml-al-add-card);
    border-radius: var(--ml-al-add-radius);
    border: 1px solid var(--ml-al-add-olive-soft);
    box-shadow: var(--ml-al-add-shadow);
    overflow: hidden;
    margin-bottom: 1.75rem !important;
}

body.ml-child-add-listing-modern #submit-job-form .form-section .pf-head {
    padding: 1.25rem 1.5rem 0.75rem;
    background: linear-gradient(135deg, rgba(79, 90, 62, 0.06) 0%, transparent 55%);
    border-bottom: 1px solid var(--ml-al-add-olive-soft);
}

body.ml-child-add-listing-modern #submit-job-form .form-section .pf-head .title-style-1 h5 {
    font-size: 1.125rem;
    font-weight: 700;
    color: #2d3328;
}

body.ml-child-add-listing-modern #submit-job-form .form-section-wrapper.active .form-section {
    box-shadow: 0 12px 40px rgba(79, 90, 62, 0.12);
}

body.ml-child-add-listing-modern #submit-job-form .form-group {
    border-top-color: rgba(79, 90, 62, 0.08);
    padding: 1.25rem 1.5rem;
}

body.ml-child-add-listing-modern #submit-job-form .field > input:focus,
body.ml-child-add-listing-modern #submit-job-form .field > textarea:focus {
    border-bottom-color: var(--ml-al-add-olive) !important;
}

body.ml-child-add-listing-modern #submit-job-form .form-section-wrapper.form-footer .form-section {
    background: transparent;
    border: none;
    box-shadow: none;
}

body.ml-child-add-listing-modern #submit-job-form .form-section-wrapper.form-footer .listing-form-submit-btn {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
    width: 100%;
    max-width: min(100%, 720px);
    margin: 0 auto;
    flex-wrap: unset !important;
    justify-content: unset !important;
}

body.ml-child-add-listing-modern #submit-job-form .listing-form-submit-btn .skip-preview-btn {
    grid-column: 1 / -1;
    width: 100% !important;
    flex-basis: auto !important;
    margin-bottom: 0 !important;
}

body.ml-child-add-listing-modern #submit-job-form .listing-form-submit-btn .preview-btn {
    grid-column: 1;
    width: 100% !important;
    flex-basis: auto !important;
}

body.ml-child-add-listing-modern #submit-job-form .listing-form-submit-btn .save-listing-button {
    grid-column: 2;
    width: 100% !important;
    flex-basis: auto !important;
}

body.ml-child-add-listing-modern #submit-job-form .listing-form-submit-btn .preview-btn:nth-child(2):nth-last-child(1) {
    grid-column: 1 / -1;
}

body.ml-child-add-listing-modern #submit-job-form .listing-form-submit-btn button[type="submit"] {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 48px;
    height: auto !important;
    padding: 0.75rem 1.15rem !important;
    font-size: 0.9375rem !important;
    font-weight: 600 !important;
    line-height: 1.2;
    border-radius: 12px !important;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

body.ml-child-add-listing-modern #submit-job-form .listing-form-submit-btn button[type="submit"] i {
    position: static !important;
    top: auto !important;
    margin: 0 !important;
    font-size: 1.125rem;
    line-height: 1;
}

body.ml-child-add-listing-modern #submit-job-form .skip-preview-btn.buttons.button-2 {
    background: var(--ml-al-add-olive) !important;
    color: #fff !important;
    border: none !important;
    box-shadow: 0 6px 20px rgba(79, 90, 62, 0.28);
}

body.ml-child-add-listing-modern #submit-job-form .skip-preview-btn.buttons.button-2:hover {
    background: #5a6748 !important;
    color: #fff !important;
    transform: translateY(-1px);
    box-shadow: 0 10px 28px rgba(79, 90, 62, 0.32);
}

body.ml-child-add-listing-modern #submit-job-form .preview-btn.buttons.button-5,
body.ml-child-add-listing-modern #submit-job-form .save-listing-button.buttons.button-5 {
    background: #fff !important;
    color: #3d4634 !important;
    border: 1px solid #dfe3d8 !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

body.ml-child-add-listing-modern #submit-job-form .preview-btn.buttons.button-5:hover,
body.ml-child-add-listing-modern #submit-job-form .save-listing-button.buttons.button-5:hover {
    background: #fafbf8 !important;
    color: #2d3328 !important;
    border-color: rgba(79, 90, 62, 0.35) !important;
    box-shadow: 0 2px 8px rgba(79, 90, 62, 0.1);
    transform: translateY(-1px);
}

/* Tablet */
@media (min-width: 768px) {
    body.ml-child-wizard-active .add-listing-step .i-section {
        padding-top: 2rem;
    }

    .ml-child-wizard-chrome {
        padding: 0 1.5rem;
    }

    body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-step-visible {
        padding: 2rem 2.25rem;
    }

    .ml-child-wizard-nav {
        padding: 0 1.5rem;
        max-width: var(--ml-al-wizard-max);
    }
}

/* Mobile */
@media (max-width: 767px) {
    body.ml-child-wizard-active #submit-job-form .form-group.ml-child-wizard-step-visible {
        padding: 1.25rem 1rem;
        border-radius: 14px;
    }

    .ml-child-wizard-nav {
        grid-template-columns: auto 1fr;
        gap: 0.5rem;
    }

    .ml-child-wizard-nav.ml-child-wizard-nav--has-skip {
        grid-template-columns: auto 1fr auto;
    }

    .ml-child-wizard-skip {
        min-width: auto;
        padding-left: 0.85rem !important;
        padding-right: 0.85rem !important;
        font-size: 0.875rem !important;
    }

    body.ml-child-add-listing-modern #submit-job-form .form-section-wrapper.form-footer .listing-form-submit-btn {
        grid-template-columns: 1fr;
    }

    body.ml-child-add-listing-modern #submit-job-form .listing-form-submit-btn .preview-btn,
    body.ml-child-add-listing-modern #submit-job-form .listing-form-submit-btn .save-listing-button {
        grid-column: 1 / -1;
    }
}

/* Desktop wide */
@media (min-width: 1200px) {
    body.ml-child-wizard-active .add-listing-step .container {
        max-width: 820px;
    }
}

@media (max-width: 480px) {
    body.ml-child-add-listing-modern #submit-job-form .form-section-wrapper.form-footer .listing-form-submit-btn {
        grid-template-columns: 1fr;
    }
}
