/* ============================================================================
 * Smart Form Modal - Perfex CRM Plugin
 * Universal dynamic form modal with theme integration
 * ============================================================================ */

/* CSS Variables - Inherit from theme */
:root {
    --smart-form-primary: var(--color-primary-normal-bg, #2b65e8);
    --smart-form-primary-hover: var(--color-primary-hover-bg, #497beb);
    --smart-form-secondary: var(--color-secondary-normal-bg, #1e293b);
    --smart-form-accent: var(--color-accent-normal-bg, #10B981);
    --smart-form-success: var(--success, #10B981);
    --smart-form-gray-50: var(--gray-50, #F8FAFC);
    --smart-form-gray-100: var(--gray-100, #F1F5F9);
    --smart-form-gray-200: var(--gray-200, #E2E8F0);
    --smart-form-gray-300: var(--gray-300, #CBD5E1);
    --smart-form-gray-600: var(--gray-600, #475569);
    --smart-form-gray-900: var(--gray-900, #0F172A);
    --smart-form-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --smart-form-radius: 16px;
}

/* ============================================================================
 * Modal Overlay
 * ============================================================================ */

.smart-form-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 99998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.smart-form-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ============================================================================
 * Modal Container
 * ============================================================================ */

.smart-form-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.smart-form-modal.active {
    opacity: 1;
    visibility: visible;
}

.smart-form-modal.active .smart-form-card {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* ============================================================================
 * Modal Card
 * ============================================================================ */

.smart-form-card {
    background: #ffffff;
    border-radius: var(--smart-form-radius);
    box-shadow: var(--smart-form-shadow);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateY(30px) scale(0.95);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    position: relative;
}

/* ============================================================================
 * Close Button
 * ============================================================================ */

.smart-form-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 36px;
    height: 36px;
    border: none;
    background: var(--smart-form-gray-100);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
}

.smart-form-close:hover {
    background: var(--smart-form-gray-200);
    transform: rotate(90deg);
}

.smart-form-close svg {
    width: 18px;
    height: 18px;
    stroke: var(--smart-form-gray-600);
    stroke-width: 2;
}

/* ============================================================================
 * Header Section
 * ============================================================================ */

.smart-form-header {
    padding: 1.5rem 2rem 1.25rem;
    text-align: center;
    background: #ffffff;
    border-bottom: 1px solid var(--smart-form-gray-100);
}

/* Mini Logo */
.smart-form-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}

.smart-form-logo img {
    height: 32px;
    width: auto;
    object-fit: contain;
}

/* Title Row with Icon */
.smart-form-title-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    margin-bottom: 0.375rem;
}

.smart-form-icon {
    width: 32px;
    height: 32px;
    background: color-mix(in srgb, var(--smart-form-primary) 10%, transparent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.smart-form-icon svg {
    width: 18px;
    height: 18px;
    stroke: var(--smart-form-primary);
    stroke-width: 2;
}

.smart-form-title {
    font-size: 1.375rem;
    font-weight: 800;
    color: var(--smart-form-secondary);
    margin: 0;
    line-height: 1.3;
    letter-spacing: -0.02em;
}

.smart-form-subtitle {
    font-size: 0.9rem;
    color: var(--smart-form-gray-600);
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
}

.smart-form-subtitle svg {
    width: 15px;
    height: 15px;
    stroke: var(--smart-form-accent);
}

/* ============================================================================
 * Form Body
 * ============================================================================ */

.smart-form-body {
    padding: 1.5rem 2rem;
    overflow-y: auto;
    flex: 1;
}

.smart-form-fields {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* ============================================================================
 * Form Fields
 * ============================================================================ */

.smart-form-field {
    position: relative;
}

.smart-form-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--smart-form-gray-900);
    margin-bottom: 0.5rem;
}

.smart-form-label svg {
    width: 16px;
    height: 16px;
    stroke: var(--smart-form-primary);
    flex-shrink: 0;
}

.smart-form-label .required {
    color: var(--smart-form-primary);
    font-size: 0.75rem;
}

.smart-form-input,
.smart-form-select,
.smart-form-textarea {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--smart-form-gray-900);
    background: var(--smart-form-gray-50);
    border: 2px solid var(--smart-form-gray-200);
    border-radius: 10px;
    transition: all 0.2s ease;
    outline: none;
}

.smart-form-input:focus,
.smart-form-select:focus,
.smart-form-textarea:focus {
    background: #ffffff;
    border-color: var(--smart-form-primary);
    box-shadow: 0 0 0 4px rgba(43, 101, 232, 0.1);
}

.smart-form-input::placeholder,
.smart-form-textarea::placeholder {
    color: var(--smart-form-gray-300);
}

.smart-form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

.smart-form-textarea {
    min-height: 100px;
    resize: vertical;
}

/* Date input styling */
.smart-form-input[type="date"] {
    cursor: pointer;
}

.smart-form-input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.smart-form-input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

/* Phone input with flag placeholder */
.smart-form-input[type="tel"] {
    padding-left: 1rem;
}

/* ============================================================================
 * Honeypot Field (Hidden)
 * ============================================================================ */

.smart-form-honeypot {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    tab-index: -1;
}

/* ============================================================================
 * Submit Button - Flat Branded Design
 * ============================================================================ */

.smart-form-submit {
    width: 100%;
    padding: 1rem 1.5rem;
    background: var(--smart-form-primary);
    color: #ffffff;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    transition: all 0.2s ease;
    margin-top: 0.5rem;
    position: relative;
    overflow: hidden;
}

.smart-form-submit:hover {
    background: var(--smart-form-primary-hover);
    transform: translateY(-1px);
}

.smart-form-submit:active {
    transform: translateY(0);
    background: var(--smart-form-primary);
}

.smart-form-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.smart-form-submit-text {
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.smart-form-submit-subtext {
    font-size: 0.75rem;
    opacity: 0.9;
    font-weight: 500;
}

/* Loading state */
.smart-form-submit.loading .smart-form-submit-content {
    opacity: 0;
}

.smart-form-submit.loading .smart-form-spinner {
    opacity: 1;
}

.smart-form-submit-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    transition: opacity 0.2s ease;
}

.smart-form-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.smart-form-spinner svg {
    width: 24px;
    height: 24px;
    animation: smartFormSpin 1s linear infinite;
}

@keyframes smartFormSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ============================================================================
 * Countdown Timer
 * ============================================================================ */

.smart-form-timer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    margin-top: 0.75rem;
    padding: 0.5rem 0.875rem;
    background: color-mix(in srgb, var(--smart-form-primary) 8%, white);
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--smart-form-primary);
    font-weight: 600;
}

.smart-form-timer svg {
    width: 14px;
    height: 14px;
    stroke: var(--smart-form-primary);
    animation: timerPulse 1s ease-in-out infinite;
}

@keyframes timerPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.smart-form-timer-text {
    font-variant-numeric: tabular-nums;
}

/* Timer urgency states */
.smart-form-timer.urgent {
    background: #FEF3C7;
    color: #D97706;
}

.smart-form-timer.urgent svg {
    stroke: #D97706;
}

.smart-form-timer.critical {
    background: #FEE2E2;
    color: #DC2626;
    animation: timerShake 0.5s ease-in-out;
}

.smart-form-timer.critical svg {
    stroke: #DC2626;
}

@keyframes timerShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

/* ============================================================================
 * Marketing Message - Conversion Optimized
 * ============================================================================ */

.smart-form-marketing {
    text-align: center;
    margin-top: 0.875rem;
    padding: 0.75rem;
    background: var(--smart-form-gray-50);
    border-radius: 8px;
    border: 1px solid var(--smart-form-gray-100);
}

.smart-form-marketing-text {
    font-size: 0.8rem;
    color: var(--smart-form-gray-600);
    margin: 0;
    line-height: 1.5;
}

.smart-form-marketing-text strong {
    color: var(--smart-form-secondary);
    font-weight: 600;
}

.smart-form-marketing-highlight {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--smart-form-accent);
    font-weight: 600;
}

.smart-form-marketing-highlight svg {
    width: 14px;
    height: 14px;
    stroke: var(--smart-form-accent);
}

/* ============================================================================
 * Trust Badges
 * ============================================================================ */

.smart-form-trust {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.smart-form-trust-badge {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: var(--smart-form-gray-600);
    font-weight: 600;
}

.smart-form-trust-badge svg {
    width: 14px;
    height: 14px;
    stroke: var(--smart-form-accent);
}

/* ============================================================================
 * Success State
 * ============================================================================ */

.smart-form-success {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 2rem;
    min-height: 300px;
}

.smart-form-success.active {
    display: flex;
}

.smart-form-success-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--smart-form-success) 0%, #059669 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
    animation: smartFormSuccessPop 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes smartFormSuccessPop {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.smart-form-success-icon svg {
    width: 40px;
    height: 40px;
    stroke: #ffffff;
    stroke-width: 3;
    animation: smartFormCheckDraw 0.4s ease-out 0.3s both;
}

@keyframes smartFormCheckDraw {
    0% { stroke-dasharray: 50; stroke-dashoffset: 50; }
    100% { stroke-dashoffset: 0; }
}

.smart-form-success-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--smart-form-secondary);
    margin: 0 0 0.5rem;
}

.smart-form-success-text {
    font-size: 1rem;
    color: var(--smart-form-gray-600);
    margin: 0;
    max-width: 280px;
}

/* Success Action Button */
.smart-form-success-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1.25rem;
    padding: 0.75rem 1.5rem;
    background: var(--smart-form-primary);
    color: #ffffff;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.smart-form-success-action:hover {
    background: var(--smart-form-primary-hover);
    transform: translateY(-1px);
}

/* Success Extras - Quick Contact */
.smart-form-success-extras {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--smart-form-gray-100);
    width: 100%;
}

.smart-form-success-extras-label {
    font-size: 0.8rem;
    color: var(--smart-form-gray-600);
    margin: 0 0 0.75rem;
}

.smart-form-success-contacts {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
}

.smart-form-success-contact {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.875rem;
    background: var(--smart-form-gray-50);
    border: 1px solid var(--smart-form-gray-200);
    border-radius: 6px;
    color: var(--smart-form-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.smart-form-success-contact:hover {
    background: var(--smart-form-primary);
    border-color: var(--smart-form-primary);
    color: #ffffff;
}

.smart-form-success-contact svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
}

/* ============================================================================
 * Error State
 * ============================================================================ */

.smart-form-error {
    background: #FEF2F2;
    border: 1px solid #FECACA;
    border-radius: 8px;
    padding: 0.875rem 1rem;
    margin-bottom: 1rem;
    display: none;
}

.smart-form-error.active {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.smart-form-error svg {
    width: 20px;
    height: 20px;
    stroke: #DC2626;
    flex-shrink: 0;
    margin-top: 0.125rem;
}

.smart-form-error-text {
    font-size: 0.875rem;
    color: #991B1B;
    margin: 0;
}

/* Field validation error */
.smart-form-field.has-error .smart-form-input,
.smart-form-field.has-error .smart-form-select,
.smart-form-field.has-error .smart-form-textarea {
    border-color: #DC2626;
    background: #FEF2F2;
}

.smart-form-field-error {
    font-size: 0.75rem;
    color: #DC2626;
    margin-top: 0.375rem;
    display: none;
}

.smart-form-field.has-error .smart-form-field-error {
    display: block;
}

/* ============================================================================
 * Footer
 * ============================================================================ */

.smart-form-footer {
    padding: 1rem 2rem 1.5rem;
    background: var(--smart-form-gray-50);
    border-top: 1px solid var(--smart-form-gray-100);
}

.smart-form-footer-text {
    font-size: 0.75rem;
    color: var(--smart-form-gray-600);
    text-align: center;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
}

.smart-form-footer-text svg {
    width: 14px;
    height: 14px;
    stroke: var(--smart-form-accent);
}

/* ============================================================================
 * Responsive - Mobile Optimizations
 * ============================================================================ */

@media (max-width: 480px) {
    .smart-form-modal {
        padding: 0;
        align-items: flex-end;
    }

    .smart-form-card {
        max-width: 100%;
        max-height: 95vh;
        border-radius: var(--smart-form-radius) var(--smart-form-radius) 0 0;
        transform: translateY(100%);
    }

    .smart-form-modal.active .smart-form-card {
        transform: translateY(0);
    }

    .smart-form-header {
        padding: 1.5rem 1.5rem 1rem;
    }

    .smart-form-body {
        padding: 1rem 1.5rem;
    }

    .smart-form-footer {
        padding: 1rem 1.5rem 1.5rem;
        /* Account for safe area on iOS */
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0));
    }

    .smart-form-title {
        font-size: 1.25rem;
    }

    .smart-form-icon {
        width: 48px;
        height: 48px;
    }

    .smart-form-icon svg {
        width: 24px;
        height: 24px;
    }

    /* Drag handle for mobile */
    .smart-form-card::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: var(--smart-form-gray-300);
        border-radius: 2px;
    }
}

/* ============================================================================
 * Accessibility
 * ============================================================================ */

.smart-form-modal:focus {
    outline: none;
}

.smart-form-input:focus-visible,
.smart-form-select:focus-visible,
.smart-form-textarea:focus-visible,
.smart-form-submit:focus-visible,
.smart-form-close:focus-visible {
    outline: 2px solid var(--smart-form-primary);
    outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .smart-form-overlay,
    .smart-form-modal,
    .smart-form-card,
    .smart-form-submit,
    .smart-form-success-icon,
    .smart-form-success-icon svg,
    .smart-form-spinner svg {
        animation: none;
        transition: none;
    }
}

/* ============================================================================
 * Dark Mode Support (if theme uses it)
 * ============================================================================ */

@media (prefers-color-scheme: dark) {
    .smart-form-card {
        /* Keep light theme for modal - uncomment below to enable dark mode */
        /* background: #1e293b;
        color: #f1f5f9; */
    }
}

/* ============================================================================
 * Print Styles
 * ============================================================================ */

@media print {
    .smart-form-overlay,
    .smart-form-modal {
        display: none !important;
    }
}

