/* ===== Zapoye AI Chatbot ===== */

body:has(.chatbot) .back-to-top {
    bottom: 92px;
}

@media (max-width: 768px) {
    body:has(.chatbot) .back-to-top {
        bottom: calc(84px + env(safe-area-inset-bottom));
    }
}

.chatbot {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1100;
    font-family: var(--font);
}

/* ── Toggle ── */
.chatbot-toggle {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(145deg, #6e3dfc 0%, #9333ea 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 8px 32px rgba(110, 61, 252, 0.45),
        0 0 0 4px rgba(110, 61, 252, 0.12);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.chatbot-toggle:hover {
    transform: scale(1.05);
    box-shadow:
        0 12px 36px rgba(110, 61, 252, 0.5),
        0 0 0 4px rgba(110, 61, 252, 0.18);
}

.chatbot-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.chatbot-toggle-icon--close {
    position: absolute;
    opacity: 0;
    transform: scale(0.7) rotate(-90deg);
}

.chatbot.is-open .chatbot-toggle-icon--open {
    opacity: 0;
    transform: scale(0.7) rotate(90deg);
}

.chatbot.is-open .chatbot-toggle-icon--close {
    opacity: 1;
    transform: scale(1) rotate(0);
}

.chatbot-toggle-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(110, 61, 252, 0.45);
    animation: chatbotPulse 2.5s ease-out infinite;
    pointer-events: none;
}

.chatbot.is-open .chatbot-toggle-pulse {
    display: none;
}

@keyframes chatbotPulse {
    0% { transform: scale(1); opacity: 0.7; }
    100% { transform: scale(1.35); opacity: 0; }
}

.chatbot-toggle-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2.5px solid #fff;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

.chatbot-toggle-badge[hidden] {
    display: none;
}

.chatbot.is-open .chatbot-toggle-badge {
    display: none;
}

/* ── Panel ── */
.chatbot-panel {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 400px;
    max-width: calc(100vw - 28px);
    height: 580px;
    max-height: calc(100dvh - 110px);
    background: #fff;
    border-radius: 24px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow:
        0 24px 80px rgba(0, 0, 0, 0.18),
        0 0 0 1px rgba(110, 61, 252, 0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: opacity 0.32s ease, visibility 0.32s ease, transform 0.32s cubic-bezier(0.34, 1.4, 0.64, 1);
}

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

/* ── Header ── */
.chatbot-header {
    position: relative;
    flex-shrink: 0;
    overflow: hidden;
}

.chatbot-header-bg {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #6e3dfc 0%, #7c3aed 45%, #9333ea 100%);
}

.chatbot-header-bg::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 120%, rgba(255, 255, 255, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 90% -20%, rgba(255, 255, 255, 0.12) 0%, transparent 40%);
}

.chatbot-header-content {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 18px 20px;
    color: #fff;
}

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.chatbot-avatar {
    position: relative;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

.chatbot-avatar-letter {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
    font-size: 1.25rem;
    font-weight: 800;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.chatbot-avatar-ring {
    position: absolute;
    inset: -3px;
    border-radius: 17px;
    border: 2px solid rgba(255, 255, 255, 0.25);
    animation: chatbotRing 3s linear infinite;
}

@keyframes chatbotRing {
    to { transform: rotate(360deg); }
}

.chatbot-title {
    font-size: 1.0625rem;
    font-weight: 800;
    line-height: 1.2;
    margin: 0;
    letter-spacing: -0.02em;
}

.chatbot-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    opacity: 0.9;
    margin-top: 3px;
}

.chatbot-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.8);
    animation: chatbotStatusBlink 2s ease-in-out infinite;
}

@keyframes chatbotStatusBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chatbot-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.22);
}

/* ── Body / Messages ── */
.chatbot-body {
    flex: 1;
    min-height: 0;
    background: #f4f4f6;
    position: relative;
}

.chatbot-body::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(110, 61, 252, 0.04) 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
}

.chatbot-messages {
    position: relative;
    height: 100%;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
    width: 5px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(110, 61, 252, 0.25);
    border-radius: 4px;
}

.chatbot-date-label {
    align-self: center;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid var(--border);
}

.chatbot-msg {
    display: flex;
    gap: 10px;
    max-width: 88%;
    animation: chatbotMsgIn 0.35s cubic-bezier(0.34, 1.2, 0.64, 1);
}

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

.chatbot-msg--bot {
    align-self: flex-start;
    max-width: 94%;
}

.chatbot-msg--user {
    align-self: flex-end;
    flex-direction: row-reverse;
    max-width: 88%;
}

.chatbot-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--purple), #9333ea);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 800;
    margin-top: 4px;
    box-shadow: 0 2px 8px rgba(110, 61, 252, 0.25);
}

.chatbot-msg--user .chatbot-msg-avatar {
    background: #1a1a1e;
    box-shadow: none;
    font-size: 0.625rem;
}

.chatbot-msg-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.chatbot-bubble {
    padding: 12px 15px;
    border-radius: 18px;
    font-size: 0.875rem;
    line-height: 1.6;
    word-break: break-word;
}

.chatbot-msg--bot .chatbot-bubble {
    background: #fff;
    color: var(--text);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    padding: 14px 16px;
}

.chatbot-bubble--md {
    min-width: 0;
}

.chatbot-msg--user .chatbot-bubble {
    background: linear-gradient(135deg, #6e3dfc, #7c3aed);
    color: #fff;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 14px rgba(110, 61, 252, 0.3);
}

.chatbot-msg-time {
    font-size: 0.625rem;
    font-weight: 500;
    color: var(--text-muted);
    padding: 0 4px;
}

.chatbot-msg--user .chatbot-msg-time {
    text-align: right;
}

.chatbot-bubble a {
    color: var(--purple);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chatbot-msg--user .chatbot-bubble a {
    color: #fff;
}

.chatbot-bubble strong {
    font-weight: 700;
    color: var(--text);
}

/* ChatGPT-style prose */
.chatbot-prose {
    font-size: 0.875rem;
    line-height: 1.65;
}

.chatbot-prose > *:first-child {
    margin-top: 0 !important;
}

.chatbot-prose > *:last-child {
    margin-bottom: 0 !important;
}

.chatbot-prose p {
    margin: 0 0 12px;
}

.chatbot-prose h3 {
    font-size: 0.9375rem;
    font-weight: 800;
    margin: 16px 0 8px;
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1.35;
}

.chatbot-prose h3:first-child {
    margin-top: 0;
}

.chatbot-prose h4 {
    font-size: 0.875rem;
    font-weight: 700;
    margin: 14px 0 6px;
    color: var(--text);
}

.chatbot-prose ul,
.chatbot-prose ol {
    margin: 4px 0 14px;
    padding-left: 1.35em;
}

.chatbot-prose li {
    margin: 6px 0;
    padding-left: 2px;
}

.chatbot-prose ul li::marker {
    color: var(--purple);
}

.chatbot-prose ol li::marker {
    font-weight: 700;
    color: var(--purple);
}

.chatbot-prose blockquote {
    margin: 12px 0;
    padding: 10px 14px;
    border-left: 3px solid var(--purple);
    background: rgba(110, 61, 252, 0.05);
    border-radius: 0 10px 10px 0;
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

.chatbot-prose hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 14px 0;
}

.chatbot-prose code {
    font-family: ui-monospace, 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.8125em;
    background: #f0f0f3;
    color: #7c3aed;
    padding: 2px 7px;
    border-radius: 5px;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.chatbot-prose pre {
    margin: 12px 0;
    padding: 14px 16px;
    background: #1a1a1e;
    border-radius: 10px;
    overflow-x: auto;
}

.chatbot-prose pre code {
    display: block;
    background: none;
    border: none;
    padding: 0;
    color: #e4e4e7;
    font-size: 0.8125rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.chatbot-product-list {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chatbot-bubble ul,
.chatbot-bubble ol {
    margin: 6px 0 0;
    padding-left: 18px;
}

.chatbot-bubble li {
    margin: 4px 0;
}

.chatbot-product-card {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
    padding: 10px;
    background: #f8f8fa;
    border-radius: 12px;
    border: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.chatbot-product-card:hover {
    border-color: rgba(110, 61, 252, 0.35);
    transform: translateX(2px);
    color: inherit;
}

.chatbot-product-card img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: 10px;
    background: #fff;
    flex-shrink: 0;
}

.chatbot-product-card span {
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.35;
}

.chatbot-product-card small {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--purple);
    margin-top: 3px;
}

/* Typing */
.chatbot-typing-wrap {
    display: flex;
    gap: 10px;
    align-self: flex-start;
    max-width: 88%;
}

.chatbot-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
    background: #fff;
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.chatbot-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--purple);
    opacity: 0.4;
    animation: chatbotTyping 1.3s ease-in-out infinite;
}

.chatbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatbotTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Footer ── */
.chatbot-footer {
    flex-shrink: 0;
    background: #fff;
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}

.chatbot-quick-scroll {
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chatbot-quick-scroll::-webkit-scrollbar {
    display: none;
}

.chatbot-quick {
    display: flex;
    gap: 8px;
    padding: 12px 16px 0;
    width: max-content;
    min-width: 100%;
}

.chatbot-quick:empty {
    display: none;
}

.chatbot-chip {
    flex-shrink: 0;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--purple);
    background: rgba(110, 61, 252, 0.07);
    border: 1px solid rgba(110, 61, 252, 0.15);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.chatbot-chip:hover {
    background: rgba(110, 61, 252, 0.14);
    border-color: rgba(110, 61, 252, 0.35);
    transform: translateY(-1px);
}

.chatbot-compose {
    padding: 12px 16px 6px;
}

.chatbot-input-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 6px 6px 16px;
    background: #f4f4f6;
    border: 1px solid var(--border);
    border-radius: 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chatbot-input-box:focus-within {
    border-color: rgba(110, 61, 252, 0.4);
    box-shadow: 0 0 0 3px rgba(110, 61, 252, 0.1);
    background: #fff;
}

.chatbot-input {
    flex: 1;
    height: 38px;
    border: none;
    background: transparent;
    font-size: 0.875rem;
    color: var(--text);
    outline: none;
}

.chatbot-input::placeholder {
    color: var(--text-muted);
}

.chatbot-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--purple), #7c3aed);
    color: #fff;
    flex-shrink: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.chatbot-send:hover:not(:disabled) {
    transform: scale(1.06);
}

.chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-footer-note {
    text-align: center;
    font-size: 0.625rem;
    font-weight: 500;
    color: var(--text-muted);
    padding: 4px 16px 10px;
    letter-spacing: 0.02em;
}

/* ── Mobile ── */
@media (max-width: 480px) {
    .chatbot {
        bottom: calc(16px + env(safe-area-inset-bottom));
        right: calc(16px + env(safe-area-inset-right));
    }

    .chatbot-toggle {
        width: 56px;
        height: 56px;
    }

    .chatbot-panel {
        width: calc(100vw - 32px);
        height: min(580px, calc(100dvh - 96px));
        bottom: 70px;
        border-radius: 20px;
    }

    .chatbot-msg {
        max-width: 92%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chatbot-panel,
    .chatbot-msg,
    .chatbot-toggle-pulse,
    .chatbot-avatar-ring,
    .chatbot-status-dot {
        animation: none;
        transition: none;
    }
}
