/**
 * EMCF Frontend Form Styles
 *
 * @package EM_Contact_Form
 * @since 2.0.0
 * @updated 2.3.0 - Enhanced styling with CSS variables
 */

/* ============================================
   CSS Variables (defaults, overridden by plugin)
   ============================================ */
:root {
    --emcf-primary-color: #2563EB;
    --emcf-accent-color: #1e293b;
    --emcf-button-color: #2563EB;
    --emcf-button-text-color: #ffffff;
    --emcf-label-color: #374151;
    --emcf-heading-color: #1e293b;
    --emcf-input-border: #d1d5db;
    --emcf-input-focus: #2563EB;
    --emcf-error-color: #dc2626;
    --emcf-success-color: #16a34a;
    --emcf-border-radius: 8px;
    --emcf-form-padding-top: 40px;
    --emcf-form-padding-bottom: 40px;
}

/* ============================================
   Base Form Styles
   ============================================ */
.emcf-form {
    max-width: 700px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.emcf-form label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 14px;
    color: var(--emcf-label-color);
}

.emcf-form input[type="text"],
.emcf-form input[type="email"],
.emcf-form input[type="tel"],
.emcf-form input[type="url"],
.emcf-form input[type="number"],
.emcf-form input[type="date"],
.emcf-form input[type="phone"],
.emcf-form select,
.emcf-form textarea {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--emcf-input-border);
    border-radius: var(--emcf-border-radius);
    font-size: 16px;
    color: #1f2937;
    background-color: #fff;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.emcf-form input::placeholder,
.emcf-form textarea::placeholder {
    color: #9ca3af;
}

.emcf-form textarea {
    min-height: 120px;
    resize: vertical;
}

.emcf-form .required,
.emcf-form .emcf-required {
    color: var(--emcf-error-color);
    margin-left: 2px;
}

.emcf-form .form-row {
    display: flex;
    gap: 20px;
}

.emcf-form .form-row > div {
    flex: 1;
}

.emcf-form .form-section {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
}

.emcf-form .form-section h3 {
    margin-top: 0;
}

/* ============================================
   Legacy Conditional Sections
   ============================================ */
.emcf-form .conditional-section {
    display: none;
}

.emcf-form .conditional-section.active {
    display: block;
}

/* ============================================
   Checkbox and Radio Groups
   ============================================ */
.emcf-form .checkbox-group,
.emcf-form .radio-group,
.emcf-form fieldset {
    margin-bottom: 20px;
    border: none;
    padding: 0;
}

.emcf-form .checkbox-group legend,
.emcf-form .radio-group legend,
.emcf-form fieldset legend {
    margin-bottom: 12px;
    padding: 0;
    font-weight: 600;
    font-size: 14px;
    color: var(--emcf-label-color);
}

.emcf-form .checkbox-group label,
.emcf-form .radio-group label {
    display: flex;
    align-items: center;
    font-weight: normal;
    margin-bottom: 10px;
    cursor: pointer;
    font-size: 15px;
    color: var(--emcf-label-color);
}

.emcf-form .checkbox-group input[type="checkbox"],
.emcf-form .radio-group input[type="radio"],
.emcf-form input[type="checkbox"],
.emcf-form input[type="radio"] {
    width: 18px;
    height: 18px;
    margin-right: 10px;
    accent-color: var(--emcf-primary-color);
    cursor: pointer;
}

/* Radio button grid layout (2 columns like getmortgagehelp.ca) */
.emcf-form .radio-group.emcf-radio-grid,
.emcf-form fieldset.emcf-radio-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.emcf-form .emcf-radio-grid label {
    background: #fff;
    border: 1px solid var(--emcf-input-border);
    border-radius: var(--emcf-border-radius);
    padding: 12px 15px;
    margin-bottom: 0;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.emcf-form .emcf-radio-grid label:hover {
    border-color: var(--emcf-primary-color);
    background-color: #f8fafc;
}

.emcf-form .emcf-radio-grid input:checked + span,
.emcf-form .emcf-radio-grid label:has(input:checked) {
    border-color: var(--emcf-primary-color);
    background-color: #eff6ff;
}

/* ============================================
   Help Text
   ============================================ */
.emcf-form .help-text {
    font-size: 13px;
    color: #6b7280;
    margin-top: 6px;
    margin-bottom: 15px;
}

/* ============================================
   Submit Button (Legacy)
   ============================================ */
.emcf-form button[type="submit"] {
    background: var(--emcf-button-color);
    color: var(--emcf-button-text-color);
    border: none;
    padding: 14px 40px;
    font-size: 16px;
    font-weight: 600;
    border-radius: var(--emcf-border-radius);
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    width: 100%;
}

.emcf-form button[type="submit"]:hover {
    filter: brightness(0.9);
    transform: translateY(-1px);
}

.emcf-form button[type="submit"]:focus {
    outline: 2px solid var(--emcf-button-color);
    outline-offset: 2px;
}

.emcf-form button[type="submit"]:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

/* ============================================
   Messages
   ============================================ */
.emcf-form .emcf-message,
.emcf-message {
    padding: 15px 20px;
    border-radius: var(--emcf-border-radius);
    margin-bottom: 20px;
    font-size: 15px;
}

.emcf-form .emcf-message.success,
.emcf-message.success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.emcf-form .emcf-message.error,
.emcf-message.error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* ============================================
   Honeypot Field (Hidden)
   ============================================ */
.emcf-form .emcf-hp {
    position: absolute;
    left: -9999px;
    top: -9999px;
    opacity: 0;
    height: 0;
    width: 0;
    overflow: hidden;
}

/* ============================================
   Turnstile
   ============================================ */
.emcf-form .cf-turnstile {
    margin-bottom: 20px;
}

/* ============================================
   Accessibility - Focus States
   ============================================ */
.emcf-form input:focus,
.emcf-form select:focus,
.emcf-form textarea:focus {
    outline: none;
    border-color: var(--emcf-input-focus);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ============================================
   Dynamic Form Styles (v2.0)
   ============================================ */

/* Form wrapper - Page Builder Compatible */
.emcf-form-wrapper {
    max-width: 700px;
    margin: 0 auto;
    padding: 20px;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
}

/* Elementor compatibility */
.elementor-widget-shortcode .emcf-form-wrapper,
.elementor-shortcode .emcf-form-wrapper {
    padding-top: 0;
    padding-bottom: 20px;
}

/* When form is the first element after header */
.elementor-section:first-child .emcf-form-wrapper,
.elementor-container:first-child .emcf-form-wrapper,
.e-con:first-child .emcf-form-wrapper {
    padding-top: 60px;
}

/* WPBakery / Visual Composer compatibility */
.wpb_content_element .emcf-form-wrapper,
.vc_column_container .emcf-form-wrapper {
    padding-top: 40px;
    padding-bottom: 40px;
}

/* Divi compatibility */
.et_pb_module .emcf-form-wrapper {
    padding-top: 40px;
    padding-bottom: 40px;
}

/* Beaver Builder compatibility */
.fl-module .emcf-form-wrapper {
    padding-top: 40px;
    padding-bottom: 40px;
}

/* Gutenberg block compatibility */
.wp-block-shortcode .emcf-form-wrapper,
.wp-block-html .emcf-form-wrapper {
    padding-top: 40px;
    padding-bottom: 40px;
}

/* Form title and description */
.emcf-form-title {
    margin: 0 0 10px 0;
    font-size: 28px;
    font-weight: 700;
    color: var(--emcf-heading-color);
}

.emcf-form-description {
    margin: 0 0 15px 0;
    color: #6b7280;
    font-size: 16px;
    line-height: 1.6;
}

/* Fields container */
.emcf-fields-container {
    margin-bottom: 20px;
}

/* Field wrapper */
.emcf-field-wrapper {
    margin-bottom: 20px;
}

/* Field spacing fix - remove double margin */
.emcf-field-wrapper input,
.emcf-field-wrapper select,
.emcf-field-wrapper textarea {
    margin-bottom: 0;
}

/* Width classes */
.emcf-field-width-100 {
    width: 100%;
}

.emcf-field-width-50 {
    flex: 0 0 calc(50% - 10px);
}

.emcf-field-width-33 {
    flex: 0 0 calc(33.333% - 14px);
}

.emcf-field-width-66 {
    flex: 0 0 calc(66.666% - 7px);
}

/* Flex row for side-by-side fields */
.emcf-fields-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

/* Conditional hidden fields */
.emcf-conditional-hidden,
.emcf-form [data-conditional]:not(.emcf-show) {
    display: none !important;
}

.emcf-form [data-conditional].emcf-show {
    display: block !important;
}

/* Section heading - OVERRIDE THEME STYLES */
.emcf-form h3.emcf-section-heading,
.emcf-form .emcf-section-heading,
.emcf-form-wrapper h3.emcf-section-heading,
.emcf-form-wrapper .emcf-section-heading,
h3.emcf-section-heading,
.emcf-section-heading,
.emcf-field-heading,
.emcf-field-heading label,
.emcf-form .emcf-field-wrapper[data-type="heading"] label,
.emcf-form .emcf-field-wrapper.emcf-field-heading h3,
.emcf-form-wrapper .emcf-field-wrapper.emcf-field-heading h3 {
    margin: 30px 0 15px 0 !important;
    padding-bottom: 0 !important;
    border-bottom: none !important;
    font-size: 20px !important;
    font-weight: 700 !important;
    color: #1e293b !important;
    color: var(--emcf-heading-color) !important;
    opacity: 1 !important;
    background: transparent !important;
}

.emcf-field-wrapper:first-child .emcf-section-heading,
.emcf-field-wrapper:first-child .emcf-field-heading,
.emcf-field-wrapper:first-child[data-type="heading"] label,
.emcf-field-wrapper:first-child h3.emcf-section-heading {
    margin-top: 0 !important;
}

/* HTML content field */
.emcf-field-html {
    margin-bottom: 20px;
}

.emcf-field-html p {
    margin: 0 0 10px 0;
}

/* Submit section */
.emcf-submit-section {
    margin-top: 30px;
    padding-top: 25px;
    border-top: 1px solid #e5e7eb;
}

/* Submit button (dynamic forms) */
.emcf-submit-btn {
    background: var(--emcf-button-color);
    color: var(--emcf-button-text-color);
    border: none;
    padding: 14px 40px;
    font-size: 16px;
    font-weight: 600;
    border-radius: var(--emcf-border-radius);
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    width: 100%;
}

.emcf-submit-btn:hover {
    filter: brightness(0.9);
    transform: translateY(-1px);
}

.emcf-submit-btn:focus {
    outline: 2px solid var(--emcf-button-color);
    outline-offset: 2px;
}

.emcf-submit-btn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

/* Error state for form fields */
.emcf-form .emcf-field-error input,
.emcf-form .emcf-field-error select,
.emcf-form .emcf-field-error textarea {
    border-color: #dc3545;
}

.emcf-form .emcf-error-message {
    color: #dc3545;
    font-size: 13px;
    margin-top: -10px;
    margin-bottom: 15px;
}

/* Form error at top */
.emcf-form-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 20px;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 600px) {
    .emcf-form .form-row {
        flex-direction: column;
        gap: 0;
    }
    
    .emcf-form button[type="submit"],
    .emcf-submit-btn {
        width: 100%;
    }
    
    .emcf-field-width-50,
    .emcf-field-width-33,
    .emcf-field-width-66 {
        flex: 0 0 100% !important;
    }
}

/* ============================================
   Loading States & Spinners
   ============================================ */

/* Loading button state */
.emcf-form button.emcf-loading,
.emcf-submit-btn.emcf-loading {
    background: var(--emcf-button-color);
    opacity: 0.85;
    cursor: wait;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* Inline spinner for button */
.emcf-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: emcf-spin 0.8s linear infinite;
}

/* Form loading overlay */
.emcf-form-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    border-radius: var(--emcf-border-radius);
    backdrop-filter: blur(2px);
}

.emcf-loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 30px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.emcf-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e5e7eb;
    border-radius: 50%;
    border-top-color: var(--emcf-primary-color);
    animation: emcf-spin 0.8s linear infinite;
}

.emcf-loading-indicator span {
    font-size: 14px;
    color: #6b7280;
    font-weight: 500;
}

/* Spin animation */
@keyframes emcf-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Success flash animation */
.emcf-success-flash {
    animation: emcf-success-pulse 0.5s ease-out;
}

@keyframes emcf-success-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.4);
    }
    50% {
        box-shadow: 0 0 0 15px rgba(22, 163, 74, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(22, 163, 74, 0);
    }
}

/* Pulse animation for loading button */
.emcf-loading {
    animation: emcf-button-pulse 1.5s ease-in-out infinite;
}

@keyframes emcf-button-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.75;
    }
}
