/* Reset and base styles */
* {
    box-sizing: border-box;
}

/* CSS Variables for theming */
:root {
    --primary: 262 83% 58%;
    --primary-foreground: 210 40% 98%;
    --secondary: 210 40% 96%;
    --secondary-foreground: 222.2 84% 4.9%;
    --muted: 210 40% 96%;
    --muted-foreground: 215.4 16.3% 46.9%;
    --accent: 210 40% 96%;
    --accent-foreground: 222.2 84% 4.9%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 210 40% 98%;
    --border: 214.3 31.8% 91.4%;
    --input: 214.3 31.8% 91.4%;
    --ring: var(--primary);
    --background: 0 0% 100%;
    --foreground: 222.2 84% 4.9%;
    --card: 0 0% 100%;
    --card-foreground: 222.2 84% 4.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 222.2 84% 4.9%;
    
    /* Custom gradients */
    --gradient-primary: linear-gradient(135deg, hsl(var(--primary)), hsl(279 100% 65%));
    --gradient-subtle: linear-gradient(180deg, hsl(var(--background)), hsl(210 40% 98%));
    
    /* Shadows */
    --shadow-chat: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-chat-panel: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --shadow-chat-button: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    /* Chat specific colors */
    --chat-user-bg: hsl(var(--primary));
    --chat-user-text: hsl(var(--primary-foreground));
    --chat-bot-bg: hsl(var(--secondary));
    --chat-bot-text: hsl(var(--secondary-foreground));
    --chat-input-bg: hsl(var(--background));
}

/* Widget container */
.chatbot-widget {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 999999; /* Increased z-index */
}

/* Apply inherited font only to text elements to avoid breaking icons */
.chatbot-widget .chat-header,
.chatbot-widget .chat-messages,
.chatbot-widget .chat-input textarea {
    font-family: inherit;
}

/* Chat panel */
.chat-panel {
    display: none;
    width: 384px;
    height: 500px;
    background: hsl(var(--card));
    border-radius: 16px;
    box-shadow: var(--shadow-chat-panel);
    border: 1px solid hsl(var(--border));
    margin-bottom: 16px;
    overflow: hidden;
    overflow-x: hidden; /* Prevent horizontal scroll */
    opacity: 0;
    transform: scale(0.95) translateY(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-panel.open {
    display: flex;
    flex-direction: column;
    opacity: 1;
    transform: scale(1) translateY(0);
}

/* Mobile responsive */
@media (max-width: 767px) {
    .chat-panel.open {
        width: 100%;
        height: 100%;
        max-width: 100vw;
        border-radius: 0;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        margin: 0;
        z-index: 999999;
    }
    .chat-button {
        position: fixed;
        bottom: 16px;
        right: 16px;
        z-index: 999999;
    }
    .chat-panel.open + .chat-button {
        display: none; /* Hide button when panel is open on mobile */
    }
}

/* Header */
.chat-header {
    background: var(--gradient-primary);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-avatar {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-header-text h3 {
    font-weight: 600;
    font-size: 14px;
    margin: 0;
}

.chat-header-text p {
    font-size: 12px;
    opacity: 0.9;
    margin: 0;
}

.chat-close-btn {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    align-items: flex-end;
}

.message.user {
    justify-content: flex-end;
}

.message.bot {
    justify-content: flex-start;
}

.message-content {
    max-width: 80%;
    padding: 12px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
}

.message.user .message-content {
    background: var(--chat-user-bg);
    color: var(--chat-user-text);
    border-bottom-right-radius: 4px;
}

.message.bot .message-content {
    background: var(--chat-bot-bg);
    color: var(--chat-bot-text);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 12px;
    color: hsl(var(--muted-foreground));
    margin-top: 4px;
    padding: 0 4px;
}

/* Product links */
.product-links {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.product-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.2s;
}

.product-link:hover {
    box-shadow: var(--shadow-chat);
}

.product-info {
    flex: 1;
    min-width: 0;
}

.product-name {
    font-weight: 500;
    font-size: 12px;
    color: hsl(var(--foreground));
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Quick replies */
.quick-replies {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-reply-btn {
    padding: 4px 12px;
    background: hsla(var(--primary), 0.1);
    color: hsl(var(--primary));
    border: none;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.quick-reply-btn:hover {
    background: hsla(var(--primary), 0.2);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px;
    background: var(--chat-bot-bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    max-width: 80%;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: hsl(var(--muted-foreground));
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    30% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Input area */
.chat-input {
    border-top: 1px solid hsl(var(--border));
    background: var(--chat-input-bg);
    padding: 16px;
    display: flex;
    gap: 8px;
}

div.chatbot-widget .chat-input textarea#messageInput {
    flex: 1;
    background: hsl(var(--background));
    border: 1px solid hsl(var(--primary)) !important; /* Use primary color for border */
    border-radius: 12px !important; /* Ensure border-radius is applied */
    padding: 8px 16px !important;
    font-size: 14px !important;
    outline: none !important;
    transition: border-color 0.2s, box-shadow 0.2s;
    resize: none !important; /* Disable manual resizing */
    line-height: 1.5 !important;
    min-height: 24px !important; /* Force initial height to override theme styles */
    height: auto !important; /* Allow JS to resize it */
    max-height: 120px !important; /* Set a max-height */
    overflow-y: auto !important; /* Add scroll for long messages */
}

div.chatbot-widget .chat-input textarea#messageInput:focus {
    border-color: hsl(var(--primary)) !important;
    box-shadow: 0 0 0 2px hsla(var(--ring), 0.2) !important;
}

.send-btn {
    width: 40px;
    height: 40px;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    align-self: flex-end; /* Align to bottom */
    margin-bottom: 2px; /* Adjust alignment */
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.1) rotate(5deg);
    filter: brightness(1.2);
    transition: transform 0.2s ease-out, filter 0.2s ease-out;
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Force border-radius on chat buttons */
.chatbot-widget button {
    border-radius: 50% !important; /* Use !important to override conflicting styles */
}

.chatbot-widget .send-btn,
.chatbot-widget .quick-reply-btn {
    border-radius: 12px !important;
}

.chatbot-widget .chat-close-btn {
	border-radius: 50% !important;
}

/* Chat button */
.chat-button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    box-shadow: var(--shadow-chat-button);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.chat-button.closed {
    background: var(--gradient-primary);
    color: white;
    animation: pulse-gentle 2s infinite;
}

.chat-button.open {
    background: hsl(var(--secondary));
    color: hsl(var(--foreground));
}

.chat-button:hover {
    transform: scale(1.1);
}

/* Notification badge */
.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    background: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 500;
    animation: bounce-in 0.5s ease-out;
}

/* Animations */
@keyframes pulse-gentle {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
}

@keyframes bounce-in {
    0% {
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* Icons (crisp SVG masks — tint with currentColor instead of emoji glyphs) */
.icon-message::before,
.icon-close::before,
.icon-send::before,
.icon-link::before {
    content: "";
    display: inline-block;
    width: 18px;
    height: 18px;
    background-color: currentColor;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
}

.icon-message::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z'/%3E%3C/svg%3E");
}

.icon-close::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5' stroke-linecap='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'/%3E%3Cline x1='6' y1='6' x2='18' y2='18'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5' stroke-linecap='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'/%3E%3Cline x1='6' y1='6' x2='18' y2='18'/%3E%3C/svg%3E");
}

.icon-send::before {
    transform: scaleX(-1); /* Flip icon for RTL */
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='22' y1='2' x2='11' y2='13'/%3E%3Cpolygon points='22 2 15 22 11 13 2 9 22 2'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='22' y1='2' x2='11' y2='13'/%3E%3Cpolygon points='22 2 15 22 11 13 2 9 22 2'/%3E%3C/svg%3E");
}

.icon-link::before {
    width: 14px;
    height: 14px;
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71'/%3E%3Cpath d='M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71'/%3E%3Cpath d='M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71'/%3E%3C/svg%3E");
}

.chat-button .icon-message::before,
.chat-button .icon-close::before {
    width: 24px;
    height: 24px;
}

/* Welcome Bubbles */
#wgc-welcome-bubbles {
    position: fixed;
    bottom: 90px;
    right: 20px;
    z-index: 10002;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.wgc-bubble {
    background: #ffffff;
    padding: 12px 16px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    max-width: 280px;
    direction: rtl;
    text-align: right;
    font-size: 14px;
    color: #333;
    animation: fadeIn 0.3s ease-in;
}

.wgc-close-bubble {
    background: #ffffff;
    color: #999;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 8px;
    align-self: flex-end;
}

.wgc-close-bubble:hover {
    background: #f4f6f8;
    color: #333;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
