/* Chatbot Widget Styles */
.chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
}

/* Backdrop for large mode */
.chatbot-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.chatbot-backdrop.active {
    opacity: 1;
    pointer-events: all;
}

/* Floating Button */
.chatbot-trigger {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent-gradient, linear-gradient(135deg, var(--accent-primary, #667eea) 0%, var(--accent-secondary, #764ba2) 100%));
    border: none;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.3s ease;
}

.chatbot-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.chatbot-trigger.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0);
}

.chatbot-trigger svg {
    width: 24px;
    height: 24px;
}

.chatbot-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    font-size: 12px;
    font-weight: 600;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

/* Chat Window */
.chatbot-window {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 40px);
    background: var(--bg-primary, white);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Size Modes */
.chatbot-window.size-small {
    width: 380px;
    height: 600px;
}

.chatbot-window.size-medium {
    width: 760px;
    height: 600px;
}

.chatbot-window.size-large {
    width: 80vw;
    height: 90vh;
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, -50%);
}

.chatbot-window.size-large.open {
    transform: translate(-50%, -50%) scale(1);
}

.chatbot-window.open {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: all;
}

.chatbot-window.minimized .chatbot-body,
.chatbot-window.minimized .chatbot-footer {
    display: none;
}

.chatbot-window.minimized {
    height: auto;
}

/* Header */
.chatbot-header {
    background: var(--accent-gradient, linear-gradient(135deg, var(--accent-primary, #667eea) 0%, var(--accent-secondary, #764ba2) 100%));
    color: white;
    padding: 16px 20px;
    border-radius: 16px 16px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chatbot-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--bg-primary, white);
    padding: 4px;
}

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

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

.status-dot {
    width: 6px;
    height: 6px;
    background: #2ecc71;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

.chatbot-minimize,
.chatbot-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chatbot-minimize:hover,
.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Body */
.chatbot-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary, #f8f9fa);
    position: relative;
    overflow: hidden;
}

/* Welcome Screen */
.chatbot-welcome {
    text-align: center;
    padding: 20px;
}

.welcome-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    background: var(--accent-gradient, linear-gradient(135deg, var(--accent-primary, #667eea) 0%, var(--accent-secondary, #764ba2) 100%));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.chatbot-welcome h4 {
    margin: 0 0 8px;
    font-size: 20px;
    color: var(--text-primary, #2c3e50);
}

.chatbot-welcome p {
    margin: 0 0 20px;
    color: var(--text-secondary, #7f8c8d);
}

.welcome-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.suggestion-btn {
    background: var(--bg-primary, white);
    border: 1px solid var(--border-color, #e0e0e0);
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    text-align: left;
    color: var(--text-primary, #2c3e50);
}

.suggestion-btn:hover {
    border-color: var(--accent-primary, #667eea);
    background: var(--accent-light, #f8f9ff);
    transform: translateX(4px);
}

/* Messages */
.chatbot-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
}

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

.chatbot-messages::-webkit-scrollbar-track {
    background: var(--bg-secondary, #f8f9fa);
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--border-color, #e0e0e0);
    border-radius: 4px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary, #667eea);
}

.messages-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.messages-spacer {
    height: 18px;
    flex-shrink: 0;
}

.message {
    display: flex;
    gap: 12px;
    animation: slideIn 0.3s ease;
}

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-primary, #667eea);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--accent-primary, #3498db);
}

.message-content {
    flex: 1;
    background: var(--bg-primary, white);
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    line-height: 1.5;
    font-size: 14px;
    color: var(--text-primary, #2c3e50);
}

.message.user .message-content {
    background: var(--accent-primary, #667eea);
    color: white;
}

/* AI Response Images and Containers */
.message-content img {
    max-width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
    margin: 0.75rem 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.message-content .image-container {
    max-width: 100%;
    margin: 1rem 0;
}

.message-content .image-text-flex {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 1rem 0;
}

/* On medium+ screens, allow side-by-side layout */
.chatbot-window.size-medium .message-content .image-text-flex,
.chatbot-window.size-large .message-content .image-text-flex {
    flex-direction: row;
    align-items: flex-start;
}

.chatbot-window.size-medium .message-content .image-text-flex img,
.chatbot-window.size-large .message-content .image-text-flex img {
    max-width: 300px;
    flex-shrink: 0;
}

/* Small mode - always stack vertically with smaller images */
.chatbot-window.size-small .message-content img {
    max-width: 100%;
}

.chatbot-window.size-small .message-content .image-text-flex {
    flex-direction: column;
}

/* Ensure images don't break layout on mobile */
@media (max-width: 768px) {
    .message-content img {
        max-width: 100%;
    }

    .message-content .image-text-flex {
        flex-direction: column !important;
    }
}

/* ============================================= */
/* AI-Generated HTML Element Styling */
/* Ensures all AI responses use theme colors */
/* ============================================= */

/* Divs and containers */
.message-content div,
.message-content .ai-response {
    color: inherit;
    background: transparent;
}

/* Headings */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    color: var(--text-primary, #2c3e50);
    margin: 1rem 0 0.5rem 0;
    font-weight: 600;
    line-height: 1.3;
}

.message-content h1 { font-size: 1.5em; }
.message-content h2 { font-size: 1.3em; }
.message-content h3 { font-size: 1.15em; }
.message-content h4 { font-size: 1.05em; }
.message-content h5 { font-size: 1em; }
.message-content h6 { font-size: 0.95em; }

/* Paragraphs */
.message-content p {
    color: var(--text-primary, #2c3e50);
    margin: 0.5rem 0;
    line-height: 1.6;
}

/* Lists */
.message-content ul,
.message-content ol {
    color: var(--text-primary, #2c3e50);
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message-content li {
    color: var(--text-primary, #2c3e50);
    margin: 0.25rem 0;
    line-height: 1.5;
}

/* Links */
.message-content a {
    color: var(--accent-primary, #667eea);
    text-decoration: underline;
    transition: color 0.2s;
}

.message-content a:hover {
    color: var(--text-primary, #2c3e50);
}

/* Strong and emphasis */
.message-content strong,
.message-content b {
    color: var(--text-primary, #2c3e50);
    font-weight: 600;
}

.message-content em,
.message-content i {
    color: var(--text-primary, #2c3e50);
    font-style: italic;
}

/* Code blocks */
.message-content code {
    background: var(--bg-secondary, #f5f5f5);
    color: var(--text-primary, #2c3e50);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: var(--bg-secondary, #f5f5f5);
    color: var(--text-primary, #2c3e50);
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.75rem 0;
    border: 1px solid var(--border-color, #e0e0e0);
}

.message-content pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
}

/* Blockquotes */
.message-content blockquote {
    background: var(--bg-secondary, #f5f5f5);
    color: var(--text-secondary, #666);
    border-left: 4px solid var(--accent-primary, #667eea);
    padding: 0.75rem 1rem;
    margin: 0.75rem 0;
    border-radius: 0 6px 6px 0;
}

/* Tables */
.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.75rem 0;
    background: var(--bg-primary, white);
    color: var(--text-primary, #2c3e50);
}

.message-content th {
    background: var(--bg-secondary, #f5f5f5);
    color: var(--text-primary, #2c3e50);
    font-weight: 600;
    padding: 0.5rem;
    border: 1px solid var(--border-color, #e0e0e0);
    text-align: left;
}

.message-content td {
    background: var(--bg-primary, white);
    color: var(--text-primary, #2c3e50);
    padding: 0.5rem;
    border: 1px solid var(--border-color, #e0e0e0);
}

/* Horizontal rules */
.message-content hr {
    border: none;
    border-top: 1px solid var(--border-color, #e0e0e0);
    margin: 1rem 0;
}

/* Spans and inline elements */
.message-content span {
    color: inherit;
}

/* Form elements (if AI generates any) */
.message-content input,
.message-content textarea,
.message-content select {
    background: var(--bg-primary, white);
    color: var(--text-primary, #2c3e50);
    border: 1px solid var(--border-color, #e0e0e0);
    padding: 0.5rem;
    border-radius: 4px;
}

/* Buttons (if AI generates any) */
.message-content button {
    background: var(--accent-primary, #667eea);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
}

.message-content button:hover {
    opacity: 0.9;
}

/* User messages should keep their distinct styling */
.message.user .message-content h1,
.message.user .message-content h2,
.message.user .message-content h3,
.message.user .message-content h4,
.message.user .message-content h5,
.message.user .message-content h6,
.message.user .message-content p,
.message.user .message-content li,
.message.user .message-content strong,
.message.user .message-content em,
.message.user .message-content span,
.message.user .message-content div,
.message.user .message-content a {
    color: white !important;
}

.message.user .message-content code {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.message.user .message-content pre {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    color: white;
}

/* Scroll to Bottom */
.scroll-to-bottom {
    position: absolute;
    bottom: 80px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: var(--bg-primary, white);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    color: var(--text-primary, #2c3e50);
}

.scroll-to-bottom:hover {
    background: var(--bg-secondary, #f8f9fa);
    transform: translateY(-2px);
}

.scroll-to-bottom.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Footer */
.chatbot-footer {
    padding: 16px 20px;
    background: var(--bg-primary, white);
    border-top: 1px solid var(--border-color, #e0e0e0);
    border-radius: 0 0 16px 16px;
}

.chatbot-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.chatbot-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chatbot-input {
    flex: 1;
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 16px;
    resize: none;
    min-height: 40px;
    max-height: 100px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    background: var(--bg-primary, white);
    color: var(--text-primary, #2c3e50);
    overflow-y: hidden;
}

.chatbot-input:focus {
    border-color: var(--accent-primary, #667eea);
}

.chatbot-send {
    width: 40px;
    height: 40px;
    background: var(--accent-gradient, linear-gradient(135deg, var(--accent-primary, #667eea) 0%, var(--accent-secondary, #764ba2) 100%));
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.chatbot-send:hover:not(:disabled) {
    transform: scale(1.1);
}

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

.chatbot-powered {
    text-align: center;
    font-size: 11px;
    color: var(--text-tertiary, #95a5a6);
    margin-top: 8px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    /* Adjust chatbot toggle button to sit above mobile nav */
    .chatbot-widget {
        bottom: 80px;
    }

    /* Force full-screen on mobile regardless of size mode */
    .chatbot-window,
    .chatbot-window.size-small,
    .chatbot-window.size-medium,
    .chatbot-window.size-large {
        width: 100% !important;
        height: 100dvh !important; /* Use dynamic viewport height for keyboard adjustment */
        max-width: 100vw !important;
        max-height: 100dvh !important;
        bottom: 0 !important;
        right: 0 !important;
        top: 0 !important;
        left: 0 !important;
        border-radius: 0 !important;
        transform: none !important;
        position: fixed !important;
    }

    .chatbot-window.size-large.open {
        transform: none !important;
    }

    /* Hide backdrop on mobile */
    .chatbot-backdrop {
        display: none !important;
    }

    /* Minimal padding/margins for mobile */
    .chatbot-header {
        border-radius: 0;
        padding: 12px 16px;
    }

    .chatbot-footer {
        border-radius: 0;
        padding: 12px 16px;
    }

    .chatbot-messages {
        padding: 12px;
    }

    .chatbot-body {
        padding: 0;
    }

    /* Hide size toggle button on mobile */
    .chatbot-minimize {
        display: none !important;
    }

    /* Adjust service grid for mobile */
    .service-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
        margin: 0.75rem 0;
    }

    .service-card[data-service-uid] {
        margin: 0.25rem;
    }

    /* Smaller message gaps */
    .messages-container {
        gap: 12px;
    }
}
