/* Variables */
:root {
    --bew-primary: #2563eb;
    --bew-primary-hover: #1d4ed8;
    --bew-bg: #ffffff;
    --bew-text: #1e293b;
    --bew-text-light: #64748b;
    --bew-border: #e2e8f0;
    --bew-radius: 12px;
    --bew-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --bew-font: 'Inter', system-ui, -apple-system, sans-serif;
}

/* Container */
.bew-container {
    font-family: var(--bew-font);
    font-size: 14px;
    background: var(--bew-bg);
    border: 1px solid var(--bew-border);
    border-radius: var(--bew-radius);
    box-shadow: var(--bew-shadow);
    width: 100%;
    max-width: 660px;
    margin: 0 auto 2rem;
    overflow: visible;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

/* Stronger override when the widget is mounted under a host that sets tiny fonts */
#blog-engagement-root>.bew-container {
    font-size: 14px !important;
}

/* Explicit safeguard if host page adds margins to root mount */
#blog-engagement-root>.bew-container {
    margin-top: 0 !important;
}

.bew-content {
    padding: 0 1.5rem 1.5rem;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hidden {
    display: none !important;
}

/* Typography */
.bew-header h3 {
    margin: 0 0 0.5rem 0;
    color: var(--bew-text);
    font-size: 1.5em;
    font-weight: 600;
    line-height: 1.2;
    padding-top: 0;
    margin-top: 0 !important;
}

/* Optional root mount normalization */
#blog-engagement-root {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

/* Small top inset so heading isn't flush against the container edge */
#blog-engagement-root>.bew-container .bew-content {
    padding-top: 15px !important;
}

.bew-header p {
    margin: 0;
    color: var(--bew-text-light);
    font-size: 0.95em;
}

.bew-header {
    display: block;
    text-align: center;
    margin-top: 0;
    margin-bottom: 1rem;
}

/* Split Layout */
.bew-split-container {
    display: flex;
    align-items: flex-start;
    margin-top: 1rem;
    flex-wrap: nowrap;
}

.bew-split-side {
    flex: 0 0 calc(50% - 0.5rem);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 0 1rem;
    min-height: 120px;
    max-width: calc(50% - 0.5rem);
    box-sizing: border-box;
}

.bew-split-side p {
    margin: 0 0 1.5rem 0;
    color: var(--bew-text-light);
    font-size: 0.95em;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    width: 100%;
    box-sizing: border-box;
}

.bew-divider {
    width: 1px;
    flex-shrink: 0;
    background-color: var(--bew-border);
    margin: 0 0.5rem;
}

/* Buttons */
.bew-btn {
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1em;
}

.bew-btn-primary {
    background: var(--bew-primary);
    color: white;
}

.bew-btn-primary:hover {
    background: var(--bew-primary-hover);
}

.bew-btn-secondary {
    background: #f1f5f9;
    color: var(--bew-text);
}

.bew-btn-secondary:hover {
    background: #e2e8f0;
}

.bew-btn-text {
    background: transparent;
    color: var(--bew-text-light);
    padding: 0.5rem;
}

.bew-btn-text:hover {
    color: var(--bew-text);
}

.bew-close-btn {
    background: none;
    border: none;
    font-size: 1.5em;
    color: var(--bew-text-light);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.bew-close-btn:hover {
    color: var(--bew-text);
}

/* Subtle reset link styling */
.bew-reset-link {
    background: none;
    border: none;
    color: var(--bew-text-light);
    font-size: 14px;
    cursor: pointer;
    padding: 0;
    margin-left: 6px;
    margin-top: 5px;
    /* Visual alignment with turn counter */
}

.bew-reset-link:hover {
    color: var(--bew-text);
    text-decoration: underline;
}

/* Summary View */
.bew-body {
    color: var(--bew-text);
    line-height: 1.6;
}

.bew-cta-btn {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.75rem 1.5rem;
    background: var(--bew-primary);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
}

/* Form - FIXED SPACING AND ALIGNMENT */
.bew-step {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.bew-step label {
    font-weight: 500;
    color: var(--bew-text);
}

textarea,
input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--bew-border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95em;
    resize: vertical;
    box-sizing: border-box;
}

textarea:focus,
input:focus {
    outline: none;
    border-color: var(--bew-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Success State */
.bew-success-message {
    text-align: center;
    padding: 2rem 0;
}

.bew-check-icon {
    width: 48px;
    height: 48px;
    background: #dcfce7;
    color: #16a34a;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin: 0 auto 1rem;
}

/* Chat Interface */
.bew-chat-body {
    min-height: 60px;
    max-height: calc(60vh);
    height: auto;
    overflow-y: auto;
    padding: 0.75rem;
    background: #f8fafc;
    border-top: 1px solid var(--bew-border);
    border-bottom: 1px solid var(--bew-border);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: max-height 0.18s ease;
}

/* Enhanced capture interface styling for natural continuation */
.bew-capture-transition {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.bew-capture-header {
    text-align: left;
}

.bew-capture-header h3 {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--bew-text);
    margin: 0 0 0.5rem 0;
    line-height: 1.3;
}

.bew-capture-header p {
    font-size: 0.9em;
    color: var(--bew-text-light);
    margin: 0;
    line-height: 1.4;
}

/* Form styling for visual continuity with chat */
.bew-capture-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.bew-capture-form input[type="email"] {
    background: white;
    border: 1px solid var(--bew-border);
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 14px !important;
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
}

.bew-capture-form input[type="email"]::placeholder {
    font-size: 14px !important;
    color: var(--bew-text-light);
}

.bew-capture-form input[type="email"]:focus {
    outline: none;
    border-color: var(--bew-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.bew-capture-form .bew-btn {
    align-self: stretch;
    justify-content: center;
    font-size: 14px !important;
}

.bew-privacy-note {
    font-size: 0.75rem;
    color: var(--bew-text-light);
    text-align: center;
    margin: 0;
    line-height: 1.3;
}

.bew-privacy-note a {
    color: var(--bew-primary);
    text-decoration: none;
}

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

/* Ensure consistent readable font sizing inside the chat area */
.bew-chat-body,
.bew-chat-msg,
.bew-chat-msg.bot,
.bew-chat-msg.user,
#bew-chat-input,
.bew-chat-input-area .bew-btn,
.bew-chat-input-area button {
    font-size: 1em !important;
}

/* Placeholder text size */
#bew-chat-input::placeholder {
    font-size: 1em;
    color: var(--bew-text-light);
}

.bew-chat-msg {
    max-width: 80%;
    padding: 0.6rem 0.9rem;
    border-radius: 12px;
    font-size: 1em;
    line-height: 1.4;
}

.bew-chat-msg.bot {
    align-self: flex-start;
    background: white;
    border: 1px solid var(--bew-border);
    color: var(--bew-text);
    border-bottom-left-radius: 2px;
}

.bew-chat-msg.user {
    align-self: flex-end;
    background: var(--bew-primary);
    color: white;
    border-bottom-right-radius: 2px;
}

/* Force readable minimum sizes for critical chat elements */
#blog-engagement-widget .bew-chat-msg.bot,
#blog-engagement-widget .bew-chat-msg.user {
    font-size: 14px !important;
    line-height: 1.4 !important;
}

#blog-engagement-widget #bew-chat-send,
#blog-engagement-widget .bew-chat-input-area .bew-btn {
    font-size: 14px !important;
}

/* Placeholder rules with vendor prefixes */
#blog-engagement-widget #bew-chat-input::placeholder {
    font-size: 13px !important;
    color: var(--bew-text-light) !important;
    -webkit-font-smoothing: antialiased;
}

#blog-engagement-widget #bew-chat-input::-webkit-input-placeholder {
    font-size: 13px !important;
}

#blog-engagement-widget #bew-chat-input:-ms-input-placeholder {
    font-size: 13px !important;
}

/* Global fallbacks: ensure critical chat elements are at least 14px */
.bew-chat-msg.bot,
.bew-chat-msg.user {
    font-size: 14px !important;
    line-height: 1.4 !important;
}

button#bew-chat-send {
    font-size: 14px !important;
}

input#bew-chat-input::placeholder {
    font-size: 14px !important;
    color: var(--bew-text-light) !important;
}

input#bew-chat-input::-webkit-input-placeholder {
    font-size: 14px !important;
}

input#bew-chat-input:-ms-input-placeholder {
    font-size: 14px !important;
}

/* Make the send button less wide and visually compact */
#blog-engagement-widget button#bew-chat-send,
#blog-engagement-widget .bew-chat-input-area .bew-btn {
    padding: 0.45rem 0.85rem !important;
    max-width: 120px !important;
    width: auto !important;
}

/* FIXED: Simple flow buttons - align to the left instead of right */
#bew-btn-next,
#bew-btn-submit {
    width: auto;
    align-self: flex-start;
    padding: 0.65rem 1.15rem;
}

/* Ensure email input uses inline validation look consistent */
#bew-email-input {
    font-size: 1rem;
}

/* Enforce readable minimum font size for primary action buttons */
#bew-btn-summarize,
#bew-btn-question,
#bew-btn-next,
#bew-btn-submit {
    font-size: 14px !important;
    line-height: 1.2 !important;
}

/* Error flash for invalid email */
.bew-input-error {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2) !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Ensure input and button align nicely in tight preview containers */
#blog-engagement-widget .bew-chat-input-area {
    gap: 0.5rem !important;
}

.bew-chat-input-area {
    padding: 0.75rem;
    display: flex;
    gap: 0.5rem;
}

#bew-chat-input {
    flex: 1;
    padding: 0.6rem;
    border: 1px solid var(--bew-border);
    border-radius: 8px;
    font-size: 1em;
}

.bew-chat-msg.loading {
    color: var(--bew-text-light);
    font-style: italic;
    background: transparent;
    border: none;
    padding: 0;
}

/* Enhanced dual-view mode responsive design */

/* Conversation completion state styling */
.bew-conversation-complete {
    position: relative;
}

.bew-conversation-complete .bew-chat-body {
    opacity: 1 !important;
    pointer-events: auto !important;
    background: #f8fafc;
    border-bottom: none;
}

.bew-conversation-complete .bew-chat-input-area {
    opacity: 0.6;
    pointer-events: none;
    transition: opacity 0.3s ease;
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    border-radius: 0 0 var(--bew-radius) var(--bew-radius);
}

.bew-conversation-complete .bew-chat-input-area input {
    background-color: #f8fafc;
    color: var(--bew-text-light);
    cursor: not-allowed;
    border-color: #e2e8f0;
}

.bew-conversation-complete .bew-chat-input-area button {
    background-color: #e2e8f0;
    color: var(--bew-text-light);
    cursor: not-allowed;
    border: 1px solid #cbd5e1;
}

/* Disabled input state styling for conversation completion */
.bew-chat-input-area[style*="opacity: 0.6"] {
    transition: opacity 0.3s ease;
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
}

.bew-chat-input-area[style*="opacity: 0.6"] input {
    background-color: #f8fafc;
    color: var(--bew-text-light);
    cursor: not-allowed;
    border-color: #e2e8f0;
}

.bew-chat-input-area[style*="opacity: 0.6"] button {
    background-color: #e2e8f0;
    color: var(--bew-text-light);
    cursor: not-allowed;
    border: 1px solid #cbd5e1;
}

/* Dual-view mode: Enhanced positioning for conversation continuation */
#bew-chat-interface:not(.hidden)+#bew-chat-capture:not(.hidden) {
    margin-top: 0;
    border-top: none;
    background: #f8fafc;
    border-radius: 0 0 var(--bew-radius) var(--bew-radius);
}

#bew-chat-interface:not(.hidden)+#bew-chat-capture:not(.hidden) .bew-content {
    padding: 1.5rem;
    background: #f8fafc;
    border-top: 1px solid var(--bew-border);
    border-radius: 0 0 var(--bew-radius) var(--bew-radius);
}

/* Enhanced capture interface styling for natural continuation */
.bew-capture-transition {
    animation: slideInUp 0.4s ease-out;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bew-capture-header {
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--bew-border);
}

.bew-capture-header h3 {
    font-size: 1.2em;
    font-weight: 600;
    color: var(--bew-text);
    margin: 0 0 0.5rem 0;
    line-height: 1.3;
}

.bew-capture-header p {
    font-size: 0.95em;
    color: var(--bew-text-light);
    margin: 0;
}

.bew-expert-btn {
    font-size: 14px;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--bew-primary);
    color: var(--bew-primary);
    border-radius: 999px;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s;
    margin-left: auto;
}

.bew-expert-btn:hover {
    background: var(--bew-primary);
    color: white;
}



.bew-capture-form input[type="email"] {
    background: white;
    border: 2px solid var(--bew-border);
    border-radius: 10px;
    padding: 0.875rem 1rem;
    font-size: 1em;
    width: 100%;
    box-sizing: border-box;
    transition: all 0.2s ease;
    font-family: inherit;
    font-weight: 500;
}

.bew-capture-form input[type="email"]:focus {
    outline: none;
    border-color: var(--bew-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    background: #fefefe;
}

.bew-capture-form input[type="email"]::placeholder {
    color: var(--bew-text-light);
    font-weight: 400;
}

.bew-capture-form .bew-btn {
    padding: 0.875rem 1.5rem;
    font-weight: 600;
    font-size: 1em;
    border-radius: 10px;
    transition: all 0.2s ease;
}

.bew-capture-form .bew-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.bew-privacy-note {
    font-size: 0.8rem;
    color: var(--bew-text-light);
    text-align: center;
    margin: 0.5rem 0 0 0;
    line-height: 1.4;
    padding: 0.75rem;
    background: rgba(248, 250, 252, 0.8);
    border-radius: 8px;
    border: 1px solid rgba(226, 232, 240, 0.5);
}

.bew-privacy-note a {
    color: var(--bew-primary);
    text-decoration: none;
    font-weight: 500;
}

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

/* Smooth transitions for conversation completion state */
.bew-chat-interface {
    transition: all 0.3s ease;
}

.bew-chat-capture {
    transition: all 0.3s ease;
}

/* Enhanced success message with conversation context */
.bew-success-message {
    text-align: center;
    padding: 2rem 1rem;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-radius: var(--bew-radius);
    border: 1px solid #bae6fd;
}

.bew-success-message h3 {
    color: var(--bew-text);
    margin-bottom: 1rem;
    font-size: 1.3em;
}

.bew-success-message p {
    line-height: 1.6;
    margin-bottom: 1rem;
    color: var(--bew-text);
    font-size: 1em;
}

/* Visual separator between chat and capture in dual-view */
#bew-chat-interface:not(.hidden)+#bew-chat-capture:not(.hidden)::before {
    content: '';
    display: block;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, var(--bew-primary) 20%, var(--bew-primary) 80%, transparent 100%);
    margin: 0;
    opacity: 0.3;
}

/* Responsive adjustments for dual-view mode */
@media (max-width: 768px) {
    #bew-chat-interface:not(.hidden)+#bew-chat-capture:not(.hidden) .bew-content {
        padding: 1.25rem 1rem;
    }

    .bew-capture-header h3 {
        font-size: 1.1em;
    }

    .bew-capture-header p {
        font-size: 0.9em;
    }

    .bew-capture-form {
        gap: 0.875rem;
    }

    .bew-capture-form input[type="email"] {
        padding: 0.75rem 0.875rem;
        font-size: 0.95em;
    }

    .bew-capture-form .bew-btn {
        padding: 0.75rem 1.25rem;
        font-size: 0.95em;
    }

    .bew-privacy-note {
        font-size: 0.75rem;
        padding: 0.625rem;
    }
}

@media (max-width: 480px) {
    #bew-chat-interface:not(.hidden)+#bew-chat-capture:not(.hidden) .bew-content {
        padding: 1rem 0.875rem;
    }

    .bew-capture-header {
        padding-bottom: 0.625rem;
    }

    .bew-capture-header h3 {
        font-size: 1em;
        margin-bottom: 0.375rem;
    }

    .bew-capture-header p {
        font-size: 0.85em;
        line-height: 1.4;
    }

    .bew-capture-form {
        gap: 0.75rem;
    }

    .bew-capture-form input[type="email"] {
        padding: 0.65rem 0.75rem;
        font-size: 0.9em;
    }

    .bew-capture-form .bew-btn {
        padding: 0.65rem 1rem;
        font-size: 0.9em;
    }

    .bew-privacy-note {
        font-size: 0.7rem;
        padding: 0.5rem;
        margin-top: 0.375rem;
    }

    .bew-success-message {
        padding: 1.5rem 0.875rem;
    }

    .bew-success-message h3 {
        font-size: 1.1em;
    }

    .bew-success-message p {
        font-size: 0.9em;
    }
}

/* Enhanced container styling for dual-view mode */
.bew-container:has(#bew-chat-interface:not(.hidden) + #bew-chat-capture:not(.hidden)) {
    box-shadow: 0 8px 25px -5px rgba(0, 0, 0, 0.1), 0 4px 10px -3px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(37, 99, 235, 0.1);
}

/* Enhanced focus management for accessibility */
.bew-capture-form input[type="email"]:focus-visible {
    outline: 2px solid var(--bew-primary);
    outline-offset: 2px;
}

.bew-capture-form .bew-btn:focus-visible {
    outline: 2px solid var(--bew-primary);
    outline-offset: 2px;
}

/* Summary Actions */
.bew-summary-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.bew-link-secondary {
    color: var(--bew-text-light);
    text-decoration: underline;
    font-size: 0.9em;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
}

.bew-link-secondary:hover {
    color: var(--bew-primary);
}
/* Branding Footer */
.bew-branding {
    text-align: center;
    font-size: 11px;
    color: var(--bew-text-light);
    padding: 8px 0 12px;
    opacity: 0.7;
}
.bew-branding a {
    color: inherit;
    text-decoration: none;
    font-weight: 600;
}
.bew-branding a:hover {
    text-decoration: underline;
}
