/**
 * AI Chatbot Widget Styles
 */

/* ==========================================================================
   CSS Variables (inherits from theme)
   ========================================================================== */
.ai-chatbot-widget {
    --chatbot-primary: #6366f1;
    --chatbot-radius: 16px;
    --chatbot-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

/* ==========================================================================
   SVG Reset - Ensure icons display correctly
   ========================================================================== */
.ai-chatbot-widget svg {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: auto;
    height: auto;
    fill: none !important;
    stroke: currentColor !important;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ai-chatbot-widget svg * {
    visibility: visible !important;
    opacity: 1 !important;
}

/* ==========================================================================
   Widget Container
   ========================================================================== */
.ai-chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ==========================================================================
   Toggle Button
   ========================================================================== */
.ai-chatbot-toggle {
    width: 60px !important;
    height: 60px !important;
    min-width: 60px !important;
    min-height: 60px !important;
    max-width: 60px !important;
    max-height: 60px !important;
    padding: 0 !important;
    border-radius: 50%;
    background: var(--chatbot-primary) !important;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--chatbot-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    color: white !important;
    flex-shrink: 0;
    aspect-ratio: 1 / 1;
    box-sizing: border-box;
}

.ai-chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 15px 50px rgba(99, 102, 241, 0.4);
}

.ai-chatbot-toggle svg {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    stroke: white !important;
    color: white !important;
}

.ai-chatbot-toggle svg * {
    stroke: white !important;
}

.ai-chatbot-icon-close {
    display: none;
}

.ai-chatbot-open .ai-chatbot-icon-chat {
    display: none;
}

.ai-chatbot-open .ai-chatbot-icon-close {
    display: block;
}

/* ==========================================================================
   Chat Window
   ========================================================================== */
.ai-chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: var(--chatbot-radius);
    box-shadow: var(--chatbot-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
}

.ai-chatbot-open .ai-chatbot-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ==========================================================================
   Header
   ========================================================================== */
.ai-chatbot-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--chatbot-primary);
    color: white;
}

.ai-chatbot-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.ai-chatbot-avatar svg {
    width: 24px !important;
    height: 24px !important;
    min-width: 24px !important;
    min-height: 24px !important;
    stroke: white !important;
    color: white !important;
}

.ai-chatbot-avatar svg * {
    stroke: white !important;
}

.ai-chatbot-info {
    flex: 1;
}

.ai-chatbot-name {
    display: block;
    font-weight: 600;
    font-size: 15px;
}

.ai-chatbot-status {
    display: block;
    font-size: 12px;
    opacity: 0.8;
}

.ai-chatbot-minimize {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
    max-width: 32px !important;
    max-height: 32px !important;
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white !important;
    transition: background 0.2s;
    flex-shrink: 0;
    aspect-ratio: 1 / 1;
    box-sizing: border-box;
}

.ai-chatbot-minimize svg {
    width: 16px !important;
    height: 16px !important;
    min-width: 16px !important;
    min-height: 16px !important;
    stroke: white !important;
    color: white !important;
}

.ai-chatbot-minimize svg * {
    stroke: white !important;
}

.ai-chatbot-minimize:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ==========================================================================
   Messages Container
   ========================================================================== */
.ai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f8fafc;
}

/* Individual Message */
.ai-chatbot-message {
    display: flex;
    animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-chatbot-message-content {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

/* Bot Message */
.ai-chatbot-message-bot {
    justify-content: flex-start;
}

.ai-chatbot-message-bot .ai-chatbot-message-content {
    background: #ffffff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

/* User Message */
.ai-chatbot-message-user {
    justify-content: flex-end;
}

.ai-chatbot-message-user .ai-chatbot-message-content {
    background: var(--chatbot-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Markdown Styles */
.ai-chatbot-message-content p {
    margin: 8px 0;
}

.ai-chatbot-message-content p:first-child {
    margin-top: 0;
}

.ai-chatbot-message-content p:last-child {
    margin-bottom: 0;
}

.ai-chatbot-message-content strong {
    font-weight: 600;
}

.ai-chatbot-message-content em {
    font-style: italic;
}

.ai-chatbot-message-content a {
    color: #4f46e5;
    text-decoration: underline;
}

.ai-chatbot-message-user .ai-chatbot-message-content a {
    color: #ffffff;
}

.ai-inline-code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
    color: #e11d48;
}

.ai-chatbot-message-user .ai-inline-code {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.ai-code-block {
    background: #1e293b;
    color: #f1f5f9;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85em;
    margin: 10px 0;
    line-height: 1.4;
}

.ai-blockquote {
    border-left: 3px solid #cbd5e1;
    margin: 10px 0;
    padding-left: 12px;
    color: #64748b;
    font-style: italic;
}

.ai-chatbot-message-content ul, 
.ai-chatbot-message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.ai-chatbot-message-content li {
    margin-bottom: 4px;
}

.ai-chatbot-message-content hr {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 16px 0;
}

/* ==========================================================================
   Typing Indicator
   ========================================================================== */
.ai-typing .ai-chatbot-message-content {
    display: flex;
    gap: 4px;
    padding: 16px 20px;
}

.ai-typing-dot {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.ai-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.ai-typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ==========================================================================
   Input Area
   ========================================================================== */
.ai-chatbot-input-area {
    padding: 16px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
}

.ai-chatbot-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

.ai-chatbot-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.ai-chatbot-input:focus {
    border-color: var(--chatbot-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.ai-chatbot-input::placeholder {
    color: #94a3b8;
}

.ai-chatbot-send {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    max-width: 44px !important;
    max-height: 44px !important;
    padding: 0 !important;
    border: none;
    border-radius: 50%;
    background: var(--chatbot-primary) !important;
    color: white !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
    aspect-ratio: 1 / 1;
    box-sizing: border-box;
}

.ai-chatbot-send svg {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    min-height: 20px !important;
    stroke: white !important;
    color: white !important;
}

.ai-chatbot-send svg * {
    stroke: white !important;
}

.ai-chatbot-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.ai-chatbot-send:active {
    transform: scale(0.95);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 480px) {
    .ai-chatbot-widget {
        bottom: 10px;
        right: 10px;
    }
    
    .ai-chatbot-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        bottom: 70px;
        right: -5px;
        border-radius: 12px;
    }
    
    .ai-chatbot-toggle {
        width: 54px;
        height: 54px;
    }
}

/* ==========================================================================
   Scrollbar
   ========================================================================== */
.ai-chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chatbot-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.ai-chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}
