/**
 * AI Chatbot Styles
 * 
 * Modern, clean chatbot UI with:
 * - WhatsApp-style floating button
 * - Slide-up chat panel
 * - Message bubbles
 * - Loading animations
 * - RTL support
 * - Responsive design
 */

/* ======================================
   CSS Variables
   ====================================== */
:root {
    --chatbot-primary: #0a9a6e;
    --chatbot-primary-dark: #087d59;
    --chatbot-primary-light: #e8f5f0;
    --chatbot-bg: #ffffff;
    --chatbot-bg-secondary: #f8f9fa;
    --chatbot-text: #1a1a2e;
    --chatbot-text-light: #6c757d;
    --chatbot-border: #e9ecef;
    --chatbot-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --chatbot-shadow-light: 0 2px 8px rgba(0, 0, 0, 0.08);
    --chatbot-bubble-user: #0a9a6e;
    --chatbot-bubble-assistant: #f1f3f5;
    --chatbot-panel-width: 380px;
    --chatbot-panel-height: 550px;
    --chatbot-button-size: 60px;
    --chatbot-border-radius: 16px;
    --chatbot-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode variables */
.dark {
    --chatbot-bg: #1e2335;
    --chatbot-bg-secondary: #2a2f45;
    --chatbot-text: #e8eaed;
    --chatbot-text-light: #9ca3af;
    --chatbot-border: #3a4055;
    --chatbot-bubble-assistant: #2a2f45;
}

/* ======================================
   Floating Toggle Button
   ====================================== */
.chatbot-toggle-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9998;
    width: var(--chatbot-button-size);
    height: var(--chatbot-button-size);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-dark) 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(10, 154, 110, 0.4);
    transition: var(--chatbot-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 30px rgba(10, 154, 110, 0.5);
}

.chatbot-toggle-btn:active {
    transform: scale(0.95);
}

.chatbot-toggle-btn--active {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    box-shadow: 0 4px 20px rgba(220, 53, 69, 0.4);
}

.chatbot-icon {
    width: 28px;
    height: 28px;
}

/* RTL Support */
[dir="rtl"] .chatbot-toggle-btn {
    right: auto;
    left: 24px;
}

/* ======================================
   Chat Panel
   ====================================== */
.chatbot-panel {
    position: fixed;
    bottom: 100px;
    right: 24px;
    z-index: 9997;
    width: var(--chatbot-panel-width);
    max-width: calc(100vw - 48px);
    height: var(--chatbot-panel-height);
    max-height: calc(100vh - 140px);
    background: var(--chatbot-bg);
    border-radius: var(--chatbot-border-radius);
    box-shadow: var(--chatbot-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--chatbot-border);
}

/* RTL Support */
[dir="rtl"] .chatbot-panel {
    right: auto;
    left: 24px;
}

/* Panel Animations */
.chatbot-panel-enter {
    transition: all 0.3s ease-out;
}

.chatbot-panel-enter-start {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
}

.chatbot-panel-enter-end {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.chatbot-panel-leave {
    transition: all 0.2s ease-in;
}

.chatbot-panel-leave-start {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.chatbot-panel-leave-end {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
}

/* ======================================
   Header
   ====================================== */
.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-dark) 100%);
    color: white;
    flex-shrink: 0;
}

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: white;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatbot-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
}

.chatbot-header-text {
    display: flex;
    flex-direction: column;
}

.chatbot-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
}

.chatbot-subtitle {
    font-size: 12px;
    opacity: 0.9;
    margin: 0;
    line-height: 1.3;
}

.chatbot-header-actions {
    display: flex;
    gap: 8px;
}

.chatbot-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition);
}

.chatbot-action-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.3);
}

.chatbot-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ======================================
   Messages Container
   ====================================== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--chatbot-bg-secondary);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Custom scrollbar */
.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--chatbot-border);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--chatbot-text-light);
}

/* ======================================
   Welcome Message
   ====================================== */
.chatbot-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px 16px;
    flex: 1;
}

.chatbot-welcome-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--chatbot-primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.chatbot-welcome-icon svg {
    color: var(--chatbot-primary);
}

.chatbot-welcome-text {
    font-size: 16px;
    font-weight: 500;
    color: var(--chatbot-text);
    margin: 0 0 8px;
}

.chatbot-welcome-hint {
    font-size: 13px;
    color: var(--chatbot-text-light);
    margin: 0;
}

/* ======================================
   Message Bubbles
   ====================================== */
.chatbot-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.chatbot-message--user {
    align-self: flex-end;
    align-items: flex-end;
}

.chatbot-message--assistant {
    align-self: flex-start;
    align-items: flex-start;
}

/* RTL adjustments */
[dir="rtl"] .chatbot-message--user {
    align-self: flex-start;
    align-items: flex-start;
}

[dir="rtl"] .chatbot-message--assistant {
    align-self: flex-end;
    align-items: flex-end;
}

.chatbot-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: var(--chatbot-shadow-light);
}

.chatbot-bubble--user {
    background: var(--chatbot-bubble-user);
    color: white;
    border-bottom-right-radius: 4px;
}

[dir="rtl"] .chatbot-bubble--user {
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 4px;
}

.chatbot-bubble--assistant {
    background: var(--chatbot-bubble-assistant);
    color: var(--chatbot-text);
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .chatbot-bubble--assistant {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 4px;
}

.chatbot-bubble-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.6;
}

/* Markdown styles inside bubbles */
.chatbot-bubble-text strong {
    font-weight: 600;
}

.chatbot-bubble-text em {
    font-style: italic;
}

.chatbot-bubble-text ul,
.chatbot-bubble-text ol {
    margin: 8px 0;
    padding-left: 20px;
}

.chatbot-bubble-text li {
    margin: 4px 0;
}

.chatbot-bubble-text br+br {
    display: block;
    content: "";
    margin-top: 8px;
}

.chatbot-timestamp {
    font-size: 11px;
    color: var(--chatbot-text-light);
    margin-top: 4px;
    padding: 0 4px;
}

/* ======================================
   Loading Indicator (Typing Animation)
   ====================================== */
.chatbot-bubble--loading {
    padding: 16px 20px;
}

.chatbot-typing-indicator {
    display: flex;
    gap: 4px;
}

.chatbot-typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--chatbot-primary);
    border-radius: 50%;
    animation: chatbot-typing 1.4s infinite ease-in-out both;
}

.chatbot-typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.chatbot-typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

.chatbot-typing-indicator span:nth-child(3) {
    animation-delay: 0s;
}

@keyframes chatbot-typing {

    0%,
    80%,
    100% {
        transform: scale(0.7);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ======================================
   Error Message
   ====================================== */
.chatbot-error {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
    border-radius: 12px;
    font-size: 13px;
}

.chatbot-error svg {
    flex-shrink: 0;
}

/* ======================================
   Input Form
   ====================================== */
.chatbot-input-form {
    padding: 12px 16px;
    background: var(--chatbot-bg);
    border-top: 1px solid var(--chatbot-border);
    flex-shrink: 0;
}

.chatbot-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--chatbot-bg-secondary);
    border: 1px solid var(--chatbot-border);
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
    transition: var(--chatbot-transition);
}

.chatbot-input-wrapper:focus-within {
    border-color: var(--chatbot-primary);
    box-shadow: 0 0 0 3px rgba(10, 154, 110, 0.1);
}

.chatbot-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    color: var(--chatbot-text);
    padding: 8px 0;
    min-width: 0;
}

.chatbot-input::placeholder {
    color: var(--chatbot-text-light);
}

.chatbot-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--chatbot-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition);
    flex-shrink: 0;
}

.chatbot-send-btn:hover:not(:disabled) {
    background: var(--chatbot-primary-dark);
    transform: scale(1.05);
}

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ======================================
   Responsive Design
   ====================================== */
@media (max-width: 480px) {
    .chatbot-toggle-btn {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    [dir="rtl"] .chatbot-toggle-btn {
        right: auto;
        left: 16px;
    }

    .chatbot-panel {
        bottom: 88px;
        right: 12px;
        left: 12px;
        width: auto;
        max-width: none;
        height: calc(100vh - 120px);
        max-height: calc(100vh - 120px);
        border-radius: 20px;
    }

    [dir="rtl"] .chatbot-panel {
        right: 12px;
        left: 12px;
    }

    .chatbot-icon {
        width: 24px;
        height: 24px;
    }

    .chatbot-header {
        padding: 14px;
    }

    .chatbot-avatar {
        width: 40px;
        height: 40px;
    }

    .chatbot-title {
        font-size: 15px;
    }

    .chatbot-messages {
        padding: 12px;
    }

    .chatbot-bubble {
        padding: 10px 14px;
    }

    .chatbot-bubble-text {
        font-size: 13px;
    }
}

/* ======================================
   Alpine.js x-cloak
   ====================================== */
[x-cloak] {
    display: none !important;
}