/* ==========================================================================
   Chat Widget — Marketing site chat bubble + window
   Uses existing CSS variables from main.css
   ========================================================================== */

/* --- Bubble button (bottom-right corner) --- */
.chat-widget-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-orange, #C65000);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: 9997;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.18);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-widget-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0,0,0,0.24);
}

.chat-widget-bubble svg {
    width: 26px;
    height: 26px;
    fill: currentColor;
}

.chat-widget-bubble.hidden {
    display: none;
}

/* --- Chat window --- */
.chat-widget-window {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 380px;
    height: 520px;
    background: var(--bg-white, #fff);
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.chat-widget-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* --- Header --- */
.chat-widget-header {
    background: var(--bg-dark, #1a1a1a);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-widget-header-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.chat-widget-header-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.chat-widget-header-close:hover {
    opacity: 1;
}

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

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

/* Scrollbar styling */
.chat-widget-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-widget-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-widget-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}

/* --- Message bubbles --- */
.chat-widget-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-widget-msg.user {
    align-self: flex-end;
    background: var(--primary-orange, #C65000);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-widget-msg.assistant {
    align-self: flex-start;
    background: var(--bg-light, #f3f4f6);
    color: var(--text-primary, #1a1a1a);
    border-bottom-left-radius: 4px;
}

/* Markdown in assistant messages */
.chat-widget-msg.assistant strong {
    font-weight: 600;
}

.chat-widget-msg.assistant em {
    font-style: italic;
}

.chat-widget-msg.assistant code {
    background: rgba(0,0,0,0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

.chat-widget-msg.assistant a {
    color: var(--primary-orange, #C65000);
    text-decoration: underline;
}

.chat-widget-msg.assistant ul,
.chat-widget-msg.assistant ol {
    margin: 6px 0;
    padding-left: 20px;
}

.chat-widget-msg.assistant li {
    margin: 2px 0;
}

.chat-widget-msg.assistant p {
    margin: 0 0 8px;
}

.chat-widget-msg.assistant p:last-child {
    margin-bottom: 0;
}

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

.chat-widget-typing span {
    width: 7px;
    height: 7px;
    background: #9ca3af;
    border-radius: 50%;
    animation: chatWidgetBounce 1.2s infinite;
}

.chat-widget-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.chat-widget-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes chatWidgetBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* --- Starter prompts --- */
.chat-widget-starters {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 16px 16px;
}

.chat-widget-starter {
    background: var(--bg-white, #fff);
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-primary, #1a1a1a);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
    line-height: 1.4;
}

.chat-widget-starter:hover {
    border-color: var(--primary-orange, #C65000);
    background: #fef7f2;
}

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

.chat-widget-textarea {
    flex: 1;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    max-height: 100px;
    min-height: 40px;
    outline: none;
    transition: border-color 0.15s;
    background: var(--bg-white, #fff);
    color: var(--text-primary, #1a1a1a);
}

.chat-widget-textarea:focus {
    border-color: var(--primary-orange, #C65000);
}

.chat-widget-textarea::placeholder {
    color: #9ca3af;
}

.chat-widget-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--primary-orange, #C65000);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.chat-widget-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

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

/* --- Email gate overlay --- */
.chat-widget-email-gate {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px;
    z-index: 10;
    text-align: center;
}

.chat-widget-email-gate h3 {
    font-size: 17px;
    font-weight: 600;
    margin: 0 0 8px;
    color: var(--text-primary, #1a1a1a);
}

.chat-widget-email-gate p {
    font-size: 14px;
    color: var(--text-secondary, #6b7280);
    margin: 0 0 20px;
    line-height: 1.5;
}

.chat-widget-email-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    margin-bottom: 12px;
    font-family: inherit;
}

.chat-widget-email-input:focus {
    border-color: var(--primary-orange, #C65000);
}

.chat-widget-email-submit {
    width: 100%;
    padding: 10px;
    background: var(--primary-orange, #C65000);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
    font-family: inherit;
}

.chat-widget-email-submit:hover {
    opacity: 0.9;
}

.chat-widget-email-skip {
    background: none;
    border: none;
    color: var(--text-secondary, #6b7280);
    cursor: pointer;
    font-size: 13px;
    margin-top: 12px;
    padding: 4px;
    font-family: inherit;
}

.chat-widget-email-skip:hover {
    color: var(--text-primary, #1a1a1a);
}

/* --- Error message --- */
.chat-widget-msg.error {
    align-self: center;
    background: #fef2f2;
    color: #991b1b;
    border-radius: 10px;
    font-size: 13px;
    text-align: center;
    max-width: 90%;
}

/* --- Mobile (full viewport) --- */
@media (max-width: 480px) {
    .chat-widget-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

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

/* Hide widget on pages where cookie banner might overlap */
.cookie-consent.show ~ .chat-widget-bubble {
    bottom: 88px;
}
