/* ═══════════════════════════════════════════════════════════════
   THE BUUT B STORE — AI Chatbot Widget
   Premium floating chat UI · Dark glassmorphism · Mobile-first
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
    --chat-primary: #10b981;
    --chat-primary-glow: rgba(16, 185, 129, 0.3);
    --chat-dark: #0f172a;
    --chat-dark-mid: #1e293b;
    --chat-dark-surface: #263348;
    --chat-border: rgba(255, 255, 255, 0.06);
    --chat-text: #f1f5f9;
    --chat-text-muted: #94a3b8;
    --chat-radius: 20px;
    --chat-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.5),
                   0 0 0 1px rgba(255, 255, 255, 0.05);
    --chat-width: 400px;
    --chat-height: 580px;
    --chat-font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── Floating Premium Toggle Button ── */
#chatbot-toggle {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 9998;
    height: 60px;
    width: 60px; /* Expands on hover */
    border-radius: 30px;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, #10b981, #0ea5e9, #6366f1);
    background-size: 200% 200%;
    color: white;
    display: flex;
    align-items: center;
    padding: 0;
    box-shadow: 0 10px 25px rgba(14, 165, 233, 0.3),
                inset 0 0 0 1px rgba(255, 255, 255, 0.2);
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    outline: none;
    -webkit-tap-highlight-color: transparent;
    animation: chatOrbGradient 4s ease infinite;
    overflow: hidden;
}

@keyframes chatOrbGradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.chat-toggle-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    position: relative;
    padding: 0 18px; /* Centers the icon perfectly */
}

#chatbot-toggle .chat-toggle-text {
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    opacity: 0;
    transform: translateX(-10px);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    width: 0;
    overflow: hidden;
    margin-left: 0;
}

#chatbot-toggle:hover {
    width: 135px;
    box-shadow: 0 15px 35px rgba(99, 102, 241, 0.4),
                inset 0 0 0 1px rgba(255, 255, 255, 0.3);
    transform: translateY(-4px);
}

#chatbot-toggle:hover .chat-toggle-text {
    opacity: 1;
    transform: translateX(0);
    width: auto;
    margin-left: 8px;
}

#chatbot-toggle:active {
    transform: translateY(0) scale(0.95);
}

#chatbot-toggle svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

#chatbot-toggle .chat-icon-close {
    position: absolute;
    left: 18px;
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

#chatbot-toggle.active {
    width: 60px;
    border-radius: 50%;
    transform: scale(0.9);
}

#chatbot-toggle.active .chat-toggle-text {
    display: none;
}

#chatbot-toggle.active .chat-icon-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

#chatbot-toggle.active .chat-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Premium Notification Dot */
#chatbot-toggle .chat-notification {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background: #f43f5e;
    border-radius: 50%;
    border: 2px solid #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    color: transparent;
    animation: chatPulseNotifNew 2s infinite;
}

@keyframes chatPulseNotifNew {
    0% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.6); }
    70% { box-shadow: 0 0 0 8px rgba(244, 63, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0); }
}

/* ── Chat Window ── */
#chatbot-window {
    position: fixed;
    bottom: 100px;
    left: 30px;
    z-index: 9999;
    width: var(--chat-width);
    height: var(--chat-height);
    max-height: calc(100dvh - 130px);
    background: var(--chat-dark);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--chat-font);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom left;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid var(--chat-border);
}

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

/* ── Chat Header ── */
.chatbot-header {
    background: linear-gradient(135deg, var(--chat-dark-mid), var(--chat-dark));
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.chatbot-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--chat-primary), #059669);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.chatbot-header-avatar svg {
    width: 22px;
    height: 22px;
    color: white;
}

.chatbot-header-info {
    flex: 1;
    min-width: 0;
}

.chatbot-header-title {
    font-size: 15px;
    font-weight: 800;
    color: var(--chat-text);
    letter-spacing: -0.02em;
    margin: 0;
    line-height: 1.2;
}

.chatbot-header-status {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
}

.chatbot-header-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chat-primary);
    animation: chatStatusPulse 2s ease-in-out infinite;
}

@keyframes chatStatusPulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 var(--chat-primary-glow); }
    50% { opacity: 0.7; box-shadow: 0 0 0 4px transparent; }
}

.chatbot-header-status span {
    font-size: 11px;
    font-weight: 600;
    color: var(--chat-text-muted);
}

.chatbot-header-close {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: 1px solid var(--chat-border);
    background: transparent;
    color: var(--chat-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chatbot-header-close:hover {
    background: rgba(255, 255, 255, 0.08);
    color: white;
}

.chatbot-header-close svg {
    width: 16px;
    height: 16px;
}

/* ── Chat Messages Area ── */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: linear-gradient(180deg, var(--chat-dark) 0%, #0c1524 100%);
    scroll-behavior: smooth;
}

/* Custom scrollbar */
.chatbot-messages::-webkit-scrollbar {
    width: 5px;
}
.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}
.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ── Message Bubbles ── */
.chat-msg {
    display: flex;
    gap: 10px;
    max-width: 88%;
    animation: chatMsgIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes chatMsgIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Bot messages — left aligned */
.chat-msg.bot {
    align-self: flex-start;
}

.chat-msg.bot .chat-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--chat-primary), #059669);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-msg.bot .chat-msg-avatar svg {
    width: 14px;
    height: 14px;
    color: white;
}

.chat-msg.bot .chat-bubble {
    background: var(--chat-dark-surface);
    color: var(--chat-text);
    border-radius: 4px 16px 16px 16px;
    padding: 12px 16px;
    font-size: 13.5px;
    line-height: 1.6;
    border: 1px solid var(--chat-border);
}

/* User messages — right aligned */
.chat-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg.user .chat-bubble {
    background: linear-gradient(135deg, var(--chat-primary), #059669);
    color: white;
    border-radius: 16px 4px 16px 16px;
    padding: 12px 16px;
    font-size: 13.5px;
    line-height: 1.6;
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.25);
}

/* ── Links in bot messages ── */
.chat-bubble a {
    color: var(--chat-primary);
    font-weight: 700;
    text-decoration: none;
    border-bottom: 1px solid rgba(16, 185, 129, 0.3);
    transition: all 0.2s ease;
}

.chat-bubble a:hover {
    color: #34d399;
    border-bottom-color: #34d399;
}

/* ── Product suggestion cards ── */
.chat-product-card {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 8px 14px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 12px;
    color: var(--chat-primary);
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

.chat-product-card:hover {
    background: rgba(16, 185, 129, 0.2);
    border-color: var(--chat-primary);
    transform: translateY(-1px);
}

.chat-product-card svg {
    width: 14px;
    height: 14px;
}

/* ── Typing Indicator ── */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 88%;
    align-self: flex-start;
    animation: chatMsgIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.chat-typing .chat-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--chat-primary), #059669);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-typing .chat-msg-avatar svg {
    width: 14px;
    height: 14px;
    color: white;
}

.chat-typing-dots {
    background: var(--chat-dark-surface);
    border: 1px solid var(--chat-border);
    border-radius: 4px 16px 16px 16px;
    padding: 14px 20px;
    display: flex;
    gap: 5px;
    align-items: center;
}

.chat-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chat-text-muted);
    animation: chatTypingBounce 1.4s ease-in-out infinite;
}

.chat-typing-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.chat-typing-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

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

/* ── Quick Action Chips ── */
.chatbot-quick-actions {
    padding: 0 16px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    background: var(--chat-dark);
    flex-shrink: 0;
}

.chat-chip {
    padding: 7px 14px;
    background: var(--chat-dark-surface);
    border: 1px solid var(--chat-border);
    border-radius: 100px;
    color: var(--chat-text-muted);
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-family: var(--chat-font);
}

.chat-chip:hover {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
    color: var(--chat-primary);
}

/* ── Input Area ── */
.chatbot-input-area {
    padding: 12px 16px 16px;
    background: var(--chat-dark-mid);
    border-top: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.chatbot-input-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

#chatbot-input {
    width: 100% !important;
    padding: 12px 16px !important;
    background: #0f172a !important;
    border: 1px solid rgba(255, 255, 255, 0.06) !important;
    border-radius: 14px !important;
    color: #f1f5f9 !important;
    font-size: 13.5px !important;
    font-weight: 500 !important;
    font-family: var(--chat-font) !important;
    outline: none !important;
    transition: all 0.2s ease !important;
    -webkit-appearance: none !important;
    -webkit-text-fill-color: #f1f5f9 !important;
    opacity: 1 !important;
}

#chatbot-input::placeholder {
    color: #475569 !important;
    font-weight: 500 !important;
    -webkit-text-fill-color: #475569 !important;
}

#chatbot-input:focus {
    border-color: rgba(16, 185, 129, 0.4) !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1) !important;
    background: #0f172a !important;
    color: #f1f5f9 !important;
    -webkit-text-fill-color: #f1f5f9 !important;
}

#chatbot-send {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    border: none;
    background: linear-gradient(135deg, var(--chat-primary), #059669);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

#chatbot-send:hover {
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
    transform: scale(1.05);
}

#chatbot-send:active {
    transform: scale(0.95);
}

#chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#chatbot-send svg {
    width: 18px;
    height: 18px;
}

/* ── Powered By Footer ── */
.chatbot-powered {
    text-align: center;
    padding: 6px 0 4px;
    background: var(--chat-dark-mid);
    font-size: 9px;
    font-weight: 600;
    color: #334155;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    #chatbot-window {
        bottom: 80px; /* Sits just above the toggle button */
        left: 16px;
        right: auto;
        width: calc(100vw - 32px); /* Leaves 16px margin on both sides */
        height: 75dvh; /* Takes up 75% of screen height */
        max-height: 600px;
        border-radius: var(--chat-radius); /* Restore rounded corners */
        box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4); /* Stronger shadow for floating effect */
    }

    #chatbot-toggle {
        bottom: 16px;
        left: 16px;
        right: auto;
        width: 54px;
        height: 54px;
        border-radius: 50%;
    }

    #chatbot-toggle:hover {
        width: 54px;
        transform: none;
    }
    
    #chatbot-toggle .chat-toggle-text {
        display: none !important;
    }

    #chatbot-toggle svg {
        width: 24px;
        height: 24px;
    }

    .chatbot-header {
        padding: 16px;
        /* Safe area for notched phones */
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .chatbot-input-area {
        padding: 12px 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    #chatbot-window {
        width: calc(100vw - 32px);
        max-width: 420px;
        left: 16px;
        right: auto;
        bottom: 88px;
    }
}

/* ── Respect reduced motion preference ── */
@media (prefers-reduced-motion: reduce) {
    .chat-msg,
    .chat-typing,
    #chatbot-window,
    #chatbot-toggle {
        animation: none !important;
        transition-duration: 0.1s !important;
    }
    .chatbot-header-status-dot,
    .chat-typing-dots span,
    #chatbot-toggle .chat-notification {
        animation: none !important;
    }
}

/* ── Ensure chatbot sits above everything ── */
#chatbot-toggle,
#chatbot-window {
    font-family: var(--chat-font) !important;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#chatbot-window *,
#chatbot-window *::before,
#chatbot-window *::after {
    box-sizing: border-box;
}
