/**
 * Custom Validation Styles for Aviation Classifieds
 * Form validation visual indicators
 */

/* Error field styles */
.error-field {
    border: 2px solid #dc3545 !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
    background-color: #fff5f5 !important;
}

/* Error label styles */
.error-label {
    color: #dc3545 !important;
    font-weight: bold !important;
}

.error-label:after {
    content: " *";
    color: #dc3545;
    font-weight: bold;
}

/* Error message styles */
.error-message {
    color: #dc3545;
    font-size: 12px;
    font-weight: 500;
    margin-top: 10px;
    display: inline-block;
    line-height: 1.4;
    clear: both;
    width: auto;
    position: absolute;
    top: -5px;
    right: 10px;
    padding: 4px 8px;
    z-index: 10;
    text-align:right;
    white-space: nowrap;
}

.title-container {
    position:relative;
}

.title-container #listing_title {

}

.title-container .error-message {
    top: 20px !important;
}

/* Error messages positioned in form quarters within end units */
.stm-form-1-end-unit .stm-form-1-quarter .error-message {
    position: absolute;
    top: -22px;
    right: 10px;
    text-align: right;
    border-radius: 4px;
    z-index: 10;
    white-space: nowrap;
    color: #c00;
    font-size: 12px;
    margin: -2px 0 0;
}

/* Error messages in form intro units */
.stm-form1-intro-unit .error-message {
    position: absolute;
    top: 0;
    right: 0;
    margin: 0;
    padding: 4px 8px;
    background-color: #fff5f5;
    border: 1px solid #dc3545;
    border-radius: 4px;
    z-index: 10;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    width: auto;
}

/* Select2 error styles */
.select2-container.error-field .select2-selection,
.select2-container.error-field .select2-selection--single,
.select2-container.error-field .select2-selection--multiple {
    border: 2px solid #dc3545 !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
    background-color: #fff5f5 !important;
}

.select2-container.error-field .select2-selection:focus,
.select2-container.error-field .select2-selection--single:focus,
.select2-container.error-field .select2-selection--multiple:focus {
    border-color: #c82333 !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.35) !important;
}

/* Position error messages correctly for Select2 */
.select2-container.error-field + .error-message {
    display: block !important;
    margin-top: 5px;
    position: relative;
    z-index: 1;
}

/* Make sure Select2 container inherits error styling */
.select2-container.error-field {
    display: block !important;
    width: 100% !important;
}

/* Additional Select2 error targeting */
span.select2-container.error-field .select2-selection {
    border: 2px solid #dc3545 !important;
    background-color: #fff5f5 !important;
}

span.select2-container.error-field span.select2-selection {
    border: 2px solid #dc3545 !important;
    background-color: #fff5f5 !important;
}

/* Checkbox/Radio error styles */
.checker.error-field {
    border: 2px solid #dc3545 !important;
    border-radius: 4px;
    padding: 5px;
    background-color: #fff5f5 !important;
}

/* Image gallery error styles */
.stm-media-car-gallery .stm-placeholder.error-field {
    border: 2px dashed #dc3545 !important;
    background-color: #fff5f5 !important;
}

.stm-media-car-gallery .stm-placeholder.error-field .inner {
    background-color: rgba(220, 53, 69, 0.1) !important;
}

/* Video field error styles */
.stm-video-link-unit.error-field {
    border: 2px solid #dc3545 !important;
    border-radius: 4px;
    padding: 10px;
    background-color: #fff5f5 !important;
    margin-bottom: 10px;
}

/* TinyMCE editor error styles */
#wp-stm_seller_notes-wrap.error-field {
    border: 2px solid #dc3545 !important;
    border-radius: 4px;
    background-color: #fff5f5 !important;
}

#wp-stm_seller_notes-wrap.error-field .wp-editor-container {
    border: none !important;
}

/* Form error message container */
.form-error-message {
    margin-bottom: 20px;
    padding: 15px;
    border-radius: 4px;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
}


.form-error-message .alert {
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    color: #721c24;
}

.form-error-message .alert ul {
    margin: 0;
    padding-left: 20px;
}

.form-error-message .alert li {
    margin-bottom: 5px;
    font-weight: 500;
}

/* Success states (when validation passes) */
.success-field {
    border: 2px solid #28a745 !important;
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25) !important;
    background-color: #f8fff8 !important;
}

/* Hover states for better UX */
.error-field:hover {
    border-color: #c82333 !important;
}

.error-field:focus {
    border-color: #c82333 !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.35) !important;
}

/* Animation for error appearance */
.error-field {
    animation: errorPulse 0.3s ease-in-out;
}

@keyframes errorPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
    }
}

/* Error message fade in */
.error-message {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .error-message {
        font-size: 11px;
        margin-top: 3px;
    }
    
    .form-error-message {
        padding: 10px;
        margin-bottom: 15px;
    }
    
    .error-field {
        border-width: 1px !important;
    }
}

/* Specific styling for different field types */
input[type="text"].error-field,
input[type="email"].error-field,
input[type="number"].error-field,
input[type="tel"].error-field,
textarea.error-field {
    border: 2px solid #dc3545 !important;
    background-color: #fff5f5 !important;
}

/* Price field specific styling */
input[name="stm_car_price"].error-field {
    border: 2px solid #dc3545 !important;
    background-color: #fff5f5 !important;
}

/* Required field indicator */
.stm-form-1-quarter label[data-required="true"]:after,
.stm-form1-intro-unit label[data-required="true"]:after {
    content: " *";
    color: #dc3545;
    font-weight: bold;
}

/* Loading state styles */
.validating {
    position: relative;
}

.validating:after {
    content: "";
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007cba;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: translateY(-50%) rotate(0deg); }
    100% { transform: translateY(-50%) rotate(360deg); }
}

/* Improved contrast for accessibility */
.error-field:focus {
    outline: 2px solid #dc3545 !important;
    outline-offset: 2px !important;
}

/* Fix for Motors theme specific elements */
.stm-form-checking-user .error-field {
    border-color: #dc3545 !important;
}

.stm-form-1-quarter .error-field,
.stm-form1-intro-unit .error-field {
    border-color: #2980B9 !important;
}

/* Ensure error styles override theme styles */
.stm_add_car_form .error-field,
#stm_sell_a_car_form .error-field {
    border: 2px solid #2980B9 !important;
}

/* High specificity for important error indicators */
body .stm_add_car_form .error-field,
body #stm_sell_a_car_form .error-field {
    border-color: #2980B9 !important;
    box-shadow: none !important;
    background-color: #fff !important;
}

/* Ensure containers have relative positioning for absolute error messages */
.stm-form-1-quarter,
.stm-form1-intro-unit,
.stm-form-1-end-unit {
    position: relative;
    margin-bottom: 20px !important;
}

/* Save Draft Button Styling - Grey and Less Prominent */
.btn-save-ad button.save-draft-btn,
.btn-save-ad button {
    background-color: #6c757d !important;
    border-color: #6c757d !important;
    color: white !important;
    opacity: 0.8 !important;
}

.btn-save-ad button.save-draft-btn:hover,
.btn-save-ad button:hover {
    background-color: #5a6268 !important;
    border-color: #545b62 !important;
    opacity: 0.9 !important;
}

.btn-save-ad button:disabled,
.btn-save-ad button.disabled {
    background-color: #6c757d !important;
    border-color: #6c757d !important;
    opacity: 0.3 !important;
    cursor: not-allowed !important;
}

.btn-save-ad button:disabled:hover,
.btn-save-ad button.disabled:hover {
    background-color: #6c757d !important;
    border-color: #6c757d !important;
    opacity: 0.3 !important;
    transform: none !important;
}

/* Proceed button styling - keep original look but maybe slightly different */
.btn-ppl button {
    background-color: #007cba !important;
    border-color: #007cba !important;
    color: white !important;
}

.btn-ppl button:hover {
    background-color: #005a87 !important;
    border-color: #004085 !important;
}

/* Button spacing when both are present */
.add-car-btns-wrap .btn-save-ad {
    margin-right: 10px;
}

/* Responsive button layout */
@media (max-width: 768px) {
    .add-car-btns-wrap .btn-save-ad,
    .add-car-btns-wrap .btn-ppl {
        margin-bottom: 10px;
        margin-right: 0;
    }
    
    .add-car-btns-wrap {
        flex-direction: column;
    }
}

/* High specificity Select2 error styles */
body .select2-container.error-field .select2-selection,
body .select2-container.error-field .select2-selection--single,
body .select2-container.error-field .select2-selection--multiple,
body span.select2-container.error-field .select2-selection,
body span.select2-container.error-field span.select2-selection,
.stm_add_car_form .select2-container.error-field .select2-selection,
.stm_add_car_form .select2-container.error-field .select2-selection--single,
#stm_sell_a_car_form .select2-container.error-field .select2-selection,
#stm_sell_a_car_form .select2-container.error-field .select2-selection--single {
    border: 2px solid #dc3545 !important;
    background-color: #fff5f5 !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
}

/* Override any theme-specific Select2 styling */
.select2-container--default.error-field .select2-selection--single,
.select2-container--default.error-field .select2-selection--multiple {
    border: 2px solid #dc3545 !important;
    background-color: #fff5f5 !important;
}

/* Ensure error messages are visible and positioned correctly */
.select2-container + .error-message,
.select2-container.error-field + .error-message {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    margin-top: 5px !important;
    color: #dc3545 !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    clear: both;
}

/* Make sure Select2 dropdown positioning doesn't interfere with error messages */
.select2-container.error-field {
    z-index: auto !important;
}

.select2-container.error-field + .error-message {
    z-index: 1 !important;
    position: relative !important;
}

/* ===================================
   Admin Customer Creation Section
   =================================== */

.admin-customer-creation {
    background: #f8f9fa;
    border: 2px solid #007cba;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.admin-customer-toggle {
    margin-bottom: 15px;
}

.admin-toggle-label {
    display: flex;
    align-items: center;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    user-select: none;
}

.admin-toggle-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 10px;
    cursor: pointer;
}

.admin-toggle-label .toggle-text {
    color: #007cba;
}

.admin-customer-fields {
    background: white;
    padding: 20px;
    border-radius: 6px;
    border: 1px solid #ddd;
    margin-top: 15px;
}

.customer-section-header h4 {
    margin: 0 0 5px 0;
    color: #333;
    font-size: 18px;
}

.customer-section-description {
    margin: 0 0 20px 0;
    color: #666;
    font-size: 14px;
}

/* Email Field with Lookup Loader */
.customer-email-group {
    position: relative;
    margin-bottom: 20px;
}

.customer-email-group .email-lookup-loader {
    position: absolute;
    right: 10px;
    top: 38px;
    color: #007cba;
}

.customer-email-group .email-lookup-loader i {
    font-size: 16px;
    animation: spin 1s linear infinite;
}

.customer-email-validation {
    font-size: 12px;
    margin-top: 5px;
    min-height: 18px;
}

.customer-email-validation.success {
    color: #28a745;
}

.customer-email-validation.error {
    color: #dc3545;
}

/* Existing Customer Selection Box */
.existing-customer-box {
    background: #e8f4fd;
    border: 2px solid #007cba;
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 20px;
}

.existing-customer-info {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.existing-customer-info i {
    font-size: 32px;
    color: #007cba;
    margin-right: 15px;
}

.existing-customer-info .customer-details {
    display: flex;
    flex-direction: column;
}

.existing-customer-info .customer-name {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 3px;
}

.existing-customer-info .customer-meta {
    font-size: 13px;
    color: #666;
}

.existing-customer-box .button {
    margin-right: 10px;
    padding: 8px 16px;
    font-size: 14px;
}

.existing-customer-box .use-existing-customer {
    background-color: #28a745;
    border-color: #28a745;
    color: white;
}

.existing-customer-box .use-existing-customer:hover {
    background-color: #218838;
    border-color: #1e7e34;
}

.existing-customer-box .create-new-anyway {
    background-color: #6c757d;
    border-color: #6c757d;
    color: white;
}

.existing-customer-box .create-new-anyway:hover {
    background-color: #5a6268;
    border-color: #545b62;
}

/* New Customer Fields */
.new-customer-fields .form-group {
    margin-bottom: 20px;
}

.new-customer-fields .form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    color: #333;
    font-size: 14px;
}

.new-customer-fields .form-group label .required {
    color: #dc3545;
}

.new-customer-fields .form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.new-customer-fields .form-group input:focus {
    outline: none;
    border-color: #007cba;
    box-shadow: 0 0 0 0.2rem rgba(0, 124, 186, 0.25);
}

.new-customer-fields .form-group .field-hint {
    display: block;
    font-size: 12px;
    color: #666;
    margin-top: 5px;
    font-style: italic;
}

/* Form Row (for side-by-side fields) */
.new-customer-fields .form-row {
    display: flex;
    gap: 15px;
    margin-bottom: 0;
}

.new-customer-fields .form-row .form-group {
    flex: 1;
}

.new-customer-fields .form-row .half-width {
    width: 50%;
}

/* Username Validation Message */
.username-validation {
    font-size: 12px;
    margin-top: 5px;
    min-height: 18px;
}

.username-validation.success {
    color: #28a745;
}

.username-validation.error {
    color: #dc3545;
}

/* Password Notice */
.customer-password-notice {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 4px;
    padding: 12px;
    display: flex;
    align-items: flex-start;
    margin-top: 15px;
}

.customer-password-notice i {
    color: #856404;
    font-size: 18px;
    margin-right: 10px;
    margin-top: 2px;
}

.customer-password-notice span {
    color: #856404;
    font-size: 13px;
    line-height: 1.4;
}

/* Customer Field Error States */
.customer-field.error-field {
    border: 2px solid #dc3545 !important;
    background-color: #fff5f5 !important;
}

.customer-field.success-field {
    border: 2px solid #28a745 !important;
    background-color: #f8fff8 !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .admin-customer-creation {
        padding: 15px;
    }

    .admin-customer-fields {
        padding: 15px;
    }

    .new-customer-fields .form-row {
        flex-direction: column;
        gap: 0;
    }

    .new-customer-fields .form-row .half-width {
        width: 100%;
    }

    .existing-customer-box .button {
        display: block;
        width: 100%;
        margin-right: 0;
        margin-bottom: 10px;
    }

    .existing-customer-info {
        flex-direction: column;
        align-items: flex-start;
    }

    .existing-customer-info i {
        margin-bottom: 10px;
    }
}

/* Animation for field reveal */
@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        max-height: 1000px;
        transform: translateY(0);
    }
}

.admin-customer-fields {
    animation: slideDown 0.3s ease-out;
}

/* ===================================
   Customer Credentials Modal
   =================================== */

.customer-credentials-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.customer-credentials-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(3px);
}

.customer-credentials-content {
    position: relative;
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    z-index: 1;
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.credentials-header {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    padding: 20px;
    border-radius: 8px 8px 0 0;
    text-align: center;
}

.credentials-header i {
    font-size: 48px;
    margin-bottom: 10px;
}

.credentials-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.credentials-body {
    padding: 30px;
}

.credentials-body > p {
    margin: 0 0 20px 0;
    font-size: 15px;
    color: #666;
}

.credential-row {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 15px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.credential-row strong {
    min-width: 90px;
    color: #333;
    font-size: 14px;
}

.credential-value {
    flex: 1;
    font-family: 'Courier New', monospace;
    background: white;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 14px;
    color: #495057;
    word-break: break-all;
}

.copy-btn {
    background: #007cba;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    white-space: nowrap;
}

.copy-btn:hover {
    background: #005a87;
}

.copy-btn.copied {
    background: #28a745;
}

.credential-warning {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 4px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
}

.credential-warning i {
    color: #856404;
    font-size: 20px;
}

.credential-warning {
    color: #856404;
    font-size: 13px;
    line-height: 1.4;
}

.credentials-footer {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 0 0 8px 8px;
    text-align: center;
}

.close-credentials-modal {
    background: #007cba;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: background 0.2s;
}

.close-credentials-modal:hover {
    background: #005a87;
}

/* Responsive modal */
@media (max-width: 768px) {
    .customer-credentials-content {
        width: 95%;
        max-width: none;
    }

    .credentials-body {
        padding: 20px;
    }

    .credential-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .credential-row strong {
        min-width: auto;
    }

    .copy-btn {
        width: 100%;
    }
}