/* ====================================================================
   Corxor ChatBot Widget - Modern, Accessible, Mobile-Responsive
   ==================================================================== */

:root {
    --chatbot-primary: #2563eb;
    --chatbot-primary-hover: #1d4ed8;
    --chatbot-bg: #ffffff;
    --chatbot-text: #1f2937;
    --chatbot-text-light: #6b7280;
    --chatbot-border: #e5e7eb;
    --chatbot-user-bubble: #eff6ff;
    --chatbot-user-text: #1e40af;
    --chatbot-assistant-bubble: #f3f4f6;
    --chatbot-assistant-text: #374151;
    --chatbot-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --chatbot-z-index: 999999;
}

/* ====================================================================
   Floating Action Button (FAB) - Modern AI Chat Icon
   ==================================================================== */

.chatbot-fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4);
    z-index: var(--chatbot-z-index);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.chatbot-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 30px rgba(59, 130, 246, 0.5);
}

.chatbot-fab:focus {
    outline: 3px solid var(--chatbot-primary);
    outline-offset: 2px;
}

.chatbot-fab:active {
    transform: scale(0.95);
}

/* AI Sparkle Icon - Default state */
.chatbot-fab .fab-icon-chat,
.chatbot-fab .fab-icon-close {
    position: absolute;
    transition: all 0.3s ease;
}

.chatbot-fab .fab-icon-chat {
    opacity: 1;
    transform: scale(1);
}

.chatbot-fab .fab-icon-close {
    opacity: 0;
    transform: scale(0.5) rotate(-90deg);
}

/* When open - show close icon */
.chatbot-fab.chatbot-open .fab-icon-chat {
    opacity: 0;
    transform: scale(0.5) rotate(90deg);
}

.chatbot-fab.chatbot-open .fab-icon-close {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.chatbot-fab svg {
    width: 28px;
    height: 28px;
    color: white;
    fill: white;
}

.chatbot-fab-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 12px;
    height: 12px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

/* ====================================================================
   Chat Panel
   ==================================================================== */

.chatbot-panel {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 550px;
    max-height: calc(100vh - 120px);
    background: var(--chatbot-bg);
    border-radius: 16px;
    box-shadow: var(--chatbot-shadow);
    z-index: var(--chatbot-z-index);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot-panel.chatbot-visible {
    display: flex;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Mobile: Full-screen drawer */
@media (max-width: 640px) {
    /* Prevent body scroll when chat is open */
    body.chatbot-modal-open {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
    }

    .chatbot-panel {
        position: fixed;
        top: 0;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile */
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        z-index: 999999;
        display: none;
        flex-direction: column;
        overflow: hidden;
    }

    .chatbot-panel.chatbot-visible {
        display: flex;
    }

    .chatbot-fab {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
        z-index: 999998;
    }

    /* Mobile: Header - fixed at top */
    .chatbot-header {
        padding: 12px 16px;
        padding-top: max(12px, env(safe-area-inset-top));
        flex-shrink: 0;
    }

    /* Mobile: Larger close button for easier tap */
    .chatbot-close {
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
        min-height: 40px !important;
        background: rgba(255, 255, 255, 0.2) !important;
        border-radius: 50% !important;
        flex-shrink: 0;
    }

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

    /* Mobile: Body scrollable area */
    .chatbot-body {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 16px;
        min-height: 0; /* Important for flex scroll */
    }

    /* Mobile: Messages must not overflow */
    .chatbot-message {
        max-width: 100%;
    }

    .chatbot-message-content {
        max-width: 85%;
    }

    .chatbot-message-bubble {
        word-break: break-word;
        white-space: pre-wrap;
    }

    /* Mobile: Footer input area - fixed at bottom */
    .chatbot-footer {
        flex-shrink: 0;
        background: white;
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        border-top: 1px solid var(--chatbot-border);
        overflow: hidden;
    }

    .chatbot-input-wrapper {
        display: flex;
        gap: 8px;
        align-items: center;
        width: 100%;
        max-width: 100%;
        overflow: hidden;
    }

    .chatbot-input {
        flex: 1;
        min-width: 0; /* Critical: prevents input from overflowing */
        padding: 12px 16px;
        font-size: 16px; /* Prevents iOS zoom on focus */
        border-radius: 24px;
        height: 44px;
        max-height: 44px;
        box-sizing: border-box;
    }

    .chatbot-send {
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        max-width: 44px !important;
        flex-shrink: 0;
        flex-grow: 0;
    }

    /* Hide quick actions on mobile to save space */
    .chatbot-quick-actions {
        display: none;
    }
}

/* ====================================================================
   Chat Header
   ==================================================================== */

.chatbot-header {
    background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-hover) 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    z-index: 10;
}

.chatbot-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.chatbot-header-text h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
}

.chatbot-header-text p {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
    line-height: 1.2;
}

.chatbot-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    color: white;
}

.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chatbot-close:focus {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* ====================================================================
   Chat Body (Messages Area)
   ==================================================================== */

.chatbot-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f9fafb;
}

.chatbot-body::-webkit-scrollbar {
    width: 6px;
}

.chatbot-body::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-body::-webkit-scrollbar-thumb {
    background: var(--chatbot-border);
    border-radius: 3px;
}

.chatbot-body::-webkit-scrollbar-thumb:hover {
    background: var(--chatbot-text-light);
}

/* ====================================================================
   Messages
   ==================================================================== */

.chatbot-message {
    display: flex;
    gap: 10px;
    animation: fadeIn 0.3s ease;
}

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

.chatbot-message.user {
    flex-direction: row-reverse;
}

.chatbot-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.chatbot-message.assistant .chatbot-message-avatar {
    background: var(--chatbot-primary);
    color: white;
}

.chatbot-message.user .chatbot-message-avatar {
    background: var(--chatbot-user-text);
    color: white;
}

.chatbot-message-content {
    max-width: 75%;
    min-width: 0; /* Critical for flex overflow */
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chatbot-message.user .chatbot-message-content {
    align-items: flex-end;
}

.chatbot-message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.chatbot-message.assistant .chatbot-message-bubble {
    background: var(--chatbot-assistant-bubble);
    color: var(--chatbot-assistant-text);
    border-bottom-left-radius: 4px;
}

.chatbot-message.user .chatbot-message-bubble {
    background: var(--chatbot-user-bubble);
    color: var(--chatbot-user-text);
    border-bottom-right-radius: 4px;
}

.chatbot-message-time {
    font-size: 11px;
    color: var(--chatbot-text-light);
    padding: 0 4px;
}

/* ====================================================================
   Typing Indicator
   ==================================================================== */

.chatbot-typing {
    display: none;
    align-items: center;
    gap: 10px;
}

.chatbot-typing.active {
    display: flex;
}

.chatbot-typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--chatbot-assistant-bubble);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.chatbot-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--chatbot-text-light);
    border-radius: 50%;
    animation: typingDot 1.4s infinite;
}

.chatbot-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.7; }
    30% { transform: translateY(-8px); opacity: 1; }
}

/* ====================================================================
   Quick Actions
   ==================================================================== */

.chatbot-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 12px;
}

.chatbot-quick-action {
    background: white;
    border: 1px solid var(--chatbot-border);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    color: var(--chatbot-text);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.chatbot-quick-action:hover {
    background: var(--chatbot-primary);
    color: white;
    border-color: var(--chatbot-primary);
    transform: translateY(-1px);
}

.chatbot-quick-action:focus {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 2px;
}

/* ====================================================================
   Chat Footer (Input Area)
   ==================================================================== */

.chatbot-footer {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--chatbot-border);
    flex-shrink: 0;
}

.chatbot-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chatbot-input {
    flex: 1;
    border: 1px solid var(--chatbot-border);
    border-radius: 24px;
    padding: 12px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    transition: border-color 0.2s;
}

.chatbot-input:focus {
    outline: none;
    border-color: var(--chatbot-primary);
}

.chatbot-input::placeholder {
    color: var(--chatbot-text-light);
}

.chatbot-send {
    background: var(--chatbot-primary);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    color: white;
}

.chatbot-send:hover:not(:disabled) {
    background: var(--chatbot-primary-hover);
    transform: scale(1.05);
}

.chatbot-send:focus {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 2px;
}

.chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-send svg {
    width: 20px;
    height: 20px;
}

/* ====================================================================
   Accessibility & Utilities
   ==================================================================== */

.chatbot-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.chatbot-hidden {
    display: none !important;
}

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 2px;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
