/* Wrapper: full viewport, no transform so backdrop fixed works */
.wetail-docs-ai-wrapper {
    position: fixed;
    inset: 0;
    z-index: 9998;
    pointer-events: none;
}

.wetail-docs-ai-wrapper * {
    pointer-events: auto;
}

.wetail-docs-ai-wrapper .wetail-docs-ai-backdrop {
    pointer-events: none;
}

/* Backdrop: full viewport, click outside to close when expanded */
.wetail-docs-ai-backdrop {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: transparent;
    backdrop-filter: none;
    transition:
        background 0.4s cubic-bezier(0.33, 1, 0.68, 1),
        backdrop-filter 0.4s cubic-bezier(0.33, 1, 0.68, 1);
}

.wetail-docs-ai-wrapper.is-expanded .wetail-docs-ai-backdrop {
    pointer-events: auto;
    /*background:
    radial-gradient(circle at top left, rgba(126,130,255,0.18), #f90c0c0a 55%), 
    radial-gradient(circle at bottom right, rgba(255,143,143,0.10), rgba(0,0,0,0.12));*/
    backdrop-filter: blur(4px);
}

/* Container: bar at bottom center */
.wetail-docs-ai-container {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    width: 200px;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
}

.wetail-docs-ai-container .wetail-docs-ai-bar-wrap,
.wetail-docs-ai-container .wetail-docs-ai-messages {
    pointer-events: auto;
}

.wetail-docs-ai-bar-wrap {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Message count badge: above bar when chat is closed; click to open chat */
.wetail-docs-ai-message-count {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: -12px;
    z-index: 1;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    color: #111;
    cursor: pointer;
    background: #fff;
    border: 1px solid #ff46083e;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    white-space: nowrap;
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.wetail-docs-ai-wrapper.is-expanded .wetail-docs-ai-message-count {
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(4px);
    pointer-events: none;
}

.wetail-docs-ai-wrapper:not(.is-expanded) .wetail-docs-ai-message-count {
    opacity: 1;
    visibility: visible;
}

.wetail-docs-ai-message-count:empty {
    display: none;
}

.wetail-docs-ai-container {
    transition: bottom 0.5s cubic-bezier(0.33, 1, 0.68, 1), width 0.5s cubic-bezier(0.33, 1, 0.68, 1);
}

.wetail-docs-ai-wrapper.is-expanded .wetail-docs-ai-container {
    bottom: 40px;
    width: min(90vw, 480px);
}

/* Messages area above the bar (overlay, no heavy box) */
.wetail-docs-ai-messages {
    width: 100%;
    max-height: min(60vh, 400px);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 0 0 12px;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    max-height: 0;
    padding: 0;
    overflow: hidden;
    transition: opacity 0.35s ease, visibility 0.35s ease, max-height 0.35s ease, padding 0.35s ease;
}

.wetail-docs-ai-wrapper.is-expanded .wetail-docs-ai-messages {
    opacity: 1;
    visibility: visible;
    /* Remaining viewport height above input bar (expanded at 40px from bottom) */
    max-height: calc(100vh - 120px);
    padding: 0 0 12px;
    overflow-y: auto;
    overflow-x: hidden;
    pointer-events: auto;
}

.wetail-docs-ai-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0;
    max-height: min(60vh, 360px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.wetail-docs-ai-wrapper.is-expanded .wetail-docs-ai-chat-messages {
    max-height: 100%;
}

/* Input bar (pill) with glassmorphism */
.wetail-docs-ai-bar {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 48px;
    padding: 6px 10px 6px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
    box-shadow:
        0 4px 24px rgba(88, 28, 135, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    transition: box-shadow 0.5s cubic-bezier(0.33, 1, 0.68, 1), border-color 0.5s cubic-bezier(0.33, 1, 0.68, 1);
}

.wetail-docs-ai-container.is-expanded .wetail-docs-ai-bar {
    box-shadow:
        0 8px 32px rgba(88, 28, 135, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.18);
}

/* Magic icon in bar: spins 1 turn after bar has expanded/shrunk; smooth ease-in-out (Tailwind-style) */
.wetail-docs-ai-bar-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    margin-right: 10px;
    background: url("../images/magic_icon.svg") center/contain no-repeat;
    color: #111;
    opacity: 0.85;
    transform: rotate(-180deg);
    transition: transform 0.6s cubic-bezier(0.45, 0, 0.55, 1) 0.1s;
}

.wetail-docs-ai-wrapper.is-expanded .wetail-docs-ai-bar-icon {
    transform: rotate(0deg);
}

/* Bar label "Chat" when collapsed */
.wetail-docs-ai-bar-label {
    flex: 1;
    min-width: 0;
    padding: 8px 4px 8px 0;
    font-size: 15px;
    font-weight: 500;
    color: #111;
}

.wetail-docs-ai-wrapper.is-expanded .wetail-docs-ai-bar-label {
    display: none;
}

.wetail-docs-ai-bar .wetail-docs-ai-input {
    flex: 1;
    min-width: 0;
    min-height: 36px;
    padding: 8px 4px 8px 0;
    border: none;
    border-radius: 0;
    background: transparent !important;
    color: #111;
    /* iOS Safari zoom prevention needs at least 16px */
    font-size: 16px !important;
    font-weight: 500  !important;
    line-height: 1.4;
    caret-color: #111;
    transition: opacity 0.2s ease;
}

.wetail-docs-ai-bar .wetail-docs-ai-input::placeholder {
    color: rgba(0, 0, 0, 0.5);
}

.wetail-docs-ai-bar .wetail-docs-ai-input:focus {
    outline: none;
    box-shadow: none;
}

.wetail-docs-ai-wrapper:not(.is-expanded) .wetail-docs-ai-bar .wetail-docs-ai-input {
    display: none;
}

/* Collapse (close) button: two arrows inwards, visible when expanded */
.wetail-docs-ai-bar-close {
    display: none;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: #111;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.33, 1, 0.68, 1), background 0.2s ease;
}

.wetail-docs-ai-wrapper.is-expanded .wetail-docs-ai-bar-close {
    display: flex;
}

.wetail-docs-ai-bar-close:hover {
    background: rgba(255, 255, 255, 0.35);
}

.wetail-docs-ai-bar-close::after {
    content: '';
    width: 14px;
    height: 15px;
    background: url("../images/collapse_icon.svg") center/contain no-repeat;
}

/* Send button (arrow) inside bar */
.wetail-docs-ai-bar .wetail-docs-ai-send {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    margin-left: 10px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #FF4608;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.33, 1, 0.68, 1), opacity 0.3s ease, box-shadow 0.3s cubic-bezier(0.33, 1, 0.68, 1);
    /*box-shadow: 0 2px 8px rgba(136, 58, 234, 0.35);*/
}

.wetail-docs-ai-bar .wetail-docs-ai-send:hover {
    transform: scale(1.05);
    opacity: 1;
    box-shadow: 0 4px 12px rgba(136, 58, 234, 0.45);
}

.wetail-docs-ai-bar .wetail-docs-ai-send:active {
    transform: scale(0.98);
}

.wetail-docs-ai-bar .wetail-docs-ai-send::after {
    content: '';
    width: 14px;
    height: 14px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 2L11 13'/%3E%3Cpath d='M22 2L15 22L11 13L2 9L22 2z'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* Message bubbles (overlay, balanced transparency) */
.wetail-docs-ai-msg {
    max-width: 92%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px  !important;
    font-weight: 500 !important;
    line-height: 1.5 !important;
    color: #111;
    word-wrap: break-word;
    white-space: normal;
    animation: wetail-docs-ai-msg-in 0.45s cubic-bezier(0.33, 1, 0.68, 1) forwards;
}

@keyframes wetail-docs-ai-msg-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.wetail-docs-ai-msg--assistant {
    position: relative;
    padding-right: 40px;
    align-self: flex-start;
    background: linear-gradient(172deg, #ffe9e9d1 0%, rgb(237 250 255 / 70%) 100%);
    border: 1px solid rgb(255, 70,8 / 14%);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(4px);
}

.wetail-docs-ai-msg--thinking {
    padding-right: 14px;
}

.wetail-docs-ai-thinking {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
}

.wetail-docs-ai-thinking__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #111;
    opacity: 0.6;
    animation: wetail-docs-ai-thinking-bounce 0.6s ease-in-out infinite both;
}

.wetail-docs-ai-thinking__dot:nth-child(1) { animation-delay: 0s; }
.wetail-docs-ai-thinking__dot:nth-child(2) { animation-delay: 0.12s; }
.wetail-docs-ai-thinking__dot:nth-child(3) { animation-delay: 0.24s; }

@keyframes wetail-docs-ai-thinking-bounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.6;
    }
    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

.wetail-docs-ai-msg__body {
    display: block;
}

.wetail-docs-ai-msg-copy {
    position: absolute !important;
    top: 8px  !important;
    right: 8px  !important;
    width: 28px  !important;
    height: 28px  !important;
    padding: 0 !important;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.06);
    color: #111;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease;
}

.wetail-docs-ai-msg-copy:hover {
    background: rgba(0, 0, 0, 0.1);
}

.wetail-docs-ai-msg-copy.is-copied {
    background: rgba(34, 197, 94, 0.2);
    color: #15803d;
}

.wetail-docs-ai-msg-copy::before {
    content: '';
    width: 14px;
    height: 14px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='13' height='13' rx='2' ry='2'/%3E%3Cpath d='M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1'/%3E%3C/svg%3E") center/contain no-repeat;
}

.wetail-docs-ai-msg-copy.is-copied::before {
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6L9 17l-5-5'/%3E%3C/svg%3E") center/contain no-repeat;
}

.wetail-docs-ai-msg--assistant a {
    color: #111;
    text-decoration: underline;
}

.wetail-docs-ai-msg--user {
    align-self: flex-end;
    background: #ffffffdf;
    border: 1px solid rgba(0, 0, 0, 0.113);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(4px);
}

/* Legacy / unused (kept if any script still references) */
.wetail-docs-ai-response,
.wetail-docs-ai-response.is-error {
    display: none;
}

@media (max-width: 640px) {
    .wetail-docs-ai-container.is-expanded {
        width: calc(100vw - 32px);
        left: 50%;
        transform: translateX(-50%);
        /* Keep exact expanded position on mobile too */
        bottom: 40px;
    }

    .wetail-docs-ai-wrapper.is-expanded .wetail-docs-ai-messages {
        max-height: calc(100vh - 120px);
        padding: 0 0 10px;
    }

    .wetail-docs-ai-wrapper.is-expanded .wetail-docs-ai-chat-messages {
        max-height: 100%;
    }
}
