/**
 * Chatbot Preview Widget Styles
 * 
 * Reusable CSS for chatbot preview widget in both admin and frontend.
 * This file is loaded independently and works without Tailwind.
 */

/* ============================================
   Base Container & Variables
   ============================================ */
.chatbot-preview {
    --cb-primary-color: #3B82F6;
    --cb-font-family: inherit;
    --cb-border-radius: 12px;
    --cb-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --cb-transition: all 0.2s ease;

    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 380px;
    height: 500px;
    min-height: 0;
    border-radius: var(--cb-border-radius);
    box-shadow: var(--cb-shadow);
    overflow: hidden;
    font-family: var(--cb-font-family);
    background: var(--cb-bg-primary);
}

/* Light Mode Variables */
.chatbot-preview--light {
    --cb-bg-primary: #ffffff;
    --cb-bg-secondary: #f9fafb;
    --cb-bg-tertiary: #f3f4f6;
    --cb-text-primary: #111827;
    --cb-text-secondary: #6b7280;
    --cb-text-muted: #9ca3af;
    --cb-border-color: #e5e7eb;
    --cb-user-bubble-bg: #ffffff;
    --cb-user-bubble-border: #e5e7eb;
    --cb-user-bubble-text: #374151;
}

/* Dark Mode Variables */
.chatbot-preview--dark {
    --cb-bg-primary: #1f2937;
    --cb-bg-secondary: #111827;
    --cb-bg-tertiary: #374151;
    --cb-text-primary: #f9fafb;
    --cb-text-secondary: #d1d5db;
    --cb-text-muted: #9ca3af;
    --cb-border-color: #374151;
    --cb-user-bubble-bg: #374151;
    --cb-user-bubble-border: #4b5563;
    --cb-user-bubble-text: #e5e7eb;
}

/* ============================================
   Header
   ============================================ */
.chatbot-preview__header {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 12px;
    padding: 16px;
    color: #ffffff;
    background-color: var(--cb-primary-color);
}

.chatbot-preview__avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
    border-radius: 50%;
    font-size: 18px;
}

.chatbot-preview__avatar svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.chatbot-preview__info {
    flex: 1;
    min-width: 0;
}

.chatbot-preview__name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chatbot-preview__status {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    opacity: 0.85;
}

.chatbot-preview__status-dot {
    width: 6px;
    height: 6px;
    background: #22c55e;
    border-radius: 50%;
}

.chatbot-preview__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 6px;
    color: #ffffff;
    cursor: pointer;
    transition: var(--cb-transition);
}

.chatbot-preview__close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.chatbot-preview__close svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.chatbot-preview__actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chatbot-preview__menu {
    position: relative;
}

.chatbot-preview__menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 6px;
    color: #ffffff;
    cursor: pointer;
    transition: var(--cb-transition);
}

.chatbot-preview__menu-toggle:hover {
    background: rgba(255, 255, 255, 0.25);
}

.chatbot-preview__menu-toggle svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.chatbot-preview__menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 140px;
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.15);
    padding: 6px;
    display: none;
    z-index: 10;
}

.chatbot-preview__menu.is-open .chatbot-preview__menu-panel {
    display: block;
}

.chatbot-preview__menu-item {
    width: 100%;
    border: none;
    background: transparent;
    color: #0f172a;
    text-align: left;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.chatbot-preview__menu-item:hover {
    background: rgba(15, 23, 42, 0.08);
}

.chatbot-preview--dark .chatbot-preview__menu-panel {
    background: #111827;
    border-color: rgba(255, 255, 255, 0.1);
}

.chatbot-preview--dark .chatbot-preview__menu-item {
    color: #f9fafb;
}

.chatbot-preview--dark .chatbot-preview__menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* ============================================
   Loading State
   ============================================ */
.chatbot-preview__loading {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--cb-bg-secondary);
}

.chatbot-preview__loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--cb-border-color);
    border-top-color: var(--cb-primary-color);
    border-radius: 50%;
    animation: chatbot-spin 0.7s linear infinite;
}

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

/* ============================================
   Messages Area
   ============================================ */
.chatbot-preview__messages {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--cb-bg-secondary);
}

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

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

.chatbot-preview__messages::-webkit-scrollbar-thumb {
    background: var(--cb-border-color);
    border-radius: 2px;
}

/* ============================================
   Message Bubbles
   ============================================ */
.chatbot-preview__message {
    display: flex;
    max-width: 85%;
    min-width: 0;
}

.chatbot-preview__message--bot {
    justify-content: flex-start;
}

.chatbot-preview__message--user {
    justify-content: flex-end;
    margin-left: auto;
}

.chatbot-preview__bubble {
    padding: 10px 16px;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Bot Bubble */
.chatbot-preview__message--bot .chatbot-preview__bubble {
    background: var(--cb-primary-color);
    color: #ffffff;
}

/* User Bubble */
.chatbot-preview__message--user .chatbot-preview__bubble {
    background: var(--cb-user-bubble-bg);
    border: 1px solid var(--cb-user-bubble-border);
    color: var(--cb-user-bubble-text);
}

/* System Message */
.chatbot-preview__message--system {
    justify-content: center;
    max-width: 100%;
}

.chatbot-preview__message--system .chatbot-preview__bubble {
    background: transparent;
    border: 1px dashed var(--cb-border-color);
    color: var(--cb-text-secondary);
    font-size: 12px;
    padding: 6px 10px;
    box-shadow: none;
}

/* Bubble Styles - Rounded */
.chatbot-preview--bubble-rounded .chatbot-preview__bubble {
    border-radius: 16px;
}

/* Bubble Styles - Pill */
.chatbot-preview--bubble-pill .chatbot-preview__bubble {
    border-radius: 24px;
    padding-left: 20px;
    padding-right: 20px;
}

/* Bubble Styles - Square */
.chatbot-preview--bubble-square .chatbot-preview__bubble {
    border-radius: 6px;
}

/* ============================================
   Form Message
   ============================================ */
.chatbot-preview__message--form {
    max-width: 100%;
}

.chatbot-preview__bubble--form {
    background: var(--cb-bg-primary);
    color: var(--cb-text-primary);
    border: 1px solid var(--cb-border-color);
    width: 100%;
}

.chatbot-preview__message--form .chatbot-preview__bubble,
.chatbot-preview__message--form .chatbot-preview__bubble--form {
    background: var(--cb-bg-primary);
    color: var(--cb-text-primary);
    border: 1px solid var(--cb-border-color);
}

.chatbot-preview__form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chatbot-preview__form-title {
    font-weight: 600;
    font-size: 14px;
}

.chatbot-preview__form-description {
    font-size: 12px;
    color: var(--cb-text-secondary);
}

.chatbot-preview__form-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    color: var(--cb-text-primary);
}

.chatbot-preview__form-label input,
.chatbot-preview__form-label textarea,
.chatbot-preview__form-label select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--cb-border-color);
    border-radius: 8px;
    background: var(--cb-bg-secondary);
    color: var(--cb-text-primary);
    font-size: 13px;
}

.chatbot-preview__form-label textarea {
    resize: vertical;
    min-height: 80px;
}

.chatbot-preview__form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    color: var(--cb-text-primary);
}

.chatbot-preview__form-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--cb-text-secondary);
}

.chatbot-preview__form-option span {
    color: inherit;
}

.chatbot-preview__form-required {
    color: #ef4444;
    margin-left: 4px;
}

.chatbot-preview__form-captcha {
    padding: 10px;
    border: 1px dashed var(--cb-border-color);
    border-radius: 8px;
    text-align: center;
    font-size: 12px;
    color: var(--cb-text-muted);
}

.chatbot-preview__form-submit {
    border: none;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--cb-primary-color);
    color: #ffffff;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: var(--cb-transition);
}

.chatbot-preview__form-submit:hover {
    filter: brightness(0.95);
}

.chatbot-preview__form-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.chatbot-preview__form-empty {
    font-size: 12px;
    color: var(--cb-text-muted);
}

/* ============================================
   Typing Indicator
   ============================================ */
.chatbot-preview__typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
}

.chatbot-preview__typing-dot {
    width: 6px;
    height: 6px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    animation: chatbot-typing 1.4s infinite ease-in-out both;
}

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

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

@keyframes chatbot-typing {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================
   Suggested Questions
   ============================================ */
.chatbot-preview__suggestions {
    display: flex;
    flex-shrink: 0;
    flex-direction: column;
    gap: 8px;
    padding: 0 16px 12px;
    background: var(--cb-bg-secondary);
}

.chatbot-preview__suggestion {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 6px 12px;
    font-size: 12px;
    color: var(--cb-primary-color);
    background: var(--cb-bg-primary);
    border: 1px solid var(--cb-primary-color);
    border-radius: 16px;
    cursor: pointer;
    transition: var(--cb-transition);
}

.chatbot-preview__suggestion:hover {
    background: var(--cb-primary-color);
    color: #ffffff;
}

/* ============================================
   Bottom Area (Input & Footer)
   ============================================ */
.chatbot-preview__bottom {
    display: flex;
    flex-shrink: 0;
    flex-direction: column;
    background: var(--cb-bg-primary);
    border-top: 1px solid var(--cb-border-color);
}

/* ============================================
   Input Area
   ============================================ */
.chatbot-preview__input-area {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}

.chatbot-preview__input-wrapper {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 8px;
    padding: 10px 16px;
    background: var(--cb-bg-tertiary);
    border-radius: 24px;
}

.chatbot-preview__input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 13px;
    color: var(--cb-text-primary);
    outline: none;
}

.chatbot-preview__input::placeholder {
    color: var(--cb-text-muted);
}

.chatbot-preview__send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--cb-primary-color);
    border: none;
    border-radius: 50%;
    color: #ffffff;
    cursor: pointer;
    transition: var(--cb-transition);
}

.chatbot-preview__send-btn:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

.chatbot-preview__send-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* ============================================
   Footer / Branding
   ============================================ */
.chatbot-preview__footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px;
    font-size: 10px;
    color: var(--cb-text-muted);
    background: var(--cb-bg-primary);
}

.chatbot-preview__footer svg {
    width: 10px;
    height: 10px;
    fill: currentColor;
}

/* ============================================
   Animations
   ============================================ */
.chatbot-preview--animated .chatbot-preview__message {
    animation: chatbot-message-in 0.3s ease-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbot-preview--animated .chatbot-preview__bubble {
    transition: transform 0.2s ease;
}

.chatbot-preview--animated .chatbot-preview__bubble:hover {
    transform: scale(1.02);
}

/* Bounce animation for preview toggle */
@keyframes chatbot-bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.chatbot-preview--bounce {
    animation: chatbot-bounce 0.5s ease-in-out;
}

/* ============================================
   Floating Widget Button
   ============================================ */
.chatbot-widget-button {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    background: var(--cb-primary-color, #3B82F6);
    border: none;
    border-radius: 50%;
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    transition: all 0.3s ease;
    overflow: hidden;
    padding: 0;
}

.chatbot-widget-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

/* Avatar icon — visible when closed */
.chatbot-widget-button__avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    transition: opacity 0.2s ease, transform 0.3s ease;
    position: absolute;
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

/* Close icon — hidden when closed */
.chatbot-widget-button__close {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    opacity: 0;
    transform: scale(0.5) rotate(-90deg);
    transition: opacity 0.2s ease, transform 0.3s ease;
}

.chatbot-widget-button__close svg {
    width: 24px;
    height: 24px;
    fill: #ffffff;
}

/* Active (open) state — swap avatar ↔ close */
.chatbot-widget-button.active .chatbot-widget-button__avatar {
    opacity: 0;
    transform: scale(0.5) rotate(90deg);
}

.chatbot-widget-button.active .chatbot-widget-button__close {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

/* ============================================
   Preview Container (Admin)
   ============================================ */
.chatbot-preview-container {
    position: relative;
}

.chatbot-preview-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.chatbot-preview-label__text {
    font-size: 14px;
    font-weight: 500;
    color: #374151;
}

.chatbot-preview-label__badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    color: #059669;
    background: #d1fae5;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================
   Widget Container (Public Frontend)
   ============================================ */
/* Widget mode - floating position */
.ai-platform-chatbot-container--widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
}

.ai-platform-chatbot-container--widget .chatbot-preview {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 500px;
    max-height: calc(100vh - 150px);
    display: none;
}

/* Bottom-left widget position override */
.ai-platform-chatbot-container--bottom-left {
    right: auto;
    left: 24px;
}

.ai-platform-chatbot-container--bottom-left .chatbot-preview {
    right: auto;
    left: 24px;
}

/* Inline mode - embedded in page */
.ai-platform-chatbot-container--inline {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
}
