/**
 * Chat Widget - Lovable/Shadcn UI Style
 * Modern design with exact HSL color tokens and smooth animations
 */

/* Container with exact HSL color tokens */
#woo-ai-chat-container {
    /* Base colors - Light mode */
    --background: 0 0% 96%;
    --foreground: 220 20% 10%;
    --card: 0 0% 100%;
    --border: 220 13% 91%;
    --input: 220 13% 91%;
    --ring: 217 91% 60%;
    --muted: 220 14% 96%;
    --muted-foreground: 220 9% 46%;
    --primary: 217 91% 60%;
    --accent: 160 84% 39%;
    
    /* Chat-specific colors - Light mode */
    --chat-header: 145 63% 42%;
    --chat-header-foreground: 0 0% 100%;
    --chat-user-bubble: 217 91% 53%;
    --chat-user-bubble-foreground: 0 0% 100%;
    --chat-bot-bubble: 220 14% 96%;
    --chat-bot-bubble-foreground: 220 20% 10%;
    --chat-surface: 0 0% 100%;
    --chat-input-border: 220 13% 91%;
    --chat-shadow: 220 20% 10%;
    
    --radius: 1rem;
    
    position: fixed;
    bottom: 20px;
    z-index: 999999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

/* Dark Mode */
#woo-ai-chat-container.dark-mode {
    --background: 222 47% 11%;
    --foreground: 210 40% 98%;
    --card: 217 33% 17%;
    --border: 217 33% 17%;
    --input: 217 33% 22%;
    --muted: 217 33% 17%;
    --muted-foreground: 215 20% 65%;
    
    /* Chat-specific colors - Dark mode */
    --chat-header: 145 63% 35%;
    --chat-user-bubble: 217 91% 60%;
    --chat-user-bubble-foreground: 0 0% 100%;
    --chat-bot-bubble: 217 33% 20%;
    --chat-bot-bubble-foreground: 210 40% 98%;
    --chat-surface: 222 47% 11%;
    --chat-input-border: 217 33% 22%;
    --chat-shadow: 222 47% 5%;
}

.woo-ai-hidden {
    display: none !important;
}

/* Chat Button */
#woo-ai-chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background-color: hsl(var(--chat-header));
    color: hsl(var(--chat-header-foreground));
    cursor: pointer;
    box-shadow: 0 8px 30px -12px hsl(var(--chat-shadow) / 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

#woo-ai-chat-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px -12px hsl(var(--chat-shadow) / 0.4);
}

#woo-ai-chat-button svg {
    width: 28px;
    height: 28px;
}

/* Chat Window */
#woo-ai-chat-window {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 100px);
    background: hsl(var(--chat-surface));
    border: 1px solid hsl(var(--border));
    border-radius: 16px;
    box-shadow: 0 8px 30px -12px hsl(var(--chat-shadow) / 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#woo-ai-chat-container[style*="left"] #woo-ai-chat-window {
    right: auto;
    left: 0;
}

/* Header - Green background with white text */
#woo-ai-chat-header {
    padding: 14px 16px;
    background-color: hsl(var(--chat-header));
    color: hsl(var(--chat-header-foreground));
    font-weight: 600;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    transition: background-color 0.3s ease;
}

#woo-ai-chat-header-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#woo-ai-chat-header-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

#woo-ai-theme-toggle,
#woo-ai-chat-close {
    background: none;
    border: none;
    color: hsl(var(--chat-header-foreground));
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    padding: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#woo-ai-theme-toggle:hover,
#woo-ai-chat-close:hover {
    background-color: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
}

#woo-ai-chat-close {
    font-size: 22px;
}

/* Lead Form */
#woo-ai-chat-form {
    padding: 24px;
    flex: 1;
    overflow-y: auto;
}

#woo-ai-chat-form h3 {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 600;
    color: hsl(var(--foreground));
}

#woo-ai-chat-form > p {
    margin: 0 0 20px;
    color: hsl(var(--muted-foreground));
    font-size: 13px;
}

#woo-ai-lead-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

#woo-ai-lead-form input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid hsl(var(--input));
    border-radius: 8px;
    font-size: 14px;
    box-sizing: border-box;
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#woo-ai-lead-form input:focus {
    outline: none;
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 3px hsl(var(--ring) / 0.1);
}

#woo-ai-lead-form input::placeholder {
    color: hsl(var(--muted-foreground));
}

#woo-ai-lead-form button {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background-color: hsl(var(--chat-header));
    color: hsl(var(--chat-header-foreground));
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 4px;
}

#woo-ai-lead-form button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

#woo-ai-lead-form button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Error message */
.woo-ai-error {
    background-color: hsl(var(--destructive) / 0.1);
    color: hsl(var(--destructive));
    padding: 10px 12px;
    border-radius: calc(var(--radius) - 2px);
    margin-bottom: 14px;
    font-size: 13px;
    border: 1px solid hsl(var(--destructive) / 0.2);
}

/* Messages Area */
#woo-ai-chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background-color: hsl(var(--chat-surface));
}

/* Individual Messages */
.woo-ai-message {
    max-width: 75%;
    padding: 10px 14px;
    margin-bottom: 12px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    animation: messageSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.woo-ai-message-user {
    background: hsl(var(--chat-user-bubble));
    color: hsl(var(--chat-user-bubble-foreground));
    margin-left: auto;
    border-bottom-right-radius: 4px;
    display: block;
}

.woo-ai-message-assistant {
    background: hsl(var(--chat-bot-bubble));
    color: hsl(var(--chat-bot-bubble-foreground));
    margin-right: auto;
    border-bottom-left-radius: 4px;
    display: block;
}

.woo-ai-message-text {
    display: block;
    white-space: pre-wrap;
    word-break: break-word;
}

.woo-ai-message-text a {
    color: hsl(var(--chat-user-bubble-foreground));
    font-weight: 600;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: opacity 0.2s;
}

.woo-ai-message-text a:hover {
    opacity: 0.85;
}

.woo-ai-message-user .woo-ai-message-text a {
    color: hsl(var(--chat-user-bubble-foreground));
    font-weight: 600;
}

.woo-ai-message-assistant .woo-ai-message-text a {
    color: hsl(var(--chat-bot-bubble-foreground));
    font-weight: 600;
    text-decoration-color: hsl(var(--chat-bot-bubble-foreground) / 0.5);
}

/* Typing Indicator */
.woo-ai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: hsl(var(--chat-bot-bubble));
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    max-width: 60px;
    margin-bottom: 12px;
}

.woo-ai-typing span {
    width: 8px;
    height: 8px;
    background: hsl(var(--muted-foreground) / 0.4);
    border-radius: 50%;
    animation: woo-ai-typing-animation 1.4s infinite ease-in-out;
}

.woo-ai-typing span:nth-child(1) {
    animation-delay: 0ms;
}

.woo-ai-typing span:nth-child(2) {
    animation-delay: 150ms;
}

.woo-ai-typing span:nth-child(3) {
    animation-delay: 300ms;
}

@keyframes woo-ai-typing-animation {
    0%, 60%, 100% { 
        transform: translateY(0);
        opacity: 0.4;
    }
    30% { 
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Input Area */
#woo-ai-chat-input {
    padding: 12px 16px;
    border-top: 1px solid hsl(var(--chat-input-border));
    background: hsl(var(--chat-surface));
    display: flex;
    gap: 8px;
    align-items: center;
}

#woo-ai-message-input {
    flex: 1;
    padding: 10px 14px;
    border: none;
    background: transparent;
    font-size: 14px;
    color: hsl(var(--foreground));
    transition: all 0.2s;
}

#woo-ai-message-input:focus {
    outline: none;
}

#woo-ai-message-input::placeholder {
    color: hsl(var(--muted-foreground));
}

#woo-ai-send-button {
    padding: 0;
    background: hsl(var(--chat-header));
    color: hsl(var(--chat-header-foreground));
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 36px;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

#woo-ai-send-button:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px hsl(var(--chat-header) / 0.3);
}

#woo-ai-send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

#woo-ai-send-button svg {
    width: 18px;
    height: 18px;
}

/* Scrollbar styling */
#woo-ai-chat-messages::-webkit-scrollbar,
#woo-ai-chat-form::-webkit-scrollbar {
    width: 6px;
}

#woo-ai-chat-messages::-webkit-scrollbar-track,
#woo-ai-chat-form::-webkit-scrollbar-track {
    background: transparent;
}

#woo-ai-chat-messages::-webkit-scrollbar-thumb,
#woo-ai-chat-form::-webkit-scrollbar-thumb {
    background: hsl(var(--muted));
    border-radius: 3px;
}

#woo-ai-chat-messages::-webkit-scrollbar-thumb:hover,
#woo-ai-chat-form::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--muted-foreground) / 0.5);
}
