/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #10A37F;
    --secondary-color: #1A1A1A;
    --background-color: #F7F7F8;
    --text-color: #202123;
    --accent-color: #8E8EA0;
    --success-color: #10A37F;
    --error-color: #D73A49;
    --warning-color: #F59E0B;
    --border-color: #E5E5E5;
    --hover-color: #F0F0F0;
    --code-bg: #F6F8FA;
    --message-bg: #FFFFFF;
    --sidebar-bg: #FFFFFF;
    
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    
    --border-radius: 8px;
    --padding: 16px;
    --gap: 12px;
    
    --sidebar-width: 320px;
    --header-height: 60px;
}

/* Dark mode variables */
[data-theme="dark"] {
    --primary-color: #10A37F;
    --secondary-color: #F7F7F8;
    --background-color: #1A1A1A;
    --text-color: #F5F5F5;
    --accent-color: #B3B3B3;
    --success-color: #4CAF50;
    --error-color: #F44336;
    --warning-color: #FF9800;
    --border-color: #404040;
    --hover-color: #333333;
    --code-bg: #262626;
    --message-bg: #262626;
    --sidebar-bg: #1F1F1F;
}

/* Dark mode specific adjustments */
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background: var(--code-bg);
    color: var(--text-color);
    border-color: var(--border-color);
}

[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
    border-color: var(--primary-color);
}

[data-theme="dark"] .btn-primary {
    background: var(--primary-color);
    color: white;
}

[data-theme="dark"] .btn-secondary {
    background: var(--code-bg);
    color: var(--text-color);
    border-color: var(--border-color);
}

[data-theme="dark"] .btn-secondary:hover {
    background: var(--hover-color);
    border-color: var(--primary-color);
}

[data-theme="dark"] .btn-secondary.confirm-state {
    background: #ff6b6b;
    color: white;
    border-color: #ff5252;
}

[data-theme="dark"] .btn-secondary.confirm-state:hover {
    background: #ff5252;
    border-color: #ff4444;
}

[data-theme="dark"] .loading-overlay {
    background: rgba(33, 33, 33, 0.9);
}

[data-theme="dark"] .toast {
    color: white;
}

/* Dark mode placeholder and help text improvements */
[data-theme="dark"] input::placeholder,
[data-theme="dark"] select::placeholder,
[data-theme="dark"] textarea::placeholder {
    color: var(--accent-color);
    opacity: 1;
}

[data-theme="dark"] .help-text {
    color: var(--accent-color);
}

[data-theme="dark"] .metric-label {
    color: var(--accent-color);
}

[data-theme="dark"] .status-indicator {
    color: var(--text-color);
}

/* Dark mode copy button improvements */
[data-theme="dark"] .message.assistant .copy-button {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-color);
}

[data-theme="dark"] .message.assistant .copy-button:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Dark mode AI avatar and thinking message enhancements */
[data-theme="dark"] .message.assistant .message-avatar,
[data-theme="dark"] .bot-typing-message .message-avatar {
    background: linear-gradient(135deg, #4c6ef5 0%, #6c5ce7 100%);
    box-shadow: 0 2px 8px rgba(76, 110, 245, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .bot-typing-message .message-content {
    background: linear-gradient(135deg, #2a2d3a 0%, #3a3d4a 100%);
    border: 1px solid rgba(76, 110, 245, 0.3);
    box-shadow: 0 2px 12px rgba(76, 110, 245, 0.2);
}

[data-theme="dark"] .bot-typing-message .message-content::before {
    background: linear-gradient(90deg, transparent, rgba(76, 110, 245, 0.2), transparent);
}

[data-theme="dark"] .typing-dot {
    background: linear-gradient(135deg, #4c6ef5 0%, #6c5ce7 100%);
    box-shadow: 0 2px 4px rgba(76, 110, 245, 0.4);
}

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.5;
    font-size: 14px;
}

/* Main Layout */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Configuration Sidebar */
.config-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: transform 0.3s ease-out;
}

.config-sidebar.hidden {
    transform: translateX(-100%);
}

.app-container.sidebar-hidden .chat-main {
    margin-left: 0;
}

/* Mobile sidebar backdrop */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    backdrop-filter: blur(2px);
}

.config-header {
    padding: var(--padding);
    border-bottom: 1px solid var(--border-color);
    background: var(--background-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.config-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.theme-toggle-icon:hover {
    background: var(--hover-color);
    border-color: var(--primary-color);
}

.theme-toggle-icon .theme-icon {
    font-size: 16px;
    transition: opacity 0.2s ease;
    position: absolute;
}

[data-theme="light"] .theme-toggle-icon .dark-icon,
[data-theme="dark"] .theme-toggle-icon .light-icon {
    opacity: 0.3;
}

[data-theme="light"] .theme-toggle-icon .light-icon,
[data-theme="dark"] .theme-toggle-icon .dark-icon {
    opacity: 1;
}

.close-sidebar-btn {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--accent-color);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
}

.close-sidebar-btn:hover {
    background: var(--border-color);
    color: var(--text-color);
}

.config-section {
    padding: var(--padding);
    border-bottom: 1px solid var(--border-color);
}

.config-section:last-of-type {
    border-bottom: none;
}

.config-section label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-color);
    font-size: 13px;
}

.config-section input,
.config-section select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: var(--font-family);
    font-size: 14px;
    background: var(--message-bg);
    color: var(--text-color);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.config-section input:focus,
.config-section select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.1);
}

.config-section input[type="password"] {
    font-family: var(--font-mono);
    letter-spacing: 2px;
}

.help-text {
    display: block;
    margin-top: 4px;
    color: var(--accent-color);
    font-size: 12px;
}

/* Buttons */
.btn-primary,
.btn-secondary {
    padding: 10px 16px;
    border: none;
    border-radius: var(--border-radius);
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    width: 100%;
    justify-content: center;
}

.btn-primary:hover:not(:disabled) {
    background: #0D8B66;
    transform: translateY(-1px);
}

.btn-primary:disabled {
    background: var(--accent-color);
    cursor: not-allowed;
}

.btn-secondary {
    background: white;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    width: 100%;
    justify-content: center;
    margin-top: 8px;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--hover-color);
    border-color: var(--accent-color);
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.refresh-icon {
    font-size: 16px;
    transition: transform 0.3s;
}

.btn-secondary:hover .refresh-icon {
    transform: rotate(180deg);
}

/* Clear Chat Confirmation State */
.btn-secondary.confirm-state {
    background: #ff6b6b;
    color: white;
    border-color: #ff5252;
    animation: pulse-warning 1s infinite;
}

.btn-secondary.confirm-state:hover {
    background: #ff5252;
    border-color: #ff4444;
}

@keyframes pulse-warning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

/* Metrics Panel */
.metrics-panel {
    padding: var(--padding);
    background: var(--code-bg);
    margin-top: auto;
}

.metrics-panel h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-color);
}

.metric-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 13px;
}

.metric-label {
    color: var(--accent-color);
}

.metric-value {
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--text-color);
}

/* Status Indicator */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: var(--padding);
    border-top: 1px solid var(--border-color);
    font-size: 13px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: background-color 0.3s;
}

.status-connected {
    background-color: var(--success-color);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.2);
}

.status-disconnected {
    background-color: var(--accent-color);
}

.status-error {
    background-color: var(--error-color);
    box-shadow: 0 0 0 2px rgba(215, 58, 73, 0.2);
}

/* Chat Main Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--message-bg);
    overflow: hidden;
}

.chat-header {
    height: var(--header-height);
    padding: 0 var(--padding);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--message-bg);
}

.toggle-sidebar-btn {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-color);
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.toggle-sidebar-btn:hover {
    background-color: var(--hover-color);
}

.chat-header h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-color);
    flex: 1;
    text-align: center;
}

.chat-controls .btn-secondary {
    width: auto;
    margin: 0;
    padding: 8px 12px;
    font-size: 13px;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--padding);
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--accent-color);
}

.welcome-message h3 {
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-color);
}

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease-out;
}

.message.user {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.message.assistant {
    flex-direction: row;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 500;
    flex-shrink: 0;
}

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

.message.assistant .message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.2);
    position: relative;
    overflow: hidden;
}

.message.assistant .message-avatar::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transform: rotate(45deg);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
    50% { transform: translateX(100%) translateY(100%) rotate(45deg); }
    100% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
}

.message-content {
    flex: 1;
    padding: 12px 16px;
    max-width: 70%;
    border-radius: 18px;
    position: relative;
}

.message.user .message-content {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 6px;
}

.message.assistant .message-content {
    background: var(--message-bg);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 6px;
}

/* Copy button styles */
.copy-button {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.15);
    border: none;
    border-radius: 6px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s, background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.message-content:hover .copy-button {
    opacity: 1;
}

.copy-button:hover {
    background: rgba(0, 0, 0, 0.2);
}

.message.user .copy-button {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

.message.user .copy-button:hover {
    background: rgba(255, 255, 255, 0.4);
}

.message.assistant .copy-button {
    background: rgba(0, 0, 0, 0.15);
    color: var(--text-color);
}

.message.assistant .copy-button:hover {
    background: rgba(0, 0, 0, 0.25);
}

.copy-button svg {
    width: 14px;
    height: 14px;
}

/* Theme Toggle Styles - Now in header */

.theme-text {
    flex: 1;
    text-align: left;
}

.message-text {
    line-height: 1.6;
    word-wrap: break-word;
}

.message.user .message-text {
    color: white;
}

.message.user .message-text h1,
.message.user .message-text h2, 
.message.user .message-text h3,
.message.user .message-text h4,
.message.user .message-text h5,
.message.user .message-text h6 {
    color: white;
}

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

.message.user .message-text pre {
    background: rgba(255, 255, 255, 0.1);
}

.message.user .message-text blockquote {
    border-left-color: rgba(255, 255, 255, 0.5);
    color: rgba(255, 255, 255, 0.8);
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 11px;
    color: var(--accent-color);
    font-family: var(--font-mono);
    margin-top: 4px;
    opacity: 0.8;
}

.message.user .message-meta {
    color: rgba(255, 255, 255, 0.8);
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Thinking Section */
.thinking-section {
    background: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin: 8px 0;
    overflow: hidden;
}

.thinking-header {
    padding: 8px 12px;
    background: var(--hover-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 500;
    color: var(--accent-color);
    user-select: none;
}

.thinking-section:not(.expanded) .thinking-header {
    border-bottom: none;
}

.thinking-section.expanded .thinking-header {
    border-bottom: 1px solid var(--border-color);
}

.thinking-toggle {
    font-size: 10px;
    transition: transform 0.2s;
}

.thinking-toggle.expanded {
    transform: rotate(90deg);
}

.thinking-content {
    padding: 0;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.4;
    color: var(--text-color);
    white-space: pre-wrap;
    background: white;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
}

.thinking-content.expanded {
    max-height: 400px;
    overflow-y: auto;
    padding: 12px;
}

/* Markdown Rendering */
.message-text h1, .message-text h2, .message-text h3,
.message-text h4, .message-text h5, .message-text h6 {
    margin: 12px 0 8px 0;
    font-weight: 600;
}

.message-text h1 { font-size: 18px; }
.message-text h2 { font-size: 16px; }
.message-text h3 { font-size: 14px; }

.message-text p {
    margin: 8px 0;
}

.message-text ul, .message-text ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-text li {
    margin: 4px 0;
}

.message-text code {
    background: var(--code-bg);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 12px;
}

.message-text pre {
    background: var(--code-bg);
    padding: 12px;
    border-radius: var(--border-radius);
    overflow-x: auto;
    margin: 8px 0;
}

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

.message-text blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--accent-color);
}

.message-text table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
}

.message-text th, .message-text td {
    border: 1px solid var(--border-color);
    padding: 8px;
    text-align: left;
}

.message-text th {
    background: var(--hover-color);
    font-weight: 500;
}

/* Image Handling */
.message-text img {
    max-width: 100%;
    width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    margin: 8px 0;
    display: block;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    object-fit: contain;
}

.image-container {
    position: relative;
    display: block;
    max-width: 100%;
    margin: 8px 0;
    overflow: hidden;
}

.image-download-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 12px;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.image-container:hover .image-download-btn {
    opacity: 1;
}

.image-download-btn:hover {
    background: rgba(0, 0, 0, 0.9);
}

.image-download-btn svg {
    width: 14px;
    height: 14px;
}

/* Mermaid Diagrams */
.mermaid {
    text-align: center;
    margin: 16px 0;
}

/* Streaming Animation */
.streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--primary-color);
    animation: blink 1s infinite;
    margin-left: 2px;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Chat Input */
.chat-input-container {
    padding: var(--padding);
    border-top: 1px solid var(--border-color);
    background: var(--message-bg);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--message-bg);
    transition: border-color 0.2s;
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary-color);
}

#chat-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font-family);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-color);
    background: transparent;
    max-height: 120px;
    min-height: 60px;
    height: 60px;
}

#chat-input::placeholder {
    color: var(--accent-color);
}

.send-button {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background: #0D8B66;
    transform: translateY(-1px);
}

.send-button:disabled {
    background: var(--accent-color);
    cursor: not-allowed;
    opacity: 0.5;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-size: 12px;
    color: var(--accent-color);
}

.typing-indicator {
    display: none;
    font-style: italic;
    color: var(--accent-color);
}

/* Bot Typing Message */
.bot-typing-message {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease-out;
}

.bot-typing-message .message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 500;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.2);
    position: relative;
    overflow: hidden;
}

.bot-typing-message .message-avatar::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transform: rotate(45deg);
    animation: shimmer 3s infinite;
}

.bot-typing-message .message-content {
    padding: 12px 16px;
    max-width: 70%;
    border-radius: 18px;
    background: linear-gradient(135deg, #f8f9ff 0%, #e8ecff 100%);
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-bottom-left-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 12px rgba(102, 126, 234, 0.1);
    position: relative;
    overflow: hidden;
}

.bot-typing-message .message-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.1), transparent);
    animation: thinking-wave 2s infinite;
}

@keyframes thinking-wave {
    0% { left: -100%; }
    100% { left: 100%; }
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    position: relative;
    z-index: 1;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    animation: typingDots 1.4s infinite ease-in-out;
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

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

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

@keyframes typingDots {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.6;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

.loading-overlay p {
    color: white;
    font-size: 14px;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 16px;
    border-radius: var(--border-radius);
    color: white;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.3s ease-out;
    min-width: 280px;
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--error-color);
}

.toast.warning {
    background: var(--warning-color);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

/* Responsive Design */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }
    
    /* Solidify viewport sizing across the stack */
    html, body {
        height: 100%;
        min-height: 100dvh;
        height: -webkit-fill-available;
    }
    
    .toggle-sidebar-btn {
        display: block;
    }
    
    .close-sidebar-btn {
        display: flex;
    }
    
    .app-container {
        height: 100vh; /* Legacy fallback */
        height: -webkit-fill-available; /* iOS fallback */
    }
    
    .config-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh; /* Legacy fallback */
        height: -webkit-fill-available; /* iOS fallback */
        z-index: 1000;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        background: var(--sidebar-bg);
    }
    
    /* Modern dynamic viewport units take priority */
    @supports (height: 100dvh) {
        .app-container {
            height: 100dvh;
            min-height: 100svh;
        }
        
        .config-sidebar {
            height: 100dvh;
            min-height: 100svh;
        }
    }
    
    .config-sidebar.hidden {
        transform: translateX(-100%);
    }
    
    .chat-main {
        height: 100%;
        min-height: 0;
    }
    
    .chat-messages {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
    }
    
    .chat-input-container {
        position: sticky;
        bottom: 0;
        background: white;
        padding-bottom: calc(var(--padding) + env(safe-area-inset-bottom));
    }
    
    .chat-header {
        justify-content: flex-start;
        gap: 16px;
    }
    
    .chat-header h1 {
        text-align: left;
        font-size: 18px;
    }
    
    .config-header h2 {
        font-size: 16px;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .chat-input {
        font-size: 16px;
    }
    
    .metrics-panel {
        font-size: 12px;
    }
    
    .metric-item {
        font-size: 12px;
    }
    
    /* Mobile image constraints */
    .message-text img {
        max-width: calc(100vw - 120px);
        width: auto;
    }
    
    .image-container {
        max-width: calc(100vw - 120px);
    }
}

@media (max-width: 480px) {
    :root {
        --padding: 12px;
    }
    
    .chat-input-wrapper {
        padding: 8px;
    }
    
    .message {
        gap: 8px;
    }
    
    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    /* Extra small screen image constraints */
    .message-text img {
        max-width: calc(100vw - 80px);
        width: auto;
    }
    
    .image-container {
        max-width: calc(100vw - 80px);
    }
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar,
.config-sidebar::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.config-sidebar::-webkit-scrollbar-track {
    background: var(--background-color);
}

.chat-messages::-webkit-scrollbar-thumb,
.config-sidebar::-webkit-scrollbar-thumb {
    background: var(--accent-color);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.config-sidebar::-webkit-scrollbar-thumb:hover {
    background: #6B7280;
}
