/* Chatbot Plugin Styles */

/* Set default variables in CSS as fallback */
:root {
    --chatbot-primary-color: #4a6cf7;  
    --chatbot-primary-color-light: rgba(74, 108, 247, 0.2);
    --chatbot-primary-color-dark: #3a5bf0;
    --chatbot-danger-color: #f44336;
    --chatbot-danger-color-light: rgba(244, 67, 54, 0.2);
    --chatbot-danger-color-dark: #d32f2f;
}

/* Chat button */
.chat-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 65px;
    height: 65px;
    background-color: var(--chatbot-primary-color, #4a6cf7); /* Use CSS variable */
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--chatbot-primary-color-light, rgba(74, 108, 247, 0.35));
    z-index: 999;
    transition: all 0.3s ease;
    border: none;
    text-decoration: none;
    direction: ltr !important;
    padding: 0 !important;
    padding-inline: 0 !important;
    padding-block: 0 !important;
    margin: 0 !important;
    margin-inline: 0 !important;
    margin-block: 0 !important;
}

.chat-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px var(--chatbot-primary-color-light, rgba(74, 108, 247, 0.4));
}

.chat-button:active {
    transform: scale(0.95);
}

.chat-icon {
    color: white;
    font-size: 28px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 28px;
    height: 28px;
}

/* For custom uploaded images */
.chat-icon-image {
    width: 28px;
    height: 28px;
    object-fit: contain;
    max-width: 100%;
    max-height: 100%;
    display: block;
}

.chatbot-container {
    width: 380px;
    height: 580px; /* Set a fixed height */
    position: fixed;
    bottom: 90px;
    right: 20px;
    border: none;
    border-radius: 12px;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    z-index: 998;
    display: none;
    transition: all 0.3s ease;
    background-color: #fff;
    animation: chatbot-fade-in 0.3s ease-out;
    box-sizing: border-box;
    direction: ltr !important;
    text-align: left !important;
    padding: 0 !important;
    padding-inline: 0 !important;
    padding-block: 0 !important;
    margin: 0 !important;
    margin-inline: 0 !important;
    margin-block: 0 !important;
}

.chatbot-container *,
.chat-button * {
    direction: ltr !important;
    text-align: left !important;
}

@keyframes chatbot-fade-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbot-container.active {
    display: flex;
    flex-direction: column;
}

.chatbot-header {
    background-color: var(--chatbot-primary-color, #4a6cf7);
    color: white;
    padding: 12px 16px !important;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 18px;
    border-radius: 10px 10px 0 0;
    padding-inline: 16px !important;
    padding-block: 12px !important;
}

.chatbot-header-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chatbot-header-title {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
}

.chatbot-header-branding {
    display: flex;
    align-items: center;
    gap: 4px;
}

.powered-by-text {
    font-size: 9px;
    font-weight: 400;
    opacity: 0.85;
    line-height: 1;
}

.aipass-logo-link {
    text-decoration: none !important;
    display: inline-flex;
    transition: opacity 0.2s ease;
}

.aipass-logo-link:hover {
    opacity: 0.9;
}

.aipass-logo {
    display: inline-flex !important;
    align-items: center;
    background-color: white !important;
    padding: 1px 4px 1px 1px;
    border-radius: 5px 0px 5px 5px;
    gap: 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: transform 0.2s ease;
}

.aipass-logo-link:hover .aipass-logo {
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25) !important;
}

.aipass-ai-box {
    background-color: #8A4FFF !important;
    color: white !important;
    font-weight: bold;
    font-size: 9px;
    padding: 1px 3px;
    border-radius: 3px 0px 3px 3px;
    line-height: 1;
}

.aipass-pass-text {
    color: #8A4FFF !important;
    font-weight: 600;
    font-size: 9px;
    line-height: 1;
}

.chatbot-close {
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    transition: opacity 0.2s;
}

.chatbot-close:hover {
    opacity: 0.8;
}

.chatbot-messages {
    height: calc(100% - 120px); /* Subtract header and input container heights */
    overflow-y: auto;
    padding: 20px !important;
    padding-inline: 20px !important;
    padding-block: 20px !important;
    background-color: #ffffff;
    display: none; /* Hide messages area initially when welcome screen is shown */
    position: relative;
}

.chatbot-message {
    margin-bottom: 15px;
    padding: 12px 18px !important;
    padding-inline: 18px !important;
    padding-block: 12px !important;
    border-radius: 18px;
    max-width: 75%;
    clear: both;
    position: relative;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    animation: message-fade-in 0.3s ease-out;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

@keyframes message-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbot-message-sender {
    font-size: 12px;
    margin-bottom: 4px;
    font-weight: 600;
    opacity: 0.8;
}

.chatbot-message.user {
    background-color: #4a6cf7;
    color: white;
    border-top-right-radius: 4px;
    float: right !important;
    margin-left: auto !important;
    margin-right: 0 !important;
}

.chatbot-message.ai {
    background-color: #f1f8ff;
    color: #333;
    border-top-left-radius: 4px;
    float: left !important;
    border-left: 3px solid var(--chatbot-primary-color, #4a6cf7);
    margin-right: auto !important;
    margin-left: 0 !important;
}

.chatbot-message.admin {
    background-color: #fff2e6;
    color: #333;
    border-top-left-radius: 4px;
    float: left !important;
    border-left: 3px solid #ff9933;
    margin-right: auto !important;
    margin-left: 0 !important;
}

.chatbot-message.system {
    background-color: #f8f8f8;
    color: #555;
    border-top-left-radius: 4px;
    float: left !important;
    border-left: 3px solid #999;
    font-style: italic;
    margin-right: auto !important;
    margin-left: 0 !important;
}

.chatbot-input-container {
    display: flex;
    flex-direction: column;
    padding: 15px 20px !important;
    padding-inline: 20px !important;
    padding-block: 15px !important;
    background-color: white;
    border-top: 1px solid #f0f0f0;
    gap: 10px;
}

.chatbot-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chatbot-input {
    flex-grow: 1;
    padding: 14px 20px !important;
    padding-inline: 20px !important;
    padding-block: 14px !important;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    outline: none;
    font-size: 15px;
    transition: border-color 0.3s, box-shadow 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.chatbot-input:focus {
    border-color: var(--chatbot-primary-color, #4a6cf7);
    box-shadow: 0 0 0 3px var(--chatbot-primary-color-light, rgba(74, 108, 247, 0.1));
}

.chatbot-send-btn {
    background-color: var(--chatbot-primary-color, #4a6cf7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    min-width: 50px;
    min-height: 50px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s, transform 0.2s;
    box-shadow: 0 2px 5px var(--chatbot-primary-color-light, rgba(74, 108, 247, 0.2));
}

.chatbot-send-btn:hover {
    background-color: var(--chatbot-primary-color-dark, #3a5bf0);
    transform: scale(1.05);
}

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

.chatbot-end-btn-container {
    display: flex;
    justify-content: center;
    width: 100%;
}

.chatbot-end-btn {
    color: var(--chatbot-danger-color, #f44336);
    background-color: white;
    border: 1px solid var(--chatbot-danger-color, #f44336);
    border-radius: 5px;
    padding: 8px 16px !important;
    padding-inline: 16px !important;
    padding-block: 8px !important;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    box-shadow: 0 1px 3px var(--chatbot-danger-color-light, rgba(244, 67, 54, 0.1));
}

.chatbot-end-btn:hover {
    background-color: var(--chatbot-danger-color-light, rgba(244, 67, 54, 0.1));
    transform: translateY(-2px);
}

.chatbot-end-btn:active {
    transform: translateY(0);
}

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

/* Character counter */
.chatbot-char-counter {
    font-size: 12px;
    color: #888;
    text-align: right;
    margin-bottom: 5px;
    width: 100%;
    padding-right: 10px;
}

.chatbot-char-counter.warning {
    color: #ff9900;
    font-weight: bold;
}

.chatbot-char-counter.error {
    color: #ff0000;
    font-weight: bold;
}

/* Welcome Screen */
.chatbot-welcome-screen {
    padding: 20px !important;
    padding-inline: 20px !important;
    padding-block: 20px !important;
    text-align: center;
    background-color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0; /* Start from the top, no header */
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    height: 100%; /* Full height now */
    width: 100%;
    box-sizing: border-box;
    border-radius: 12px; /* Match container border radius */
}

.chatbot-welcome-screen h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: var(--chatbot-primary-color, #4a6cf7);
    font-size: 28px;
    font-weight: 600;
    width: 100%;
}

.chatbot-welcome-screen p {
    font-size: 18px;
    color: #333;
    margin-bottom: 40px;
    line-height: 1.5;
    width: 100%;
}

.chatbot-name-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 320px;
    margin-top: 20px;
}

.chatbot-name-input {
    width: 100%;
    padding: 16px 20px;
    border: 1px solid #ddd;
    border-radius: 30px;
    outline: none;
    font-size: 16px;
    margin-bottom: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: border-color 0.3s, box-shadow 0.3s;
    -webkit-appearance: none; /* Remove default styling on iOS */
    appearance: none;
    background-color: #fff;
    color: #333;
    min-height: 50px;
    text-align: left;
    box-sizing: border-box;
}

.chatbot-name-input:focus {
    border-color: var(--chatbot-primary-color, #4a6cf7);
    box-shadow: 0 2px 8px var(--chatbot-primary-color-light, rgba(74, 108, 247, 0.2));
}

.chatbot-start-btn {
    background-color: var(--chatbot-primary-color, #4a6cf7);
    color: white;
    border: none;
    border-radius: 30px;
    padding: 16px 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 16px;
    width: 100%;
    transition: background-color 0.3s, transform 0.2s;
    -webkit-appearance: none; /* Remove default styling on iOS */
    appearance: none;
    box-sizing: border-box;
    min-height: 50px;
}

.chatbot-start-btn:hover {
    background-color: var(--chatbot-primary-color-dark, #3a5bf0);
    transform: translateY(-2px);
}

.chatbot-start-btn:active {
    transform: translateY(0);
}

/* System message for status info within chat */
.chatbot-system-message {
    font-size: 13px;
    padding: 8px 12px;
    text-align: center;
    color: #777;
    background-color: #f8f8f8;
    border-radius: 15px;
    margin: 10px auto;
    clear: both;
    width: 80%;
    max-width: 300px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    font-weight: 500;
    animation: message-fade-in 0.3s ease-out;
}

/* New chat button */
.chatbot-new-chat-btn {
    background-color: var(--chatbot-primary-color, #4a6cf7);
    color: white;
    border: none;
    border-radius: 5px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    margin: 10px 0;
    transition: all 0.3s ease;
    font-weight: 500;
}

.chatbot-new-chat-btn:hover {
    background-color: var(--chatbot-primary-color-dark, #3a5bf0);
    transform: translateY(-2px);
}

.chatbot-new-chat-btn:active {
    transform: translateY(0);
}

/* Themes */
.chatbot-container.dark {
    background-color: #333;
    color: #fff;
}

.chatbot-container.dark .chatbot-header {
    background-color: #222;
}

.chatbot-container.dark .chatbot-messages {
    background-color: #444;
}

.chatbot-container.dark .chatbot-message.user {
    background-color: #4a6cf7;
    color: white;
}

.chatbot-container.dark .chatbot-message.ai {
    background-color: #555;
    color: #fff;
}

.chatbot-container.dark .chatbot-message.admin {
    background-color: #664c33;
    color: #fff;
}

.chatbot-container.dark .chatbot-message.system {
    background-color: #333;
    color: #bbb;
    border-left: 3px solid #777;
}

.chatbot-container.dark .chatbot-message-sender {
    color: #ddd;
}

.chatbot-container.dark .chatbot-input-container {
    background-color: #333;
    border-top-color: #555;
}

.chatbot-container.dark .chatbot-input {
    background-color: #555;
    color: #fff;
    border-color: #666;
}

.chatbot-container.dark .chatbot-end-btn-container {
    background-color: transparent;
}

.chatbot-container.dark .chatbot-end-btn {
    background-color: #333;
    color: #ff6b6b;
    border-color: #ff6b6b;
}

.chatbot-container.dark .chatbot-end-btn:hover {
    background-color: rgba(255, 107, 107, 0.15);
}

.chatbot-container.dark .chatbot-welcome-screen {
    background-color: #333;
}

.chatbot-container.dark .chatbot-welcome-screen h3 {
    color: #4a90e2;
}

.chatbot-container.dark .chatbot-welcome-screen p {
    color: #eee;
}

.chatbot-container.dark .chatbot-name-input {
    background-color: #555;
    color: #fff;
    border-color: #666;
}

.chatbot-container.dark .chatbot-system-message {
    background-color: #444;
    color: #ccc;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.chatbot-container.dark .chatbot-new-chat-btn {
    background-color: #4a90e2;
}

.chatbot-container.dark .chatbot-new-chat-btn:hover {
    background-color: #3a80d2;
}

/* Mobile optimization */
@media screen and (max-width: 768px) {
    .chatbot-container {
        width: 100% !important;
        height: 100vh !important;
        position: fixed !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        border-radius: 0 !important;
        z-index: 999999 !important;
    }
    
    .chatbot-header {
        border-radius: 0 !important;
        padding: 15px 20px !important;
    }
    
    .chatbot-messages {
        height: calc(100% - 130px) !important; /* Adjust for header and input container */
    }
    
    .chat-button {
        z-index: 999998 !important; /* One less than the container */
    }
    
    /* Optimize welcome screen for mobile */
    .chatbot-welcome-screen {
        height: 100vh !important;
        padding: 40px 20px !important;
    }
    
    /* Hide the chat button when the chat is open */
    .chat-button.hidden-mobile {
        display: none !important;
    }
}

/* Simple text-based typing indicator */
.chatbot-simple-typing-indicator {
    font-size: 14px;
    color: var(--chatbot-primary-color, #4a6cf7);
    font-weight: 500;
    text-align: center;
    padding: 8px 0;
    border-top: 1px solid #f0f0f0;
    background-color: rgba(255, 255, 255, 0.9);
    animation: typing-pulse 1.5s infinite alternate ease-in-out;
    position: absolute;
    bottom: 80px; /* Position above the input area */
    left: 0;
    right: 0;
    z-index: 5;
}

@keyframes typing-pulse {
    0% {
        opacity: 0.8;
    }
    100% {
        opacity: 1;
    }
}

.chatbot-container.dark .chatbot-simple-typing-indicator {
    color: #4a90e2;
    background-color: rgba(51, 51, 51, 0.9);
    border-top: 1px solid #444;
}

.chatbot-typing-indicator .chatbot-message-sender {
    margin-bottom: 5px;
}

.chatbot-typing-animation {
    display: flex;
    align-items: center;
    margin: 6px 0;
}

.chatbot-typing-text {
    font-size: 14px;
    color: #666;
    font-style: italic;
    margin-left: 6px;
}

.chatbot-typing-dot {
    width: 10px;
    height: 10px;
    margin: 0 3px;
    background-color: var(--chatbot-primary-color, #4a6cf7);
    border-radius: 50%;
    animation: chatbot-typing-dot-animation 1.4s infinite ease-in-out both;
    opacity: 0.8;
    display: inline-block;
}

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

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

@keyframes chatbot-typing-dot-animation {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* Loading animation for chat initialization */
.chatbot-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
    padding: 0;
    flex-direction: column;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.95);
    z-index: 10;
}

.chatbot-loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--chatbot-primary-color-light, rgba(74, 108, 247, 0.1));
    border-radius: 50%;
    border-left-color: var(--chatbot-primary-color, #4a6cf7); 
    animation: chatbot-spinner 1s cubic-bezier(0.42, 0.61, 0.58, 0.41) infinite;
    margin-bottom: 20px;
    filter: drop-shadow(0 0 2px var(--chatbot-primary-color-light, rgba(74, 108, 247, 0.1)));
}

.chatbot-loading-text {
    font-size: 18px;
    color: var(--chatbot-primary-color, #4a6cf7);
    font-weight: 500;
    margin-top: 5px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

@keyframes chatbot-spinner {
    to {
        transform: rotate(360deg);
    }
}

/* Admin status badges */
.chatbot-admin-status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    margin-left: 10px;
}

.chatbot-admin-status-active {
    background-color: #e6f7e6;
    color: #2e7d32;
}

.chatbot-admin-status-ended {
    background-color: #fff0e0;
    color: #e65100;
}

.chatbot-admin-status-archived {
    background-color: #f0f0f0;
    color: #757575;
}

/* Status indicators in admin table */
.chatbot-admin-status-active {
    color: #2e7d32;
    font-weight: bold;
}

.chatbot-admin-status-ended {
    color: #e65100;
    font-weight: bold;
}

.chatbot-admin-status-archived {
    color: #757575;
    font-style: italic;
}