/* Modern, Performance-Optimized Styles */
:root {
    /* iOS Safe Area Support */
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    
    /* Theme variables - will be set by JavaScript */
    --primary-color: #f97316;
    --secondary-color: #ea580c;
    --accent-color: #4f46e5;
    --accent-color-light: #fef3c7;
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    
    /* Status colors */
    --warning-bg: #fff3cd;
    --warning-border: #ffeaa7;
    --warning-text: #856404;
    --success-bg: #d4edda;
    --success-border: #c3e6cb;
    --success-text: #155724;
    --error-color: #dc3545;
    --error-hover: #c82333;
    --success-color: #28a745;
    --primary-shadow: rgba(249, 115, 22, 0.1);
    
    /* Component visibility variables - controlled by UX Configuration Manager */
    --feedback-display: flex;
    --metadata-display: block;
    --settings-button-display: flex;
    --settings-panel-display: block;
    --system-status-display: block;
    --model-selector-display: block;
    --performance-monitor-display: block;
    --theme-controls-display: block;
    --actions-section-display: block;
    
    /* Color system component visibility */
    --color-presets-display: block;
    --custom-color-picker-display: block;
    --color-accessibility-test-display: block;
    --advanced-options-display: none;
    --admin-section-display: none;
    --export-chat-display: inline-block;
    --anonymous-state-display: block;
    --authenticated-state-display: none;
    
    /* Layout variables */
    --border-radius: 8px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --transition: all 0.2s ease;
}

/* ==== COMPONENT VISIBILITY SYSTEM ====
 * All component visibility controlled by CSS custom properties
 * This ensures configuration-driven show/hide without DOM breakage
 */

/* Authentication states */
#anonymousState {
    display: var(--anonymous-state-display) !important;
}

#authenticatedState {
    display: var(--authenticated-state-display) !important;
}

/* Settings panel and controls */
.settings-button,
#settingsButton {
    display: var(--settings-button-display) !important;
}

.settings-panel,
#settingsPanel {
    display: var(--settings-panel-display, block);
}

/* Settings panel sections */
#systemStatusContent,
.system-status-section {
    display: var(--system-status-display) !important;
}

#aiModelContent,
.model-selector-section {
    display: var(--model-selector-display) !important;
}

#performanceMonitorContent,
.performance-monitor-section {
    display: var(--performance-monitor-display) !important;
}

#themeAppearanceContent,
.theme-controls-section {
    display: var(--theme-controls-display) !important;
}

#actionsContent,
.actions-section {
    display: var(--actions-section-display) !important;
}

#advancedSettingsContent,
.advanced-options-section {
    display: var(--advanced-options-display) !important;
}

#adminSection,
.admin-section {
    display: var(--admin-section-display) !important;
}

/* Color system component visibility */
.color-presets-section {
    display: var(--color-presets-display) !important;
}

.custom-color-picker-section {
    display: var(--custom-color-picker-display) !important;
}

.color-accessibility-test-section {
    display: var(--color-accessibility-test-display) !important;
}

/* Export functionality */
.export-chat-button,
.export-controls {
    display: var(--export-chat-display) !important;
}

/* Feedback system - already implemented */
.message-feedback-below,
.feedback-button {
    display: var(--feedback-display);
}

/* User avatar dropdown menu */
.user-menu-wrapper {
    position: relative;
    display: inline-block;
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius, 8px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 220px;
    z-index: 1000;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
    pointer-events: none;
}

.user-dropdown.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.user-dropdown::before {
    content: '';
    position: absolute;
    top: -6px;
    right: 16px;
    width: 12px;
    height: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-right: none;
    transform: rotate(45deg);
    z-index: -1;
}

.dropdown-header {
    padding: 12px 16px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.dropdown-header .user-info {
    flex: 1;
    min-width: 0;
}

.dropdown-header .user-name {
    margin-bottom: 2px;
    word-break: break-word;
}

.dropdown-header .user-email {
    word-break: break-word;
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0;
}

.dropdown-item {
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    text-align: left;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    transition: background 0.2s ease;
    border-radius: 0 0 var(--border-radius, 8px) var(--border-radius, 8px);
}

.dropdown-item:hover {
    background: var(--bg-tertiary);
}

.dropdown-item svg {
    opacity: 0.7;
}

/* Dropdown animation now handled by CSS transitions in .user-dropdown */

/* ==== END COMPONENT VISIBILITY SYSTEM ==== */

/* Reset and base styles */
* {
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 0; /* Remove padding to accommodate topbar */
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: var(--transition);
    overflow-x: hidden; /* Prevent horizontal scroll */
    /* iPhone Safe Area Support */
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
    padding-bottom: var(--safe-area-inset-bottom);
}

/* Theme-based image filtering */
body.theme-light {
    --theme-filter: none;
}

body.theme-dark {
    --theme-filter: invert(1) brightness(1.5) contrast(1.2);
}

/* Enhanced Loading states */
body.loading {
    cursor: wait;
}

body.loading * {
    pointer-events: none;
}

/* Micro-interactions for buttons */
button, .control-button, .send-button {
    position: relative;
    overflow: hidden;
}

button::before, .control-button::before, .send-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

button:active::before, .control-button:active::before, .send-button:active::before {
    width: 300px;
    height: 300px;
}

/* Pulse animation for loading states */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.loading-pulse {
    animation: pulse 1.5s ease-in-out infinite;
}

/* Enhanced message animations */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Collapsible System Status */
.control-label-with-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 8px 0;
    transition: var(--transition);
    min-height: 32px;
}

.control-label-with-toggle:hover {
    color: var(--primary-color);
}

.control-label-with-toggle:hover .status-toggle {
    color: var(--primary-color);
}

.status-toggle {
    font-size: 14px;
    transition: transform 0.3s ease;
    color: var(--text-primary);
    background: transparent;
    border: none;
    padding: 2px;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
}

.system-status-content {
    overflow: hidden;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
    max-height: 150px;
    padding-top: 8px;
}

.system-status-content.collapsed {
    max-height: 0;
    padding-top: 0;
}


/* Control section collapsible functionality */
.control-section-content {
    overflow: hidden;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
    max-height: 500px; /* Higher than system status to accommodate more content */
    padding-top: 8px;
}

.control-section-content.collapsed {
    max-height: 0;
    padding-top: 0;
}

.control-group .status-toggle.collapsed {
    transform: rotate(-90deg);
}

.message {
    animation: messageSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Smooth transitions for theme changes */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Topbar Navigation */
.topbar {
    background: var(--primary-color);
    color: white;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--secondary-color);
}

.topbar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 20px;
    max-width: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
}

.topbar-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-title {
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    margin: 0;
    color: white;
    line-height: 1.2;
}

.app-subtitle {
    font-size: 12px;
    opacity: 0.8;
    font-weight: 400;
    font-family: inherit;
    color: rgba(255, 255, 255, 0.8);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.topbar-button.settings-toggle {
    border: none !important;
    background: transparent !important;
}

.topbar-button.settings-toggle:hover {
    background: rgba(255, 255, 255, 0.1) !important;
}

.topbar-button:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.topbar-button.primary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.topbar-button.primary:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.topbar-button.secondary {
    background: transparent;
    border-color: rgba(255, 255, 255, 0.4);
}

.topbar-button.secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.settings-toggle svg {
    width: 16px;
    height: 16px;
}

.settings-toggle {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

.settings-toggle:focus,
.settings-toggle:focus-visible,
.settings-toggle:focus-within {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

/* Additional comprehensive outline removal for settings button */
#settingsToggle,
.topbar-button.settings-toggle {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
}

#settingsToggle:focus,
#settingsToggle:focus-visible,
#settingsToggle:focus-within,
.topbar-button.settings-toggle:focus,
.topbar-button.settings-toggle:focus-visible,
.topbar-button.settings-toggle:focus-within {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
}

.settings-toggle:active {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
}

.settings-toggle span {
    display: none; /* Settings text always hidden - icon only */
}

.auth-container {
    display: flex;
    align-items: center;
}

.auth-state {
    display: flex;
    align-items: center;
    gap: 12px;
}

.auth-status {
    font-size: 12px;
    opacity: 0.8;
    font-weight: 500;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary-color); /* User avatar uses primary color (orange) by default */
    background: var(--bg-tertiary);
    transition: all 0.2s ease;
}

.user-avatar:hover {
    border-color: var(--accent-color); /* Show accent color on hover for interaction feedback */
    transform: scale(1.05);
}

.user-email {
    font-size: 14px;
    font-weight: 500;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* App Layout - Push-based settings panel positioning */
.app-layout {
    display: flex;
    height: calc(100vh - 60px); /* Full viewport height minus topbar */
    background: var(--bg-primary);
    transition: all var(--settings-animation-duration, 300ms) ease;
    margin-top: 0; /* Remove any margin */
    padding-top: 0; /* Remove any padding */
}

/* Chat Container - Adjusts to make room for settings panel */
.chat-container {
    flex: 1;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto; /* Allow vertical scrolling within the chat container */
    transition: all var(--settings-animation-duration, 300ms) ease;
    width: 100%; /* Ensure it takes full width within flex container */
    display: flex;
    flex-direction: column;
    min-width: 0; /* Allow flex item to shrink below content size */
    position: relative; /* For absolute positioning of child elements */
    min-height: 0; /* Critical for proper flex shrinking */
    justify-content: flex-end; /* Push content to bottom */
    /* Configuration-driven properties via CSS variables */
    padding-bottom: var(--chat-bottom-padding, 20px);
}

/* Mobile-specific chat container adjustments */
@media (max-width: 768px) {
    .chat-container {
        padding: 15px;
        padding-bottom: var(--chat-bottom-padding-mobile, 15px);
        height: auto; /* Allow container to size based on content */
        min-height: calc(100% - 30px); /* Ensure it takes up most of the space */
        
        /* 🔧 MOBILE FIX: Ensure chat area always remains visible when settings panel is open */
        flex: 1 1 auto; /* Allow shrinking but maintain minimum height */
        min-height: 40vh; /* Always reserve at least 40% viewport for chat area */
        overflow-y: auto; /* Enable scrolling within chat if needed */
    }
    
    /* Fix for iOS Safari and iPad Mini */
    .app-layout {
        height: -webkit-fill-available; /* Use available height on iOS */
        min-height: -webkit-fill-available;
    }
}

/* Phone-specific chat container adjustments */
@media (max-width: 480px) {
    .chat-container {
        padding: 10px;
        padding-bottom: var(--chat-bottom-padding-phone, 10px);
        height: auto; /* Allow container to size based on content */
        min-height: calc(100% - 20px); /* Ensure it takes up most of the space */
    }
    
    /* Additional fixes for small screens */
    body {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
}

/* Settings Panel Base Styles - Now positioned within layout flow */
.settings-panel {
    background: var(--bg-secondary);
    border-radius: 0 0 12px 12px;
    box-shadow: none;
    /* 🔧 RESPONSIVE FIX: Enhanced transitions for responsive scaling */
    transition: all var(--settings-animation-duration, 300ms) ease, width 0.3s ease, height 0.3s ease;
    overflow-y: auto;
    scrollbar-width: thin;
    flex-shrink: 0; /* Don't shrink the settings panel */
    margin: 0 20px 20px 20px; /* No top margin */
}

.settings-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 16px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 12px 12px 0 0;
    margin-top: 0;
}

.settings-panel-header h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 600;
}

.settings-close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.settings-close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.settings-panel-content {
    padding: 16px 24px 24px 24px;
}

/* Horizontal tile layout for top/bottom directions on wide screens */
@media (min-width: 1200px) {
    .app-layout[data-settings-direction="top"] .settings-panel-content,
    .app-layout[data-settings-direction="bottom"] .settings-panel-content {
        display: flex;
        flex-wrap: wrap;
        gap: 20px;
        padding: 20px;
    }
    
    .app-layout[data-settings-direction="top"] .control-group,
    .app-layout[data-settings-direction="bottom"] .control-group {
        flex: 1;
        min-width: 300px;
        margin-bottom: 0;
    }
    
}

/* Settings Panel Direction Styles - Push-based Layout */

/* TOP Direction - Column layout with settings on top */
.app-layout[data-settings-direction="top"] {
    flex-direction: column;
    /* Ensure proper layout for top settings */
    align-items: stretch;
    justify-content: flex-start;
    /* 🔧 RESPONSIVE FIX: Smooth transitions when changing directions */
    transition: flex-direction 0.3s ease, height 0.3s ease;
}

/* Top settings positioning is now handled by the dynamic approach above */

@keyframes slideDownFromTop {
    0% {
        transform: translateY(-20px);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

/* BOTTOM Direction - Column layout with settings at bottom */
.app-layout[data-settings-direction="bottom"] {
    flex-direction: column;
}

.app-layout[data-settings-direction="bottom"] .settings-panel {
    width: 100%;
    height: 0;
    overflow: hidden;
    order: 1; /* Settings appear below chat */
    border-radius: 12px 12px 0 0;
    margin: 20px 20px 0 20px; /* Left and right margins, top margin to separate from chat */
}

.app-layout[data-settings-direction="bottom"][data-settings-visible="true"] .settings-panel {
    height: var(--settings-size, 40vh);
    overflow-y: auto;
}

/* LEFT Direction - Row layout with settings on left */
.app-layout[data-settings-direction="left"] {
    flex-direction: row;
    /* 🔧 RESPONSIVE FIX: Smooth transitions when changing directions */
    transition: flex-direction 0.3s ease, height 0.3s ease;
}

.app-layout[data-settings-direction="left"] .settings-panel {
    width: 0;
    height: 100%;
    overflow: hidden;
    order: -1; /* Settings appear left of chat */
    border-radius: 0 12px 12px 0;
    margin: 20px 20px 20px 0; /* All margins except left */
}

.app-layout[data-settings-direction="left"][data-settings-visible="true"] .settings-panel {
    width: var(--settings-size, 380px);
    overflow-y: auto;
}

/* RIGHT Direction - Row layout with settings on right */
.app-layout[data-settings-direction="right"] {
    flex-direction: row;
    width: 100%;
    /* 🔧 RESPONSIVE FIX: Smooth transitions when changing directions */
    transition: flex-direction 0.3s ease, height 0.3s ease;
}

.app-layout[data-settings-direction="right"] .settings-panel {
    width: 0;
    height: 100%;
    overflow: hidden;
    order: 1; /* Settings appear right of chat */
    border-radius: 12px 0 0 12px;
    margin: 20px 0 20px 20px; /* All margins except right */
}

.app-layout[data-settings-direction="right"][data-settings-visible="true"] .settings-panel {
    width: var(--settings-size, 380px);
    overflow-y: auto;
}

/* Legacy container - now handled by main-container */

@media (max-width: 768px) {
    .topbar-content {
        padding: 10px 15px;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .topbar-left {
        flex: 1;
        min-width: 0;
    }
    
    .app-title {
        font-size: 18px;
    }
    
    .app-subtitle {
        font-size: 11px;
    }
    
    .topbar-right {
        gap: 12px;
        flex-wrap: wrap;
    }
    
    .topbar-button {
        padding: 6px 10px;
        font-size: 13px;
        /* 🔧 MOBILE FIX: Ensure proper touch targets */
        min-height: 44px;
        min-width: 44px;
        touch-action: manipulation;
    }
    
    .settings-toggle {
        /* 🔧 MOBILE FIX: Ensure button is clickable on mobile */
        min-height: 44px !important;
        min-width: 44px !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
        /* Ensure button stays responsive and accessible */
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        position: relative !important;
        z-index: 10 !important;
        /* Prevent button from being affected by layout changes */
        flex-shrink: 0 !important;
    }
    
    .settings-toggle span {
        display: none; /* Settings text always hidden - icon only */
    }
    
    .user-email {
        max-width: 120px;
        font-size: 13px;
    }
    
    /* Mobile - Keep desktop push-based layout but adjust sizing */
    .chat-container {
        padding: 15px;
    }
    
    /* Mobile settings panel adjustments */
    .settings-panel {
        margin: 10px !important; /* Smaller margins on mobile */
    }
    
    /* Mobile height is now handled by the --settings-size CSS variable */
    
    .app-layout[data-settings-direction="left"][data-settings-visible="true"] .settings-panel,
    .app-layout[data-settings-direction="right"][data-settings-visible="true"] .settings-panel {
        width: 90%; /* Most of screen width on mobile */
        max-width: 320px;
    }
    
    .control-group {
        margin-bottom: 15px;
    }
    
    .control-buttons {
        gap: 12px;
    }
    
    .control-button {
        padding: 10px 14px;
        font-size: 16px;
        min-height: 44px; /* Touch-friendly minimum size */
        flex: 1;
        max-width: none;
    }
    
    /* Make model selector full width and touch-friendly */
    #modelSelector {
        width: 100% !important;
        padding: 12px 16px;
        font-size: 16px;
        min-height: 44px;
        /* Enhanced mobile dropdown visibility */
        z-index: 1000;
        position: relative;
        border: 2px solid var(--border-color);
        border-radius: 8px;
        background: var(--bg-secondary);
        appearance: none;
        -webkit-appearance: none;
        -moz-appearance: none;
        cursor: pointer;
    }
    
    /* Improve dropdown focus state for accessibility */
    #modelSelector:focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
        border-color: var(--primary-color);
        box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    }
    
    /* Style dropdown options for better mobile visibility */
    #modelSelector option {
        padding: 10px;
        font-size: 16px;
        background: var(--bg-secondary);
        color: var(--text-primary);
    }
    
    /* Visual highlight for the AI model section on mobile */
    #aiModelContent {
        position: relative;
        padding: 8px;
        border-radius: 8px;
        background: rgba(79, 70, 229, 0.05);
        margin-bottom: 12px;
    }
    
    /* Add dropdown icon indicator */
    #modelSelector::-webkit-calendar-picker-indicator {
        background: transparent;
        color: var(--primary-color);
        font-size: 18px;
    }
    
    /* Pulse animation to draw attention when needed */
    .model-selector-highlight {
        animation: mobilePulse 2s infinite;
    }
    
    @keyframes mobilePulse {
        0% {
            box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.4);
        }
        70% {
            box-shadow: 0 0 0 10px rgba(79, 70, 229, 0);
        }
        100% {
            box-shadow: 0 0 0 0 rgba(79, 70, 229, 0);
        }
    }
    
    /* Better mobile chat layout */
    .chat-container {
        flex: 1;
        min-height: 400px;
    }
}

/* Chat Interface - Full height optimized with fixed topbar */


.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--primary-color);
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    position: relative;
    z-index: 10;
    gap: 16px;
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
}

.avatar-container {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.2);
    font-size: 24px;
}

.session-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    opacity: 0.9;
}

.session-status {
    font-weight: 500;
}

.session-details {
    font-size: 12px;
    opacity: 0.8;
    font-style: italic;
}

.chat-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.icon-button {
    background: rgba(0, 0, 0, 0.2);
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    padding: 8px;
    transition: var(--transition);
}

.icon-button:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 20px 20px 20px;
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    margin: 0 20px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

/* WebKit scrollbar styling for messages container */
.messages-container::-webkit-scrollbar {
    width: 6px;
}

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

.messages-container::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.welcome-message {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    padding: 20px;
}

.message {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    animation: messageSlideIn 0.3s ease;
}

.user-message {
    justify-content: flex-end; /* Right-align user messages */
    flex-direction: row-reverse; /* Put avatar on the right side */
}

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

.message-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.user-message .message-avatar {
    background: transparent; /* Transparent background for user avatar */
    border: 1px solid var(--primary-color); /* Border to match primary theme */
    color: var(--primary-color); /* Icon color matches theme */
}

.ai-message .message-avatar {
    background: var(--primary-color); /* Match chat header background */
    border: none; /* Clean unified look like header */
    color: white; /* Match header text color */
}

.message-content {
    flex: 1;
    width: 100%; /* Take full available width */
    background: var(--bg-primary);
    padding: 12px 16px;
    border-radius: var(--border-radius);
    border: 1px solid rgba(0, 0, 0, 0.1);
    position: relative;
    box-sizing: border-box;
}

.user-message .message-content {
    background: var(--bg-secondary); /* Use secondary background for better visibility */
    color: var(--text-primary); /* Use theme text color */
    border: 2px solid var(--primary-color); /* Border to match primary theme - consistent with other components */
    max-width: 80%;
    flex: none; /* Override flex: 1 to allow content-based sizing */
    width: fit-content; /* Size to content */
    min-width: 60px; /* Minimum width for very short messages */
    margin-left: auto; /* Push user messages to the right */
    position: relative;
    z-index: 1;
}

.ai-message .message-content {
    background: var(--primary-color); /* Match AI avatar filled background */
    color: white; /* Ensure good contrast on primary color */
    border: 2px solid var(--primary-color); /* Consistent border width with user messages */
    margin-right: auto; /* Keep AI messages on the left */
    max-width: 80%; /* Limit width so messages don't span full width */
}

/* Markdown table styling */
.markdown-table-wrapper {
    margin: 16px 0;
    overflow-x: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    background: var(--bg-secondary);
}

.markdown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    line-height: 1.5;
}

.markdown-table th,
.markdown-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
    color: var(--text-primary);
}

.markdown-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--primary-color);
}

.markdown-table tbody tr:hover {
    background: rgba(var(--primary-color-rgb, 79, 70, 229), 0.05);
}

.markdown-table tbody tr:last-child td {
    border-bottom: none;
}

.system-message {
    justify-content: center;
    opacity: 0.8;
}

.system-message .message-avatar {
    background: var(--accent-color);
    color: white;
}

.system-message .message-content {
    background: var(--bg-primary);
    border: 1px solid var(--accent-color);
    font-size: 14px;
    font-style: italic;
    text-align: center;
    max-width: 60%;
    color: var(--text-secondary);
}

.message-timestamp {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    text-align: right;
}

/* Mobile/small screen responsive timestamp positioning */
@media (max-width: 768px), (max-height: 600px) {
    .message-timestamp {
        position: absolute;
        bottom: -20px;
        right: 44px; /* Align with message content (account for avatar width) */
        margin-top: 0;
        font-size: 11px;
        opacity: 0.8;
    }
    
    /* Add bottom margin to messages to make room for timestamp below */
    .message {
        margin-bottom: 24px; /* Extra space for timestamp below */
        position: relative; /* Enable absolute positioning for timestamp */
    }
    
    /* User messages: align timestamp to right side since messages are right-aligned */
    .message.user-message .message-timestamp {
        left: auto;
        right: 44px;
    }
    
    /* Don't apply special mobile timestamp positioning to typing indicator */
    .message.typing-indicator {
        margin-bottom: 16px; /* Normal margin for typing indicator */
    }
    
    .message.typing-indicator .message-timestamp {
        position: static; /* Reset to normal flow */
        bottom: auto;
        right: auto;
        left: auto;
        opacity: 1;
    }
    
    /* Messages with reasoning display need more bottom space for timestamp */
    .message:has(.reasoning-display) {
        margin-bottom: 28px;
    }
    
    /* Reasoning display messages: position timestamp below the reasoning area */
    .message:has(.reasoning-display) .message-timestamp {
        bottom: -22px;
    }
}

/* Typing indicator */
.typing-indicator {
    justify-content: flex-start; /* Default: AI thinking aligns left like AI messages */
    flex-direction: row; /* Avatar on left like AI messages */
}

.typing-indicator .message-content {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    min-height: 48px; /* Same as regular chat bubbles */
    display: flex;
    align-items: center;
    padding: 12px 16px;
}

/* Thinking content styles */
.thinking-content {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
}

.thinking-text {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
}

.thinking-subtext {
    font-size: 13px;
    color: var(--text-secondary);
    opacity: 0.8;
    font-style: italic;
}

.thinking-dots-inline {
    display: inline-flex;
    gap: 4px;
    margin-left: 4px;
    align-items: center;
}

.thinking-dots-inline .dot {
    width: 6px;
    height: 6px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: thinkingPulse 1.4s infinite ease-in-out;
}

.thinking-dots-inline .dot:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots-inline .dot:nth-child(2) { animation-delay: -0.16s; }
.thinking-dots-inline .dot:nth-child(3) { animation-delay: 0s; }

@keyframes thinkingPulse {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.4;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Matrix thinking style for reasoning display */
.matrix-thinking {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    position: relative;
}

.matrix-text {
    font-weight: 500;
    font-size: 14px;
    z-index: 2;
    position: relative;
}


/* Reasoning Display Styles */
.reasoning-display {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border: 2px solid var(--primary-color);
    border-radius: 16px;
    padding: 12px 16px;
    margin-bottom: 16px;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    position: relative;
}

.reasoning-display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color), var(--accent-color));
    border-radius: 16px 16px 0 0;
}

.reasoning-display:hover {
    border-color: var(--secondary-color);
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.matrix-header {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
    padding: 8px 0;
    color: var(--text-primary);
    position: relative;
}

/* Removed duplicate "Thinking Process" text */

.matrix-toggle {
    font-size: 12px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.3s ease;
    color: var(--text-secondary);
    font-weight: normal;
    display: inline-block;
    width: 16px;
    text-align: center;
    line-height: 1;
}

.matrix-header:hover .matrix-toggle {
    color: var(--primary-color);
}

.reasoning-display.expanded .matrix-toggle {
    color: var(--primary-color);
}

.matrix-reasoning-content {
    display: none;
    margin-top: 16px;
    padding: 20px;
    background: var(--bg-primary);
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary);
    max-height: 500px;
    overflow-y: auto;
    border-left: 4px solid var(--primary-color);
    border: 2px solid rgba(0, 0, 0, 0.03);
    animation: reasoningSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    letter-spacing: 0.02em;
    position: relative;
}

.matrix-reasoning-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, var(--primary-color), transparent);
}

/* Enhanced typography for reasoning text */
.matrix-reasoning-content strong {
    color: var(--accent-color);
    font-weight: 700;
}

.matrix-reasoning-content em {
    color: var(--secondary-color);
    font-style: normal;
    font-weight: 500;
}

.reasoning-display.expanded .matrix-reasoning-content {
    display: block;
}

@keyframes reasoningSlideIn {
    from {
        opacity: 0;
        max-height: 0;
        padding-top: 0;
        padding-bottom: 0;
    }
    to {
        opacity: 1;
        max-height: 400px;
        padding-top: 12px;
        padding-bottom: 12px;
    }
}

.final-response {
    margin-top: 8px;
}

/* Enhanced reasoning content formatting */
.matrix-reasoning-content strong {
    color: var(--primary-color, #4f46e5);
    font-weight: 600;
}

.matrix-reasoning-content em {
    color: var(--secondary-color, #7c3aed);
    font-style: italic;
    font-weight: 500;
}

/* Dark theme adjustments for reasoning display */
[data-theme="dark"] .reasoning-display,
@media (prefers-color-scheme: dark) {
    .reasoning-display {
        background: var(--bg-secondary);
        border-color: var(--primary-color);
        box-shadow: 0 1px 3px rgba(255, 255, 255, 0.1);
    }
    
    .matrix-reasoning-content {
        background: var(--bg-primary);
        color: var(--text-secondary);
        border: 1px solid rgba(255, 255, 255, 0.05);
    }
}

/* Legacy typing dots - keeping for fallback */
.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ChatGPT-Style Input Container */
.input-container {
    padding: 16px 20px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color, rgba(0, 0, 0, 0.1));
}

.input-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color, rgba(0, 0, 0, 0.1));
    border-radius: 24px;
    padding: 8px 12px;
    max-width: 768px;
    margin: 0 auto;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 1px var(--primary-color);
}

#messageInput {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    min-height: 32px;
    max-height: 200px;
    overflow-y: auto;
    padding: 4px 8px;
    transition: none;
}

/* Input Icon Buttons */
.input-icon-button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    user-select: none; /* Prevent text selection issues */
    -webkit-user-select: none;
    pointer-events: auto; /* Ensure clicks work but don't block other events */
}

.input-icon-button:hover {
    background: var(--bg-tertiary, rgba(0, 0, 0, 0.05));
    color: var(--text-primary);
}

/* Hide attachment button for now */
#attachButton {
    display: none;
}

/* Microphone recording state */
.input-icon-button.recording {
    background: rgba(255, 0, 0, 0.1);
    animation: pulse-red 1.5s infinite;
}

.input-icon-button.recording:hover {
    background: rgba(255, 0, 0, 0.2);
}

@keyframes pulse-red {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.4);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(255, 0, 0, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 0, 0, 0);
    }
}

#messageInput::placeholder {
    color: var(--text-secondary);
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-button:hover:not(:disabled) {
    background: var(--bg-secondary);
    color: var(--primary-color);
}

.icon-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Chat header icon buttons */
.chat-header .icon-button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: white;
    padding: 6px;
    width: 32px;
    height: 32px;
    transition: all 0.2s ease;
}

.chat-header .icon-button:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chat-header .icon-button svg {
    transition: all 0.2s ease;
}

/* Quick theme toggle specific styling */
#quickThemeToggle {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#quickThemeToggle:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

/* Quick color swap toggle specific styling */
#quickColorSwapToggle {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#quickColorSwapToggle:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.send-button {
    background: var(--primary-color);
    color: white;
    border: 2px solid var(--primary-color);
    border-radius: 16px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.send-button:hover:not(:disabled) {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.send-button:disabled {
    background: var(--primary-color);
    border-color: var(--primary-color);
    opacity: 0.3;
    cursor: not-allowed;
}

/* Theme-specific styling for better visibility */
body.theme-light .send-button {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    border: 3px solid var(--primary-color);
}

body.theme-light .user-message .message-content {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* AI message feedback alignment - centered under bubble */
.ai-message .message-feedback-below {
    display: var(--feedback-display, flex);
    justify-content: center; /* Center the entire feedback container */
    width: 100%; /* Full width for centering */
    margin: 6px 0 0 0; /* Remove side margins */
}

/* ===== EXPORT MENU STYLING ===== */
.export-menu {
    position: fixed;
    z-index: 1000;
}

.export-menu-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    min-width: 160px;
}

.export-option {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 14px;
}

.export-option:hover {
    background: var(--hover-bg, rgba(0, 0, 0, 0.05));
}

.export-option:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

.export-icon {
    margin-right: 10px;
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.export-label {
    font-weight: 500;
}

/* Fullscreen mode */
.chat-container.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    z-index: 9999;
    border-radius: 0;
    padding: var(--safe-area-inset-top) var(--safe-area-inset-right) var(--safe-area-inset-bottom) var(--safe-area-inset-left);
}

body.chat-fullscreen {
    overflow: hidden;
    /* Prevent iOS bounce scrolling */
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Hide topbar and settings panel in fullscreen mode */
body.chat-fullscreen .topbar {
    display: none !important;
}

body.chat-fullscreen .controls-panel {
    display: none !important;
}

/* iPhone-specific fixes */
@media (max-width: 480px) {
    .chat-container.fullscreen {
        /* Use webkit-fill-available for older iOS versions */
        height: 100vh;
        height: -webkit-fill-available;
        height: 100dvh;
        /* Ensure proper display on iPhone */
        min-height: 100vh;
        min-height: -webkit-fill-available;
        min-height: 100dvh;
    }
    
    /* Mobile chat header optimization */
    .chat-controls {
        gap: 4px;
        min-width: 0; /* Allow controls to shrink */
    }
    
    .chat-header {
        padding: 12px 16px;
        min-height: 52px;
        flex-wrap: nowrap;
    }
    
    .chat-title {
        flex: 1;
        min-width: 0; /* Allow title to shrink */
        overflow: hidden;
    }
    
    .chat-title span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 14px;
    }
    
    .chat-header .icon-button {
        width: 28px;
        height: 28px;
        padding: 4px;
        flex-shrink: 0;
    }
    
    .chat-header .icon-button svg {
        width: 16px;
        height: 16px;
    }
    
    /* Ensure input area stays visible on mobile */
    .input-container {
        position: sticky;
        bottom: 0;
        z-index: 10;
        background: var(--bg-primary);
        border-top: 1px solid var(--border-color);
        padding: 12px 16px;
        /* Account for iOS safe area */
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    
    .input-wrapper {
        max-width: 100%;
        border-radius: 20px;
        padding: 8px 12px;
    }
    
    /* Prevent layout issues with virtual keyboard */
    .chat-container {
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }
    
    .messages-container {
        /* Ensure messages don't get cut off by input */
        padding-bottom: env(safe-area-inset-bottom);
        /* Account for input container height */
        max-height: calc(100vh - 120px);
        max-height: calc(100dvh - 120px);
        overflow-y: auto;
    }
}

/* Controls Panel - Full height optimized with toggle animation */
.controls-panel {
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    padding: 24px;
    height: calc(100vh - 90px);
    overflow-y: auto;
    box-sizing: border-box;
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 1;
    transform: translateX(0);
    border: 1px solid var(--border-color, rgba(0, 0, 0, 0.05));
}

.control-group {
    margin-bottom: 32px;
    background: var(--bg-primary);
    border-radius: 10px;
    padding: 16px;
    border: 1px solid var(--border-color, rgba(0, 0, 0, 0.05));
    transition: var(--transition);
}

.control-group:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-label {
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: block;
    font-size: 15px;
    letter-spacing: -0.01em;
    position: relative;
    padding-bottom: 8px;
}

.control-label::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 24px;
    height: 2px;
    background: var(--accent-color);
    border-radius: 1px;
}

.control-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.control-button {
    padding: 10px 16px;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    background: transparent;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.control-button:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.control-button:active {
    transform: translateY(0);
}

/* Panel Direction Select */
.panel-direction-select {
    padding: 8px 12px;
    border: 2px solid var(--primary-color);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
    min-width: 90px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 8px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 32px;
}

.panel-direction-select:hover {
    border-color: var(--secondary-color);
    background-color: var(--bg-tertiary);
}

.panel-direction-select:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Mobile optimizations for select */
@media (max-width: 768px) {
    .panel-direction-select {
        font-size: 16px; /* Prevent iOS zoom on focus */
        min-height: 44px; /* iOS touch target minimum */
    }
}

/* Panel Direction Select - Minimal Version */
.panel-direction-select-minimal {
    padding: 10px 16px;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    background: transparent;
    color: var(--primary-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    appearance: none;
    /* Remove dropdown arrow completely */
    background-image: none;
    min-width: 100px;
}

.panel-direction-select-minimal:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.panel-direction-select-minimal:focus {
    outline: none;
    background: var(--primary-color);
    color: white;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.panel-direction-select-minimal:active {
    transform: translateY(0);
}

/* Mobile optimizations for minimal select */
@media (max-width: 768px) {
    .panel-direction-select-minimal {
        font-size: 16px; /* Prevent iOS zoom on focus */
        min-height: 44px; /* iOS touch target minimum */
    }
}

/* 🔧 IMPROVED: Themed Notifications - Only for non-redundant use cases */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 16px 20px;
    border-radius: var(--border-radius, 8px);
    color: var(--text-primary);
    font-weight: 500;
    z-index: 10000;
    animation: slideIn 0.3s ease-out;
    box-shadow: var(--shadow-md);
    border-left: 4px solid;
    backdrop-filter: blur(10px);
    max-width: 380px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.notification-error {
    background: var(--error-bg, #fef2f2);
    border-left-color: var(--error-color);
    color: var(--error-text, #7f1d1d);
}

.notification-success {
    background: var(--success-bg);
    border-left-color: var(--success-color);
    color: var(--success-text);
}

.notification-info {
    background: var(--bg-secondary);
    border-left-color: var(--primary-color);
    color: var(--text-primary);
}

.notification-warning {
    background: var(--warning-bg);
    border-left-color: var(--primary-color);
    color: var(--warning-text);
}

/* Model Fallback Notification */
.model-fallback-notification {
    max-width: 400px;
    border-left: 4px solid var(--accent-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    animation: slideIn 0.3s ease-out;
}

.model-fallback-notification.enhanced {
    background: var(--bg-secondary);
    border: 1px solid var(--primary-color);
    border-left: 4px solid var(--accent-color);
    border-radius: 8px;
    padding: 12px 16px;
    margin: 8px 0;
    animation: fallbackSlideIn 0.4s ease-out;
}

.fallback-content {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.fallback-icon {
    font-size: 20px;
    flex-shrink: 0;
    margin-top: 2px;
    opacity: 0.9;
}

.fallback-text {
    flex: 1;
    line-height: 1.4;
}

.fallback-title {
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
}

.fallback-subtitle {
    color: var(--primary-color);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
}

.fallback-details {
    color: var(--text-secondary);
    font-size: 12px;
    opacity: 0.8;
}

.fallback-text strong {
    font-weight: 600;
    margin-bottom: 4px;
    display: block;
}

.model-fallback-notification.fadeOut {
    animation: slideOut 0.3s ease-in;
}

/* Model Selector Flash/Alert Effects */
.model-fallback-flash {
    animation: modelFlash 1.5s ease-in-out;
    border: 2px solid var(--accent-color) !important;
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.5) !important;
}

.model-fallback-pulse {
    animation: modelPulse 2s ease-in-out infinite;
}

.model-fallback-highlight {
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(245, 158, 11, 0.1) 50%, 
        transparent 100%) !important;
    border: 1px solid var(--accent-color) !important;
    border-radius: var(--border-radius);
    padding: 8px;
    transition: all 0.3s ease;
    animation: highlightGlow 3s ease-in-out;
}

@keyframes modelFlash {
    0% { 
        background-color: var(--bg-secondary);
        transform: scale(1);
    }
    25% { 
        background-color: rgba(245, 158, 11, 0.2);
        transform: scale(1.02);
    }
    50% { 
        background-color: rgba(245, 158, 11, 0.3);
        transform: scale(1.02);
    }
    75% { 
        background-color: rgba(245, 158, 11, 0.2);
        transform: scale(1.02);
    }
    100% { 
        background-color: var(--bg-secondary);
        transform: scale(1);
    }
}

@keyframes modelPulse {
    0% { 
        box-shadow: 0 0 5px rgba(245, 158, 11, 0.3);
    }
    50% { 
        box-shadow: 0 0 20px rgba(245, 158, 11, 0.6);
    }
    100% { 
        box-shadow: 0 0 5px rgba(245, 158, 11, 0.3);
    }
}

@keyframes highlightGlow {
    0% { 
        box-shadow: 0 0 0px rgba(245, 158, 11, 0);
    }
    30% { 
        box-shadow: 0 0 15px rgba(245, 158, 11, 0.4);
    }
    100% { 
        box-shadow: 0 0 0px rgba(245, 158, 11, 0);
    }
}

/* Animations */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Error states */
.error-message .message-content {
    background: #fee;
    border-color: var(--error-color);
    color: var(--error-color);
}

/* Context Warning Dialog */
.context-warning-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
}

.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 10003; /* Higher than all other modals */
}

.dialog-content {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 100%;
    overflow: hidden;
    animation: dialogSlideIn 0.3s ease;
}

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

.dialog-header {
    padding: 20px 20px 10px;
    border-bottom: 1px solid var(--primary-color);
}

.dialog-header h3 {
    margin: 0;
    color: var(--accent-color);
    font-size: 1.2em;
}

.dialog-body {
    padding: 20px;
    line-height: 1.6;
}

.dialog-body p {
    margin: 0 0 15px;
}

.dialog-body p:last-child {
    margin-bottom: 0;
}

.dialog-actions {
    padding: 15px 20px 20px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.dialog-button {
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.dialog-cancel {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--text-secondary);
}

.dialog-cancel:hover {
    background: var(--text-secondary);
    color: white;
}

.dialog-confirm {
    background: var(--accent-color);
    color: white;
}

.dialog-confirm:hover {
    background: #e5890a;
    transform: translateY(-1px);
}

/* Loading spinner */
.loading-indicator {
    display: none;
    text-align: center;
    padding: 20px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--bg-primary);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Dark theme adjustments */
.theme-dark {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --accent-color: #f59e0b;
    --accent-color-light: #451a03;
    --border-color: #475569;
    --success-bg: #064e3b;
    --success-border: #065f46;
    --success-text: #10b981;
    --warning-bg: #451a03;
    --warning-border: #92400e;
    --warning-text: #f59e0b;
}

/* Theme-aware matrix ticker colors */
.theme-dark .matrix-ticker {
    color: rgba(255, 255, 255, 0.9); /* Bright white for dark theme */
    background: transparent;
    box-shadow: none;
    animation: none;
}

.theme-light .matrix-ticker {
    color: rgba(0, 0, 0, 0.8); /* Dark for light theme */
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --shadow-sm: 0 2px 4px 0 rgba(0, 0, 0, 0.3);
        --shadow-md: 0 8px 12px -2px rgba(0, 0, 0, 0.3);
    }
    
    .message-content {
        border-width: 2px;
    }
}

/* Local Available Notice */
.local-available-notice {
    margin: 10px 0;
}

/* Privacy Banner */
.privacy-banner {
    position: sticky;
    top: 60px; /* Below topbar */
    background: var(--warning-bg, #fff3cd);
    border-bottom: 2px solid var(--warning-border, #ffc107);
    z-index: 999;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    animation: slideDown 0.3s ease-out;
    height: auto;
    min-height: 0;
    overflow: hidden;
    transition: min-height 0.3s ease-out, padding 0.3s ease-out, opacity 0.3s ease-out;
}

.privacy-banner-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 20px;
    gap: 16px;
}

.privacy-banner-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.privacy-banner-text {
    flex: 1;
    color: var(--warning-text, #856404);
}

.privacy-banner-text strong {
    font-weight: 600;
}

.privacy-banner-details {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.privacy-banner-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.privacy-banner-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.privacy-banner-btn.privacy-details {
    background: var(--primary);
    color: white;
}

.privacy-banner-btn.privacy-details:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.privacy-banner-btn.privacy-dismiss {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.privacy-banner-btn.privacy-dismiss:hover {
    background: var(--bg-tertiary);
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Mobile responsive privacy banner */
@media (max-width: 768px) {
    .privacy-banner-content {
        flex-direction: column;
        text-align: center;
        padding: 16px;
        gap: 12px;
    }
    
    .privacy-banner-actions {
        width: 100%;
        justify-content: center;
    }
    
    .privacy-banner-btn {
        padding: 8px 16px;
        flex: 1;
        max-width: 140px;
    }
}

/* Feedback Privacy Dialog */
.feedback-privacy-dialog .dialog-content {
    max-width: 480px;
}

.feedback-privacy-dialog .privacy-details {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    margin: 12px 0;
}

.feedback-privacy-dialog ul {
    margin: 8px 0 0 0;
    padding-left: 20px;
}

.feedback-privacy-dialog li {
    margin-bottom: 4px;
    font-size: 14px;
    color: var(--text-secondary);
}

/* Privacy warning dialog (model switching) - ensure it's on top */
.privacy-warning-dialog {
    z-index: 10004; /* Highest priority for critical privacy warnings */
}

.privacy-warning-dialog .dialog-overlay {
    z-index: 10004;
}

.local-notice-content {
    background: var(--bg-secondary);
    border: 2px solid var(--primary-color);
    border-radius: var(--border-radius);
    padding: 12px;
    font-size: 14px;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.local-notice-content:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--secondary-color);
}

.local-notice-content strong {
    color: var(--primary-color);
    font-weight: 600;
}

/* Color Swapping - When user wants to swap AI/User color roles */
.colors-swapped .user-avatar {
    border-color: var(--accent-color); /* When swapped, user avatar uses accent color */
}

.colors-swapped .user-avatar:hover {
    border-color: var(--primary-color); /* Hover shows primary color */
}

.colors-swapped .user-message .message-avatar {
    background: var(--primary-color);
    border: none; 
    color: white;
}

.colors-swapped .user-message .message-content {
    background: var(--primary-color);
    color: white;
    border: none;
}

.colors-swapped .ai-message .message-avatar {
    background: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
}

.colors-swapped .ai-message .message-content {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--primary-color);
}


/* Performance Panel */
.performance-panel {
    background: var(--bg-primary);
    border: 1px solid var(--primary-color);
    border-radius: 6px;
    padding: 10px;
    font-size: 12px;
}

.performance-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.performance-item:last-child {
    margin-bottom: 0;
}

.perf-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.perf-value {
    color: var(--primary-color);
    font-weight: 600;
    text-align: right;
    min-width: 80px;
}

/* Keep monospace font only for time and numeric metrics */
#currentTime,
#totalJourneyTime,
#tokensPerSecond,
#avgJourneyTime,
#avgResponseTime {
    font-family: 'Monaco', 'Menlo', monospace;
}

/* Message Wrapper - Separates bubble from feedback */
.message-wrapper {
    margin-bottom: 16px;
}

/* Clean Chat View Styles - Three-row vertical layout */
.chat-container.clean-view .message {
    margin-bottom: 16px; /* Spacing between full-width rows */
    padding: 0;
    display: block; /* Full-width rows */
    width: 100%;
}

/* Full-width message layout - no avatars, no bubbles */
.chat-container.clean-view .message {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Add top padding to first message in clean view using configuration */
.chat-container.clean-view .message:first-child {
    padding-top: var(--spacing-lg, 1.5rem);
}

/* Also ensure regular clean view has proper spacing */
.chat-container.clean-view {
    padding-top: 1rem;
}

/* Classic view: Add spacing for first message to prevent cramped appearance */
.chat-container.classic-view .message:first-child {
    margin-top: var(--spacing-md, 1rem);
}
/* Ensure classic view chat container has baseline spacing */
.chat-container.classic-view {
    padding-top: 0.5rem;
}

.chat-container.clean-view .user-message,
.chat-container.clean-view .ai-message {
    justify-content: stretch; /* Full width */
    flex-direction: column; /* Stack vertically */
}

.chat-container.clean-view .user-message .message-content,
.chat-container.clean-view .ai-message .message-content {
    width: 100%; /* Full width */
    max-width: none; /* Remove width restrictions */
    margin: 0; /* No side margins */
    padding: 16px 20px; /* Comfortable padding */
    border-radius: var(--border-radius, 8px);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.05));
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.6; /* Better readability */
}

.chat-container.clean-view .user-message .message-content {
    background: var(--bg-secondary); /* Match classic view - light background */
    color: var(--text-primary); /* Match classic view - dark text */
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--primary-color); /* Show primary color accent like classic */
    border-radius: var(--border-radius, 8px);
}

.chat-container.clean-view .ai-message .message-content {
    background: var(--primary-color); /* Match classic view - AI gets primary color background */
    color: white; /* Ensure good contrast on primary color background */
    border: 1px solid var(--primary-color); /* AI gets primary color border all around */
    border-left: 4px solid var(--primary-color); /* Emphasis on left */
    border-radius: var(--border-radius, 8px);
    box-shadow: 0 1px 3px var(--primary-shadow, rgba(245, 158, 11, 0.1)); /* Subtle themed shadow */
}

/* Hide avatars completely in clean view */
.chat-container.clean-view .message-avatar {
    display: none; /* No avatars in three-row layout */
}

/* Add visual indicators for message type instead of avatars */
.chat-container.clean-view .user-message .message-content::before {
    content: "You";
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--primary-color); /* Use theme primary color like classic view */
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-container.clean-view .ai-message .message-content::before {
    content: ""; /* Remove AI Assistant label in clean view */
    display: none;
}

/* Clean view message metadata styling - positioned at bottom right of each row */
.chat-container.clean-view .message-metadata {
    font-size: 10px;
    color: var(--text-secondary);
    opacity: 0.7;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-color);
}

/* Metadata info (model, time) on the left */
.chat-container.clean-view .message-metadata .metadata-info {
    text-align: left;
    /* Remove flex: 1 to prevent stretching - let content determine width */
    /* Uses global .metadata-info display rule */
}

/* Feedback controls inline on the right */
.chat-container.clean-view .message-metadata .metadata-feedback {
    text-align: right;
    /* Uses global .metadata-feedback display rule */
    gap: 6px;
    align-items: center;
}

/* Responsive: Stack metadata on narrow screens */
@media (max-width: 480px) {
    .chat-container.clean-view .message-metadata {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }
    
    .chat-container.clean-view .message-metadata .metadata-info {
        text-align: center;
        flex: none;
    }
    
    .chat-container.clean-view .message-metadata .metadata-feedback {
        text-align: center;
        justify-content: center;
    }
}

/* Clean view typography - already set above, remove duplicate */

/* Clean view feedback styling - positioned below each message row */
.chat-container.clean-view .message-feedback-below {
    margin-top: 8px;
    padding: 8px 0;
    border-top: 1px solid var(--border-color);
    background: rgba(var(--bg-tertiary, 248, 249, 250), 0.3);
}

/* Inline feedback buttons in metadata - smaller, subtle styling */
.chat-container.clean-view .metadata-feedback .feedback-button {
    background: transparent;
    border: 1px solid var(--border-color, #e2e8f0);
    color: var(--text-secondary);
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-container.clean-view .metadata-feedback .feedback-button:hover {
    background: var(--bg-secondary, #f8fafc);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.chat-container.clean-view .metadata-feedback .feedback-button.selected {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.chat-container.clean-view .metadata-feedback .feedback-comment-inline {
    font-size: 9px;
    padding: 2px 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    max-width: 120px;
    transition: border-color 0.2s ease;
}

.chat-container.clean-view .metadata-feedback .feedback-comment-inline:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 1px var(--primary-color);
}

/* Clean view thinking indicator styling - match AI message appearance */
.chat-container.clean-view .typing-indicator {
    justify-content: flex-start;
    margin-bottom: 16px;
    width: 100%;
}

.chat-container.clean-view .typing-indicator .message-content {
    background: var(--bg-secondary);
    border: 1px solid var(--primary-color);
    border-left: 4px solid var(--primary-color);
    border-radius: var(--border-radius, 8px);
    box-shadow: 0 1px 3px var(--primary-shadow, rgba(245, 158, 11, 0.1));
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 16px 20px;
    min-height: auto;
    display: flex;
    align-items: center;
}

.chat-container.clean-view .typing-indicator .message-avatar {
    display: none; /* Hide avatar in clean view */
}

.chat-container.clean-view .typing-indicator .thinking-content {
    width: 100%;
    justify-content: flex-start;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-primary);
}

/* Clean view color swap support */
.colors-swapped .chat-container.clean-view .user-message .message-content {
    background: var(--primary-color); /* Match classic view color swap */
    color: white; /* Match classic view color swap */
    border: none; /* Match classic view color swap */
}

.colors-swapped .chat-container.clean-view .user-message .message-content::before {
    color: rgba(255, 255, 255, 0.9); /* White on primary background */
}

.colors-swapped .chat-container.clean-view .ai-message .message-content {
    background: var(--bg-secondary); /* Match classic view color swap - light background */
    color: var(--text-primary); /* Match classic view color swap - dark text */
    border: 1px solid var(--primary-color); /* Match classic view color swap */
}

.colors-swapped .chat-container.clean-view .ai-message .message-content::before {
    color: var(--primary-color); /* Use theme color on light background */
}

/* Ensure clean view messages are truly full-width */
.chat-container.clean-view .user-message,
.chat-container.clean-view .ai-message {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
}

/* Message Feedback System - Below the chat bubble */
.message-feedback-below {
    margin-top: 6px;
    display: var(--feedback-display, flex); /* Controlled by JavaScript */
    justify-content: center;
    width: 100%;
}

.feedback-row {
    display: flex;
    gap: 8px;
    align-items: center;
    gap: 12px;
}

.feedback-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* Metadata visibility control - container stays visible if either metadata or feedback is enabled */
.message-metadata-container {
    display: block; /* Always show container, let children control their own visibility */
    text-align: center;
    margin-top: 6px;
}

/* Align metadata container to match message content width (not full chat window width) */
.chat-container.classic-view .message-metadata-container {
    /* In classic view with bubbles, align to the content bubble */
    margin-left: 60px; /* Account for avatar space (48px + 12px gap) */
    margin-right: 0;
    max-width: calc(100% - 60px); /* Constrain to available space */
}

.chat-container.classic-view .user-message .message-metadata-container {
    /* User messages are right-aligned, so adjust accordingly */
    margin-left: 0;
    margin-right: 60px; /* Account for avatar space */
    max-width: calc(100% - 60px);
}

.chat-container.clean-view .message-metadata-container {
    /* In clean view, content spans full width, so metadata should too */
    margin-left: 0;
    margin-right: 0;
    max-width: 100%;
}

.message-metadata {
    font-size: 9px;
    color: var(--text-secondary);
    opacity: 0.7;
    font-family: Monaco, monospace;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
}

/* Specific control for metadata info vs feedback within metadata containers */
.metadata-info {
    display: var(--metadata-display, block);
}

.metadata-feedback {
    display: var(--feedback-display, flex);
}

.user-message-metadata {
    font-size: 9px;
    color: var(--text-secondary);
    opacity: 0.7;
    font-family: Monaco, monospace;
    text-align: right;
}

/* Align user metadata to the right */
.user-metadata-container {
    text-align: right;
}

.feedback-container {
    display: block;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

.feedback-row {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* Legacy support */
.message-bottom-right {
    margin-top: 8px;
}

.message-feedback {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: center;
}

.feedback-button {
    background: transparent;
    border: 1px solid var(--text-secondary);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 12px;
    height: 20px;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.feedback-button:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.feedback-button.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.feedback-button.thumbs-up.active {
    background: var(--success-color);
    border-color: var(--success-color);
}

.feedback-button.thumbs-down.active {
    background: var(--error-color);
    border-color: var(--error-color);
}

/* Try Again button for error messages */
.try-again-button {
    background: var(--primary-color, #4f46e5) !important;
    color: white !important;
    border: none !important;
    padding: 6px 12px !important;
    border-radius: 4px !important;
    font-size: 12px !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    font-weight: 500 !important;
}

.try-again-button:hover {
    background: var(--secondary-color, #6366f1) !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.try-again-button:active {
    transform: translateY(0);
}

.try-again-container {
    margin-top: 8px;
    text-align: right;
    opacity: 0.9;
}

/* Action buttons for easter eggs */
.action-buttons-container {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-start;
}

.action-button {
    background: linear-gradient(135deg, var(--primary-color, #4f46e5) 0%, var(--secondary-color, #6366f1) 100%) !important;
    color: white !important;
    border: none !important;
    padding: 8px 16px !important;
    border-radius: 6px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
    min-height: 36px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-decoration: none !important;
}

.action-button:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important;
    background: linear-gradient(135deg, var(--secondary-color, #6366f1) 0%, var(--primary-color, #4f46e5) 100%) !important;
}

.action-button:active {
    transform: translateY(0) !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

.feedback-comment {
    padding: 2px 6px;
    border: 1px solid var(--text-secondary);
    border-radius: 4px;
    font-size: 12px;
    height: 20px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-sizing: border-box;
    vertical-align: top;
}

.feedback-comment:focus {
    outline: none;
    border-color: var(--primary-color);
}

.feedback-comment::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Compact File Upload Styles */
.file-upload-area {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 10px;
    padding: 8px 12px;
}

.upload-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.upload-btn {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.85em;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
}

.upload-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.upload-info {
    color: var(--text-secondary);
    font-size: 0.75em;
    margin-left: auto;
}

.file-upload-area.drag-over {
    border-color: var(--primary-color);
    background: rgba(79, 70, 229, 0.05);
    transform: scale(1.01);
}
    transform: scale(1.02);
}

/* Removed old upload-option styles - now using compact upload-btn */

.upload-info {
    color: var(--text-secondary);
    font-size: 0.8em;
    opacity: 0.8;
}

.attached-files {
    margin-top: 15px;
    display: none;
}

.attached-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 8px;
}

.item-icon {
    font-size: 1.2em;
    flex-shrink: 0;
}

.item-details {
    flex: 1;
    min-width: 0;
}

.item-name {
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.item-meta {
    font-size: 0.8em;
    color: var(--text-secondary);
}

.remove-item {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2em;
    padding: 4px 8px;
    border-radius: 4px;
    transition: var(--transition);
    flex-shrink: 0;
}

.remove-item:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* Mobile responsiveness for file upload */
@media (max-width: 768px) {
    .upload-options {
        flex-direction: column;
        gap: 15px;
    }
    
    .upload-option {
        flex-direction: row;
        justify-content: flex-start;
        text-align: left;
        min-width: auto;
        width: 100%;
    }
    
    .upload-icon {
        font-size: 1.5em;
        margin-bottom: 0;
    }
    
    .attached-item {
        padding: 10px;
    }
    
    .item-name {
        font-size: 0.9em;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Settings Modal Styles */
.settings-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
}

.settings-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.settings-modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--primary-bg, #1e1e2e);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.settings-modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--primary-accent, #4a4a7a);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-modal-header h2 {
    margin: 0;
    color: var(--text-primary, #e0e0e0);
}

.settings-close-btn {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary, #b0b0c0);
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.settings-close-btn:hover {
    background: var(--primary-accent, #4a4a7a);
    color: var(--text-primary, #e0e0e0);
}

.settings-modal-body {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(80vh - 80px);
}

.settings-section {
    margin-bottom: 30px;
}

.settings-section h3 {
    margin: 0 0 15px 0;
    color: var(--text-primary, #e0e0e0);
    font-size: 16px;
}

/* Settings section collapsible functionality */
.settings-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 5px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 15px;
}

.settings-section-header:hover {
    background: var(--hover-bg);
    border-radius: 6px;
    padding: 5px 8px;
    margin: 0 -8px 15px -8px;
}

.settings-section-header h3 {
    margin: 0;
    flex: 1;
}

.settings-toggle-arrow {
    font-size: 14px;
    color: var(--text-secondary);
    transition: transform 0.2s ease, color 0.2s ease;
    user-select: none;
    min-width: 16px;
    text-align: center;
}

.settings-toggle-arrow:hover {
    color: var(--primary-color);
}

.settings-toggle-arrow.collapsed {
    transform: rotate(-90deg);
}

.settings-section-content {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 1000px;
    opacity: 1;
}

.settings-section-content.collapsed {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
}

/* Toggle Switch Styles */
.settings-toggle {
    display: block;
    position: relative;
    padding: 12px 0;
    cursor: pointer;
}

.settings-toggle input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    right: 0;
    top: 12px;
    width: 50px;
    height: 24px;
    background: var(--border-color, #374151);
    border-radius: 12px;
    transition: all 0.3s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: var(--text-secondary, #9ca3af);
    border-radius: 50%;
    transition: all 0.3s;
}

.settings-toggle input:checked + .toggle-slider {
    background: var(--primary-color);
}

.settings-toggle input:checked + .toggle-slider::after {
    transform: translateX(26px);
    background: white;
}

.toggle-label {
    display: inline-block;
    color: var(--text-primary, #e0e0e0);
    padding-right: 60px;
}

.setting-description {
    font-size: 12px;
    color: var(--text-secondary, #b0b0c0);
    margin-top: 4px;
}

/* Settings Button */
.settings-button {
    background: var(--primary-accent, #4a4a7a);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.settings-button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.settings-button.danger {
    background: var(--error-color);
}

.settings-button.danger:hover {
    background: var(--error-hover);
}

/* Deployment Config */
.deployment-config {
    background: var(--secondary-bg, #2a2a3a);
    padding: 15px;
    border-radius: 8px;
}

.config-info {
    font-size: 14px;
    color: var(--text-secondary, #b0b0c0);
    line-height: 1.6;
}

/* Privacy Modal Styles */
.privacy-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10002; /* Higher than settings modal */
}

.privacy-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.privacy-modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-primary);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    overflow: hidden;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.privacy-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    gap: 12px;
}

.privacy-modal-header h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 600;
    flex: 1;
}

.privacy-header-buttons {
    display: flex;
    align-items: center;
    gap: 12px;
}

.privacy-explain-btn {
    background: var(--primary-color);
    border: none;
    color: white;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.privacy-explain-btn:hover {
    background: var(--primary-hover, var(--primary-color));
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.privacy-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.privacy-close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Mobile improvements for privacy modal */
@media (max-width: 768px) {
    .privacy-modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 0 2.5%;
        border-radius: 12px;
    }
    
    .privacy-modal-header {
        padding: 16px 20px;
        position: sticky;
        top: 0;
        z-index: 1;
        background: var(--bg-secondary);
        border-radius: 12px 12px 0 0;
    }
    
    .privacy-modal-header {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .privacy-modal-header h2 {
        font-size: 16px;
        flex: 1;
        min-width: 200px;
    }
    
    .privacy-explain-btn {
        font-size: 12px;
        padding: 6px 10px;
        order: 1;
    }
    
    .privacy-close-btn {
        width: 40px;
        height: 40px;
        font-size: 20px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        order: 2;
    }
    
    .privacy-modal-body {
        padding: 20px;
        font-size: 16px; /* Better readability on mobile */
        line-height: 1.7;
    }
    
    /* Larger touch targets for mobile links */
    .privacy-modal-body a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 8px 12px;
        margin: 4px 0;
        border-radius: 6px;
        background: rgba(79, 70, 229, 0.1);
        text-decoration: none;
        color: var(--primary-color);
        transition: all 0.2s ease;
    }
    
    .privacy-modal-body a:hover {
        background: rgba(79, 70, 229, 0.2);
        transform: translateY(-1px);
    }
}

.privacy-modal-body {
    padding: 24px;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    line-height: 1.6;
    font-size: 15px;
}

/* Better scrollbar styling for modal */
.privacy-modal-body::-webkit-scrollbar {
    width: 8px;
}

.privacy-modal-body::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.privacy-modal-body::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border-radius: 4px;
}

.privacy-modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

.privacy-status-display {
    margin-bottom: 24px;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

/* Improve text formatting in privacy modal */
.privacy-modal-body h3 {
    color: var(--primary-color);
    font-size: 16px;
    margin: 24px 0 12px 0;
    font-weight: 600;
}

.privacy-modal-body h4 {
    color: var(--text-primary);
    font-size: 15px;
    margin: 20px 0 10px 0;
    font-weight: 500;
}

.privacy-modal-body p {
    margin: 12px 0;
    color: var(--text-primary);
}

.privacy-modal-body ul {
    margin: 12px 0;
    padding-left: 24px;
}

.privacy-modal-body li {
    margin: 8px 0;
    color: var(--text-primary);
}

.privacy-modal-body strong {
    color: var(--text-primary);
    font-weight: 600;
}

.privacy-ollama-link:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    transition: all 0.2s ease;
}

/* Admin Modal Styles */
.admin-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10001; /* Higher than settings modal */
}

.admin-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
}

.admin-modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--primary-bg, #1a1a2e);
    border-radius: 16px;
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.4);
    border: 2px solid var(--primary-accent, #4a4a7a);
}

.admin-modal-header {
    padding: 24px;
    border-bottom: 2px solid var(--primary-accent, #4a4a7a);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--primary-accent, #4a4a7a), var(--secondary-bg, #2a2a3a));
}

.admin-modal-header h2 {
    margin: 0;
    color: white;
    font-size: 20px;
}

.admin-close-btn {
    background: none;
    border: none;
    font-size: 32px;
    color: white;
    cursor: pointer;
    padding: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    transition: all 0.3s;
}

.admin-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.admin-modal-body {
    padding: 24px;
    overflow-y: auto;
    max-height: calc(85vh - 100px);
}

.admin-section {
    margin-bottom: 36px;
    padding: 20px;
    background: var(--secondary-bg, #2a2a3a);
    border-radius: 12px;
    border: 1px solid var(--primary-accent, #4a4a7a);
}

.admin-section h3 {
    margin: 0 0 12px 0;
    color: var(--text-primary, #e0e0e0);
    font-size: 18px;
}

.admin-description {
    font-size: 14px;
    color: var(--text-secondary, #b0b0c0);
    margin-bottom: 20px;
    font-style: italic;
}

/* Admin Toggle Styles */
.admin-control-toggle {
    display: block;
    position: relative;
    padding: 16px 0;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.admin-control-toggle:last-child {
    border-bottom: none;
}

.admin-slider {
    background: var(--secondary-bg, #2a2a3a);
    border: 2px solid var(--primary-accent, #4a4a7a);
}

.admin-control-toggle input:checked + .admin-slider {
    background: linear-gradient(135deg, var(--primary-accent, #4a4a7a), #6a6a9a);
    border-color: #6a6a9a;
}

.admin-control-toggle input:checked + .admin-slider::after {
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Admin Button Styles */
.admin-button {
    background: var(--primary-accent, #4a4a7a);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
    margin: 8px 8px 8px 0;
    display: inline-block;
}

.admin-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.admin-button.primary {
    background: linear-gradient(135deg, #28a745, #20c997);
}

.admin-button.primary:hover {
    background: linear-gradient(135deg, #218838, #1ea7a0);
}

.admin-button.secondary {
    background: linear-gradient(135deg, #6c757d, #495057);
}

.admin-button.secondary:hover {
    background: linear-gradient(135deg, #5a6268, #3d4043);
}

.admin-button.danger {
    background: linear-gradient(135deg, var(--error-color), var(--error-hover));
}

.admin-button.danger:hover {
    background: linear-gradient(135deg, var(--error-hover), #bd2130);
}

/* Admin toggle styling to distinguish from regular settings */
.admin-control-toggle .toggle-label {
    font-weight: 500;
    color: var(--text-primary, #e0e0e0);
}

/* Dynamic viewport-based settings panel positioning */
.app-layout {
    --settings-panel-height: clamp(200px, var(--settings-size, 40vh), 60vh);
    --settings-panel-max-height: min(60vh, calc(100vh - 120px)); /* Never block main content */
}

/* Mobile-first: Top settings panel */
.app-layout[data-settings-direction="top"] .settings-panel {
    width: 100%;
    height: 0; /* Hidden by default */
    overflow: hidden;
    order: -1; /* Appear above chat */
    border-radius: 0 0 12px 12px;
    margin: 0 20px 20px 20px;
    transform-origin: top;
    transition: height 0.3s ease-out, opacity 0.3s ease-out;
    background: var(--bg-secondary, #f8fafc);
}

/* When visible, show the panel with appropriate height */
.app-layout[data-settings-direction="top"][data-settings-visible="true"] .settings-panel {
    height: var(--settings-size, 50vh) !important; /* Use the CSS variable set by JS */
    max-height: var(--settings-size, 50vh) !important; /* Ensure max-height matches */
    overflow-y: auto;
    animation: slideDownFromTop 0.3s ease-out;
}

/* Mobile dropdown visibility enhancements */
@media (max-width: 768px) {
    /* Update CSS custom properties for mobile */
    .app-layout {
        --settings-panel-height: min(50vh, 400px);
        --settings-panel-max-height: 50vh;
    }
    
    /* Reduce margins on mobile for better space usage */
    .app-layout[data-settings-direction="top"] .settings-panel {
        margin: 0 10px 10px 10px; /* Smaller margins on mobile */
        width: calc(100% - 20px); /* Account for margins */
    }
    
    /* Ensure visible state works on mobile with 50vh */
    .app-layout[data-settings-direction="top"][data-settings-visible="true"] .settings-panel {
        height: var(--settings-size, 50vh) !important;
        max-height: 50vh !important; /* 🔧 MOBILE FIX: Limit settings panel to 50vh to preserve chat area */
        display: block !important;
        overflow-y: auto !important;
    }
    
    /* 🔧 MOBILE FIX: Ensure app layout properly constrains settings and chat */
    .app-layout[data-settings-direction="top"] {
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile */
        max-height: 100vh;
        max-height: 100dvh;
        overflow: hidden; /* Prevent body scroll */
        display: flex;
        flex-direction: column;
    }
    
    /* 🔧 MOBILE FIX: Force input container to always be visible at bottom */
    .app-layout[data-settings-direction="top"] .input-container {
        position: sticky;
        bottom: 0;
        z-index: 20; /* Higher than settings panel */
        flex-shrink: 0; /* Never shrink the input area */
        order: 999; /* Always last in flex order */
    }
    /* Mobile text size improvements */
    body {
        font-size: 16px; /* Base font size for mobile readability */
        -webkit-text-size-adjust: 100%; /* Prevent iOS zoom on form focus */
        text-size-adjust: 100%;
    }
    
    /* ChatGPT-style input adjustments for mobile */
    .input-container {
        padding: 12px 16px;
    }
    
    .input-wrapper {
        max-width: 100%;
        padding: 6px 10px;
        border-radius: 20px;
    }
    
    #messageInput {
        font-size: 16px; /* Prevent iOS zoom */
        padding: 6px;
    }
    
    .input-icon-button {
        padding: 8px;
        /* Ensure 44px minimum touch target for iOS */
        min-width: 44px;
        min-height: 44px;
        /* Better tap response on mobile */
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        /* Prevent double-tap zoom on iOS */
        touch-action: manipulation;
    }
    
    /* Enhanced recording state visibility on mobile */
    .input-icon-button.recording {
        background: rgba(255, 0, 0, 0.15);
        border: 2px solid rgba(255, 0, 0, 0.3);
        transform: scale(1.05); /* Slightly larger when recording */
    }
    
    /* Prevent accidental activation during scrolling */
    .input-icon-button:active {
        transform: scale(0.95);
    }
    
    .send-button {
        padding: 8px 14px;
        font-size: 14px;
    }
    
    /* Minimum font sizes for small text */
    .message-metadata,
    .user-message-metadata,
    .feedback-comment,
    .admin-control-toggle .toggle-label,
    small,
    .small-text {
        font-size: 14px !important; /* Minimum readable size on mobile */
    }
    
    /* Mobile AI message feedback alignment */
    .ai-message .message-feedback-below {
        display: var(--feedback-display, flex);
        justify-content: center !important; /* Center on mobile too */
        width: 100% !important; /* Full width for centering */
        margin: 6px 0 0 0 !important; /* Consistent centering */
        flex-wrap: wrap; /* Allow wrapping on very small screens */
        justify-content: center; /* Center content */
    }
    
    /* Mobile-specific settings panel adjustments */
    .app-layout[data-settings-direction="top"] .settings-panel {
        /* Safe area padding for iPhone */
        padding-top: max(16px, var(--safe-area-inset-top));
    }
    
    /* Enhanced AI model section visibility */
    .ai-model-section {
        background: rgba(var(--primary-accent-rgb, 74, 74, 122), 0.15);
        border: 2px solid rgba(var(--primary-accent-rgb, 74, 74, 122), 0.3);
        border-radius: 12px;
        padding: 16px;
        margin-bottom: 20px;
        position: relative;
        animation: mobilePulse 2s infinite;
    }
    
    /* Pulse animation to draw attention */
    @keyframes mobilePulse {
        0%, 100% {
            box-shadow: 0 0 0 0 rgba(var(--primary-accent-rgb, 74, 74, 122), 0.4);
        }
        50% {
            box-shadow: 0 0 0 8px rgba(var(--primary-accent-rgb, 74, 74, 122), 0);
        }
    }
    
    /* Enhanced dropdown styling */
    .ai-model-section select {
        min-height: 44px;
        font-size: 16px;
        padding: 12px 16px;
        border: 2px solid var(--primary-accent, #4a4a7a);
        background: var(--secondary-bg, #2a2a3a);
        color: var(--text-primary, #e0e0e0);
        border-radius: 8px;
        width: 100%;
        appearance: none;
        background-image: url("data:image/svg+xml;charset=US-ASCII,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'><path fill='%23ffffff' d='M2 0L0 2h4zm0 5L0 3h4z'/></svg>");
        background-repeat: no-repeat;
        background-position: right 12px center;
        background-size: 12px;
        transition: all 0.3s ease;
    }
    
    /* Enhanced focus states */
    .ai-model-section select:focus {
        outline: none;
        border-color: var(--primary-accent, #4a4a7a);
        box-shadow: 0 0 0 3px rgba(var(--primary-accent-rgb, 74, 74, 122), 0.3);
        transform: scale(1.02);
    }
    
    /* Enhanced dropdown options */
    .ai-model-section select option {
        background: var(--secondary-bg, #2a2a3a);
        color: var(--text-primary, #e0e0e0);
        padding: 12px 16px;
        font-size: 16px;
        min-height: 44px;
    }
    
    /* Label styling improvements */
    .ai-model-section label {
        display: block;
        font-weight: 600;
        font-size: 16px;
        color: var(--text-primary, #e0e0e0);
        margin-bottom: 8px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    /* Add visual indicator for mobile-optimized dropdown */
    .ai-model-section::before {
        content: "📱 TAP TO SELECT MODEL";
        position: absolute;
        top: -8px;
        right: 12px;
        background: var(--primary-accent, #4a4a7a);
        color: white;
        padding: 4px 8px;
        border-radius: 4px;
        font-size: 10px;
        font-weight: bold;
        letter-spacing: 0.5px;
        z-index: 1;
        animation: fadeInOut 3s infinite;
        pointer-events: none;
    }
    
    @keyframes fadeInOut {
        0%, 50%, 100% { opacity: 1; }
        25%, 75% { opacity: 0.6; }
    }
    
    /* Mobile keyboard/picker indicator */
    .ai-model-section.mobile-picker-open::after {
        content: "✅ SELECTING...";
        position: absolute;
        bottom: -12px;
        left: 50%;
        transform: translateX(-50%);
        background: #28a745;
        color: white;
        padding: 6px 12px;
        border-radius: 6px;
        font-size: 11px;
        font-weight: bold;
        letter-spacing: 0.5px;
        z-index: 10;
        animation: slideUp 0.3s ease-out;
    }
    
    @keyframes slideUp {
        0% {
            opacity: 0;
            transform: translateX(-50%) translateY(10px);
        }
        100% {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
        }
    }
    
    /* Mobile keyboard and input improvements */
    #messageInput {
        font-size: 16px !important; /* Prevent iOS zoom on focus */
        -webkit-appearance: none; /* Remove iOS styling */
        border-radius: 12px;
    }
    
    .input-wrapper {
        /* Ensure input area is above virtual keyboard */
        margin-bottom: max(16px, var(--safe-area-inset-bottom));
    }
    
    /* Enhanced touch targets for all interactive elements */
    .control-toggle,
    .slider,
    button,
    .toggle-button,
    input,
    select {
        min-height: 44px;
        min-width: 44px;
        font-size: 16px; /* Prevent iOS zoom */
    }
    
    /* Better spacing for touch interaction */
    .settings-group {
        margin-bottom: 24px;
    }
    
    .control-toggle {
        padding: 16px 0;
    }
    
    /* Mobile interaction feedback states */
    .ai-model-section.mobile-focused {
        animation: mobileHighlight 0.5s ease-in-out;
        background: rgba(var(--primary-accent-rgb, 74, 74, 122), 0.25) !important;
        border-color: var(--primary-accent, #4a4a7a) !important;
        box-shadow: 0 0 15px rgba(var(--primary-accent-rgb, 74, 74, 122), 0.5);
    }
    
    .ai-model-section.mobile-touched {
        transform: scale(0.98);
        transition: transform 0.1s ease-out;
    }
    
    .ai-model-section.mobile-selected {
        animation: mobileSuccess 0.8s ease-out;
        border-color: #28a745 !important;
        background: rgba(40, 167, 69, 0.15) !important;
    }
    
    /* Hide the tap indicator when picker is open */
    .ai-model-section.mobile-picker-open::before {
        display: none;
    }
    
    @keyframes mobileHighlight {
        0% {
            transform: scale(1);
            box-shadow: 0 0 0 0 rgba(var(--primary-accent-rgb, 74, 74, 122), 0.5);
        }
        50% {
            transform: scale(1.02);
            box-shadow: 0 0 20px rgba(var(--primary-accent-rgb, 74, 74, 122), 0.8);
        }
        100% {
            transform: scale(1);
            box-shadow: 0 0 15px rgba(var(--primary-accent-rgb, 74, 74, 122), 0.5);
        }
    }
    
    @keyframes mobileSuccess {
        0% {
            border-color: var(--primary-accent, #4a4a7a);
            background: rgba(var(--primary-accent-rgb, 74, 74, 122), 0.15);
        }
        30% {
            border-color: var(--success-color);
            background: rgba(40, 167, 69, 0.25);
            transform: scale(1.01);
        }
        100% {
            border-color: var(--success-color);
            background: rgba(40, 167, 69, 0.15);
            transform: scale(1);
        }
    }
    
    /* iOS-specific improvements */
    @supports (-webkit-appearance: none) {
        /* Better momentum scrolling on iOS */
        .messages-container {
            -webkit-overflow-scrolling: touch;
            scroll-behavior: smooth;
        }
        
        /* Fix iOS Safari bottom padding issue */
        .input-wrapper {
            padding-bottom: max(16px, var(--safe-area-inset-bottom));
        }
        
        /* Better tap highlighting */
        button, .feedback-button, select {
            -webkit-tap-highlight-color: rgba(99, 102, 241, 0.2);
        }
    }
    
    /* Mobile table improvements */
    .markdown-table-wrapper {
        margin: 12px 0;
        font-size: 13px; /* Slightly smaller on mobile */
        border-radius: 6px;
    }
    
    .markdown-table th,
    .markdown-table td {
        padding: 8px 12px; /* Smaller padding on mobile */
        font-size: 13px;
        line-height: 1.4;
    }
    
    /* Stack tables horizontally on very small screens */
    @media (max-width: 480px) {
        .markdown-table th,
        .markdown-table td {
            padding: 6px 8px;
            font-size: 12px;
            word-break: break-word;
        }
        
        .markdown-table-wrapper {
            box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
        }
        
        /* Mobile-optimized action buttons */
        .action-buttons-container {
            justify-content: center; /* Center buttons on mobile */
            margin-top: 10px;
        }
        
        .action-button {
            min-width: 120px !important; /* Minimum touch target width */
            min-height: 44px !important; /* iOS recommended touch target height */
            padding: 12px 16px !important; /* Larger padding for easier tapping */
            font-size: 14px !important; /* Slightly larger text on mobile */
        }
        
        /* Mobile fullscreen button enhancement */
        #fullscreenToggle {
            min-width: 44px !important; /* WCAG touch target */
            min-height: 44px !important;
            padding: 10px !important;
            background: rgba(255, 255, 255, 0.15) !important;
            border: 2px solid rgba(255, 255, 255, 0.3) !important;
        }
        
        #fullscreenToggle:hover,
        #fullscreenToggle:active {
            background: rgba(255, 255, 255, 0.25) !important;
            border-color: rgba(255, 255, 255, 0.5) !important;
            transform: scale(1.05) !important;
        }
    }
}

/* Privacy Popup Content Styles */
.privacy-popup-content {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
    color: var(--text-primary);
}

.privacy-highlight {
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: 8px;
    margin: 12px 0;
    border-left: 4px solid var(--primary-color);
}

.privacy-guarantee {
    background: var(--success-bg, #d4edda);
    border: 1px solid var(--success-border, #c3e6cb);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 8px;
    margin: 16px 0;
    text-align: center;
    font-size: 14px;
    line-height: 1.4;
}

.auth-provider-data {
    background: #f0f8ff;
    color: #1a5490;
    padding: 12px;
    border-radius: 8px;
    margin: 12px 0;
    border-left: 4px solid #2196f3;
}

.server-storage-info {
    background: var(--bg-secondary);
    padding: 12px;
    border-radius: 8px;
    margin: 12px 0;
    border: 1px solid var(--border-color);
}

.environment-info {
    margin: 8px 0;
}

.privacy-control {
    background: #fff3cd;
    color: #856404;
    padding: 12px;
    border-radius: 8px;
    margin: 12px 0;
    border-left: 4px solid #ffc107;
}

.privacy-action-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    margin: 4px 8px 4px 0;
    font-size: 13px;
    transition: background-color 0.2s ease;
}

.privacy-action-btn:hover {
    background: var(--secondary-color);
}

.fresh-start-options {
    margin: 16px 0;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.privacy-highlights {
    margin: 16px 0;
    padding: 16px;
    background: rgba(156, 163, 175, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(156, 163, 175, 0.3);
}

.privacy-item {
    margin: 8px 0;
    display: flex;
    align-items: center;
}

.privacy-icon {
    margin-right: 8px;
    font-size: 14px;
}

.privacy-section {
    margin: 16px 0;
}

.privacy-section h4 {
    margin: 12px 0 8px 0;
    color: var(--primary-color);
    font-size: 16px;
    font-weight: 600;
}

.privacy-section ul {
    margin: 8px 0;
    padding-left: 20px;
    color: var(--text-secondary);
}

.privacy-section li {
    margin: 4px 0;
    line-height: 1.5;
}

.privacy-warning {
    margin: 16px 0;
    padding: 12px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 6px;
    color: var(--text-primary);
    font-weight: 500;
}

.privacy-tip {
    margin: 16px 0;
    padding: 12px;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 6px;
    color: var(--text-primary);
}

.privacy-footer {
    margin-top: 16px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 14px;
    font-style: italic;
}

.privacy-actions {
    margin-top: 20px;
    text-align: center;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.privacy-guide-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
}

.privacy-guide-btn:hover {
    background: var(--primary-color-dark, #3b82f6);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Chat Bottom Controls - Copy Button */
.chat-bottom-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px 0 0 0;
    margin-top: 8px;
    border-top: 1px solid var(--border-color);
}

.copy-button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    min-height: 36px;
    outline: none;
}

.copy-button:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.copy-button:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.copy-button svg {
    flex-shrink: 0;
    opacity: 0.8;
}

.copy-button:hover svg {
    opacity: 1;
}

.copy-text, .copy-feedback {
    font-weight: 500;
    white-space: nowrap;
}

.copy-feedback {
    color: var(--success-color);
    font-weight: 600;
}

/* Chat Copy Controls - positioned at bottom of messages area */
.chat-copy-controls {
    display: none; /* Hidden by default, shown when messages exist */
    justify-content: center;
    align-items: center;
    padding: 16px 20px;
    margin-top: 16px;
    border-top: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    position: sticky;
    bottom: 0;
    z-index: 10;
}

/* Dark mode support for chat copy controls */
.theme-dark .chat-copy-controls {
    background: rgba(30, 41, 59, 0.8);
}

/* Mobile optimizations for copy button */
@media (max-width: 768px) {
    .copy-button {
        padding: 10px 16px;
        font-size: 15px;
        min-height: 44px; /* Better touch target */
    }
    
    .chat-bottom-controls {
        padding: 10px 0 0 0;
    }
}