/* ======== DEMO CHAT WIDGET ======== */

/* --- Floating Button --- */
.demo-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #2f3192 0%, #1a1c6e 100%);
    box-shadow: 0 4px 20px rgba(47, 49, 146, 0.4), 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    z-index: 9998;
    padding: 3px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    overflow: visible;
}

.demo-chat-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(47, 49, 146, 0.5), 0 4px 12px rgba(0, 0, 0, 0.2);
}

.demo-chat-btn:active {
    transform: scale(0.95);
}

.demo-chat-btn.demo-chat-btn--hidden {
    transform: scale(0);
    pointer-events: none;
}

.demo-mascot-btn {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    object-position: 50% 20%;
    display: block;
    background: #fff;
}

/* Hi! badge */
.demo-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ff4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    font-family: Arial, sans-serif;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    pointer-events: none;
}

/* --- Chat Panel --- */
.demo-chat-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    height: 520px;
    max-height: calc(100vh - 120px);
    max-height: calc(100dvh - 120px);
    background: var(--card-bg, #fff);
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18), 0 2px 12px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0) translateY(20px);
    transform-origin: bottom right;
    opacity: 0;
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s ease,
                visibility 0.3s ease;
}

.demo-chat-panel.demo-chat-panel--open {
    transform: scale(1) translateY(0);
    opacity: 1;
    visibility: visible;
}

/* --- Header --- */
.demo-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, #2f3192 0%, #1a1c6e 100%);
    color: #fff;
    flex-shrink: 0;
    min-height: 56px;
}

.demo-chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.demo-chat-avatar {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    background: #fff;
}

.demo-mascot-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    object-position: 50% 20%;
    display: block;
    background: #fff;
}

.demo-chat-header-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.demo-chat-title {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
}

.demo-chat-subtitle {
    font-size: 0.7rem;
    opacity: 0.8;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.demo-chat-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}

.demo-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* --- Header Action Buttons --- */
.demo-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.demo-chat-header-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
}

.demo-chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* --- History Panel --- */
.demo-chat-history-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--card-bg, #fff);
    z-index: 10;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.demo-chat-history-panel.demo-history--open {
    transform: translateX(0);
}

.demo-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, #2f3192 0%, #1a1c6e 100%);
    color: #fff;
    flex-shrink: 0;
}

.demo-history-title {
    font-size: 1rem;
    font-weight: 700;
}

.demo-history-back {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}

.demo-history-back:hover {
    background: rgba(255, 255, 255, 0.3);
}

.demo-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
}

.demo-history-empty {
    text-align: center;
    color: #999;
    padding: 40px 16px;
    font-size: 0.85rem;
}

.demo-history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}

.demo-history-item:hover {
    background: #f0f0f5;
}

.demo-history-item.demo-history-item--active {
    background: #e8e8f5;
}

.demo-history-item-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2f3192, #3a3cb5);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.demo-history-item-icon svg {
    width: 16px;
    height: 16px;
    fill: #fff;
}

.demo-history-item-content {
    flex: 1;
    min-width: 0;
}

.demo-history-item-title {
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #1a1a2e;
    line-height: 1.3;
}

.demo-history-item-time {
    font-size: 0.7rem;
    color: #999;
    line-height: 1.3;
}

.demo-history-item-delete {
    background: none;
    border: none;
    color: #ccc;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.demo-history-item-delete:hover {
    color: #e53935;
    background: rgba(229, 57, 53, 0.1);
}

/* --- Messages Area --- */
.demo-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}

.demo-msg {
    display: flex;
    max-width: 85%;
    animation: msgFadeIn 0.3s ease;
}

.demo-msg--bot {
    align-self: flex-start;
}

.demo-msg--user {
    align-self: flex-end;
}

.demo-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.875rem;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: break-word;
}

.demo-msg--bot .demo-msg-bubble {
    background: #f0f0f5;
    color: #1a1a2e;
    border-bottom-left-radius: 4px;
}

.demo-msg--user .demo-msg-bubble {
    background: linear-gradient(135deg, #2f3192, #3a3cb5);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* --- Product Cards --- */
.demo-products {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.demo-product-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.2s, transform 0.15s;
    min-height: 56px;
}

.demo-product-card:hover {
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}

.demo-product-img {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    background: #f5f5f5;
}

.demo-product-info {
    flex: 1;
    min-width: 0;
}

.demo-product-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: #1a1a2e;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
}

.demo-product-price {
    font-size: 0.75rem;
    color: #2f3192;
    font-weight: 700;
    margin-top: 2px;
}

.demo-product-arrow {
    color: #999;
    flex-shrink: 0;
    font-size: 1.1rem;
}

/* --- Typing Indicator --- */
.demo-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    align-self: flex-start;
    padding: 4px 0;
}

.demo-typing-avatar {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    perspective: 400px;
}

.demo-typing-avatar .demo-mascot-avatar {
    /* no animation */
}

.demo-typing-dots {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    background: #f0f0f5;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.demo-typing-dots span {
    width: 7px;
    height: 7px;
    background: #999;
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.demo-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.demo-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* --- Input Area --- */
.demo-chat-input-area {
    padding: 12px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    background: var(--card-bg, #fff);
}

.demo-chat-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.demo-chat-input {
    flex: 1;
    border: 1.5px solid #ddd;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s;
    background: #fafafa;
    min-width: 0;
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}

.demo-chat-input:focus {
    border-color: #2f3192;
    background: #fff;
}

.demo-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #2f3192, #3a3cb5);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.demo-chat-send:hover {
    transform: scale(1.05);
}

.demo-chat-send:active {
    transform: scale(0.92);
}

.demo-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* --- Markdown-lite in bot messages --- */
.demo-msg--bot .demo-msg-bubble strong {
    font-weight: 700;
}

.demo-msg--bot .demo-msg-bubble a {
    color: #2f3192;
    text-decoration: underline;
}

.demo-msg--bot .demo-msg-bubble ul {
    margin: 6px 0 2px 0;
    padding-left: 18px;
}

.demo-msg--bot .demo-msg-bubble li {
    margin-bottom: 3px;
}

/* ======== 3D MASCOT ANIMATIONS ======== */

@keyframes mascotBtnBob {
    0%, 100% { transform: translateY(0) rotateY(0deg); }
    25% { transform: translateY(-3px) rotateY(5deg); }
    50% { transform: translateY(-1px) rotateY(0deg); }
    75% { transform: translateY(-3px) rotateY(-5deg); }
}

@keyframes mascotIdle {
    0%, 100% { transform: translateY(0) rotateY(0deg) rotateX(0deg); }
    25% { transform: translateY(-2px) rotateY(4deg) rotateX(2deg); }
    50% { transform: translateY(0) rotateY(0deg) rotateX(0deg); }
    75% { transform: translateY(-2px) rotateY(-4deg) rotateX(-2deg); }
}

@keyframes mascotThinking {
    0%, 100% { transform: rotateZ(0deg) scale(1); }
    25% { transform: rotateZ(-8deg) scale(1.05); }
    50% { transform: rotateZ(0deg) scale(1); }
    75% { transform: rotateZ(8deg) scale(1.05); }
}

@keyframes mascotWave {
    0% { transform: rotate(0deg); }
    15% { transform: rotate(-20deg); }
    30% { transform: rotate(15deg); }
    45% { transform: rotate(-15deg); }
    60% { transform: rotate(10deg); }
    75% { transform: rotate(-5deg); }
    100% { transform: rotate(0deg); }
}

@keyframes mascotTalking {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

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

@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes chatSlideUp {
    from { transform: scale(0.8) translateY(30px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

/* --- Mascot State Classes --- */
.demo-mascot-avatar.mascot--thinking {
    /* no animation */
}

.demo-mascot-avatar.mascot--talking {
    /* no animation */
}

/* ======== RESPONSIVE DESIGN ======== */

/* Tablet - medium screens */
@media (max-width: 768px) {
    .demo-chat-panel {
        width: 340px;
        height: 480px;
        bottom: 90px;
        right: 16px;
    }

    .demo-chat-btn {
        bottom: 20px;
        right: 16px;
        width: 54px;
        height: 54px;
    }
}

/* Mobile landscape and small tablets */
@media (max-width: 600px) {
    .demo-chat-panel {
        width: calc(100vw - 16px);
        height: calc(100vh - 80px);
        height: calc(100dvh - 80px);
        max-height: none;
        bottom: 8px;
        right: 8px;
        left: 8px;
        border-radius: 14px;
    }

    .demo-chat-btn {
        bottom: 68px; /* above mobile-bottom-nav (44px + gap) */
        right: 16px;
        width: 52px;
        height: 52px;
    }

    .demo-chat-messages {
        padding: 12px;
    }

    .demo-msg {
        max-width: 90%;
    }

    .demo-chat-input-area {
        padding: 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
}

/* Small mobile phones */
@media (max-width: 400px) {
    .demo-chat-panel {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 0;
    }

    .demo-chat-header {
        padding: 10px 14px;
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
    }

    .demo-chat-btn {
        bottom: 64px;
        right: 12px;
        width: 50px;
        height: 50px;
    }

    .demo-msg-bubble {
        font-size: 0.82rem;
        padding: 8px 12px;
    }

    .demo-chat-input {
        padding: 9px 14px;
        font-size: 1rem; /* prevents iOS zoom */
    }

    .demo-chat-send {
        width: 38px;
        height: 38px;
    }

    .demo-product-card {
        padding: 6px 8px;
    }

    .demo-product-img {
        width: 38px;
        height: 38px;
    }

    .demo-product-name {
        font-size: 0.75rem;
    }
}

/* Landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
    .demo-chat-panel {
        height: calc(100vh - 16px);
        height: calc(100dvh - 16px);
        max-height: none;
        bottom: 8px;
        right: 8px;
        width: min(380px, calc(100vw - 80px));
    }

    .demo-chat-btn {
        bottom: 12px;
        right: 12px;
        width: 48px;
        height: 48px;
    }

    .demo-chat-header {
        padding: 8px 14px;
        min-height: 48px;
    }

    .demo-chat-avatar {
        width: 32px;
        height: 32px;
    }

    .demo-chat-messages {
        padding: 10px;
        gap: 8px;
    }

    .demo-chat-input-area {
        padding: 8px;
    }
}

/* Very tall screens (e.g. iPad portrait) */
@media (min-height: 900px) and (min-width: 769px) {
    .demo-chat-panel {
        height: 580px;
    }
}

/* When panel is open on mobile, hide the floating button */
@media (max-width: 600px) {
    .demo-chat-panel.demo-chat-panel--open ~ .demo-chat-btn,
    .demo-chat-widget--open .demo-chat-btn {
        transform: scale(0);
        pointer-events: none;
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    .demo-mascot-btn,
    .demo-mascot-avatar,
    .demo-typing-dots span,
    .demo-msg,
    .demo-chat-panel {
        animation: none !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .demo-chat-panel {
        background: #1a1a2e;
        box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
    }

    .demo-msg--bot .demo-msg-bubble {
        background: #2a2a3e;
        color: #e0e0e0;
    }

    .demo-chat-input-area {
        border-top-color: #333;
        background: #1a1a2e;
    }

    .demo-chat-input {
        background: #2a2a3e;
        border-color: #444;
        color: #e0e0e0;
    }

    .demo-chat-input:focus {
        background: #2a2a3e;
        border-color: #5a5cdd;
    }

    .demo-product-card {
        background: #2a2a3e;
        border-color: #444;
    }

    .demo-product-name {
        color: #e0e0e0;
    }

    .demo-typing-dots {
        background: #2a2a3e;
    }

    .demo-history-item:hover {
        background: #2a2a3e;
    }

    .demo-history-item.demo-history-item--active {
        background: #333360;
    }

    .demo-history-item-title {
        color: #e0e0e0;
    }

    .demo-chat-history-panel {
        background: #1a1a2e;
    }
}
