/**
 * Bricks Chatbot Styles
 */

/* ==========================================
   Container
   ========================================== */

.bricks-chatbot-container {
    display: flex;
    flex-direction: column;
    border: 1px solid #e0e0e0;
    border-radius: 16px;
    overflow: hidden;
    background: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-width: 100%;
    margin: 0 auto;
}

/* ==========================================
   Messages Container
   ========================================== */

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f8f9fa;
    min-height: 400px;
}

/* Scrollbar styling */
.chatbot-messages::-webkit-scrollbar {
    width: 8px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* ==========================================
   Message Bubbles
   ========================================== */

.chatbot-message {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    max-width: 75%;
    margin-bottom: 4px;
}

.chatbot-message--user {
    align-self: flex-end;
    flex-direction: row;
}

.chatbot-message--bot {
    align-self: flex-start;
    flex-direction: row;
    align-items: flex-start;
}

.chatbot-message--user {
    gap: 10px;
}

.chatbot-message--bot {
    gap: 10px;
}

/* ==========================================
   Avatars
   ========================================== */

.chatbot-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.chatbot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chatbot-avatar--bot {
    align-self: flex-start;
}

.chatbot-avatar--user {
    align-self: flex-start;
}

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

.chatbot-name {
    font-size: 12px;
    font-weight: 600;
    color: #65676b;
    margin-bottom: 4px;
    padding-left: 4px;
}

.chatbot-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 15px;
}

/* User message styling */
.chatbot-message--user .chatbot-bubble {
    background-color: #0084ff;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

/* Bot message styling */
.chatbot-message--bot .chatbot-bubble {
    background-color: #e4e6eb;
    color: #050505;
    border-bottom-left-radius: 4px;
}

/* Reset margins for elements inside bubble */
.chatbot-bubble > *:first-child {
    margin-top: 0;
}

.chatbot-bubble > *:last-child {
    margin-bottom: 0;
}

/* ==========================================
   Animations
   ========================================== */

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

.chatbot-message.animate-in {
    animation: slideInUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ==========================================
   Buttons
   ========================================== */

.chatbot-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding-left: 0;
}

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

.chatbot-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    outline: none;
    white-space: nowrap;
    font-family: inherit;
}

.chatbot-btn:focus {
    outline: none;
}

/* Primary button */
.chatbot-btn--primary {
    background: #0084ff;
    color: #ffffff;
}

.chatbot-btn--primary:hover:not(:disabled) {
    background: #0073e6;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 132, 255, 0.3);
}

/* Secondary button */
.chatbot-btn--secondary {
    background: #e4e6eb;
    color: #050505;
}

.chatbot-btn--secondary:hover:not(:disabled) {
    background: #d8dadf;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Outline button */
.chatbot-btn--outline {
    background: transparent;
    border: 2px solid #0084ff;
    color: #0084ff;
}

.chatbot-btn--outline:hover:not(:disabled) {
    background: #0084ff;
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 132, 255, 0.3);
}

/* Disabled state */
.chatbot-btn:disabled,
.chatbot-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

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

/* ==========================================
   Typing Indicator
   ========================================== */

.chatbot-typing-indicator {
    display: none;
    padding: 12px 16px;
    background: #e4e6eb;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    margin-left: 20px;
    margin-bottom: 16px;
}

.chatbot-typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #90949c;
    border-radius: 50%;
    margin: 0 3px;
    animation: typing 1.4s infinite ease-in-out;
}

.chatbot-typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.chatbot-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-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;
    }
}

/* ==========================================
   Restart Button
   ========================================== */

.chatbot-restart-btn {
    padding: 14px 20px;
    border: none;
    border-top: 1px solid #e0e0e0;
    background: #f8f9fa;
    color: #0084ff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
    text-align: center;
    font-family: inherit;
    width: 100%;
}

.chatbot-restart-btn:hover {
    background: #e9ecef;
    color: #0073e6;
}

.chatbot-restart-btn:active {
    background: #dee2e6;
}

/* ==========================================
   Initial Message
   ========================================== */

.chatbot-initial-message {
    /* Container for the first message */
}

/* ==========================================
   Responsive Design
   ========================================== */

@media (max-width: 768px) {
    .chatbot-message {
        max-width: 85%;
    }

    .chatbot-bubble {
        font-size: 14px;
        padding: 10px 14px;
    }

    .chatbot-btn {
        padding: 8px 16px;
        font-size: 13px;
    }

    .chatbot-messages {
        padding: 15px;
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .chatbot-message {
        max-width: 90%;
    }

    .bricks-chatbot-container {
        border-radius: 12px;
    }

    .chatbot-buttons {
        gap: 6px;
    }
}

/* ==========================================
   Accessibility
   ========================================== */

/* Focus styles */
.chatbot-btn:focus-visible {
    outline: 3px solid rgba(0, 132, 255, 0.5);
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .chatbot-message.animate-in {
        animation: none;
    }

    .chatbot-typing-indicator span {
        animation: none;
    }

    .chatbot-btn {
        transition: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .chatbot-bubble {
        border: 2px solid currentColor;
    }

    .bricks-chatbot-container {
        border-width: 2px;
    }
}

/* ==========================================
   Dark Mode Support (optional)
   ========================================== */

@media (prefers-color-scheme: dark) {
    .bricks-chatbot-container {
        background: #1e1e1e;
        border-color: #333;
    }

    .chatbot-messages {
        background: #2a2a2a;
    }

    .chatbot-message--bot .chatbot-bubble {
        background-color: #3a3a3a;
        color: #e0e0e0;
    }

    .chatbot-restart-btn {
        background: #2a2a2a;
        border-color: #333;
        color: #0084ff;
    }

    .chatbot-restart-btn:hover {
        background: #3a3a3a;
    }

    .chatbot-typing-indicator {
        background: #3a3a3a;
    }

    .chatbot-btn--secondary {
        background: #3a3a3a;
        color: #e0e0e0;
    }

    .chatbot-btn--secondary:hover:not(:disabled) {
        background: #4a4a4a;
    }
}

/* ==========================================
   Print Styles
   ========================================== */

@media print {
    .chatbot-restart-btn,
    .chatbot-buttons,
    .chatbot-typing-indicator {
        display: none !important;
    }

    .bricks-chatbot-container {
        box-shadow: none;
        border: 1px solid #000;
    }

    .chatbot-message {
        page-break-inside: avoid;
    }
}

/* ==========================================
   Builder Preview Styles
   ========================================== */

.chatbot-builder-response-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f0f0f1;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
}

.chatbot-builder-response-id {
    color: #1e1e1e;
    font-family: monospace;
    background: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid #ddd;
}

.chatbot-builder-initial-badge {
    background: #0073aa;
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chatbot-builder-empty {
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-style: italic;
}

/* Show nestable children in builder for our chatbot */
.brxe-chatbot .brx-nestable-children {
    display: flex !important;
    flex-direction: column;
    gap: 16px;
}

.brxe-chatbot .brx-nestable-children .brxe-chatbot-response {
    display: block !important;
}