/* 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: #4f46e5;
    --secondary-color: #6366f1;
    --accent-color: #f59e0b;
    --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;
    
    /* 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;
}

/* 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;
}

.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-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); /* Subtract topbar height */
    background: var(--bg-primary);
    transition: all var(--settings-animation-duration, 300ms) ease;
}

/* Chat Container - Adjusts to make room for settings panel */
.chat-container {
    flex: 1;
    padding: 20px;
    box-sizing: border-box;
    overflow: hidden;
    transition: all var(--settings-animation-duration, 300ms) ease;
}

/* Settings Panel Base Styles - Now positioned within layout flow */
.settings-panel {
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    transition: all var(--settings-animation-duration, 300ms) ease;
    overflow-y: auto;
    scrollbar-width: thin;
    flex-shrink: 0; /* Don't shrink the settings panel */
}

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

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

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

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

/* 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;
}

.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 20px; /* 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;
}

.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 20px 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;
    }
    
    .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 size overrides */
    .app-layout[data-settings-direction="top"][data-settings-visible="true"] .settings-panel,
    .app-layout[data-settings-direction="bottom"][data-settings-visible="true"] .settings-panel {
        height: 50vh; /* Smaller height on mobile */
    }
    
    .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 {
        height: 70vh;
        min-height: 400px;
    }
}

/* Chat Interface - Full height optimized with topbar */
.chat-container {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 90px); /* Full viewport height minus narrower topbar and padding */
    overflow: hidden;
    transition: var(--transition);
    position: relative; /* Ensure proper positioning context */
}

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

.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; /* Prevent horizontal scrolling */
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth; /* Smooth scrolling behavior */
    /* Ensure proper scrollbar visibility */
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) var(--bg-primary);
}

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

.messages-container::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
    opacity: 0.7;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
    opacity: 1;
}

.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-start; /* Left-align user messages like AI */
}

@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: transparent; /* Transparent background for user bubble */
    color: var(--text-primary); /* Use theme text color */
    border: 2px solid var(--primary-color); /* Border to match primary theme */
    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 */
}

.ai-message .message-content {
    background: var(--primary-color); /* Match AI avatar filled background */
    color: white; /* Ensure good contrast on primary color */
    border: none; /* Clean unified look like avatar */
}

/* 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 left side since messages are right-aligned */
    .message.user-message .message-timestamp {
        right: auto;
        left: 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 - Matrix style */
.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;
    position: relative;
    overflow: hidden;
}

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

.matrix-ticker {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: bold;
    opacity: 0.9;
    flex: 1;
    height: 100%;
    display: flex;
    align-items: center;
    overflow: hidden;
    white-space: nowrap;
    letter-spacing: 1px;
    position: relative;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(255,255,255,0.1) 50%, 
        transparent 100%);
    animation: tickerGlow 2s ease-in-out infinite alternate;
}

@keyframes tickerGlow {
    0% {
        box-shadow: inset 0 0 5px rgba(255,255,255,0.1);
    }
    100% {
        box-shadow: inset 0 0 10px rgba(255,255,255,0.2);
    }
}

/* 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;
    }
}

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

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-primary);
    border: 2px solid var(--primary-color);
    border-radius: 24px;
    padding: 8px 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease; /* Only transition focus states */
    max-width: 100%;
}

.input-wrapper:focus-within {
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#messageInput {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    min-height: 32px;
    max-height: 104px;
    overflow-y: hidden;
    padding: 8px 0;
    transition: none; /* Remove transitions to prevent jitter during dictation */
}

#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: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.send-button:hover {
    background: var(--secondary-color);
}

.send-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Fullscreen mode */
.chat-container.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    border-radius: 0;
}

body.chat-fullscreen {
    overflow: hidden;
}

/* 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);
}

/* Notifications */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 16px;
    border-radius: 6px;
    color: white;
    z-index: 10000;
    max-width: 300px;
    word-wrap: break-word;
}

.notification-error {
    background: #dc3545;
}

.notification-success {
    background: #28a745;
}

.notification-info {
    background: #17a2b8;
}

.notification-warning {
    background: #f59e0b;
}

/* 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: #dc3545;
    color: #dc3545;
}

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

.dialog-overlay {
    position: absolute;
    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;
}

.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 */
}

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

.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-message .message-avatar {
    background: var(--primary-color); /* User gets filled primary when swapped */
    border: none; 
    color: white;
}

.colors-swapped .user-message .message-content {
    background: var(--primary-color); /* User bubble gets primary color when swapped */
    color: white;
    border: none;
}

.colors-swapped .ai-message .message-avatar {
    background: transparent; /* AI gets outlined when swapped */
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
}

.colors-swapped .ai-message .message-content {
    background: var(--bg-secondary); /* AI gets secondary background when swapped */
    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;
}

/* Message Feedback System - Below the chat bubble */
.message-feedback-below {
    margin-top: 6px;
}

.feedback-meta-container {
    background: transparent;
    border-radius: 6px;
    padding: 4px 6px;
    border: none;
    display: inline-block; /* Fit to content */
}

.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: #28a745;
    border-color: #28a745;
}

.feedback-button.thumbs-down.active {
    background: #dc3545;
    border-color: #dc3545;
}

/* 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;
}

.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(--secondary-bg, #2a2a3a);
    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, #b0b0c0);
    border-radius: 50%;
    transition: all 0.3s;
}

.settings-toggle input:checked + .toggle-slider {
    background: var(--primary-accent, #4a4a7a);
}

.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: #dc3545;
}

.settings-button.danger:hover {
    background: #c82333;
}

/* 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: 80vh;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

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

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

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

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

.privacy-status-display {
    margin-bottom: 20px;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.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, #dc3545, #c82333);
}

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

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

/* Mobile dropdown visibility enhancements */
@media (max-width: 768px) {
    /* 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%;
    }
    
    /* Minimum font sizes for small text */
    .message-metadata,
    .feedback-comment,
    .admin-control-toggle .toggle-label,
    small,
    .small-text {
        font-size: 14px !important; /* Minimum readable size on mobile */
    }
    
    /* Mobile-optimized settings panel positioning */
    .app-layout[data-settings-direction="top"] .settings-panel {
        max-height: 50vh !important; /* Never take more than half the screen */
        border-bottom-left-radius: 12px;
        border-bottom-right-radius: 12px;
        border-top-left-radius: 0;
        border-top-right-radius: 0;
        /* 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: #28a745;
            background: rgba(40, 167, 69, 0.25);
            transform: scale(1.01);
        }
        100% {
            border-color: #28a745;
            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);
        }
    }
}
}