/* LeadSync Chat Widget */

:root {
    --ls-chat-accent: #626ed4;
    --ls-chat-accent-hover: #4f59b8;
    --ls-chat-bg: #ffffff;
    --ls-chat-bg-secondary: #f8f9fa;
    --ls-chat-text: #333333;
    --ls-chat-text-muted: #6c757d;
    --ls-chat-border: #e5e7eb;
    --ls-chat-user-bg: #626ed4;
    --ls-chat-user-text: #ffffff;
    --ls-chat-bot-bg: #f0f1f9;
    --ls-chat-bot-text: #333333;
    --ls-chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    --ls-chat-radius: 16px;
    --ls-chat-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --ls-chat-width: 380px;
    --ls-chat-height: 520px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --ls-chat-bg: #1e1e2e;
        --ls-chat-bg-secondary: #2a2a3c;
        --ls-chat-text: #e0e0e0;
        --ls-chat-text-muted: #9a9ab0;
        --ls-chat-border: #3a3a4c;
        --ls-chat-bot-bg: #2a2a3c;
        --ls-chat-bot-text: #e0e0e0;
        --ls-chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    }
}

/* Bubble */
.ls-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #11b981;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(17, 185, 129, 0.4);
    z-index: 99999;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    padding: 0;
}

.ls-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(17, 185, 129, 0.5);
}

.ls-chat-bubble:focus-visible {
    outline: 3px solid var(--ls-chat-accent);
    outline-offset: 3px;
}

.ls-chat-bubble svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.ls-chat-bubble[aria-expanded="true"] {
    display: none;
}

/* Panel */
.ls-chat-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: var(--ls-chat-width);
    height: var(--ls-chat-height);
    max-height: calc(100vh - 48px);
    background: var(--ls-chat-bg);
    border-radius: var(--ls-chat-radius);
    box-shadow: var(--ls-chat-shadow);
    display: flex;
    flex-direction: column;
    z-index: 99999;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ls-chat-panel[aria-hidden="false"] {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

@media (prefers-reduced-motion: reduce) {
    .ls-chat-bubble,
    .ls-chat-panel {
        transition: none;
    }
}

/* Header */
.ls-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--ls-chat-border);
    background: var(--ls-chat-bg);
    flex-shrink: 0;
}

.ls-chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ls-chat-header-title {
    font-family: var(--ls-chat-font);
    font-size: 15px;
    font-weight: 600;
    color: var(--ls-chat-text);
    margin: 0;
}

.ls-chat-header-subtitle {
    font-family: var(--ls-chat-font);
    font-size: 11px;
    color: var(--ls-chat-text-muted);
    margin: 0;
}

.ls-chat-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--ls-chat-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
}

.ls-chat-close:hover {
    background: var(--ls-chat-bg-secondary);
    color: var(--ls-chat-text);
}

.ls-chat-close:focus-visible {
    outline: 2px solid var(--ls-chat-accent);
    outline-offset: 1px;
}

.ls-chat-close svg {
    width: 18px;
    height: 18px;
}

/* Messages area */
.ls-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.ls-chat-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-family: var(--ls-chat-font);
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.ls-chat-message--user {
    align-self: flex-end;
    background: var(--ls-chat-user-bg);
    color: var(--ls-chat-user-text);
    border-bottom-right-radius: 4px;
}

.ls-chat-message--bot {
    align-self: flex-start;
    background: var(--ls-chat-bot-bg);
    color: var(--ls-chat-bot-text);
    border-bottom-left-radius: 4px;
}

.ls-chat-message--bot a {
    color: var(--ls-chat-accent);
    text-decoration: underline;
}

.ls-chat-message--bot a:hover {
    color: var(--ls-chat-accent-hover);
}

/* Welcome message */
.ls-chat-welcome {
    text-align: center;
    padding: 24px 16px;
    color: var(--ls-chat-text-muted);
    font-family: var(--ls-chat-font);
    font-size: 13px;
    line-height: 1.5;
}

.ls-chat-welcome-icon {
    font-size: 28px;
    margin-bottom: 8px;
    display: block;
}

/* Sources */
.ls-chat-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.ls-chat-source {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--ls-chat-bg);
    border: 1px solid var(--ls-chat-border);
    border-radius: 20px;
    font-family: var(--ls-chat-font);
    font-size: 12px;
    color: var(--ls-chat-accent);
    text-decoration: none;
    transition: background 0.15s ease;
}

.ls-chat-source:hover {
    background: var(--ls-chat-bg-secondary);
    text-decoration: none;
}

.ls-chat-source svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

/* Typing indicator */
.ls-chat-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--ls-chat-bot-bg);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

.ls-chat-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ls-chat-text-muted);
    animation: ls-chat-bounce 1.2s infinite ease-in-out;
}

.ls-chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.ls-chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes ls-chat-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .ls-chat-typing-dot {
        animation: none;
        opacity: 0.6;
    }
}

/* Input area */
.ls-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--ls-chat-border);
    background: var(--ls-chat-bg);
    flex-shrink: 0;
}

.ls-chat-input {
    flex: 1;
    border: 1px solid var(--ls-chat-border);
    border-radius: 12px;
    padding: 10px 14px;
    font-family: var(--ls-chat-font);
    font-size: 14px;
    color: var(--ls-chat-text);
    background: var(--ls-chat-bg-secondary);
    resize: none;
    min-height: 40px;
    max-height: 96px;
    line-height: 1.4;
    outline: none;
}

.ls-chat-input::placeholder {
    color: var(--ls-chat-text-muted);
}

.ls-chat-input:focus {
    border-color: var(--ls-chat-accent);
    box-shadow: 0 0 0 2px rgba(98, 110, 212, 0.15);
}

.ls-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: var(--ls-chat-accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    transition: background 0.15s ease;
}

.ls-chat-send:hover {
    background: var(--ls-chat-accent-hover);
}

.ls-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ls-chat-send:focus-visible {
    outline: 2px solid var(--ls-chat-accent);
    outline-offset: 2px;
}

.ls-chat-send svg {
    width: 18px;
    height: 18px;
}

/* Footer */
.ls-chat-footer {
    text-align: center;
    padding: 8px 16px;
    font-family: var(--ls-chat-font);
    font-size: 11px;
    color: var(--ls-chat-text-muted);
    border-top: 1px solid var(--ls-chat-border);
    background: var(--ls-chat-bg);
    flex-shrink: 0;
}

.ls-chat-footer a {
    color: var(--ls-chat-accent);
    text-decoration: none;
}

.ls-chat-footer a:hover {
    text-decoration: underline;
}

/* Resolution check & escalation UI */
.ls-chat-resolution {
    align-self: flex-start;
    background: var(--ls-chat-bot-bg);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    padding: 12px 14px;
    max-width: 85%;
    font-family: var(--ls-chat-font);
}

.ls-chat-resolution-label {
    font-size: 14px;
    line-height: 1.4;
    color: var(--ls-chat-bot-text);
    margin: 0 0 10px 0;
}

.ls-chat-btn-group {
    display: flex;
    gap: 8px;
}

.ls-chat-btn {
    padding: 8px 20px;
    border-radius: 8px;
    border: 1px solid var(--ls-chat-border);
    font-family: var(--ls-chat-font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.ls-chat-btn:focus-visible {
    outline: 2px solid var(--ls-chat-accent);
    outline-offset: 1px;
}

.ls-chat-btn--yes {
    background: var(--ls-chat-accent);
    color: #fff;
    border-color: var(--ls-chat-accent);
}

.ls-chat-btn--yes:hover {
    background: var(--ls-chat-accent-hover);
    border-color: var(--ls-chat-accent-hover);
}

.ls-chat-btn--no {
    background: var(--ls-chat-bg);
    color: var(--ls-chat-text);
}

.ls-chat-btn--no:hover {
    background: var(--ls-chat-bg-secondary);
    border-color: var(--ls-chat-text-muted);
}

.ls-chat-btn--full {
    width: 100%;
}

.ls-chat-contact-details {
    font-size: 14px;
    color: var(--ls-chat-bot-text);
    margin: 0 0 10px 0;
    line-height: 1.4;
}

.ls-chat-contact-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ls-chat-form-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--ls-chat-border);
    border-radius: 8px;
    font-family: var(--ls-chat-font);
    font-size: 13px;
    color: var(--ls-chat-text);
    background: var(--ls-chat-bg);
    outline: none;
    box-sizing: border-box;
}

.ls-chat-form-input::placeholder {
    color: var(--ls-chat-text-muted);
}

.ls-chat-form-input:focus {
    border-color: var(--ls-chat-accent);
    box-shadow: 0 0 0 2px rgba(98, 110, 212, 0.15);
}

.ls-chat-form-error {
    font-size: 12px;
    color: #e53e3e;
    margin: 0;
}

/* Mobile: full-screen panel */
@media (max-width: 480px) {
    .ls-chat-panel {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .ls-chat-bubble {
        bottom: 16px;
        right: 16px;
    }
}
