/* ========================================
   Ellis AI Chatbot Styles - Optimized for Performance
   Load Once, Show/Hide with CSS
   ======================================== */

/* Ellis Chatbot Floating Action Button (FAB) - Custom Button */
.ellis-chatbot-fab {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    z-index: 10000 !important;
    box-shadow: 0 4px 12px rgba(0, 63, 45, 0.3) !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease !important;
}

/* Custom FAB button styling */
.ellis-custom-fab {
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    outline: none;
}

    .ellis-custom-fab:focus {
        outline: 2px solid #003F2D;
        outline-offset: 2px;
    }

    .ellis-custom-fab img {
        width: 48px;
        height: 48px;
        display: block;
        pointer-events: none;
    }

    .ellis-chatbot-fab:hover {
        transform: scale(1.05) !important;
        box-shadow: 0 6px 16px rgba(0, 63, 45, 0.4) !important;
    }

    .ellis-chatbot-fab:active {
        transform: scale(0.95) !important;
    }

/* Ellis Assistant Window - Always in DOM, controlled by CSS */
.ellis-assistant-window {
    position: fixed;
    top: clamp(20px, calc(100vh - 840px), calc(100vh - 520px)); /* Smart positioning: minimum 20px from top, but ensure at least 400px height */
    bottom: 90px;
    right: 30px;
    width: 800px;
    height: auto; /* Let height be calculated by top/bottom constraints */
    min-height: 400px;
    max-height: calc(100vh - 120px); /* Account for positioning + padding */
    background: white;
    border: 1px solid var(--divider-grey, #e0e0e0);
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
    z-index: 10001; /* Ensure it's above everything including mobile menu */
    display: flex;
    flex-direction: column;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
    will-change: opacity, transform;
    backface-visibility: hidden;
    overflow: hidden;
}

/* Visible state - smooth fade in and slide up */
.ellis-assistant-window.ellis-visible {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
    pointer-events: auto;
}

/* Hidden state - fade out and slide down, but keep in DOM for instant re-show */
.ellis-assistant-window.ellis-hidden {
    opacity: 0;
    transform: translateY(20px);
    visibility: hidden;
    pointer-events: none;
}

/* Header */
.ellis-assistant-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid var(--divider-grey, #e0e0e0);
    background: var(--dark-green, #003F2D);
    color: white;
    border-radius: 16px 16px 0 0;
    flex-shrink: 0;
}

    .ellis-assistant-header h6 {
        margin: 0;
        font-size: 20px;
        font-weight: 600;
        letter-spacing: 0.15px;
        color: #FFFFFF;
    }

.ellis-close-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.87);
    transition: background-color 0.2s ease;
}

    .ellis-close-button:hover {
        background: rgba(255, 255, 255, 0.15);
        color: #FFFFFF;
    }

    .ellis-close-button:active {
        opacity: 0.5;
    }

    .ellis-close-button svg {
        width: 24px;
        height: 24px;
    }
/* Container */
.ellis-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    background: linear-gradient(180deg, #FAFAFA 0%, #FFFFFF 100%);
    max-height: 100%;
    min-height: 0; /* Allow flex item to shrink below content size */
}

/* Specific constraints for Native Federation container */
#ellis-native-federation-container.ellis-container {
    height: 100%;
    max-height: 100%;
    overflow: hidden; /* Prevent Ellis component from overflowing */
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Ensure the main Ellis window properly constrains Native Federation content */
.ellis-assistant-window:has(#ellis-native-federation-container) {
    overflow: hidden !important;
}

/* Additional safety for Native Federation content */
.ellis-assistant-window #ellis-native-federation-container {
    flex: 1;
    min-height: 0;
    contain: layout size style;
}

.ellis-assistant-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #FFFFFF;
}

/* Loading state */
.ellis-loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 48px 32px;
    text-align: center;
    background: linear-gradient(180deg, #FAFAFA 0%, #FFFFFF 100%);
}

    .ellis-loading-container p {
        margin: 16px 0 8px 0;
        color: var(--light-grey, #5E6A6C);
        font-size: 18px;
        line-height: 1.6;
    }

    .ellis-loading-container .ellis-loading-hint {
        margin: 0;
        color: var(--light-grey, #5E6A6C);
        font-size: 15px;
        font-style: italic;
    }

.ellis-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e5e7eb;
    border-top-color: var(--dark-green, #003F2D);
    border-radius: 50%;
    animation: ellis-spin 1s linear infinite;
}

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

/* Error state */
.ellis-error-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 48px 32px;
    text-align: center;
    background: linear-gradient(180deg, #FAFAFA 0%, #FFFFFF 100%);
}

    .ellis-error-container svg {
        margin-bottom: 16px;
    }

.ellis-error-message {
    margin: 16px 0;
    color: var(--light-grey, #5E6A6C);
    font-size: 18px;
    line-height: 1.6;
}

.ellis-retry-button {
    background: var(--dark-green, #003F2D);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: background-color 0.2s, transform 0.1s;
}

    .ellis-retry-button:hover {
        background: #002a1f;
    }

    .ellis-retry-button:active {
        transform: scale(0.98);
    }

/* Welcome and Suggested Prompts Styles */
.ellis-welcome-text {
    padding: 48px 32px 24px 32px;
    font-size: 28px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--dark-green, #003F2D);
    margin: 0;
}

.ellis-description-text {
    padding: 0 32px 32px 32px;
    font-size: 18px;
    line-height: 1.6;
    color: var(--light-grey, #5E6A6C);
    margin: 0;
}

.ellis-suggested-prompts {
    padding: 16px 32px 32px 32px;
    width: 100%;
}

    .ellis-suggested-prompts h6 {
        margin: 0 0 16px 0;
        font-size: 16px;
        font-weight: 600;
        color: var(--light-grey, #5E6A6C);
        letter-spacing: -0.14px;
        text-align: center;
    }

.ellis-prompt-card {
    background: #FFFFFF;
    border: 1px solid var(--divider-grey, #e0e0e0);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

    .ellis-prompt-card:hover {
        border-color: var(--dark-green, #003F2D);
        box-shadow: 0 4px 12px rgba(0, 63, 45, 0.12);
        transform: translateY(-2px);
    }

    .ellis-prompt-card:active {
        transform: scale(0.98);
    }

    .ellis-prompt-card:last-child {
        margin-bottom: 0;
    }

.ellis-prompt-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.ellis-prompt-icon {
    font-size: 20px;
    color: var(--dark-green, #003F2D);
}

.ellis-prompt-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--Text-Dark-Text-Dark, #1A1A1A);
    letter-spacing: -0.14px;
}

.ellis-prompt-description {
    margin: 0;
    font-size: 15px;
    color: var(--light-grey, #5E6A6C);
    line-height: 1.5;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .ellis-assistant-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        border: none;
        z-index: 10000; /* Ensure it's above everything on mobile */
    }

    /* Ensure header is always visible and properly positioned on mobile */
    .ellis-assistant-header {
        border-radius: 0;
        padding: 16px 20px;
        /* Add safe area padding for notched devices */
        padding-top: max(16px, env(safe-area-inset-top));
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
        position: sticky;
        top: 0;
        z-index: 10;
        flex-shrink: 0;
        min-height: 56px; /* Ensure minimum height */
    }

    .ellis-assistant-header h6 {
        font-size: 18px;
        flex: 1; /* Ensure title takes available space */
    }

    /* Ensure close button is always visible and tappable on mobile */
    .ellis-close-button {
        padding: 8px;
        min-width: 40px;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        z-index: 11;
    }

    .ellis-close-button svg {
        width: 24px;
        height: 24px;
        pointer-events: none; /* Ensure tap goes to button, not SVG */
    }

    .ellis-chatbot-fab {
        bottom: 80px !important;
        /* Add safe area padding */
        bottom: max(80px, calc(80px + env(safe-area-inset-bottom))) !important;
    }

    /* Mobile-specific sizing for custom FAB */
    .ellis-custom-fab {
        width: 56px;
        height: 56px;
    }

    .ellis-custom-fab img {
        width: 48px;
        height: 48px;
    }

    /* Ensure container doesn't overlap with header */
    .ellis-container {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        /* Add safe area padding at bottom */
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }

    .ellis-welcome-text {
        padding: 32px 20px 16px 20px;
        font-size: 22px;
    }

    .ellis-description-text {
        padding: 0 20px 24px 20px;
        font-size: 16px;
    }

    .ellis-suggested-prompts {
        padding: 16px 20px 24px 20px;
    }

    .ellis-prompt-card {
        padding: 16px;
    }

    .ellis-prompt-title {
        font-size: 15px;
    }

    .ellis-prompt-description {
        font-size: 14px;
    }

    .ellis-loading-container,
    .ellis-error-container {
        padding: 32px 20px;
        /* Add safe area padding */
        padding-bottom: max(32px, calc(32px + env(safe-area-inset-bottom)));
    }

    .ellis-loading-container p,
    .ellis-error-message {
        font-size: 16px;
    }

    .ellis-loading-container .ellis-loading-hint {
        font-size: 14px;
    }
}

/* Additional mobile fixes for very small screens */
@media (max-width: 480px) {
    .ellis-assistant-header {
        padding: 12px 16px;
        padding-top: max(12px, env(safe-area-inset-top));
        min-height: 52px;
    }

    .ellis-assistant-header h6 {
        font-size: 16px;
    }

    .ellis-close-button {
        min-width: 36px;
        min-height: 36px;
    }
}

/* Fix for landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .ellis-assistant-header {
        padding: 10px 16px;
        padding-top: max(10px, env(safe-area-inset-top));
        min-height: 48px;
    }

    .ellis-assistant-header h6 {
        font-size: 16px;
    }

    .ellis-container {
        /* In landscape, content area is smaller */
        max-height: calc(100vh - 48px);
    }
}

/* Small desktop screens - prevent clipping */
@media (min-height: 600px) and (max-height: 900px) and (min-width: 769px) {
    .ellis-assistant-window {
        top: max(20px, calc(100vh - 620px));
        height: auto;
        min-height: 400px;
        max-height: calc(100vh - 120px);
    }
}

/* Tablet responsive */
@media (min-width: 769px) and (max-width: 1024px) {
    .ellis-assistant-window {
        width: 700px;
        top: max(20px, calc(100vh - 840px));
        height: auto;
        min-height: 400px;
        max-height: calc(100vh - 120px);
        right: 20px;
        bottom: 90px;
    }

    .ellis-welcome-text {
        padding: 40px 28px 20px 28px;
        font-size: 24px;
    }

    .ellis-description-text {
        padding: 0 28px 28px 28px;
    }

    .ellis-suggested-prompts {
        padding: 16px 28px 28px 28px;
    }
}

/* Large screens */
@media (min-width: 1440px) {
    .ellis-assistant-window {
        width: 900px;
        top: max(20px, calc(100vh - 970px));
        height: auto;
        min-height: 500px;
        max-height: calc(100vh - 120px);
    }

    .ellis-welcome-text {
        padding: 56px 40px 24px 40px;
        font-size: 32px;
    }

    .ellis-description-text {
        padding: 0 40px 32px 40px;
        font-size: 20px;
    }

    .ellis-suggested-prompts {
        padding: 16px 40px 40px 40px;
    }
}

/* Ultra-wide screens */
@media (min-width: 1920px) {
    .ellis-assistant-window {
        width: 1000px;
        top: max(20px, calc(100vh - 1020px));
        height: auto;
        min-height: 600px;
        max-height: calc(100vh - 120px);
    }

    .ellis-welcome-text {
        padding: 64px 48px 24px 48px;
        font-size: 36px;
    }

    .ellis-description-text {
        padding: 0 48px 32px 48px;
        font-size: 22px;
    }

    .ellis-suggested-prompts {
        padding: 16px 48px 48px 48px;
    }
}

/* Performance optimizations */
.ellis-assistant-window,
.ellis-container {
    contain: layout style paint;
}

/* Smooth scrolling for container */
.ellis-container {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e0 transparent;
}

    .ellis-container::-webkit-scrollbar {
        width: 6px;
    }

    .ellis-container::-webkit-scrollbar-track {
        background: transparent;
    }

    .ellis-container::-webkit-scrollbar-thumb {
        background: #cbd5e0;
        border-radius: 3px;
    }

        .ellis-container::-webkit-scrollbar-thumb:hover {
            background: #a0aec0;
        }

/* Animation performance optimizations */
@media (prefers-reduced-motion: reduce) {
    .ellis-assistant-window,
    .ellis-chatbot-fab,
    .ellis-prompt-card,
    .ellis-close-button,
    .ellis-retry-button {
        transition: none !important;
        animation: none !important;
    }
}

/* Ensure proper z-index layering */
.ellis-chatbot-fab,
.ellis-assistant-window {
    isolation: isolate;
}

/* Print styles - hide chatbot when printing */
@media print {
    .ellis-chatbot-fab,
    .ellis-assistant-window {
        display: none !important;
    }
}

/* Dark mode support (optional - if application supports dark mode) */
@media (prefers-color-scheme: dark) {
    .ellis-assistant-window {
        background: #1f2937;
        box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
        border-color: #374151;
    }

    .ellis-container {
        background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
    }

    .ellis-assistant-content {
        background: #1f2937;
    }

    .ellis-welcome-text {
        color: #17E88F;
    }

    .ellis-description-text {
        color: #d1d5db;
    }

    .ellis-suggested-prompts h6 {
        color: #d1d5db;
    }

    .ellis-prompt-card {
        background: #374151;
        border-color: #4b5563;
    }

        .ellis-prompt-card:hover {
            background: #4b5563;
            border-color: #17E88F;
        }

    .ellis-prompt-title {
        color: #f9fafb;
    }

    .ellis-prompt-description {
        color: #d1d5db;
    }

    .ellis-loading-container,
    .ellis-error-container {
        background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
    }

    .ellis-loading-container p,
    .ellis-error-message {
        color: #d1d5db;
    }

    .ellis-loading-container .ellis-loading-hint {
        color: #9ca3af;
    }

    .ellis-spinner {
        border-color: #4b5563;
        border-top-color: #17E88F;
    }
}
