/**
 * Public (Frontend) Styles
 */

:root {
    --chatbot-primary-color: #0066cc;
    --chatbot-bg-color: #ffffff;
    --chatbot-text-color: #1d2327;
    --chatbot-border-color: #dcdcde;
    --chatbot-user-msg-bg: #0066cc;
    --chatbot-user-msg-text: #ffffff;
    --chatbot-assistant-msg-bg: #f0f0f1;
    --chatbot-assistant-msg-text: #1d2327;
}

.wp-ai-chatbot-widget {
    position: fixed;
    bottom: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

.wp-ai-chatbot-widget.position-right {
    right: 20px;
}

.wp-ai-chatbot-widget.position-left {
    left: 20px;
}

.wp-ai-chatbot-widget.inline-widget {
    position: relative;
    bottom: auto;
    right: auto;
    left: auto;
}

/* Theme Modes */
.wp-ai-chatbot-widget.theme-dark {
    --chatbot-bg-color: #1d2327;
    --chatbot-text-color: #f0f0f1;
    --chatbot-border-color: #3c434a;
    --chatbot-assistant-msg-bg: #2c3338;
    --chatbot-assistant-msg-text: #f0f0f1;
}

/* Widget Sizes */
.wp-ai-chatbot-widget.size-small .chatbot-window {
    width: 320px;
    height: 450px;
}

.wp-ai-chatbot-widget.size-medium .chatbot-window {
    width: 380px;
    height: 550px;
}

.wp-ai-chatbot-widget.size-large .chatbot-window {
    width: 450px;
    height: 650px;
}

/* Toggle Button */
.chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chatbot-primary-color);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: all 0.3s ease;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

.chatbot-icon,
.chatbot-icon-default {
    width: 32px;
    height: 32px;
}

.chatbot-icon {
    border-radius: 50%;
    object-fit: cover;
}

/* Chatbot Window */
.chatbot-window {
    position: absolute;
    bottom: 80px;
    background: var(--chatbot-bg-color);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

.wp-ai-chatbot-widget.position-right .chatbot-window {
    right: 0;
}

.wp-ai-chatbot-widget.position-left .chatbot-window {
    left: 0;
}

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

/* Header */
.chatbot-header {
    background: var(--chatbot-primary-color);
    color: #fff;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chatbot-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chatbot-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
}

.chatbot-status.online::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4caf50;
    margin-right: 6px;
}

.chatbot-actions {
    display: flex;
    gap: 8px;
}

.chatbot-action-btn {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: background 0.2s;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-action-btn:hover {
    background: rgba(255,255,255,0.1);
}

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

/* Messages Container */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--chatbot-bg-color);
}

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

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

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

.message {
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease;
}

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

.user-message {
    display: flex;
    justify-content: flex-end;
}

.assistant-message {
    display: flex;
    justify-content: flex-start;
}

.message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.5;
    word-wrap: break-word;
}

.user-message .message-content {
    background: var(--chatbot-user-msg-bg);
    color: var(--chatbot-user-msg-text);
}

.assistant-message .message-content {
    background: var(--chatbot-assistant-msg-bg);
    color: var(--chatbot-assistant-msg-text);
}

/* Typing Indicator */
.typing-indicator-wrapper {
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--chatbot-assistant-msg-bg);
    border-radius: 18px;
    width: fit-content;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chatbot-text-color);
    opacity: 0.4;
    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);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Input Area */
.chatbot-input-area {
    border-top: 1px solid var(--chatbot-border-color);
    background: var(--chatbot-bg-color);
}

.input-wrapper {
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-end;
    padding: 12px;
    gap: 8px;
}

.chatbot-input {
    flex: 1;
    border: 1px solid var(--chatbot-border-color);
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 14px;
    resize: none;
    max-height: 120px;
    background: var(--chatbot-bg-color);
    color: var(--chatbot-text-color);
    font-family: inherit;
}

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

.send-btn {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    border-radius: 50% !important;
    border: none !important;
    background: var(--chatbot-primary-color, #0066cc) !important;
    color: #fff !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s !important;
    flex-shrink: 0 !important;
    opacity: 1 !important;
    visibility: visible !important;
    position: relative !important;
    z-index: 10 !important;
    padding: 0 !important;
    margin: 0 !important;
    outline: none !important;
    box-shadow: none !important;
}

.send-btn:hover {
    transform: scale(1.05) !important;
}

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

.send-btn svg {
    width: 20px !important;
    height: 20px !important;
    pointer-events: none !important;
}

.send-btn.loading {
    background: #dc3545 !important;
    animation: pulse-btn 1.5s ease-in-out infinite !important;
}

.send-btn.loading svg {
    animation: spin 1s linear infinite !important;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse-btn {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* Branding */
.chatbot-branding {
    text-align: center;
    padding: 8px;
    font-size: 11px;
    color: #787c82;
    border-top: 1px solid var(--chatbot-border-color);
}

/* Welcome Popup */
.chatbot-welcome-popup {
    position: absolute;
    bottom: 80px;
    animation: slideUp 0.3s ease;
}

.wp-ai-chatbot-widget.position-right .chatbot-welcome-popup {
    right: 0;
}

.wp-ai-chatbot-widget.position-left .chatbot-welcome-popup {
    left: 0;
}

.welcome-popup-content {
    position: relative;
    background: #fff;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    max-width: 280px;
}

.welcome-popup-content p {
    margin: 0;
    color: #1d2327;
    font-size: 14px;
    line-height: 1.5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 15px;
}

.close-popup {
    position: absolute !important;
    top: -16px !important;
    right: -16px !important;
    background: #fff !important;
    border: 2px solid #dcdcde !important;
    border-radius: 50% !important;
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
    cursor: pointer !important;
    font-size: 20px !important;
    line-height: 1 !important;
    color: #1d2327 !important;
    box-shadow: 0 2px 12px rgba(0,0,0,0.2) !important;
    z-index: 1000 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s !important;
    padding: 0 !important;
    margin: 0 !important;
    opacity: 1 !important;
    visibility: visible !important;
    outline: none !important;
}

.close-popup:hover {
    background: #f0f0f1 !important;
    transform: scale(1.1) !important;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .wp-ai-chatbot-widget:not(.inline-widget) .chatbot-window {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100% !important;
        height: 100% !important;
        max-height: 100vh;
        border-radius: 0;
    }

    .chatbot-welcome-popup {
        max-width: calc(100vw - 100px);
    }

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

/* Error state */
.message-error {
    color: #d63638;
    font-size: 13px;
    padding: 8px 12px;
    background: #fcdedf;
    border-radius: 4px;
    margin-bottom: 16px;
}

/* Markdown Styling */
.assistant-message .message-content {
    line-height: 1.6;
}

.assistant-message .message-content p {
    margin: 0 0 8px 0;
}

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

.assistant-message .message-content strong,
.assistant-message .message-content b {
    font-weight: 600;
    color: var(--chatbot-primary-color);
}

.assistant-message .message-content em,
.assistant-message .message-content i {
    font-style: italic;
}

.assistant-message .message-content a {
    color: var(--chatbot-primary-color);
    text-decoration: underline;
}

.assistant-message .message-content a:hover {
    text-decoration: none;
}

.assistant-message .message-content ul,
.assistant-message .message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.assistant-message .message-content li {
    margin: 4px 0;
}

.assistant-message .message-content code {
    background: rgba(0,0,0,0.05);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
}

.assistant-message .message-content pre {
    background: rgba(0,0,0,0.05);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.assistant-message .message-content pre code {
    background: none;
    padding: 0;
}

.assistant-message .message-content h1,
.assistant-message .message-content h2,
.assistant-message .message-content h3,
.assistant-message .message-content h4 {
    margin: 12px 0 8px 0;
    font-weight: 600;
}

.assistant-message .message-content h1 { font-size: 18px; }
.assistant-message .message-content h2 { font-size: 16px; }
.assistant-message .message-content h3 { font-size: 15px; }
.assistant-message .message-content h4 { font-size: 14px; }

.assistant-message .message-content blockquote {
    border-left: 3px solid var(--chatbot-primary-color);
    padding-left: 12px;
    margin: 8px 0;
    color: #666;
    font-style: italic;
}

.assistant-message .message-content hr {
    border: none;
    border-top: 1px solid var(--chatbot-border-color);
    margin: 12px 0;
}

/* Dark theme Markdown adjustments */
.wp-ai-chatbot-widget.theme-dark .assistant-message .message-content code,
.wp-ai-chatbot-widget.theme-dark .assistant-message .message-content pre {
    background: rgba(255,255,255,0.1);
}

.wp-ai-chatbot-widget.theme-dark .assistant-message .message-content blockquote {
    color: #b0b0b0;
}