/* Ask Alex chat v20: professional bot layout, avatar, typewriter, suggestions */
.message-sources { display: none !important; }

.chat-widget {
    max-width: calc(100vw - 24px) !important;
    z-index: 9999 !important;
}

.chat-widget.active {
    display: flex !important;
    flex-direction: column !important;
    width: min(760px, calc(100vw - 24px)) !important;
    height: min(820px, calc(100vh - 24px)) !important;
    max-height: calc(100vh - 24px) !important;
}

.chat-header { flex: 0 0 auto !important; }

.chat-body {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scroll-behavior: smooth;
    padding: 18px !important;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: min-content;
}

.chat-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    width: 100%;
}

.user-row {
    justify-content: flex-end;
}

.bot-row {
    justify-content: flex-start;
}

html[lang="ar"] .bot-row,
.chat-row[dir="rtl"].bot-row {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

html[lang="ar"] .user-row,
.chat-row[dir="rtl"].user-row {
    justify-content: flex-end;
}

.chat-bot-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex: 0 0 36px;
    border: 2px solid #3498db;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
    background: #fff;
}

.chat-message {
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    max-width: 88% !important;
    font-size: 1rem;
}

.user-message {
    align-self: flex-end;
    margin-left: auto !important;
    margin-right: 0 !important;
}

.bot-message {
    align-self: flex-start;
    margin-right: auto !important;
    margin-left: 0 !important;
    position: relative;
}

.bot-message.typing::after {
    content: '▌';
    display: inline-block;
    margin-inline-start: 2px;
    animation: askAlexBlink .7s infinite;
    opacity: .8;
}

@keyframes askAlexBlink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

html[lang="ar"] .chat-message,
html[lang="ar"] .chat-welcome,
html[lang="ar"] .chat-input textarea,
.chat-message[dir="rtl"] {
    direction: rtl !important;
    text-align: right !important;
}

.chat-message[dir="ltr"],
html[lang="en"] .chat-message,
html[lang="sv"] .chat-message {
    direction: ltr !important;
    text-align: left !important;
}

html[lang="ar"] .user-message { margin-right: auto !important; margin-left: 0 !important; }
html[lang="ar"] .bot-message { margin-left: auto !important; margin-right: 0 !important; }

.chat-inline-link {
    color: #0b7ed8 !important;
    text-decoration: underline !important;
    word-break: break-all;
    direction: ltr !important;
    unicode-bidi: isolate !important;
    display: inline-block;
}

.chat-image-preview-wrap {
    margin-top: 10px;
    max-width: 260px;
}

.chat-image-preview-link {
    display: inline-block;
}

.chat-image-preview {
    display: block;
    width: 100%;
    max-width: 260px;
    max-height: 190px;
    object-fit: contain;
    border-radius: 10px;
    border: 1px solid rgba(0,0,0,.12);
    background: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,.12);
}

.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 2px 0 8px 48px;
    align-self: flex-start;
    max-width: 90%;
}

html[lang="ar"] .chat-suggestions,
.chat-suggestions[dir="rtl"] {
    direction: rtl;
    margin-left: 0;
    margin-right: 48px;
    justify-content: flex-start;
}

.chat-suggestion-btn {
    border: 1px solid rgba(52, 152, 219, .35);
    background: #ffffff;
    color: #1c6fa8;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: .9rem;
    cursor: pointer;
    transition: transform .12s ease, background .12s ease, color .12s ease;
    box-shadow: 0 2px 7px rgba(0,0,0,.06);
}

.chat-suggestion-btn:hover {
    background: #3498db;
    color: #fff;
    transform: translateY(-1px);
}

.chat-input {
    flex: 0 0 auto !important;
    display: flex !important;
    gap: 10px;
    padding: 14px !important;
    border-top: 1px solid rgba(0,0,0,.08);
}

.chat-input textarea {
    min-height: 48px !important;
    max-height: 120px !important;
    resize: vertical;
}

.chat-actions { flex: 0 0 auto !important; }

@media (max-width: 768px) {
    .chat-widget.active {
        width: calc(100vw - 10px) !important;
        height: calc(100vh - 10px) !important;
        max-height: calc(100vh - 10px) !important;
        left: 5px !important;
        right: 5px !important;
        bottom: 5px !important;
        top: 5px !important;
        border-radius: 12px !important;
    }
    .chat-body { padding: 14px !important; }
    .chat-message { max-width: 86% !important; font-size: .96rem; }
    .chat-bot-avatar { width: 32px; height: 32px; flex-basis: 32px; }
    .chat-suggestions { margin-left: 42px; max-width: calc(100% - 42px); }
    html[lang="ar"] .chat-suggestions { margin-right: 42px; }
    .chat-input { padding: 10px !important; }
}


/* v21 mobile fix: force chat widget to stay inside the viewport on phones */
@media (max-width: 768px) {
    html,
    body {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    .chat-widget,
    html[lang="ar"] .chat-widget,
    html[lang="en"] .chat-widget,
    html[lang="sv"] .chat-widget {
        position: fixed !important;
        transform: none !important;
        left: 8px !important;
        right: 8px !important;
        bottom: 8px !important;
        top: auto !important;
        width: auto !important;
        max-width: none !important;
        margin: 0 !important;
        border-radius: 14px !important;
        overflow: hidden !important;
        z-index: 999999 !important;
    }

    .chat-widget.active,
    html[lang="ar"] .chat-widget.active,
    html[lang="en"] .chat-widget.active,
    html[lang="sv"] .chat-widget.active {
        display: flex !important;
        flex-direction: column !important;
        left: 8px !important;
        right: 8px !important;
        top: 8px !important;
        bottom: 8px !important;
        width: auto !important;
        height: auto !important;
        max-height: none !important;
        transform: none !important;
    }

    .chat-header {
        flex: 0 0 auto !important;
        padding: 12px 14px !important;
    }

    .chat-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        padding: 12px !important;
    }

    .chat-input {
        flex: 0 0 auto !important;
        display: grid !important;
        grid-template-columns: 1fr 70px !important;
        gap: 8px !important;
        padding: 10px !important;
        background: #fff !important;
    }

    .chat-input textarea {
        width: 100% !important;
        min-width: 0 !important;
        min-height: 46px !important;
        max-height: 90px !important;
        font-size: 14px !important;
        box-sizing: border-box !important;
    }

    .chat-input button,
    #chat-send-btn {
        width: 70px !important;
        min-width: 70px !important;
        padding: 0 8px !important;
        box-sizing: border-box !important;
    }

    .chat-actions {
        flex: 0 0 auto !important;
        padding: 4px 10px 10px !important;
        background: #fff !important;
    }

    .chat-message {
        max-width: calc(100% - 44px) !important;
        font-size: 0.95rem !important;
        line-height: 1.6 !important;
    }

    .chat-suggestions,
    html[lang="ar"] .chat-suggestions,
    .chat-suggestions[dir="rtl"] {
        max-width: calc(100% - 44px) !important;
        margin-left: 44px !important;
        margin-right: 0 !important;
    }

    html[lang="ar"] .chat-suggestions,
    .chat-suggestions[dir="rtl"] {
        margin-right: 44px !important;
        margin-left: 0 !important;
    }

    .open-chat-btn,
    html[lang="ar"] .open-chat-btn {
        transform: none !important;
        right: 14px !important;
        left: auto !important;
        bottom: 14px !important;
        z-index: 99999 !important;
    }
}

@supports (height: 100dvh) {
    @media (max-width: 768px) {
        .chat-widget.active,
        html[lang="ar"] .chat-widget.active,
        html[lang="en"] .chat-widget.active,
        html[lang="sv"] .chat-widget.active {
            top: 8px !important;
            bottom: 8px !important;
            height: calc(100dvh - 16px) !important;
        }
    }
}


/* v27 richer question buttons */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 8px 8px;
    align-items: flex-start;
}

.chat-suggestion-btn {
    border: 1px solid rgba(52, 152, 219, 0.35);
    background: rgba(52, 152, 219, 0.10);
    color: #1d6fa5;
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    line-height: 1.35;
    max-width: 100%;
    transition: transform .15s ease, background .15s ease;
}

.chat-suggestion-btn:hover {
    background: rgba(52, 152, 219, 0.18);
    transform: translateY(-1px);
}

html[lang="ar"] .chat-suggestion-btn {
    font-family: inherit;
}

@media (max-width: 520px) {
    .chat-suggestions {
        gap: 7px;
        margin-inline: 4px;
    }

    .chat-suggestion-btn {
        border-radius: 14px;
        padding: 8px 10px;
        font-size: 0.84rem;
        flex: 1 1 45%;
    }
}

/* v37 inline electrical photo gallery */
.chat-electric-gallery {
    margin-top: 14px;
    border-top: 1px solid rgba(52,152,219,.18);
    padding-top: 12px;
}
.chat-electric-slide {
    display: block;
    width: 100%;
    max-width: 330px;
    aspect-ratio: 4/3;
    object-fit: cover;
    border-radius: 16px;
    margin: 0 auto;
    border: 1px solid rgba(52,152,219,.20);
    box-shadow: 0 8px 22px rgba(0,0,0,.08);
    transition: opacity .22s ease;
}
.chat-electric-slide.is-fading { opacity: .4; }
.chat-electric-dots {
    display: flex;
    justify-content: center;
    gap: 7px;
    margin-top: 9px;
}
.chat-electric-dot {
    width: 10px;
    height: 10px;
    border: 0;
    border-radius: 50%;
    background: rgba(52,152,219,.3);
    cursor: pointer;
}
.chat-electric-dot.active {
    background: #3498db;
    transform: scale(1.12);
}
