/**
 * iO Bonzai Chatbot Frontend Styles
 *
 * @package io_bonzai_chatbot
 */

/* Prevent FOUC (Flash of Unstyled Content) */
.io-ai-chatbot-widget {
    visibility: hidden;
}

.io-ai-chatbot-widget.io-ai-chatbot-loaded {
    visibility: visible;
}

/* Hidden elements */
.io-ai-close-icon,
.io-ai-chatbot-container,
.io-ai-typing-indicator {
    display: none;
}

.io-ai-close-icon.active,
.io-ai-chatbot-container.active {
    display: block;
}

.io-ai-typing-indicator.active {
    padding: 5px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Chatbot Widget Container */
.io-ai-chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    font-family: var(--io-search-font-family), Roboto, sans-serif;
    z-index: 999999;
    transition: var(--io-search-transition);
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
}

.io-ai-chatbot-widget.io-ai-chatbot-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* Toggle Button */
.io-ai-chatbot-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--io-chatbot-primary-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--io-search-transition);
    z-index: 1000000;
}

.io-ai-chatbot-toggle:hover {
    transform: scale(1.1);
    filter: drop-shadow(0 6px 15px rgba(0, 0, 0, 0.3));
}

.io-ai-chatbot-toggle svg {
    width: 24px;
    height: 24px;
    fill: white;
    transition: var(--io-search-transition);
}

.io-ai-chatbot-open .io-ai-chatbot-toggle {
    display: none;
}

/* Chat Container */
.io-ai-chatbot-container {
    background: var(--io-chatbot-background-color);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 500px;
    max-height: calc(100vh - 100px);
}

.io-ai-chatbot-minimized .io-ai-chatbot-container {
    height: 60px;
}

/* Chat Header */
.io-ai-chatbot-header {
    background: var(--io-chatbot-primary-color);
    color: white;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.io-ai-chatbot-title {
    font-size: var(--io-search-font-size-base);
    font-weight: 600;
    margin: 0;
}

.io-ai-chatbot-subtitle {
    font-size: var(--io-search-font-size-sm);
    opacity: 0.9;
    margin: 2px 0 0 0;
}

.io-ai-chatbot-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.io-ai-chatbot-minimize,
.io-ai-chatbot-close,
.io-ai-chatbot-clear {
    background: none;
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--io-search-transition);
}

.io-ai-chatbot-minimize:hover,
.io-ai-chatbot-close:hover,
.io-ai-chatbot-clear:hover {
    background-color: var(--io-chatbot-overlay-color-light);
}

.io-ai-chatbot-minimize svg,
.io-ai-chatbot-close svg,
.io-ai-chatbot-clear svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* Chat Messages */
.io-ai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--io-chatbot-background-color);
    min-height: 300px;
}

.io-ai-chatbot-minimized .io-ai-chatbot-messages {
    display: none;
}

.io-ai-chatbot-message {
    margin-bottom: 20px;
    animation: var(--io-search-transition);
}

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

.io-ai-message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.io-ai-message-sender {
    font-size: var(--io-search-font-size-sm);
    font-weight: 600;
    color: var(--io-chatbot-sender-text-color);
}

.io-ai-message-time {
    font-size: 11px;
    color: var(--io-chatbot-time-text-color);
}

.io-ai-message-content {
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.4;
    font-size: var(--io-search-font-size-md);
    word-wrap: break-word;
}

/* Markdown formatting within messages */
.io-ai-message-content strong {
    font-weight: 600;
}

.io-ai-message-content p,
.io-ai-message-content ul,
.io-ai-message-content ol {
    margin-bottom: 16px;
}

.io-ai-message-content p:last-child {
    margin-bottom: 0;
}

.io-ai-message-content em {
    font-style: italic;
}

.io-ai-message-content code {
    background: var(--io-chatbot-bot-bubble-code-bg-color);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: var(--io-search-font-size-sm);
}

.io-ai-message-user .io-ai-message-content code {
    background: var(--io-chatbot-overlay-color-light);
}

.io-ai-message-content del {
    text-decoration: line-through;
    opacity: 0.7;
}

.io-ai-message-content a {
    color: var(--io-chatbot-primary-color);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid transparent;
    transition: var(--io-search-transition);
}

.io-ai-message-content a:hover {
    border-bottom-color: var(--io-chatbot-primary-color);
    opacity: 0.8;
}

/* User Messages */
.io-ai-message-user .io-ai-message-content {
    background: var(--io-chatbot-user-bubble-bg-color);
    color: var(--io-chatbot-user-bubble-text-color);
    margin-left: 40px;
    border-bottom-right-radius: 4px;
}

.io-ai-message-user .io-ai-message-header {
    justify-content: right;
    column-gap: 14px;
}

/* Bot Messages */
.io-ai-message-bot .io-ai-message-content {
    background: var(--io-chatbot-bot-bubble-bg-color);
    color: var(--io-chatbot-bot-bubble-text-color);
    margin-right: 40px;
    border-bottom-left-radius: 4px;
}

.io-ai-message-bot a {
    color: var(--io-chatbot-bot-bubble-link-color);
    text-decoration: none;
}

/* Typing Indicator */
.io-ai-typing-indicator .io-ai-message-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.io-ai-typing-dots {
    display: flex;
    gap: 3px;
}

.io-ai-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--io-chatbot-typing-dots-color);
    animation: typing 1.4s infinite ease-in-out;
}

.io-ai-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.io-ai-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.6;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.io-ai-typing-text {
    font-size: var(--io-search-font-size-sm);
    color: var(--io-chatbot-sender-text-color);
    font-style: italic;
    transition: var(--io-search-transition);
}

/* Chat Input */
.io-ai-chatbot-input-container {
    padding: 10px;
    background: var(--io-chatbot-input-bg-color);
    border-top: var(--io-chatbot-input-border-size) solid var(--io-chatbot-input-border-color);
    gap: 8px;
    min-width: 0; /* Prevent flex items from overflowing */
    max-height: 150px; /* Ensure container doesn't grow too large */
}

.io-ai-chatbot-minimized .io-ai-chatbot-input-container {
    display: none;
}

.io-ai-chatbot-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
    min-width: 0; /* Prevent flex items from overflowing */
}

.io-ai-chatbot-input {
    flex: 1;
    border: none;
    outline: none !important;
    box-shadow: none !important;
    padding: 6px 10px 0;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    transition: var(--io-search-transition);
    font-family: inherit;
    overflow-y: auto;
}

.io-ai-chatbot-input::placeholder {
    color: var(--io-chatbot-input-placeholder-color);
}

/* Input field scrollbar styling - matches chat history */
.io-ai-chatbot-input::-webkit-scrollbar {
    width: 4px;
}

.io-ai-chatbot-input::-webkit-scrollbar-track {
    background: var(--io-chatbot-scrollbar-track-color);
}

.io-ai-chatbot-input::-webkit-scrollbar-thumb {
    background: var(--io-chatbot-scrollbar-thumb-color);
    border-radius: 2px;
}

.io-ai-chatbot-input::-webkit-scrollbar-thumb:hover {
    background: var(--io-chatbot-scrollbar-thumb-hover-color);
}

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

.io-ai-chatbot-send:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.3);
}

.io-ai-chatbot-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.io-ai-chatbot-send svg {
    width: 16px;
    height: 16px;
    fill: white;
}

/* Responsive Design */
@media (max-width: 480px) {
    .io-ai-chatbot-widget {
        bottom: 10px;
        right: 10px;
        left: 10px;
        width: auto;
        max-width: none;
    }

    .io-ai-chatbot-toggle {
        bottom: 10px;
        right: 10px;
    }

    .io-ai-chatbot-container {
        height: calc(100vh - 100px);
        max-height: none;
    }

    .io-ai-chatbot-messages {
        padding: 15px;
        min-height: 200px;
    }

    .io-ai-message-user .io-ai-message-content {
        margin-left: 20px;
    }

    .io-ai-message-bot .io-ai-message-content {
        margin-right: 20px;
    }
}

/* Scrollbar Styling */
.io-ai-chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

.io-ai-chatbot-messages::-webkit-scrollbar-track {
    background: var(--io-chatbot-scrollbar-track-color);
}

.io-ai-chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--io-chatbot-scrollbar-thumb-color);
    border-radius: 2px;
}

.io-ai-chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--io-chatbot-scrollbar-thumb-hover-color);
}

/* Loading States */
.io-ai-chatbot-loading {
    pointer-events: none;
}

.io-ai-chatbot-loading .io-ai-chatbot-send {
    opacity: 0.6;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .io-ai-chatbot-widget,
    .io-ai-chatbot-message,
    .io-ai-chatbot-toggle,
    .io-ai-typing-dots span {
        animation: none;
        transition: none;
    }
}

/* Character Count */
.io-ai-char-count {
    font-size: var(--io-search-font-size-sm);
    color: var(--io-chatbot-char-count-color);
    text-align: right;
    padding: 10px 4px 0;
    flex-shrink: 0; /* Prevent character count from being squeezed */
    white-space: nowrap; /* Keep it on one line */
}

.io-ai-char-warning {
    color: var(--io-chatbot-char-warning-color);
}

/* Clear Confirmation Modal */
.io-ai-clear-modal {
    position: absolute;
    top: 52px;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--io-chatbot-overlay-color-dark);
    z-index: 10;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: var(--io-search-transition);
}

.io-ai-clear-modal-content {
    background: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    text-align: center;
    max-width: 280px;
}

.io-ai-clear-modal-content p {
    margin: 0 0 20px 0;
    font-size: 15px;
    color: var(--io-chatbot-text-color);
    font-weight: 500;
}

.io-ai-clear-modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}
