/* chatbot-floating.css */

/* Floating Button */
.jd-chatbot-trigger-wrapper {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 999990;
    max-width: calc(100vw - 24px);
}

@media (max-width: 1024px) {
    .jd-chatbot-trigger-wrapper {
        bottom: 24px;
        right: 24px;
    }
}

@media (max-width: 768px) {
    .jd-chatbot-trigger-wrapper {
        bottom: calc(18px + env(safe-area-inset-bottom, 0px));
        right: 16px;
    }
}

.jd-chatbot-trigger-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #1a56f0;
    color: #fff;
    border: none;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s;
}

.jd-chatbot-trigger-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

.jd-chatbot-trigger-btn svg {
    width: 30px;
    height: 30px;
    transition: transform 0.3s, opacity 0.3s;
}

.jd-chatbot-icon-open, .jd-chatbot-icon-close {
    position: absolute;
}
.jd-chatbot-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.jd-chatbot-trigger-wrapper.jd-chat-open .jd-chatbot-icon-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}
.jd-chatbot-trigger-wrapper.jd-chat-open .jd-chatbot-icon-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}
.jd-chatbot-trigger-wrapper.jd-chat-open .jd-chatbot-trigger-btn {
    background: #ff5252;
}

/* Chat Window */
.jd-chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 360px;
    height: 550px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999991;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);
    overscroll-behavior: contain;
}

@media (max-width: 1024px) {
    .jd-chatbot-window {
        right: 20px;
        bottom: 90px;
        width: min(420px, calc(100vw - 40px));
        height: min(680px, calc(100vh - 128px));
        max-height: calc(100vh - 128px);
        border-radius: 18px;
    }
}

@media (max-width: 768px) {
    .jd-chatbot-window {
        right: 12px;
        left: 12px;
        bottom: calc(84px + env(safe-area-inset-bottom, 0px));
        width: auto;
        height: min(78vh, 620px);
        max-height: calc(100vh - 104px - env(safe-area-inset-bottom, 0px));
        border-radius: 18px;
    }
}

@media (max-width: 640px) {
    .jd-chatbot-window {
        right: 10px;
        left: 10px;
        bottom: calc(80px + env(safe-area-inset-bottom, 0px));
        height: min(74vh, 600px);
        max-height: calc(100vh - 96px - env(safe-area-inset-bottom, 0px));
        border-radius: 16px;
    }
}

.jd-chatbot-window.jd-show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.jd-chatbot-header {
    background: #1a56f0;
    color: #fff;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
}
.jd-chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}
.jd-chatbot-avatar svg {
    width: 24px;
    height: 24px;
}
.jd-chatbot-header-info {
    flex: 1;
}
.jd-chatbot-title {
    margin: 0 0 2px 0;
    font-size: 16px;
    font-weight: 700;
}
.jd-chatbot-status {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 4px;
}
.jd-chatbot-dot {
    width: 8px;
    height: 8px;
    background: #4caf50;
    border-radius: 50%;
    display: inline-block;
}

/* Body */
.jd-chatbot-body {
    flex: 1;
    background: #f8f9fa;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.jd-chatbot-actions {
    display: none;
    padding: 14px 16px 10px;
    background: linear-gradient(180deg, rgba(248,249,250,0.3) 0%, #ffffff 45%);
    border-top: 1px solid #eef2f7;
    box-shadow: 0 -10px 24px rgba(15, 23, 42, 0.04);
}

.jd-chatbot-actions.jd-has-actions {
    display: block;
}

/* Message Bubbles */
.jd-chat-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    animation: jdFadeInUp 0.3s ease;
    word-wrap: break-word;
}

@media (max-width: 1024px) {
    .jd-chatbot-header {
        padding: 18px;
        gap: 12px;
    }

    .jd-chatbot-body {
        padding: 18px;
        gap: 10px;
    }

    .jd-chat-msg {
        max-width: 88%;
    }
}

@media (max-width: 640px) {
    .jd-chatbot-header {
        padding: 14px;
        gap: 10px;
    }

    .jd-chatbot-avatar {
        width: 36px;
        height: 36px;
    }

    .jd-chatbot-avatar svg {
        width: 20px;
        height: 20px;
    }

    .jd-chatbot-title {
        font-size: 15px;
        line-height: 1.3;
    }

    .jd-chatbot-status {
        font-size: 11px;
    }

    .jd-chatbot-body {
        padding: 14px;
        gap: 10px;
    }

    .jd-chat-msg {
        max-width: 92%;
        padding: 11px 13px;
        font-size: 13px;
        line-height: 1.45;
        border-radius: 14px;
    }
}
@keyframes jdFadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.jd-msg-bot {
    align-self: flex-start;
    background: #fff;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.03);
}
.jd-msg-user {
    align-self: flex-end;
    background: #1a56f0;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.jd-chat-inline-link {
    color: #1a56f0;
    font-weight: 600;
    text-decoration: none;
}

.jd-chat-inline-link:hover {
    text-decoration: underline;
}

.jd-chat-cta {
    margin-top: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 11px 16px;
    border-radius: 14px;
    background: linear-gradient(135deg, #1a56f0 0%, #1545c0 100%);
    color: #ffffff !important;
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    box-shadow: 0 10px 24px rgba(26, 86, 240, 0.22);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.jd-chat-cta:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 28px rgba(26, 86, 240, 0.28);
}

.jd-chat-cta.jd-is-loading {
    opacity: 0.8;
    pointer-events: none;
}

.jd-chat-product-list {
    display: grid;
    gap: 12px;
    margin-top: 2px;
    width: 100%;
}

.jd-chat-product-card {
    display: grid;
    grid-template-columns: 78px minmax(0, 1fr);
    gap: 12px;
    width: 100%;
    padding: 14px;
    border: 1px solid #e7eefc;
    border-radius: 18px;
    background: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
    box-shadow: 0 10px 24px rgba(19, 55, 122, 0.08);
    animation: jdFadeInUp 0.25s ease both;
    align-items: start;
}

.jd-chat-product-media {
    width: 78px;
    height: 78px;
    border-radius: 14px;
    overflow: hidden;
    background: #eef4ff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.jd-chat-product-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.jd-chat-product-content {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.jd-chat-product-title {
    margin: 0 0 6px;
    color: var(--jd-chatbot-theme-color, #1a56f0);
    font-size: 15px;
    font-weight: 800;
    line-height: 1.35;
}

.jd-chat-product-price {
    margin-bottom: 8px;
    color: #14233d;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.3;
}

.jd-chat-product-price del {
    color: #8a94a6;
    font-weight: 600;
    margin-right: 6px;
}

.jd-chat-product-price ins {
    color: #c62828;
    text-decoration: none;
}

.jd-chat-product-meta {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 4px;
}

.jd-chat-product-meta li {
    color: #58657a;
    font-size: 12px;
    line-height: 1.45;
}

.jd-chat-product-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.jd-chat-product-primary,
.jd-chat-product-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 9px 14px;
    border-radius: 999px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    white-space: nowrap;
}

.jd-chat-product-primary {
    background: linear-gradient(135deg, var(--jd-chatbot-theme-color, #1a56f0) 0%, #1545c0 100%);
    color: #fff !important;
    box-shadow: 0 10px 18px rgba(26, 86, 240, 0.2);
}

.jd-chat-product-secondary {
    background: #fff;
    color: var(--jd-chatbot-theme-color, #1a56f0);
    border: 1px solid rgba(26, 86, 240, 0.2);
}

.jd-chat-product-primary:hover,
.jd-chat-product-secondary:hover {
    transform: translateY(-1px);
}

/* Quick Replies */
.jd-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 0;
    animation: jdFadeInUp 0.25s ease both;
}
.jd-qr-btn {
    background: linear-gradient(180deg, #ffffff 0%, #eef4ff 100%);
    border: 1px solid #c7d7fe;
    color: #1a56f0;
    padding: 9px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(26, 86, 240, 0.08);
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}
.jd-qr-btn:hover {
    background: #1a56f0;
    color: #fff;
    border-color: #1a56f0;
    transform: translateY(-1px);
}

.jd-chatbot-actions .jd-qr-btn {
    min-height: 36px;
}

@media (max-width: 768px) {
    .jd-chatbot-actions {
        padding: 12px 12px 10px;
    }

    .jd-chatbot-actions .jd-quick-replies {
        gap: 7px;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .jd-chatbot-actions .jd-quick-replies::-webkit-scrollbar {
        display: none;
    }

    .jd-chatbot-actions .jd-qr-btn {
        font-size: 12px;
        padding: 8px 12px;
        flex: 0 0 auto;
    }

    .jd-chat-product-card {
        grid-template-columns: 64px minmax(0, 1fr);
        gap: 10px;
        padding: 12px;
        border-radius: 16px;
    }

    .jd-chat-product-media {
        width: 64px;
        height: 64px;
        border-radius: 12px;
    }

    .jd-chat-product-title {
        font-size: 14px;
    }

    .jd-chat-product-price {
        font-size: 13px;
    }

    .jd-chat-product-primary,
    .jd-chat-product-secondary {
        flex: 1 1 calc(50% - 4px);
        min-height: 42px;
        padding: 10px 12px;
        font-size: 12px;
    }
}

@media (max-width: 640px) {
    .jd-chat-product-list {
        gap: 10px;
    }

    .jd-chat-product-card {
        grid-template-columns: 56px minmax(0, 1fr);
        gap: 10px;
        padding: 11px;
        border-radius: 14px;
    }

    .jd-chat-product-media {
        width: 56px;
        height: 56px;
        border-radius: 10px;
    }

    .jd-chat-product-title {
        font-size: 13px;
        line-height: 1.32;
    }

    .jd-chat-product-price {
        margin-bottom: 6px;
        font-size: 12px;
    }

    .jd-chat-product-meta li {
        font-size: 11px;
        line-height: 1.38;
    }

    .jd-chat-product-actions {
        gap: 7px;
        margin-top: 10px;
    }

    .jd-chat-product-primary,
    .jd-chat-product-secondary {
        flex: 1 1 100%;
        min-height: 40px;
        padding: 9px 12px;
        font-size: 12px;
    }

    .jd-chatbot-actions {
        padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .jd-chatbot-actions .jd-quick-replies {
        gap: 6px;
    }

    .jd-chatbot-actions .jd-qr-btn {
        min-height: 38px;
        padding: 8px 11px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .jd-chatbot-trigger-wrapper {
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    .jd-chatbot-trigger-btn {
        width: 56px;
        height: 56px;
    }

    .jd-chatbot-trigger-btn svg {
        width: 28px;
        height: 28px;
    }

    .jd-chatbot-window {
        right: 8px;
        left: 8px;
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
        height: min(80vh, 640px);
        max-height: calc(100vh - 88px - env(safe-area-inset-bottom, 0px));
        border-radius: 16px;
    }

    .jd-chatbot-header {
        padding: 12px;
    }

    .jd-chatbot-body {
        padding: 12px;
        gap: 9px;
    }

    .jd-chat-msg {
        max-width: 94%;
    }

    .jd-chat-product-card {
        grid-template-columns: 52px minmax(0, 1fr);
        padding: 10px;
        gap: 9px;
    }

    .jd-chat-product-media {
        width: 52px;
        height: 52px;
    }
}

/* Typing Indicator */
.jd-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 14px 18px;
}
.jd-typing-dot {
    width: 6px;
    height: 6px;
    background: #a0a0a0;
    border-radius: 50%;
    animation: jdTypingBounce 1.4s infinite ease-in-out both;
}
.jd-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.jd-typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes jdTypingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Input Area */
.jd-chatbot-footer {
    padding: 16px;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 10px;
}

@media (max-width: 1024px) {
    .jd-chatbot-footer {
        padding: 14px;
        gap: 9px;
    }
}

@media (max-width: 1024px) {
    .jd-chat-cta {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .jd-chat-cta {
        min-height: 44px;
        border-radius: 12px;
        padding: 12px 14px;
        font-size: 13px;
    }
}
.jd-chatbot-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    background: #fcfcfc;
}
.jd-chatbot-input:focus {
    border-color: #1a56f0;
    background: #fff;
}
.jd-chatbot-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #1a56f0;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
}
.jd-chatbot-send-btn:hover {
    background: #1545c0;
}
.jd-chatbot-send-btn:active {
    transform: scale(0.95);
}
.jd-chatbot-send-btn svg {
    margin-left: 2px;
}

@media (max-width: 640px) {
    .jd-chatbot-footer {
        padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
        gap: 8px;
    }

    .jd-chatbot-input {
        min-width: 0;
        padding: 11px 14px;
        font-size: 13px;
        border-radius: 18px;
    }

    .jd-chatbot-send-btn {
        width: 42px;
        height: 42px;
        flex: 0 0 42px;
    }

    .jd-chatbot-send-btn svg {
        width: 18px;
        height: 18px;
    }
}
