/**
 * Postal Code Widget Styles
 * Standalone component matching the reference design exactly
 */

/* Widget Container */
.ect-postal-widget-container {
    width: 100%;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: visible;
    position: relative;
    z-index: 1;
}

.ect-postal-widget {
    background: linear-gradient(135deg, #011d69 0%, #001550 100%);
    border-radius: 20px;
    padding: 40px;
    max-width: 600px;
    width: 100%;
    box-shadow: 0 10px 40px rgb(26 0 204 / 20%);
    position: relative;
    overflow: visible;
}

/* Decorative background elements */
.ect-postal-widget::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -10%;
    width: 300px;
    height: 300px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    pointer-events: none;
}

.ect-postal-widget::after {
    content: '';
    position: absolute;
    bottom: -30%;
    left: -5%;
    width: 200px;
    height: 200px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    pointer-events: none;
}

/* Widget Header */
.ect-widget-header {
    text-align: center;
    margin-bottom: 30px;
    position: relative;
    z-index: 2;
}

.ect-widget-title {
    font-size: 32px;
    font-weight: 700;
    color: #ffffff !important;
    margin: 0 0 15px 0;
    line-height: 1.2;
    text-align: center;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.ect-widget-subtitle {
    font-size: 16px;
    color: #ffffff;
    margin: 0;
    line-height: 1.5;
    opacity: 0.95;
    font-weight: 400;
}

/* Widget Form */
.ect-postal-widget-form {
    margin-bottom: 25px;
    position: relative;
    z-index: 2;
}

.ect-widget-form-group {
    margin-bottom: 15px;
    position: relative;
}

.ect-widget-input {
    width: 100%;
    padding: 16px 20px;
    font-size: 16px;
    border: none;
    border-radius: 12px;
    background: #ffffff;
    color: #333333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    outline: none;
}

.ect-widget-input::placeholder {
    color: #999999;
}

.ect-widget-input:focus {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

/* Select2 Styling for Widget */
.ect-postal-widget .select2-container {
    width: 100% !important;
}

.ect-postal-widget .select2-container .select2-selection--single {
    height: auto;
    padding: 16px 20px;
    font-size: 16px;
    border: none;
    border-radius: 12px;
    background: #ffffff;
    color: #333333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.ect-postal-widget .select2-container .select2-selection--single:focus,
.ect-postal-widget .select2-container.select2-container--focus .select2-selection--single {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
    outline: none;
}

.ect-postal-widget .select2-container .select2-selection__rendered {
    color: #333333;
    line-height: 1.5;
    padding: 0;
}

.ect-postal-widget .select2-container .select2-selection__placeholder {
    color: #999999;
}

.ect-postal-widget .select2-container .select2-selection__arrow {
    height: 100%;
    right: 10px;
}

.ect-postal-widget .select2-container .select2-selection__arrow b {
    border-color: #999999 transparent transparent transparent;
    border-width: 6px 6px 0 6px;
}

.ect-postal-widget .select2-container--open .select2-selection__arrow b {
    border-color: transparent transparent #999999 transparent;
    border-width: 0 6px 6px 6px;
}

/* Select2 Dropdown */
.ect-postal-widget .select2-dropdown {
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    background: #ffffff;
    margin-top: 4px;
    z-index: 9999;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.select2-container--open .select2-dropdown {
    z-index: 9999;
}

.ect-postal-widget .select2-search--dropdown {
    padding: 12px;
}

.ect-postal-widget .select2-search__field {
    padding: 10px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    outline: none;
}

.ect-postal-widget .select2-search__field:focus {
    border-color: #00a5cc;
}

.ect-postal-widget .select2-results__option {
    padding: 12px 16px;
    font-size: 15px;
    color: #333333;
    transition: all 0.2s ease;
}

.ect-postal-widget .select2-results__option--highlighted {
    background-color: #00a5cc !important;
    color: #ffffff !important;
    font-weight: 500;
}

.ect-postal-widget .select2-results__option--selected {
    background-color: #0088aa !important;
    color: #ffffff !important;
    font-weight: 600;
}

.ect-postal-widget .select2-results__option:hover {
    background-color: #00a5cc !important;
    color: #ffffff !important;
}

.ect-postal-widget .select2-results {
    max-height: 250px;
}

/* Error state for Select2 */
.ect-postal-widget .select2-container.error .select2-selection--single {
    border: 2px solid #ff4444;
    animation: shake 0.3s;
}

.ect-widget-submit-btn {
    width: 100%;
    padding: 16px 20px !important;
    font-size: 18px !important;
    font-weight: 600 !important;
    color: #ffffff !important;
    background: linear-gradient(135deg, #ff6b35 0%, #ff5722 100%) !important;
    border: none !important;
    border-radius: 12px !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3) !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
    outline: none !important;
}

.ect-widget-submit-btn:hover {
    background: linear-gradient(135deg, #ff5722 0%, #ff4510 100%) !important;
    box-shadow: 0 6px 20px rgba(255, 107, 53, 0.4) !important;
    transform: translateY(-2px) !important;
}

.ect-widget-submit-btn:active {
    transform: translateY(0) !important;
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3) !important;
}

/* Widget Footer - Promotional Text */
.ect-widget-footer {
    text-align: center;
    position: relative;
    z-index: 2;
    margin-top: 20px;
}

.ect-promo-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.ect-promo-line-1,
.ect-promo-line-2 {
    font-size: 15px;
    color: #ffffff;
    margin: 0;
    line-height: 1.4;
    font-weight: 500;
}

.ect-promo-line-1 {
    font-weight: 600;
}

/* Responsive Design */
@media (max-width: 768px) {
    .ect-postal-widget {
        padding: 30px 25px;
        border-radius: 16px;
    }
    
    .ect-widget-title {
        font-size: 26px;
    }
    
    .ect-widget-input,
    .ect-widget-submit-btn {
        font-size: 15px;
        padding: 14px 18px;
    }
    
    .ect-promo-line-1,
    .ect-promo-line-2 {
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .ect-postal-widget-container {
        padding: 15px;
    }
    
    .ect-postal-widget {
        padding: 25px 20px;
    }
    
    .ect-widget-title {
        font-size: 22px;
    }
    
    .ect-promo-line-1,
    .ect-promo-line-2 {
        font-size: 13px;
    }
}

/* Loading State */
.ect-postal-widget-form.loading .ect-widget-submit-btn {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.ect-postal-widget-form.loading .ect-widget-submit-btn::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin-left: -10px;
    margin-top: -10px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: ect-widget-spin 0.8s linear infinite;
}

@keyframes ect-widget-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Error State */
.ect-widget-input.error {
    border: 2px solid #ff4444;
    animation: shake 0.3s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.ect-widget-error-message {
    color: #ffffff;
    background: rgba(255, 68, 68, 0.9);
    padding: 10px 15px;
    border-radius: 8px;
    margin-top: 10px;
    font-size: 14px;
    text-align: center;
    display: none;
}

.ect-widget-error-message.show {
    display: block;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Ensure Select2 dropdown is not clipped */
.ect-postal-widget-container .select2-dropdown {
    z-index: 99999 !important;
}

.select2-container--open {
    z-index: 99999 !important;
}

/* Global Select2 dropdown styles for postal widget (when rendered outside) */
.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: #00a5cc !important;
    color: #ffffff !important;
}

.select2-container--default .select2-results__option--selected {
    background-color: #0088aa !important;
    color: #ffffff !important;
}

.select2-container--default .select2-results__option[aria-selected=true] {
    background-color: #0088aa !important;
    color: #ffffff !important;
}

/* Fix for dropdown positioning outside widget */
.select2-container--open .select2-dropdown--below {
    margin-top: 4px;
}

.select2-container--open .select2-dropdown--above {
    margin-bottom: 4px;
}

/* Ensure dropdown has enough space on mobile */
@media (max-width: 768px) {
    .ect-postal-widget-container {
        padding: 10px;
        overflow: visible;
    }
    
    .ect-postal-widget {
        padding: 30px 20px;
        overflow: visible;
    }
    
    .select2-container .select2-dropdown {
        max-height: 350px !important;
    }
    
    .select2-results__options {
        max-height: 300px !important;
    }
    
    /* Improve touch targets on mobile */
    .ect-postal-widget .select2-container--default .select2-selection--single {
        min-height: 50px;
        padding: 12px 20px;
        touch-action: manipulation;
    }
    
    .ect-postal-widget .select2-container .select2-selection__rendered {
        line-height: 26px;
    }
    
    .ect-postal-widget .select2-results__option {
        padding: 16px 20px;
        font-size: 16px;
        min-height: 52px;
        touch-action: manipulation;
    }
    
    .ect-postal-widget .select2-search__field {
        font-size: 16px !important; /* Prevents zoom on iOS */
        min-height: 44px;
        padding: 12px 16px !important;
    }
    
    /* Prevent text selection on touch */
    .select2-results__option {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
}

span.select2-results {
    overflow-y: hidden;
}
