/**
 * Artemis Chat Widget Styles
 * Superior UI Design System Implementation
 * @version 1.0.0
 */

/* ========== CSS Variables ========== */
:root {
    /* Cloudline Modern - Light Mode Color Palette */
    --artemis-primary: #9ED9F5; /* Pale Blue - ethereal sky */
    --artemis-primary-hover: #7AC5E8; /* Moonlit Blue - deeper engagement */
    --artemis-primary-rgb: 158, 217, 245; /* RGB for rgba() usage */
    --artemis-secondary: #CBE8F6; /* Arctic Blue - soft clouds */
    --artemis-secondary-rgb: 203, 232, 246;
    --artemis-accent: #8E7CC3; /* Electric Violet - elegant pop */
    --artemis-accent-hover: #A08DD6; /* Bright Violet - hover state */
    --artemis-accent-rgb: 142, 124, 195;
    --artemis-success: #34a853;
    --artemis-warning: #fbbc04;
    --artemis-danger: #ea4335;
    --artemis-text-primary: #202124;
    --artemis-text-secondary: #5f6368;
    --artemis-border: #dadce0;
    --artemis-background: #f8f9fa;
    --artemis-card: #ffffff;

    /* Cloudline Modern - Gradients */
    --artemis-gradient: linear-gradient(135deg, #9ED9F5 0%, #8E7CC3 100%); /* Pale Blue to Electric Violet */
    --artemis-gradient-soft: linear-gradient(135deg, #CBE8F6 0%, #9ED9F5 100%); /* Arctic Blue to Pale Blue */

    /* Spacing */
    --artemis-space-1: 0.25rem;
    --artemis-space-2: 0.5rem;
    --artemis-space-3: 0.75rem;
    --artemis-space-4: 1rem;
    --artemis-space-5: 1.25rem;
    --artemis-space-6: 1.5rem;
    --artemis-space-8: 2rem;

    /* Enterprise UX: Widget bottom spacing - Oct 24 2025 */
    --artemis-widget-bottom-safe: 32px; /* 25px minimum + 7px breathing room */

    /* Cloudline Modern - Blue-tinted Shadows */
    --artemis-shadow-sm: 0 1px 2px rgba(158, 217, 245, 0.08);
    --artemis-shadow-md: 0 4px 6px rgba(158, 217, 245, 0.15);
    --artemis-shadow-lg: 0 10px 15px rgba(158, 217, 245, 0.2);
    --artemis-shadow-xl: 0 20px 25px rgba(158, 217, 245, 0.25);
    --artemis-shadow-prominent: 0 8px 24px rgba(158, 217, 245, 0.4);

    /* Animations */
    --artemis-transition-fast: 150ms;
    --artemis-transition-base: 200ms;
    --artemis-transition-slow: 300ms;
    --artemis-easing: cubic-bezier(0.4, 0.0, 0.2, 1);

    /* Border Radius */
    --artemis-radius-sm: 6px;
    --artemis-radius-md: 8px;
    --artemis-radius-lg: 12px;
    --artemis-radius-full: 9999px;

    /* Z-Index - P0 FIX: Align with design system - Oct 29, 2025 */
    --artemis-z-widget: 9999; /* Unified z-index scale - matches artemis-z-chat-widget */
}

/* Cloudline Modern - Dark Mode */
[data-theme="dark"] {
    --artemis-primary: #7AC5E8; /* Moonlit Blue - night sky glow */
    --artemis-primary-rgb: 122, 197, 232;
    --artemis-secondary: #1E2A3A; /* Deep Night Blue - rich darkness */
    --artemis-secondary-rgb: 30, 42, 58;
    --artemis-accent: #A08DD6; /* Bright Violet - aurora */
    --artemis-accent-hover: #B5A3E3;
    --artemis-accent-rgb: 160, 141, 214;
    --artemis-background: #1a1f2e;
    --artemis-card: #252b3b;
    --artemis-border: #374151;
    --artemis-text-primary: #e5e7eb;
    --artemis-text-secondary: #9ca3af;

    /* Cloudline Modern - Dark mode gradients with glow */
    --artemis-gradient: linear-gradient(135deg, #7AC5E8 0%, #A08DD6 100%); /* Moonlit Blue to Bright Violet */
    --artemis-gradient-soft: linear-gradient(135deg, #1E2A3A 0%, rgba(122, 197, 232, 0.2) 100%);

    /* Cloudline Modern - Dark mode shadows with aurora glow */
    --artemis-shadow-sm: 0 1px 2px rgba(122, 197, 232, 0.12);
    --artemis-shadow-md: 0 4px 6px rgba(122, 197, 232, 0.2);
    --artemis-shadow-lg: 0 10px 15px rgba(122, 197, 232, 0.25);
    --artemis-shadow-xl: 0 20px 25px rgba(122, 197, 232, 0.3);
    --artemis-shadow-prominent: 0 8px 24px rgba(122, 197, 232, 0.5), 0 0 40px rgba(160, 141, 214, 0.3);
}

/* ========== Widget Container ========== */
.artemis-chat-widget-container {
    position: fixed;
    z-index: var(--artemis-z-widget);
}

.artemis-chat-widget-container.bottom-right {
    bottom: var(--artemis-widget-bottom-safe); /* Enterprise UX: 32px safe area - Oct 24 2025 */
    right: var(--artemis-space-6);
}

.artemis-chat-widget-container.bottom-left {
    bottom: var(--artemis-widget-bottom-safe); /* Enterprise UX: 32px safe area - Oct 24 2025 */
    left: var(--artemis-space-6);
}

.artemis-chat-widget-container.top-right {
    top: var(--artemis-space-6);
    right: var(--artemis-space-6);
}

.artemis-chat-widget-container.top-left {
    top: var(--artemis-space-6);
    left: var(--artemis-space-6);
}

/* ========== Chat Bubble (Minimized) ========== */
.artemis-chat-bubble {
    width: 64px;
    height: 64px;
    background: var(--artemis-gradient);
    border-radius: var(--artemis-radius-full);
    box-shadow: var(--artemis-shadow-prominent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 28px;
    transition: all var(--artemis-transition-base) var(--artemis-easing);
    position: relative;
    animation: artemisEntrance 0.6s var(--artemis-easing);
}

.artemis-chat-bubble:hover {
    transform: scale(1.1);
    /* Cloudline Modern - Enhanced blue-tinted glow on hover */
    box-shadow: 0 12px 32px rgba(158, 217, 245, 0.5);
}

[data-theme="dark"] .artemis-chat-bubble:hover {
    /* Cloudline Modern - Dark: Dual aurora glow */
    box-shadow: 0 12px 32px rgba(122, 197, 232, 0.6), 0 0 50px rgba(160, 141, 214, 0.4);
}

/* First visit pulse animation */
.artemis-chat-bubble.first-visit {
    animation: artemisEntrance 0.6s var(--artemis-easing), artemisPulseGlow 2.5s ease-in-out 3;
}

@keyframes artemisEntrance {
    0% {
        opacity: 0;
        transform: scale(0.3) translateY(20px);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes artemisPulseGlow {
    0%, 100% {
        box-shadow: var(--artemis-shadow-prominent);
        transform: scale(1);
    }
    50% {
        /* Cloudline Modern - Enhanced blue glow */
        box-shadow: 0 12px 36px rgba(158, 217, 245, 0.6);
        transform: scale(1.05);
    }
}

/* Cloudline Modern - Dark mode pulse glow */
[data-theme="dark"] .artemis-chat-bubble.first-visit {
    animation: artemisEntrance 0.6s var(--artemis-easing), artemisPulseGlowDark 2.5s ease-in-out 3;
}

@keyframes artemisPulseGlowDark {
    0%, 100% {
        box-shadow: var(--artemis-shadow-prominent);
        transform: scale(1);
    }
    50% {
        /* Cloudline Modern - Dark: Aurora pulse */
        box-shadow: 0 12px 36px rgba(122, 197, 232, 0.7), 0 0 60px rgba(160, 141, 214, 0.5);
        transform: scale(1.05);
    }
}

.artemis-chat-bubble-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--artemis-danger);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: var(--artemis-radius-full);
    font-size: 11px;
    font-weight: 600;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

/* ========== Chat Widget (Expanded) ========== */
.artemis-chat-widget {
    width: 420px;
    height: 680px;
    background: var(--artemis-card);
    border-radius: 16px;
    /* Cloudline Modern - Blue-tinted shadow for ethereal depth */
    box-shadow: 0 16px 48px rgba(158, 217, 245, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: artemisSlideIn 0.3s var(--artemis-easing);
}

[data-theme="dark"] .artemis-chat-widget {
    /* Cloudline Modern - Dark: Moonlit glow */
    box-shadow: 0 16px 48px rgba(122, 197, 232, 0.4), 0 0 80px rgba(160, 141, 214, 0.2);
}

/* Backdrop overlay when widget is open - Nov 2, 2025: Full viewport coverage */
.artemis-chat-backdrop {
    position: fixed;
    top: 0; /* Full viewport coverage - header handled separately with z-index */
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.1); /* Reduced from 0.3 to 0.1 for readability */
    backdrop-filter: none; /* Removed blur - users need to read page content */
    z-index: calc(var(--artemis-z-widget) - 1);
    animation: artemisFadeIn 0.2s ease-out;
    display: none;
}

.artemis-chat-backdrop.active {
    display: block;
}

@keyframes artemisBackdropFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

/* ========== Widget Header ========== */
.artemis-chat-header {
    background: var(--artemis-gradient);
    color: white;
    padding: var(--artemis-space-4);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.artemis-chat-header-left {
    display: flex;
    align-items: center;
    gap: var(--artemis-space-3);
}

.artemis-chat-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--artemis-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

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

.artemis-chat-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: var(--artemis-space-1);
    margin: 2px 0 0 0;
}

.artemis-status-dot {
    width: 6px;
    height: 6px;
    background: white;
    border-radius: var(--artemis-radius-full);
    animation: artemisPulse 2s infinite;
}

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

.artemis-chat-header-right {
    display: flex;
    gap: var(--artemis-space-2);
}

.artemis-chat-btn {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: var(--artemis-radius-sm);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--artemis-transition-base);
}

.artemis-chat-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ========== Messages Area ========== */
.artemis-chat-messages {
    flex: 1;
    overflow-y: auto; /* Use auto instead of scroll to show scrollbar only when needed */
    padding: var(--artemis-space-4);
    background: var(--artemis-background);
    display: flex;
    flex-direction: column;
    gap: var(--artemis-space-4);
    min-height: 0; /* Important for flex shrinking */
    max-height: 500px; /* DESKTOP FIX (Nov 2, 2025): Explicit max-height for scrollable area */
}

.artemis-chat-messages::-webkit-scrollbar {
    width: 10px; /* DESKTOP FIX (Nov 2, 2025): Wider scrollbar for better visibility */
    display: block !important; /* Force scrollbar to always show */
}

.artemis-chat-messages::-webkit-scrollbar-track {
    background: rgba(148, 163, 184, 0.15); /* Slightly more visible track */
    border-radius: 4px;
}

.artemis-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.5); /* More prominent thumb */
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.artemis-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.7); /* Darker on hover */
}

/* ========== Message Styles ========== */
.artemis-message {
    display: flex;
    gap: var(--artemis-space-3);
    animation: artemisFadeIn 0.3s ease-in;
}

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

.artemis-message.user {
    flex-direction: row-reverse;
}

.artemis-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--artemis-radius-full);
    background: var(--artemis-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.artemis-message.user .artemis-message-avatar {
    background: var(--artemis-text-secondary);
}

.artemis-message-content {
    max-width: 75%;
}

.artemis-message-text {
    padding: var(--artemis-space-3) var(--artemis-space-4);
    border-radius: var(--artemis-radius-md);
    background: var(--artemis-card);
    border: 1px solid var(--artemis-border);
    font-size: 14px;
    line-height: 1.6;
    color: var(--artemis-text-primary) !important; /* CRITICAL FIX: Override global p color rule */
}

/* Override global paragraph styling for chat messages */
.artemis-message-text p,
.artemis-message-text strong,
.artemis-message-text em {
    color: inherit !important; /* Inherit from parent .artemis-message-text */
}

.artemis-message.user .artemis-message-text {
    /* Cloudline Modern - Light: Soft Arctic Blue background */
    background: linear-gradient(135deg, var(--artemis-secondary) 0%, rgba(158, 217, 245, 0.3) 100%);
    border: none;
}

[data-theme="dark"] .artemis-message.user .artemis-message-text {
    /* Cloudline Modern - Dark: Subtle moonlit gradient */
    background: linear-gradient(135deg, rgba(122, 197, 232, 0.2) 0%, rgba(30, 42, 58, 0.5) 100%);
}

/* CRITICAL FIX: Dark mode styling for assistant messages */
/* Support both data-theme attribute AND dark-mode class */
[data-theme="dark"] .artemis-message:not(.user) .artemis-message-text,
body.dark-mode .artemis-message:not(.user) .artemis-message-text,
.dark-mode .artemis-message:not(.user) .artemis-message-text {
    background: var(--artemis-card) !important;  /* Dark background #252b3b */
    color: var(--artemis-text-primary) !important;  /* Light text #E8EDF2 for visibility */
    border-color: var(--artemis-border) !important;  /* Darker border in dark mode */
}

.artemis-message-time {
    font-size: 11px;
    color: var(--artemis-text-secondary);
    margin-top: var(--artemis-space-1);
    padding: 0 var(--artemis-space-1);
}

/* Markdown formatting */
.artemis-message-text p {
    margin: 0 0 var(--artemis-space-3) 0;
}

.artemis-message-text p:last-child {
    margin-bottom: 0;
}

.artemis-message-text ul,
.artemis-message-text ol {
    margin: var(--artemis-space-2) 0 var(--artemis-space-3) 0;
    padding-left: var(--artemis-space-6);
}

.artemis-message-text li {
    margin: var(--artemis-space-1) 0;
}

.artemis-message-text strong {
    font-weight: 600;
}

.artemis-message-text code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: var(--artemis-radius-sm);
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.9em;
}

.artemis-message-text pre {
    background: rgba(0, 0, 0, 0.05);
    padding: var(--artemis-space-3);
    border-radius: var(--artemis-radius-md);
    overflow-x: auto;
    margin: var(--artemis-space-3) 0;
}

.artemis-message-text pre code {
    background: none;
    padding: 0;
}

/* ========== Typing Indicator ========== */
.artemis-typing-indicator {
    display: flex;
    gap: var(--artemis-space-1);
    padding: var(--artemis-space-3);
}

.artemis-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--artemis-text-secondary);
    border-radius: var(--artemis-radius-full);
    animation: artemisTyping 1.4s infinite;
}

.artemis-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.artemis-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes artemisTyping {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ========== Targeting Panel ========== */
.artemis-targeting-panel {
    max-height: 200px;
    background: var(--artemis-card);
    border-top: 1px solid var(--artemis-border);
    overflow-y: auto;
}

.artemis-targeting-header {
    padding: var(--artemis-space-3) var(--artemis-space-4);
    border-bottom: 1px solid var(--artemis-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.artemis-targeting-header h4 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.artemis-close-targeting {
    background: none;
    border: none;
    color: var(--artemis-text-secondary);
    cursor: pointer;
    padding: var(--artemis-space-1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.artemis-close-targeting:hover {
    color: var(--artemis-text-primary);
}

.artemis-targeting-content {
    padding: var(--artemis-space-3);
    display: flex;
    flex-direction: column;
    gap: var(--artemis-space-2);
}

.artemis-targeting-card {
    background: var(--artemis-background);
    border: 1px solid var(--artemis-border);
    border-radius: var(--artemis-radius-md);
    padding: var(--artemis-space-3);
    transition: all var(--artemis-transition-base);
}

.artemis-targeting-card.selected {
    /* Cloudline Modern - Light: Soft selected state */
    background: linear-gradient(135deg, rgba(158, 217, 245, 0.15) 0%, rgba(142, 124, 195, 0.1) 100%);
    border-color: var(--artemis-primary);
    box-shadow: var(--artemis-shadow-sm);
}

[data-theme="dark"] .artemis-targeting-card.selected {
    /* Cloudline Modern - Dark: Glowing selected state */
    background: linear-gradient(135deg, rgba(122, 197, 232, 0.25) 0%, rgba(160, 141, 214, 0.15) 100%);
    border-color: var(--artemis-accent);
    box-shadow: 0 0 20px rgba(160, 141, 214, 0.3);
}

.artemis-targeting-header {
    display: flex;
    align-items: center;
    gap: var(--artemis-space-2);
    margin-bottom: var(--artemis-space-2);
}

.artemis-segment-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--artemis-primary);
}

.artemis-targeting-title {
    font-size: 13px;
    font-weight: 600;
    flex: 1;
}

.artemis-targeting-description {
    font-size: 12px;
    color: var(--artemis-text-secondary);
    line-height: 1.4;
}

.artemis-targeting-badge {
    font-size: 10px;
    /* Cloudline Modern - Accent gradient badge */
    background: linear-gradient(135deg, var(--artemis-accent) 0%, var(--artemis-accent-hover) 100%);
    color: white;
    padding: 2px 8px;
    border-radius: var(--artemis-radius-full);
    margin-top: var(--artemis-space-2);
    display: inline-block;
    box-shadow: 0 2px 8px rgba(var(--artemis-accent-rgb), 0.3);
}

[data-theme="dark"] .artemis-targeting-badge {
    /* Cloudline Modern - Dark: Glowing accent badge */
    box-shadow: 0 2px 8px rgba(var(--artemis-accent-rgb), 0.5), 0 0 20px rgba(var(--artemis-accent-rgb), 0.3);
}

/* ========== Input Area ========== */
.artemis-chat-input-container {
    padding: var(--artemis-space-4);
    padding-bottom: calc(var(--artemis-space-4) * 2.5); /* Enterprise UX: Generous bottom padding for professional appearance - Oct 24 2025 */
    background: var(--artemis-card);
    border-top: 1px solid var(--artemis-border);
    display: flex;
    gap: var(--artemis-space-3);
    align-items: flex-end;
}

.artemis-chat-input {
    flex: 1;
    padding: var(--artemis-space-3) var(--artemis-space-4);
    border: 1px solid var(--artemis-border);
    border-radius: var(--artemis-radius-md);
    font-size: 16px; /* iOS zoom prevention - minimum 16px required */
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--artemis-text-primary); /* FIX: Ensure text is always visible on mobile */
    background: white; /* Ensure proper contrast */
    resize: none;
    min-height: 44px;
    max-height: 120px;
    line-height: 1.5;
    transition: border-color var(--artemis-transition-base);
}

.artemis-chat-input:focus {
    outline: none;
    /* Cloudline Modern - Accent focus ring */
    border-color: var(--artemis-accent);
    box-shadow: 0 0 0 3px rgba(var(--artemis-accent-rgb), 0.15);
}

/* Dark mode support - ensure text is visible in dark theme */
[data-theme="dark"] .artemis-chat-input,
body.dark-mode .artemis-chat-input,
.dark-mode .artemis-chat-input {
    color: var(--artemis-text-primary); /* Light text in dark mode */
    background: var(--artemis-card); /* Dark background */
    border-color: var(--artemis-border); /* Dark border */
}

[data-theme="dark"] .artemis-chat-input:focus {
    /* Cloudline Modern - Dark: Glowing focus ring */
    box-shadow: 0 0 0 3px rgba(var(--artemis-accent-rgb), 0.25), 0 0 20px rgba(var(--artemis-accent-rgb), 0.2);
}

.artemis-chat-input::placeholder {
    color: var(--artemis-text-secondary);
}

.artemis-send-btn {
    width: 44px;
    height: 44px;
    /* Cloudline Modern - Electric Violet gradient */
    background: linear-gradient(135deg, var(--artemis-accent) 0%, var(--artemis-accent-hover) 100%);
    color: white;
    border: none;
    border-radius: var(--artemis-radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--artemis-transition-base);
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(var(--artemis-accent-rgb), 0.3);
}

.artemis-send-btn:hover {
    /* Cloudline Modern - Enhanced glow on hover */
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(var(--artemis-accent-rgb), 0.4);
}

[data-theme="dark"] .artemis-send-btn:hover {
    /* Cloudline Modern - Dark: Aurora glow */
    box-shadow: 0 6px 16px rgba(var(--artemis-accent-rgb), 0.6), 0 0 30px rgba(var(--artemis-accent-rgb), 0.3);
}

.artemis-send-btn:disabled {
    background: var(--artemis-border);
    color: var(--artemis-text-secondary);
    cursor: not-allowed;
    box-shadow: none;
}

/* ========== Responsive Design ========== */
@media (max-width: 640px) {
    .artemis-chat-widget {
        width: 100vw;
        height: 90vh; /* 90% viewport height for better mobile UX */
        height: 90dvh; /* Dynamic viewport height - accounts for browser UI */
        max-height: 90vh;
        max-height: 90dvh;
        border-radius: 16px 16px 0 0; /* Rounded top corners only */
        position: fixed !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: auto !important;
        display: flex;
        flex-direction: column;
        overflow-y: auto !important; /* ALLOW SCROLLING TO REACH INPUT FIELD */
        -webkit-overflow-scrolling: touch;
    }

    /* Enterprise UX: Mobile respects safe area for bottom spacing - Oct 24 2025 */
    .artemis-chat-widget-container {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        z-index: 90 !important; /* Lower than header (100) to not block menu button */
    }

    /* Enterprise UX: When minimized on mobile, respect safe bottom spacing - Oct 24 2025 */
    .artemis-chat-widget-container:not(.open) {
        bottom: max(var(--artemis-widget-bottom-safe), env(safe-area-inset-bottom)) !important;
    }

    /* Ensure chat bubble doesn't block header on mobile */
    .artemis-chat-bubble {
        z-index: 90 !important; /* Lower than header (100) */
    }

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

    /* Make messages container flexible to accommodate keyboard */
    .artemis-chat-messages {
        flex: 0 1 auto; /* Don't grow, allow shrink */
        min-height: 0; /* Important for flex shrinking */
        height: calc(100dvh - 180px); /* FIXED height - Reserve space for header + input */
        max-height: calc(100dvh - 180px);
        overflow-y: scroll !important; /* Always show scrollbar */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        overscroll-behavior: contain; /* Prevent page scroll */
    }

    /* Force scrollbar visibility on mobile */
    .artemis-chat-messages::-webkit-scrollbar {
        width: 8px !important; /* Wider for touch */
        display: block !important;
    }

    .artemis-chat-messages::-webkit-scrollbar-track {
        background: rgba(148, 163, 184, 0.1) !important;
    }

    .artemis-chat-messages::-webkit-scrollbar-thumb {
        background: rgba(148, 163, 184, 0.5) !important;
        border-radius: 4px !important;
        border: 2px solid transparent !important;
        background-clip: padding-box !important;
    }

    .artemis-chat-messages::-webkit-scrollbar-thumb:hover {
        background: rgba(148, 163, 184, 0.8) !important;
    }

    /* Ensure input container stays at bottom */
    .artemis-chat-input-container {
        flex-shrink: 0;
        position: sticky !important;
        bottom: 0 !important;
        background: var(--artemis-bg-primary, white) !important;
        z-index: 10 !important;
        /* Add iOS safe area padding for home indicator */
        padding-bottom: calc(var(--artemis-space-4) + env(safe-area-inset-bottom));
        padding-left: calc(var(--artemis-space-4) + env(safe-area-inset-left));
        padding-right: calc(var(--artemis-space-4) + env(safe-area-inset-right));
    }

    /* Ensure chat input is easily tappable */
    .artemis-chat-input {
        min-height: 44px; /* iOS minimum touch target */
        font-size: 16px; /* Prevent iOS zoom on focus */
    }

    /* Account for Dynamic Island / notch */
    .artemis-chat-header {
        padding-top: calc(var(--artemis-space-4) + env(safe-area-inset-top));
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    .artemis-chat-widget {
        width: 360px;
        height: 550px;
    }
}

/* ========== Accessibility ========== */
.artemis-chat-widget:focus-within {
    /* Cloudline Modern - Accent focus outline */
    outline: 2px solid var(--artemis-accent);
    outline-offset: 2px;
}

[data-theme="dark"] .artemis-chat-widget:focus-within {
    /* Cloudline Modern - Dark: Glowing outline */
    outline: 2px solid var(--artemis-accent);
    box-shadow: 0 0 0 4px rgba(var(--artemis-accent-rgb), 0.25);
}

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

    .artemis-message-text {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .artemis-chat-bubble,
    .artemis-chat-widget,
    .artemis-message,
    .artemis-chat-btn,
    .artemis-targeting-card {
        animation: none;
        transition: none;
    }
}

/* Print styles */
@media print {
    .artemis-chat-widget-container {
        display: none;
    }
}

/* ========================================================================
   CRITICAL FIX #3: Backdrop Blocking Header (Oct 30, 2025)
   Issue: Backdrop covers header buttons when chat is open
   Mobile UX Analysis: Dark mode toggle blocked by backdrop
   NOTE (Oct 31, 2025): Consolidated with Bug #1 fix at line 236
   ======================================================================== */

/* REMOVED - Duplicate rule causing opacity conflict. See line 236 for correct backdrop CSS */

/* Alternative fix: Click-through backdrop */
.artemis-chat-backdrop.click-through {
  pointer-events: none;
}

/* ========================================================================
   MOBILE FIX: Reduce backdrop opacity and remove blur on mobile (Oct 30, 2025)
   Issue: 50% black backdrop + 4px blur too heavy on mobile, makes content unreadable
   User reports:
   - "chat box is unavailable on mobile" (extremely faded)
   - "chat window is blurred out" (backdrop-filter blur effect)
   Solution: Reduce opacity to 10% and remove blur on mobile viewports
   ======================================================================== */
@media (max-width: 768px) {
  .artemis-chat-backdrop {
    background: rgba(0, 0, 0, 0.1) !important; /* Light backdrop on mobile */
    backdrop-filter: none !important; /* Remove blur effect on mobile */
  }
}

/* ========================================================================
   END OF BACKDROP FIX - October 30, 2025
   ======================================================================== */
