/**
 * MAI Smart Assistant - Chatbot Widget Styles
 *
 * @package MAI_SMART_ASSISTANT
 * @since 1.0.0
 */

/* ========================================
   CSS Variables
   ======================================== */
.mai-smart-assistant-chatbot {
    --chatbot-primary-color: #0073aa;
    --chatbot-secondary-color: #ffffff;
    --chatbot-text-color: #2c3e50;
    --chatbot-bg-color: #f8f9fa;
    --chatbot-border-color: #e1e8ed;
    --chatbot-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
    --chatbot-radius: 12px;
    --chatbot-font-size: 14px;
    --chatbot-window-width: 380px;
    --chatbot-window-height: 600px;
    --chatbot-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   Main Container
   ======================================== */
.mai-smart-assistant-chatbot {
    position: fixed !important;
    z-index: 999999 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: var(--chatbot-font-size);
    line-height: 1.5;
    /* Reset inheritance */
    text-align: left;
    direction: ltr;
}

/* CSS Reset for Chatbot */
.mai-smart-assistant-chatbot *,
.mai-smart-assistant-chatbot *::before,
.mai-smart-assistant-chatbot *::after {
    box-sizing: border-box !important;
}

.mai-smart-assistant-chatbot p,
.mai-smart-assistant-chatbot h1,
.mai-smart-assistant-chatbot h2,
.mai-smart-assistant-chatbot h3,
.mai-smart-assistant-chatbot h4,
.mai-smart-assistant-chatbot h5,
.mai-smart-assistant-chatbot h6,
.mai-smart-assistant-chatbot ul,
.mai-smart-assistant-chatbot li {
    margin: 0;
    padding: 0;
    list-style: none;
}

.mai-smart-assistant-chatbot img,
.mai-smart-assistant-chatbot svg {
    max-width: 100%;
    height: auto;
    vertical-align: middle;
}

.mai-smart-assistant-chatbot[data-position="bottom-right"] {
    bottom: 20px !important;
    right: 20px !important;
}

.mai-smart-assistant-chatbot[data-position="bottom-left"] {
    bottom: 20px !important;
    left: 20px !important;
}

/* ========================================
   Chatbot Button (Toggle)
   ======================================== */
.mai-smart-assistant-chatbot-button {
    min-width: 60px;
    height: 60px;
    border-radius: 30px;
    background-color: var(--chatbot-primary-color);
    color: #ffffff;
    border: none;
    cursor: pointer;
    box-shadow: var(--chatbot-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 20px;
    transition: var(--chatbot-transition);
    position: relative;
    overflow: hidden;
}

.chatbot-button-text {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
}

.chatbot-button-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 24px;
    height: 24px;
}

.mai-smart-assistant-chatbot-button:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

.mai-smart-assistant-chatbot-button:active {
    transform: scale(0.95);
}

.mai-smart-assistant-chatbot-button svg {
    position: absolute;
    transition: var(--chatbot-transition);
}

.mai-smart-assistant-chatbot-button .chatbot-icon {
    opacity: 1;
    transform: rotate(0deg);
}

.mai-smart-assistant-chatbot-button .close-icon {
    opacity: 0;
    transform: rotate(-90deg);
}

.chatbot-open .mai-smart-assistant-chatbot-button .chatbot-icon {
    opacity: 0;
    transform: rotate(90deg);
}

.chatbot-open .mai-smart-assistant-chatbot-button .close-icon {
    opacity: 1;
    transform: rotate(0deg);
}

/* ========================================
   Chatbot Window
   ======================================== */
.mai-smart-assistant-chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: var(--chatbot-window-width);
    max-width: calc(100vw - 40px);
    height: var(--chatbot-window-height);
    max-height: calc(100vh - 120px);
    background-color: var(--chatbot-secondary-color);
    border-radius: var(--chatbot-radius);
    box-shadow: var(--chatbot-shadow);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: var(--chatbot-transition);
    overflow: hidden;
}

.mai-smart-assistant-chatbot[data-position="bottom-left"] .mai-smart-assistant-chatbot-window {
    right: auto;
    left: 0;
}

.chatbot-open .mai-smart-assistant-chatbot-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ========================================
   Header
   ======================================== */
.chatbot-header {
    background-color: var(--chatbot-primary-color);
    color: #ffffff;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: var(--chatbot-radius) var(--chatbot-radius) 0 0;
}

.chatbot-header-info h3 {
    margin: 0 0 5px 0;
    font-size: 18px;
    font-weight: 600;
}

.chatbot-status {
    display: flex;
    align-items: center;
    font-size: 12px;
    opacity: 0.9;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #4caf50;
    margin-right: 6px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chatbot-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chatbot-new-conversation,
.chatbot-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition);
    padding: 0 !important;
}

.chatbot-new-conversation:hover,
.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.chatbot-close:hover {
    transform: rotate(90deg);
}

.chatbot-new-conversation:active,
.chatbot-close:active {
    transform: scale(0.95);
}

/* ========================================
   Messages Container
   ======================================== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-color: var(--chatbot-bg-color);
    scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* ========================================
   Messages
   ======================================== */
.message {
    margin-bottom: 16px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-content {
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 80%;
    word-wrap: break-word;
    line-height: 1.5;
}

.bot-message .message-content {
    background-color: var(--chatbot-secondary-color);
    color: var(--chatbot-text-color);
    border: 1px solid var(--chatbot-border-color);
    border-radius: var(--chatbot-radius) var(--chatbot-radius) var(--chatbot-radius) 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.user-message {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.user-message .message-content {
    background-color: var(--chatbot-primary-color);
    color: #ffffff;
    border-radius: var(--chatbot-radius) var(--chatbot-radius) 4px var(--chatbot-radius);
    max-width: 100%;
}

.message-meta {
    font-size: 11px;
    color: #718096;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-message .message-meta {
    justify-content: flex-end;
}

.message-content a {
    color: inherit;
    text-decoration: underline;
}

.user-message .message-content a {
    color: #ffffff;
}

/* Avatar images */
.message-avatar img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

/* System Message */
.system-message {
    display: flex;
    justify-content: center;
    margin: 12px 0;
}

.system-message .message-content {
    background-color: #e3f2fd;
    color: #1976d2;
    padding: 8px 14px;
    border-radius: 16px;
    font-size: 12px;
    max-width: 90%;
    text-align: center;
    border: 1px solid #bbdefb;
}

/* ========================================
   Predefined Questions
   ======================================== */
.predefined-questions-wrapper {
    margin-bottom: 20px;
}

.predefined-questions-title {
    font-size: 13px;
    color: #718096;
    margin-bottom: 10px;
    font-weight: 500;
}

.predefined-questions-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.predefined-question {
    background-color: #ffffff;
    border: 1px solid var(--chatbot-border-color);
    padding: 10px 14px;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    transition: var(--chatbot-transition);
    font-size: 13px;
    color: var(--chatbot-text-color);
}

.predefined-question:hover {
    background-color: var(--chatbot-primary-color);
    color: #ffffff;
    border-color: var(--chatbot-primary-color);
    transform: translateX(4px);
}

/* ========================================
   Typing Indicator
   ======================================== */
.chatbot-typing {
    margin-bottom: 16px;
    display: none;
}

.chatbot-typing.mai-smart-assistant-visible {
    display: block;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #cbd5e0;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ========================================
   Input Area
   ======================================== */
.chatbot-input-area {
    border-top: 1px solid var(--chatbot-border-color);
    background-color: var(--chatbot-bg-color);
}

.chatbot-form {
    display: flex;
    align-items: flex-end;
    padding: 16px;
    gap: 12px;
}

.chatbot-input {
    flex: 1;
    /* min-height: 40px; */
    max-height: 120px;
    padding: 10px 14px;
    border: 1px solid var(--chatbot-border-color);
    border-radius: 20px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    transition: var(--chatbot-transition);
    overflow-y: auto;
    margin: 0 !important;
}

.chatbot-input:focus {
    outline: none;
    border-color: var(--chatbot-primary-color);
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.1);
}

.chatbot-input::-webkit-scrollbar {
    width: 4px;
}

.chatbot-input::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-input::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 2px;
}

.chatbot-send-button {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background-color: var(--chatbot-primary-color);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition);
}

.chatbot-send-button:hover {
    background-color: var(--chatbot-primary-color);
    filter: brightness(1.1);
    transform: scale(1.05);
}

.chatbot-send-button:active {
    transform: scale(0.95);
}

.chatbot-send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}



/* ========================================
   Greeting Message
   ======================================== */
.chatbot-greeting {
    margin-bottom: 20px;
}

.chatbot-greeting .message {
    margin-bottom: 0;
}

/* ========================================
   Mobile Responsive
   ======================================== */
@media (max-width: 480px) {
    .mai-smart-assistant-chatbot-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        bottom: 70px;
    }

    .mai-smart-assistant-chatbot[data-position="bottom-right"],
    .mai-smart-assistant-chatbot[data-position="bottom-left"] {
        left: 10px;
        right: 10px;
    }

    .mai-smart-assistant-chatbot-window {
        left: 0 !important;
        right: 0 !important;
    }

    .message-content {
        max-width: 90%;
    }

    .chatbot-header {
        padding: 16px;
    }

    .chatbot-messages {
        padding: 16px;
    }

    .chatbot-form {
        padding: 12px;
    }
}

/* ========================================
   Dark Mode Support (Optional)
   ======================================== */
/* @media (prefers-color-scheme: dark) {
    .mai-smart-assistant-chatbot {
        --chatbot-text-color: #e2e8f0;
        --chatbot-bg-color: #1a202c;
        --chatbot-border-color: #2d3748;
    }

    .chatbot-messages {
        background-color: #171923;
    }

    .bot-message .message-content {
        background-color: #2d3748;
        border-color: #4a5568;
    }

    .chatbot-input {
        background-color: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .predefined-question {
        background-color: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
} */

/* ========================================
   Accessibility
   ======================================== */
.mai-smart-assistant-chatbot-button:focus,
.chatbot-close:focus,
.chatbot-send-button:focus,
.predefined-question:focus,
.chatbot-input:focus {
    outline: 2px solid var(--chatbot-primary-color);
    outline-offset: 2px;
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    .mai-smart-assistant-chatbot {
        display: none !important;
    }
}

/* ========================================
   Animation Enhancements
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    .mai-smart-assistant-chatbot,
    .mai-smart-assistant-chatbot * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
