/* ==========================================================================
   UPFRONT LEAD CAPTURE — onboarding step for the chat experience
   --------------------------------------------------------------------------
   Loaded after style.css (depends on 'pcai-style'), so these rules are
   authoritative for the form. Everything pulls from the operator's brand
   tokens injected on :root by the inline theme <style id="pcai-theme-css">:
     --pcai-primary / --pcai-secondary  (brand gradient)
     --pcai-text                        (on-brand text)
   Fallbacks keep it sane if the theme block is ever absent.

   Goal: the "Start Chatting" screen reads as a polished onboarding step
   INSIDE the chat — one clean panel on the conversation canvas, not a
   nested card-in-a-bubble, and fully brand-coloured.
   ========================================================================== */

/* --- De-nest: the bot bubble that wraps the form becomes a full-width panel
   sitting directly on the conversation canvas (no bubble chrome). The extra
   descendant class beats the themed bot-bubble background + the mobile
   full-screen .pcai-message rules. --------------------------------------- */
.pcai-messages .pcai-message.pcai-upfront-lead-form {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 8px 2px !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    animation: pcaiFormIn 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

/* The inner <form> is layout only — no second card. */
#pcai-upfront-form {
    background: transparent;
    border: 0;
    padding: 0;
    margin: 0;
}

.pcai-upfront-lead-form .pcai-message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* --- Welcome header --------------------------------------------------------- */
.pcai-welcome-header {
    text-align: center;
    margin: 4px 0 22px;
}

.pcai-welcome-header h3 {
    color: #101828;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 8px 0;
    line-height: 1.25;
}

.pcai-welcome-header p {
    color: #667085;
    font-size: 14.5px;
    line-height: 1.55;
    margin: 0 auto;
    max-width: 30em;
}

/* --- Fields ----------------------------------------------------------------- */
.pcai-form-row {
    margin-bottom: 14px;
}

.pcai-form-group {
    position: relative;
}

.pcai-form-group label {
    display: none; /* placeholders carry the label */
}

.pcai-lead-input {
    width: 100%;
    padding: 14px 16px;
    border: 1.5px solid #e4e7ec;
    border-radius: 14px;
    font-size: 16px; /* prevents iOS zoom-on-focus */
    color: #101828;
    background: #fff;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.pcai-lead-input::placeholder {
    color: #98a2b3;
}

.pcai-lead-input:hover {
    border-color: #d0d5dd;
}

.pcai-lead-input:focus {
    outline: none;
    border-color: var(--pcai-primary, #667eea);
    /* brand-tinted focus ring; color-mix line wins where supported */
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.14);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--pcai-primary, #667eea) 18%, transparent);
    background: #fff;
}

.pcai-lead-input.pcai-valid {
    border-color: #12b76a;
    background: #f6fef9;
}

.pcai-lead-input.pcai-invalid {
    border-color: #f04438;
    background: #fffbfa;
}

.pcai-lead-input:disabled {
    background: #f9fafb;
    color: #98a2b3;
    cursor: not-allowed;
}

.pcai-field-error {
    color: #d92d20;
    font-size: 12.5px;
    margin-top: 6px;
    display: none;
    font-weight: 500;
}

.pcai-form-group.pcai-error .pcai-field-error {
    display: block;
}

/* --- Consent ---------------------------------------------------------------- */
.pcai-consent-row {
    margin-bottom: 16px;
}

.pcai-consent-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    text-align: left;
}

.pcai-consent-input {
    width: 18px;
    height: 18px;
    margin: 1px 0 0;
    flex-shrink: 0;
    accent-color: var(--pcai-primary, #667eea);
    cursor: pointer;
}

.pcai-consent-text {
    color: #475467;
    font-size: 13px;
    line-height: 1.5;
}

/* --- Primary CTA ------------------------------------------------------------ */
.pcai-form-actions {
    margin-top: 22px;
    text-align: center;
}

.pcai-btn-large {
    width: 100%;
    padding: 15px 24px;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.01em;
    border-radius: 14px;
    border: none;
    background: linear-gradient(135deg, var(--pcai-primary, #667eea) 0%, var(--pcai-secondary, #764ba2) 100%);
    color: var(--pcai-text, #fff);
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 20px -10px rgba(102, 126, 234, 0.6);
    box-shadow: 0 8px 20px -10px color-mix(in srgb, var(--pcai-primary, #667eea) 70%, transparent);
    -webkit-tap-highlight-color: transparent;
}

.pcai-btn-large:hover:not(:disabled) {
    filter: brightness(1.04);
    transform: translateY(-1px);
}

.pcai-btn-large:active:not(:disabled) {
    transform: translateY(0) scale(0.99);
    filter: brightness(0.98);
}

.pcai-btn-large:disabled {
    background: #e4e7ec;
    color: #98a2b3;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.pcai-btn-large.pcai-loading {
    cursor: wait;
}

.pcai-btn-spinner {
    color: var(--pcai-text, #fff);
    font-size: 15px;
    font-weight: 500;
}

/* --- Privacy note: quiet, not a competing button --------------------------- */
.pcai-privacy-note {
    margin-top: 14px;
    text-align: center;
    padding: 0 6px;
    background: none;
    border: 0;
}

.pcai-privacy-note small {
    color: #98a2b3;
    font-size: 12px;
    line-height: 1.5;
}

.pcai-privacy-note a {
    color: var(--pcai-primary, #667eea);
    font-weight: 600;
    text-decoration: none;
}

.pcai-privacy-note a:hover {
    text-decoration: underline;
}

/* --- Disabled composer while onboarding is in progress --------------------- */
.pcai-input-row input:disabled,
.pcai-input:disabled,
.pcai-chat-input:disabled {
    background: #f2f3f5;
    color: #98a2b3;
    cursor: not-allowed;
    border-color: transparent;
}

.pcai-input-row input:disabled::placeholder {
    color: #98a2b3;
}

.pcai-input-row button:disabled,
.pcai-send-btn:disabled {
    background: #e4e7ec !important;
    color: #98a2b3;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    opacity: 1;
}

.pcai-input-row button:disabled svg,
.pcai-send-btn:disabled svg {
    color: #98a2b3;
}

/* --- Success message -------------------------------------------------------- */
.pcai-success-message {
    background: linear-gradient(135deg, #d1fadf 0%, #a6f4c5 100%);
    border: 1px solid #a6f4c5;
    border-radius: 14px;
    margin: 10px 0;
}

.pcai-success-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.pcai-success-header h3 {
    color: #05603a;
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.pcai-success-icon {
    font-size: 24px;
}

.pcai-success-message p {
    color: #027a48;
    margin: 0;
    line-height: 1.5;
}

/* --- Error message ---------------------------------------------------------- */
.pcai-error-message {
    background: #fee4e2;
    border: 1px solid #fda29b;
    border-radius: 12px;
    margin: 10px 0;
}

.pcai-error-message .pcai-message-content {
    color: #b42318;
    display: flex;
    align-items: center;
    gap: 8px;
}

.pcai-error-icon {
    font-size: 18px;
    flex-shrink: 0;
}

/* --- Responsive ------------------------------------------------------------- */
@media (max-width: 480px) {
    .pcai-welcome-header {
        margin-bottom: 20px;
    }

    .pcai-welcome-header h3 {
        font-size: 21px;
    }

    .pcai-welcome-header p {
        font-size: 14px;
    }

    .pcai-lead-input {
        padding: 14px 16px;
    }
}

/* --- Motion ----------------------------------------------------------------- */
@keyframes pcaiFormIn {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.pcai-btn-large.pcai-loading .pcai-btn-spinner {
    animation: pcaiLeadPulse 1.5s ease-in-out infinite;
}

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

.pcai-form-group.pcai-error .pcai-lead-input {
    animation: pcaiLeadShake 0.5s ease-in-out;
}

@keyframes pcaiLeadShake {
    0%, 20%, 40%, 60%, 80%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90%      { transform: translateX(-3px); }
}

/* --- Accessibility ---------------------------------------------------------- */
.pcai-lead-input:focus-visible,
.pcai-btn-large:focus-visible {
    outline: 2px solid var(--pcai-primary, #667eea);
    outline-offset: 2px;
}

@media (prefers-contrast: high) {
    .pcai-lead-input {
        border-width: 2px;
    }

    .pcai-btn-large {
        border: 2px solid var(--pcai-secondary, #2c5282);
    }

    .pcai-field-error {
        font-weight: 600;
    }
}

@media (prefers-reduced-motion: reduce) {
    .pcai-messages .pcai-message.pcai-upfront-lead-form,
    .pcai-btn-large,
    .pcai-lead-input,
    .pcai-form-group.pcai-error .pcai-lead-input {
        animation: none;
        transition: none;
    }

    .pcai-btn-large:hover {
        transform: none;
    }
}
