.cs-ai-chat {
    --cs-chat-primary: #2563eb;
    --cs-chat-primary-hover: #1d4ed8;
    --cs-chat-surface: #ffffff;
    --cs-chat-border: rgba(148, 163, 184, 0.35);
    --cs-chat-text: #0f172a;
    --cs-chat-muted: #64748b;
    --cs-chat-user-bg: #2563eb;
    --cs-chat-user-text: #ffffff;
    --cs-chat-assistant-bg: #f1f5f9;
    --cs-chat-assistant-text: #1e293b;
    --cs-chat-shadow: 0 16px 40px rgba(15, 23, 42, 0.14);
    --cs-chat-bottom: 1.25rem;
    position: fixed;
    right: 1rem;
    bottom: var(--cs-chat-bottom);
    z-index: 1060;
    font-family: Inter, "Plus Jakarta Sans", system-ui, sans-serif;
}

.cs-ai-chat--with-wa {
    --cs-chat-bottom: 5.5rem;
}

.cs-ai-chat__launcher {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    max-width: min(16rem, calc(100vw - 2rem));
    padding: 0.55rem 0.95rem 0.55rem 0.55rem;
    border: none;
    border-radius: 999px;
    background: var(--cs-chat-primary);
    color: #fff;
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.28);
    font-weight: 700;
    font-size: 0.875rem;
    line-height: 1.2;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.cs-ai-chat__launcher:hover,
.cs-ai-chat__launcher:focus-visible {
    background: var(--cs-chat-primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 16px 32px rgba(37, 99, 235, 0.34);
    outline: none;
}

.cs-ai-chat__launcher-icon {
    width: 2.35rem;
    height: 2.35rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.18);
    flex-shrink: 0;
}

.cs-ai-chat__launcher-icon svg {
    width: 1.25rem;
    height: 1.25rem;
    display: block;
}

.cs-ai-chat__launcher-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cs-ai-chat__panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.75rem);
    width: min(22.5rem, calc(100vw - 2rem));
    height: min(42rem, calc(100vh - 4.5rem));
    max-height: min(42rem, calc(100vh - 4.5rem));
    display: flex;
    flex-direction: column;
    border-radius: 1rem;
    background: var(--cs-chat-surface);
    border: 1px solid var(--cs-chat-border);
    box-shadow: var(--cs-chat-shadow);
    overflow: hidden;
}

.cs-ai-chat__panel[hidden] {
    display: none !important;
}

.cs-ai-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--cs-chat-border);
    background: #f8fafc;
}

.cs-ai-chat__header-title {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--cs-chat-text);
}

.cs-ai-chat__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    border-radius: 0.5rem;
    background: transparent;
    color: var(--cs-chat-muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.cs-ai-chat__close:hover,
.cs-ai-chat__close:focus-visible {
    background: rgba(148, 163, 184, 0.18);
    color: var(--cs-chat-text);
    outline: none;
}

.cs-ai-chat__close svg {
    width: 1.125rem;
    height: 1.125rem;
}

.cs-ai-chat__messages {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    scroll-behavior: smooth;
}

.cs-ai-chat__bubble {
    max-width: 88%;
    padding: 0.65rem 0.85rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    display: flex;
    flex-direction: column;
    gap: 0.85em; /* ~1 baris kosong antar alinea */
}

.cs-ai-chat__para {
    margin: 0;
    white-space: pre-wrap;
}

.cs-ai-chat__link {
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
}

.cs-ai-chat__bubble--assistant .cs-ai-chat__link {
    color: #1d4ed8;
}

.cs-ai-chat__bubble--user .cs-ai-chat__link {
    color: #fff;
}

.cs-ai-chat__bubble--assistant {
    align-self: flex-start;
    background: var(--cs-chat-assistant-bg);
    color: var(--cs-chat-assistant-text);
    border-bottom-left-radius: 0.25rem;
}

.cs-ai-chat__bubble--user {
    align-self: flex-end;
    background: var(--cs-chat-user-bg);
    color: var(--cs-chat-user-text);
    border-bottom-right-radius: 0.25rem;
}

.cs-ai-chat__bubble--error {
    align-self: flex-start;
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.cs-ai-chat__bubble--loading {
    align-self: flex-start;
    background: var(--cs-chat-assistant-bg);
    color: var(--cs-chat-muted);
    font-style: italic;
}

.cs-ai-chat__form {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--cs-chat-border);
    background: #fff;
}

.cs-ai-chat__input {
    flex: 1 1 auto;
    min-height: 2.5rem;
    max-height: 6rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--cs-chat-border);
    border-radius: 0.75rem;
    resize: none;
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--cs-chat-text);
    background: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.cs-ai-chat__input:focus {
    outline: none;
    border-color: var(--cs-chat-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.cs-ai-chat__input:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.cs-ai-chat__send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: none;
    border-radius: 0.75rem;
    background: var(--cs-chat-primary);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, opacity 0.15s ease;
}

.cs-ai-chat__send:hover:not(:disabled),
.cs-ai-chat__send:focus-visible:not(:disabled) {
    background: var(--cs-chat-primary-hover);
    outline: none;
}

.cs-ai-chat__send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.cs-ai-chat__send svg {
    width: 1.125rem;
    height: 1.125rem;
}

.cs-ai-chat.is-open .cs-ai-chat__launcher {
    display: none;
}

/* Keep panel anchored when launcher is hidden */
.cs-ai-chat.is-open .cs-ai-chat__panel {
    position: fixed;
    right: 1rem;
    bottom: 1.25rem;
}

@media (max-width: 575.98px) {
    .cs-ai-chat {
        right: 0.75rem;
        /* Fallback when page has no sticky mobile footer nav */
        --cs-chat-bottom: 0.85rem;
    }

    .cs-ai-chat--with-wa {
        --cs-chat-bottom: 4.75rem;
    }

    .cs-ai-chat__launcher {
        padding-right: 0.8rem;
    }

    .cs-ai-chat__launcher-label {
        max-width: 8.5rem;
    }

    .cs-ai-chat__panel {
        position: fixed;
        inset: 0;
        right: 0;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        border: none;
        z-index: 1080;
    }

    .cs-ai-chat__header {
        padding-top: calc(0.85rem + env(safe-area-inset-top, 0px));
    }

    .cs-ai-chat__messages {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
    }

    .cs-ai-chat__form {
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    }
}

/* Clear sticky public footer nav on phones/tablets (mirrors .whatsapp-float rules) */
@media (max-width: 1199.98px) {
    body.has-mobile-footer-nav .cs-ai-chat {
        bottom: calc(var(--frontend-mobile-footer-nav-height, 4.25rem) + env(safe-area-inset-bottom, 0px) + 0.85rem);
    }

    body.has-mobile-footer-nav .cs-ai-chat--with-wa,
    body.has-mobile-footer-nav:has(.whatsapp-float) .cs-ai-chat {
        bottom: calc(var(--frontend-mobile-footer-nav-height, 4.25rem) + env(safe-area-inset-bottom, 0px) + 5.25rem);
    }

    /* Open panel stays full-viewport on mobile; do not pin above footer */
    body.has-mobile-footer-nav .cs-ai-chat__panel {
        bottom: 0;
        max-height: none;
    }
}

@media (max-width: 1199.98px) and (min-width: 576px) {
    .cs-ai-chat__panel {
        position: fixed;
        inset: 0;
        width: 100%;
        max-width: none;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        border: none;
        z-index: 1080;
    }

    .cs-ai-chat__header {
        padding-top: calc(0.85rem + env(safe-area-inset-top, 0px));
    }

    .cs-ai-chat__messages {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
    }

    .cs-ai-chat__form {
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    }
}

body.cs-ai-chat-open {
    overflow: hidden;
}

body.cs-ai-chat-open .frontend-mobile-footer-nav,
body.cs-ai-chat-open .whatsapp-float,
body.cs-ai-chat-open .affiliate-referrer-float {
    visibility: hidden;
    pointer-events: none;
}
