/**
 * Checkatrade Affiliate Form - Multi-Step Styling
 * Matches Figma design specifications
 * 
 * Table of Contents:
 * 1. Container & Layout
 * 2. Typography & Headers
 * 3. Form Structure
 * 4. Input Fields & Controls
 * 5. Buttons
 * 6. Success Step & App Promotion
 * 7. Messages & Validation
 * 8. Select2 Integration
 * 9. Responsive (Container Queries)
 */

/* ========================================
   1. CONTAINER & LAYOUT
   ======================================== */
.checkatrade-affiliate-form-widget {
    width: 100%;
    max-width: 768px;
    min-width: 320px;
    margin: 0 auto;
    font-family: 'Haffer', sans-serif;
    container-type: inline-size;
    container-name: affiliate-form;
}

/* Header */
.affiliate-form-header {
    background: #ffffff;
    border: 1px solid #ededed;
    border-radius: 24px 24px 0 0;
    padding: 16px 16px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-back-button {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease;
    color: #101d41;
    width: 40px;
    height: 40px;
}

.header-back-button:hover {
    background: #f7f7f6;
}

.header-back-button svg {
    width: 24px;
    height: 24px;
}

.header-content {
    text-align: center;
}

.affiliate-form-header p {
    font-family: 'Haffer', sans-serif;
    font-size: 13px;
    font-weight: 400;
    line-height: 16px;
    color: #514c5b;
    margin: 0 0 6px 0;
}

.affiliate-api-logo {
    margin: 0;
}

.affiliate-api-logo img {
    max-width: 160px;
    height: 22px;
}

/* Content Container */
.affiliate-form-content {
    background: #f7f7f6;
    border-left: 1px solid #ededed;
    border-right: 1px solid #ededed;
    border-bottom: 1px solid #ededed;
    border-radius: 0 0 24px 24px;
    padding: 20px;
    position: relative;
    overflow: visible;
    min-height: 600px;
    display: flex;
    flex-direction: column;
}

/* ========================================
   2. TYPOGRAPHY & HEADERS
   ======================================== */
.affiliate-form-title {
    font-family: 'Degular Display', sans-serif;
    font-size: 20px;
    font-weight: 700;
    line-height: 26px;
    color: #101d41;
    margin: 0 0 4px 0;
}

.affiliate-form-subtitle {
    font-family: 'Haffer', sans-serif;
    font-size: 15px;
    font-weight: 400;
    line-height: 18px;
    color: #666666;
    margin: 0 0 16px 0;
}

/* ========================================
   3. FORM STRUCTURE
   ======================================== */
.affiliate-form {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.form-step {
    display: none;
    width: 100%;
}

.form-step.active {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.form-step-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    flex: 1;
}

/* Field Groups */
.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-group-header {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.field-group label.label {
    font-family: 'Haffer', sans-serif;
    font-size: 15px;
    font-weight: 570;
    line-height: 20px;
    color: #333333;
    margin: 0;
    display: block;
}

.field-group .field-description {
    font-family: 'Haffer', sans-serif;
    font-size: 13px;
    font-weight: 400;
    line-height: 16px;
    color: #666666;
    margin: 0;
}

/* ========================================
   4. INPUT FIELDS & CONTROLS
   ======================================== */
.input-container {
    position: relative;
    display: flex;
    align-items: center;
    background: #ffffff;
    border: 1px solid #cacfff;
    border-radius: 999px;
    padding: 10px 14px;
    gap: 8px;
    height: 44px;
    box-sizing: border-box;
}

.input-container.textarea-container {
    border-radius: 12px 12px 0 0;
    align-items: flex-start;
    height: auto;
    min-height: auto;
}

.input-container .input-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-container .input-icon svg {
    width: 100%;
    height: 100%;
    fill: #666666;
}

.input-container input,
.input-container textarea,
.input-container select {
    flex: 1;
    border: none;
    background: transparent;
    font-family: 'Haffer', sans-serif;
    font-size: 14px;
    font-weight: 400;
    line-height: 20px;
    color: #333333;
    outline: none;
    padding: 0;
    margin: 0;
    height: 20px;
}

/* Remove all focus outlines and blue boxes */
.input-container input:focus,
.input-container textarea:focus,
.input-container select:focus,
.input-container input:focus-visible,
.input-container textarea:focus-visible,
.input-container select:focus-visible {
    outline: none !important;
    box-shadow: none !important;
    border: none !important;
}

.input-container input::placeholder,
.input-container textarea::placeholder {
    color: #666666;
}

.input-container textarea {
    resize: none;
    min-height: 70px;
    line-height: 1.4;
    height: auto;
}

.input-container select {
    appearance: none;
    cursor: pointer;
    padding-right: 24px;
}

.input-container .dropdown-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    pointer-events: none;
}

.input-container:focus-within {
    border-color: #cacfff;
}

/* Image Upload Section */
.image-upload-container {
    background: #ffffff;
    border: 1px solid #cacfff;
    border-top: none;
    border-radius: 0 0 12px 12px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
}

.image-upload-container:hover {
    background: #fafafa;
}

.image-upload-container .image-upload-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    flex: 1;
    min-width: 0;
}

.image-upload-container .input-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    position: relative;
    top: -3px;
}

.image-upload-container .upload-text {
    font-family: 'Haffer', sans-serif;
    font-size: 14px;
    font-weight: 400;
    line-height: 16px;
    color: #666666;
    margin: 0;
}

.file-input-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Image Dropdown Container */
.image-dropdown-container {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.image-dropdown-toggle {
    background: transparent;
    border: none;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font-family: 'Haffer', sans-serif;
    font-size: 13px;
    font-weight: 500;
    color: #666666;
    transition: all 0.2s ease;
    white-space: nowrap;
    border-radius: 6px;
}

.image-dropdown-toggle:hover {
    background: #f0f0f0;
    color: #333333;
}

.image-dropdown-toggle .image-count {
    line-height: 1;
}

.image-dropdown-toggle .dropdown-arrow {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.image-dropdown-toggle:hover .dropdown-arrow path {
    fill: #333333;
}

/* Dropdown List */
.image-dropdown-list {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: #ffffff;
    border: 1px solid #cacfff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 300px;
    max-width: 350px;
    max-height: 280px;
    overflow-y: auto;
    z-index: 100;
}

.image-dropdown-list ul {
    list-style: none;
    padding: 8px;
    margin: 0;
}

.image-dropdown-list li {
    padding: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #ededed;
    transition: background 0.15s ease;
}

.image-dropdown-list li:last-child {
    border-bottom: none;
}

.image-dropdown-list li:hover {
    background: #f7f7f6;
    border-radius: 4px;
}

/* Image Thumbnail */
.image-dropdown-list .image-thumbnail-wrapper {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    border: 1px solid #ededed;
    flex-shrink: 0;
    background: #f7f7f6;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.image-dropdown-list .image-thumbnail-wrapper::before {
    content: '📷';
    font-size: 18px;
    position: absolute;
    opacity: 0.3;
}

.image-dropdown-list .image-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 3px;
}

.image-dropdown-list .image-thumbnail-wrapper.thumbnail-error {
    background: #fee;
}

.image-dropdown-list .image-thumbnail-wrapper.thumbnail-error::before {
    content: '⚠️';
}

/* File Info Container */
.image-dropdown-list .file-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.image-dropdown-list .file-name {
    font-family: 'Haffer', sans-serif;
    font-size: 13px;
    line-height: 16px;
    font-weight: 500;
    color: #333333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-dropdown-list .file-size {
    font-family: 'Haffer', sans-serif;
    font-size: 12px;
    line-height: 14px;
    color: #666666;
}

.image-dropdown-list .remove-image {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.15s ease;
    flex-shrink: 0;
}

.image-dropdown-list .remove-image:hover {
    background: #fee;
}

.image-dropdown-list .remove-image svg {
    width: 16px;
    height: 16px;
}

/* Checkbox Field */
.checkbox-field {
    margin-top: 4px;
}

.checkbox-container {
    display: flex;
    gap: 10px;
}

.checkbox-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.checkbox-label {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    cursor: pointer;
    font-family: 'Haffer', sans-serif;
    font-size: 13px;
    font-weight: 400;
    line-height: 16px;
    color: #666666;
}

.checkbox-box {
    width: 18px;
    height: 18px;
    min-width: 18px;
    border: 2px solid #cacfff;
    border-radius: 3px;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    margin-top: 0;
}

.checkbox-input:checked+.checkbox-label .checkbox-box {
    background: #101d41;
    border-color: #101d41;
}

.checkbox-icon {
    opacity: 0;
    transition: opacity 0.2s ease;
    width: 14px;
    height: 14px;
}

.checkbox-input:checked+.checkbox-label .checkbox-icon {
    opacity: 1;
}

.checkbox-label:hover .checkbox-box {
    border-color: #101d41;
}

.checkbox-text {
    flex: 1;
}

.checkbox-text .privacy-link {
    color: #101d41;
    text-decoration: underline;
    font-weight: 570;
    font-size: 12px;
}

.checkbox-text .privacy-link:hover {
    text-decoration: none;
}

.checkbox-container.error .checkbox-box {
    border-color: #dc3545;
}

/* ========================================
   5. BUTTONS
   ======================================== */
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: auto;
    padding-top: 16px;
}

.form-actions button,
.form-actions a {
    flex: 1;
    font-family: 'Haffer', sans-serif;
    font-size: 16px;
    font-weight: 700;
    line-height: 20px;
    padding: 12px 16px;
    border-radius: 100px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: #ffffff;
    color: #101d41 !important;
    border: 1px solid #101d41;
}

.btn-primary:visited {
    color: #101d41 !important;
}

.btn-primary:active,
.btn-primary:focus {
    color: #101d41 !important;
}

.btn-primary:hover:not(:disabled) {
    background: #101d41;
    color: #ffffff !important;
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: transparent;
    color: #101d41;
    border: 1px solid #101d41;
}

.btn-secondary:hover {
    background: #f7f7f6;
}

.btn-icon {
    width: 20px;
    height: 20px;
}

/* ========================================
   6. SUCCESS STEP & APP PROMOTION
   ======================================== */
.success-step {
    gap: 16px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.success-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-bottom: 12px;
}

.success-title {
    font-family: 'Degular Display', sans-serif;
    font-size: 20px;
    font-weight: 700;
    line-height: 26px;
    color: #101d41;
    margin: 0;
}

.success-subtitle {
    font-family: 'Haffer', sans-serif;
    font-size: 15px;
    font-weight: 400;
    line-height: 18px;
    color: #666666;
    margin: 0;
}

.success-illustration {
    margin: 0 auto;
}

.success-illustration svg {
    width: 100%;
    height: 100%;
}

.success-steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.success-step-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.success-step-header {
    display: flex;
    gap: 8px;
    align-items: center;
}

.success-step-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.success-step-title {
    font-family: 'Haffer', sans-serif;
    font-size: 15px;
    font-weight: 570;
    line-height: 22px;
    color: #101d41;
    margin: 0;
}

.success-step-description {
    font-family: 'Haffer', sans-serif;
    font-size: 13px;
    font-weight: 400;
    line-height: 18px;
    color: #666666;
    margin: 0;
    padding-left: 28px;
}

/* App Promotion Box */
.app-promotion-box {
    background: #EF4444;
    border-radius: 12px;
    padding: 16px;
    margin-top: 8px;
}

.app-promotion-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.app-promotion-title {
    font-family: 'Haffer', sans-serif;
    font-size: 16px;
    font-weight: 700;
    line-height: 22px;
    color: #ffffff;
    margin: 0;
}

.app-promotion-subtitle {
    font-family: 'Haffer', sans-serif;
    font-size: 13px;
    font-weight: 400;
    line-height: 18px;
    color: #ffffff;
    margin: 0;
}

.app-store-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.app-store-badge {
    display: inline-block;
    height: 40px;
    transition: opacity 0.2s ease;
    border-radius: 5px;
    overflow: hidden;
}

.app-store-badge:hover {
    opacity: 0.9;
}

.app-store-badge img {
    height: 100%;
    width: auto;
    display: block;
    border-radius: 5px;
}

/* Specific sizing for each badge to match mockup */
.app-store-badge.google-play {
    height: 40px;
    width: auto;
}

.app-store-badge.google-play img {
    height: 40px;
    width: auto;
}

.app-store-badge.app-store {
    height: 40px;
    width: auto;
}

.app-store-badge.app-store img {
    height: 40px;
    width: auto;
}

/* ========================================
   7. MESSAGES & VALIDATION
   ======================================== */
.message-container {
    margin: 12px 0 0 0;
    position: absolute;
    bottom: 80px;
    left: 20px;
    right: 20px;
    z-index: 10;
}

.message-container .message {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 6px;
    font-family: 'Haffer', sans-serif;
    font-size: 13px;
    line-height: 18px;
}

.message-container .message .message-icon {
    flex-shrink: 0;
}

.message-container .message .message-text {
    flex: 1;
}

.message-container .message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.message-container .message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Loading State */
button.loading {
    opacity: 0.7;
    cursor: wait;
}

/* Validation Errors */
.field-error {
    color: #dc3545;
    font-family: 'Haffer', sans-serif;
    font-size: 12px;
    line-height: 16px;
    margin-top: 4px;
}

.input-container.error {
    border-color: #dc3545;
}

/* Hide Magento's default validation styling */
.checkatrade-affiliate-form-widget .field .control {
    margin: 0;
}

.checkatrade-affiliate-form-widget .field.required>.label:after {
    content: none;
}

/* ========================================
   8. SELECT2 INTEGRATION
   ======================================== */
.select2-container--default .select2-selection--single {
    border: none !important;
    background: transparent !important;
    height: auto !important;
    padding: 0 !important;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    padding: 0 !important;
    line-height: inherit !important;
    color: #333333 !important;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #666666 !important;
    font-size: 14px !important;
    font-weight: 400 !important;
}

/* Hide Select2's default arrow since we have our own */
.select2-container--default .select2-selection--single .select2-selection__arrow {
    display: none !important;
}

.input-container .select2-container {
    flex: 1;
}

/* Select2 Dropdown Styling */
.select2-container--default .select2-results__option {
    padding: 7px 14px;
    font-family: 'Haffer', sans-serif;
    font-size: 14px;
    color: #333333;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: #cacfff !important;
    color: #101d41 !important;
}

.select2-container--default .select2-results__option[aria-selected=true] {
    background-color: #f7f7f6;
}

.select2-container--default .selection {
    display: block !important;
    height: auto !important;
    padding: 8px 0 !important;
}

.select2-dropdown {
    border: 1px solid #cacfff !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.select2-search--dropdown {
    padding: 6px;
}

.select2-search--dropdown .select2-search__field {
    border: 1px solid #cacfff;
    border-radius: 6px;
    padding: 8px 12px;
    font-family: 'Haffer', sans-serif;
    font-size: 13px;
}

.select2-search--dropdown .select2-search__field:focus {
    outline: none;
    border-color: #101d41;
}

/* Category hierarchy indentation for Select2 dropdown */
.select2-results__option span.category-level-1 {
    padding-left: 1.5em;
}

.select2-results__option span.category-level-2 {
    padding-left: 3em;
}

.select2-results__option span.category-level-3 {
    padding-left: 4.5em;
}

/* ========================================
   9. RESPONSIVE (CONTAINER QUERIES)
   ======================================== */

/* Step 1: Two-column grid for timeframe and postcode on larger containers */
@container affiliate-form (min-width: 600px) {
    .form-step[data-step="1"] .form-step-content {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto auto auto 1fr;
        gap: 16px;
        row-gap: 16px;
        flex: 1;
    }

    /* Title spans full width */
    .form-step[data-step="1"] .affiliate-form-intro {
        grid-column: 1 / -1;
    }

    /* Category selection spans full width */
    .form-step[data-step="1"] .field-group:not(.field-timeframe):not(.field-postcode) {
        grid-column: 1 / -1;
    }

    /* Timeframe and Postcode sit side by side with aligned inputs */
    .form-step[data-step="1"] .field-timeframe {
        grid-column: 1;
        display: grid;
        grid-template-rows: auto 1fr;
        align-items: start;
    }

    .form-step[data-step="1"] .field-postcode {
        grid-column: 2;
        display: grid;
        grid-template-rows: auto 1fr;
        align-items: start;
    }

    /* Ensure input containers align at the bottom of their cells and have consistent height */
    .form-step[data-step="1"] .field-timeframe .input-container,
    .form-step[data-step="1"] .field-postcode .input-container {
        align-self: end;
        min-height: 44px;
        height: 44px;
    }

    /* Actions span full width and stay at bottom */
    .form-step[data-step="1"] .form-actions {
        grid-column: 1 / -1;
        align-self: end;
    }
}

/* Step 2: Two-column layout on larger containers */
@container affiliate-form (min-width: 500px) {
    .form-step[data-step="2"] .form-step-content {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto auto auto 1fr;
        gap: 16px;
        align-content: start;
    }

    /* Title spans full width - Row 1 */
    .form-step[data-step="2"] .affiliate-form-intro {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    /* First Name - left column, Row 2 */
    .form-step[data-step="2"] .field-group:nth-child(2) {
        grid-column: 1;
        grid-row: 2;
    }

    /* Last Name - right column, Row 2 */
    .form-step[data-step="2"] .field-group:nth-child(3) {
        grid-column: 2;
        grid-row: 2;
    }

    /* Email - left column, Row 3 */
    .form-step[data-step="2"] .field-group:nth-child(4) {
        grid-column: 1;
        grid-row: 3;
    }

    /* Mobile - right column, Row 3 */
    .form-step[data-step="2"] .field-group:nth-child(5) {
        grid-column: 2;
        grid-row: 3;
    }

    /* Checkbox field spans full width - Row 4 */
    .form-step[data-step="2"] .checkbox-field {
        grid-column: 1 / -1;
        grid-row: 4;
    }

    /* Actions span full width - Row 5 (auto expands) */
    .form-step[data-step="2"] .form-actions {
        grid-column: 1 / -1;
        grid-row: 5;
        align-self: end;
    }
}

/* Smaller containers */
@container affiliate-form (max-width: 400px) {

    .affiliate-form-header {
        border-radius: 16px 16px 0 0;
        padding: 12px 12px;
    }

    .affiliate-form-content {
        border-radius: 0 0 16px 16px;
        padding: 16px;
    }

    .form-step-content {
        gap: 12px;
    }

    .affiliate-form-title {
        font-size: 18px;
        line-height: 24px;
    }

    .btn-primary,
    .btn-secondary {
        font-size: 14px;
        padding: 10px;
    }

    .app-promotion-box {
        padding: 12px;
        border-radius: 10px;
    }

    .app-promotion-title {
        font-size: 14px;
        line-height: 20px;
    }

    .app-promotion-subtitle {
        font-size: 12px;
        line-height: 16px;
    }

    .app-store-badge {
        height: 32px;
    }

    .app-store-badge.google-play,
    .app-store-badge.app-store {
        height: 32px;
    }

    .app-store-badge.google-play img,
    .app-store-badge.app-store img {
        height: 32px;
    }

    .checkbox-label {
        font-size: 11px;
        line-height: 15px;
        gap: 8px;
    }

    .checkbox-box {
        width: 16px;
        height: 16px;
        min-width: 16px;
    }

    .checkbox-icon {
        width: 12px;
        height: 12px;
    }

    /* Image upload adjustments for small screens */
    .image-upload-container .upload-text {
        font-size: 14px;
    }

    .image-dropdown-toggle {
        font-size: 11px;
        padding: 3px 6px;
    }

    .image-dropdown-list {
        min-width: 220px;
        max-width: 260px;
    }
}

/* Very small containers - stack app store buttons */
@container affiliate-form (max-width: 340px) {
    .app-store-buttons {
        flex-direction: column;
        align-items: flex-start;
    }

    .app-store-badge {
        width: 100%;
        max-width: 135px;
    }
}