:root {
  /* Main Background is Pitch Dark */
  --primary-bg: #000000; 
  --secondary-bg: #121212; /* Solid dark for settings */
  --tertiary-bg: #2d2d2d; 
  
  --accent-primary: #10a37f; 
  --accent-primary-hover: #0d8a6a; 
  --accent-primary-active: #0a7056; 
  --accent-secondary: #a1a1aa; 
  
  --text-primary: #ececf1; 
  --text-secondary: #a1a1aa; 
  --text-tertiary: #71717a; 
  
  --border-primary: #333333; 
  --border-secondary: #444444; 
  
  --shadow-color-soft: rgba(0, 0, 0, 0.2); 
  --shadow-color-medium: rgba(0, 0, 0, 0.4); 
  --shadow-color-strong: rgba(0, 0, 0, 0.6); 
  --error-color: #ef4444; 
  --success-color: #22c55e; 
  --warning-color: #facc15; 
  
  --code-bg: #1e1e1e; /* Darker VS Code style */
  --code-text: #d4d4d4; 
  --code-header-bg: #252526; 
  --code-border: #333333; 
  --code-scrollbar-bg: #333333;
  --code-scrollbar-thumb: #666666;
  
  --gradient-accent: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-primary-hover) 100%); 
  --glass-bg: rgba(20, 20, 20, 0.3); 
  --glass-border: rgba(255, 255, 255, 0.08);
  --backdrop-blur: saturate(180%) blur(25px); 
  
  --transition-fast: 0.15s ease-out;
  --transition-medium: 0.25s ease-out;
  --transition-slow: 0.4s ease-out;
  
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-secondary: 'Roboto Slab', serif; 
  --font-monospace: 'Fira Code', 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
  
  --font-size-base: 16px;
  --line-height-base: 1.65;
  --spacing-unit: 8px;
  
  --radius-small: 4px;
  --radius-medium: 6px; 
  --radius-large: 10px; 
  --radius-xl: 18px; 
  --radius-full: 9999px;
  
  --sidebar-width: 260px;
  --chat-max-width: 768px; 
}

/* Remove default flash/highlight on tap for mobile */
* {
    -webkit-tap-highlight-color: transparent;
}

.light-theme {
  --primary-bg: #f4f4f5;
  --secondary-bg: #ffffff; /* Solid white for settings */
  --tertiary-bg: #e4e4e7;
  --accent-primary: #16a34a;
  --accent-primary-hover: #15803d;
  --accent-primary-active: #166534;
  --text-primary: #18181b;
  --text-secondary: #52525b;
  --text-tertiary: #71717a;
  --border-primary: #d4d4d8;
  --border-secondary: #e4e4e7;
  --shadow-color-soft: rgba(0, 0, 0, 0.05);
  --shadow-color-medium: rgba(0, 0, 0, 0.1);
  --shadow-color-strong: rgba(0, 0, 0, 0.15);
  --code-bg: #ffffff;
  --code-text: #111827;
  --code-header-bg: #f3f4f6;
  --code-border: #e5e7eb;
  --code-scrollbar-thumb: #a1a1aa;
  --glass-bg: rgba(255, 255, 255, 0.4);
  --glass-border: rgba(0, 0, 0, 0.1);
}

@supports (font-variant-ligatures: common-ligatures) {
  :root {
    --font-monospace: 'Fira Code', 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
  }
  code, pre, kbd, samp {
    font-variant-ligatures: common-ligatures; 
  }
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: var(--font-size-base); scroll-behavior: smooth; scrollbar-width: none; height: 100%; }

body { 
    font-family: var(--font-primary); 
    background-color: var(--primary-bg); 
    color: var(--text-primary); 
    line-height: var(--line-height-base); 
    -webkit-font-smoothing: antialiased; 
    -moz-osx-font-smoothing: grayscale; 
    overflow: hidden; 
    height: 100dvh; 
    width: 100%;
    display: flex; 
    flex-direction: column; 
    text-rendering: optimizeLegibility; 
    -ms-overflow-style: none; 
}

::-webkit-scrollbar { display: none; }

a { color: var(--accent-primary); text-decoration: none; transition: color var(--transition-fast), text-shadow var(--transition-fast); }
a:hover { color: var(--accent-primary-hover); text-decoration: underline; text-shadow: 0 0 5px rgba(16, 163, 127, 0.3); }

.link-favicon {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    margin-left: 4px;
    vertical-align: text-bottom;
    background-color: white;
    border: 1px solid var(--border-primary);
}

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 2px; border-radius: var(--radius-small); }

h1, h2, h3, h4, h5, h6 { font-family: var(--font-primary); font-weight: 700; color: var(--text-primary); margin-bottom: calc(var(--spacing-unit) * 2); line-height: 1.3; }
h1 { font-size: 2.5rem; } h2 { font-size: 2rem; } h3 { font-size: 1.6rem; } h4 { font-size: 1.3rem; }
p { margin-bottom: calc(var(--spacing-unit) * 2); }
ul, ol { padding-left: calc(var(--spacing-unit) * 3); margin-bottom: calc(var(--spacing-unit) * 2); }
li { margin-bottom: var(--spacing-unit); }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }

.sidebar { 
    width: var(--sidebar-width); 
    height: 100dvh; 
    background: var(--primary-bg); 
    backdrop-filter: none; 
    -webkit-backdrop-filter: none; 
    padding: calc(var(--spacing-unit) * 2); 
    position: fixed; 
    top: 0; 
    left: 0; 
    transform: translateX(0); 
    transition: transform var(--transition-medium), width var(--transition-medium), box-shadow var(--transition-medium); 
    z-index: 1000; 
    border-right: 1px solid rgba(255, 255, 255, 0.1); 
    display: flex; 
    flex-direction: column; 
    box-shadow: var(--shadow-color-strong) 2px 0 10px; 
}
.sidebar.closed { transform: translateX(-100%); }

.sidebar-top { flex-shrink: 0; margin-bottom: var(--spacing-unit); display: flex; flex-direction: column; }
.sidebar-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.logo-wrapper { display: flex; align-items: center; gap: 10px; }
.sidebar-brand-name { font-weight: 700; font-size: 1.1rem; color: var(--text-primary); letter-spacing: 0.5px; }
.sidebar-history { flex-grow: 1; overflow-y: auto; margin-bottom: var(--spacing-unit); display: flex; flex-direction: column; padding-right: 4px; overscroll-behavior: contain; }
.sidebar-bottom { flex-shrink: 0; border-top: 1px solid var(--border-primary); padding-top: var(--spacing-unit); padding-bottom: 20px; }

.sidebar-logo {
    width: 32px;
    height: 32px;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: none;
    border-radius: 4px;
}

.sidebar-close-btn {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    border-radius: var(--radius-small);
    transition: background 0.2s, color 0.2s;
    border: 1px solid var(--border-primary);
}
.sidebar-close-btn:hover { background: var(--tertiary-bg); color: var(--text-primary); }

.history-label { font-size: 0.75rem; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.5px; margin: calc(var(--spacing-unit) * 2) 0 var(--spacing-unit) 0; padding-left: var(--spacing-unit); }

.sidebar a { display: flex; align-items: center; color: var(--text-secondary); text-decoration: none; padding: calc(var(--spacing-unit) * 1.25) calc(var(--spacing-unit) * 1.5); margin: 4px 0; border-radius: var(--radius-medium); transition: background-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast); font-size: 0.95rem; font-weight: 400; gap: 12px; position: relative; }
.sidebar a svg, .sidebar a i { width: 20px; height: 20px; text-align: center; color: var(--text-tertiary); transition: color var(--transition-fast); flex-shrink: 0; }
.sidebar a:hover { background-color: var(--tertiary-bg); color: var(--text-primary); text-decoration: none; }
.sidebar a:hover svg, .sidebar a:hover i { color: var(--text-primary); }
.sidebar a.active { background: var(--tertiary-bg); color: var(--text-primary); font-weight: 600; }
.sidebar a.active svg, .sidebar a.active i { color: var(--text-primary); }

/* Sidebar Profile Section */
.sidebar-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: var(--radius-medium);
    cursor: pointer;
    transition: background-color 0.2s;
}
.sidebar-profile:hover {
    background-color: var(--tertiary-bg);
}
.profile-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--accent-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}
.profile-avatar.large {
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
}
.profile-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.profile-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-link { justify-content: space-between; padding-right: 30px !important; }
.session-name-wrapper { display: flex; align-items: center; gap: 10px; overflow: hidden; flex-grow: 1; }
.session-name-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 3-dot menu visibility */
.session-menu-btn { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); opacity: 0; transition: opacity 0.2s; color: var(--text-tertiary); padding: 4px; border-radius: 4px; }
.session-link:hover .session-menu-btn, .session-menu-btn.active { opacity: 1; }
.session-menu-btn:hover { background-color: rgba(255,255,255,0.1); color: var(--text-primary); }

@media (max-width: 768px) {
    .session-menu-btn { opacity: 1; } /* Always visible on mobile */
}

.session-dropdown { 
    position: absolute; 
    right: 0; 
    top: 100%; 
    background: var(--secondary-bg); 
    border: 1px solid var(--border-primary); 
    border-radius: var(--radius-medium); 
    box-shadow: 0 4px 12px rgba(0,0,0,0.3); 
    z-index: 1001; 
    display: none; 
    flex-direction: column; 
    min-width: 120px; 
    overflow: hidden;
}
.session-dropdown.show { display: flex; }
.session-dropdown button { 
    text-align: left; 
    padding: 8px 12px; 
    font-size: 0.85rem; 
    color: var(--text-primary); 
    transition: background 0.2s; 
    display: flex; 
    align-items: center; 
    gap: 8px; 
}
.session-dropdown button:hover { background-color: var(--tertiary-bg); }
.session-dropdown button.delete-opt:hover { background-color: rgba(239, 68, 68, 0.2); color: var(--error-color); }

.new-chat-btn { 
    border: none;
    margin-bottom: 0 !important; 
    background: transparent;
    padding: 8px 12px;
    border-radius: var(--radius-medium);
    color: var(--text-primary);
    font-size: 0.95rem;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    width: 100%;
}
.new-chat-btn:hover { background-color: var(--tertiary-bg); border-color: transparent; }
.new-chat-btn svg { width: 16px; height: 16px; margin-right: 12px; }

.page-container { margin-left: var(--sidebar-width); transition: margin-left var(--transition-medium); width: calc(100% - var(--sidebar-width)); height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.page-container.full-width { margin-left: 0; width: 100%; }

header:not(.landing-header) { display: flex; align-items: center; justify-content: flex-start; gap: calc(var(--spacing-unit) * 2); padding: calc(var(--spacing-unit) * 1) calc(var(--spacing-unit) * 2.5); background-color: var(--primary-bg); backdrop-filter: none; -webkit-backdrop-filter: none; border-bottom: none; position: fixed; top: 0; left: var(--sidebar-width); width: calc(100% - var(--sidebar-width)); z-index: 900; min-height: 56px; transition: left var(--transition-medium), width var(--transition-medium), background-color var(--transition-medium), border-color var(--transition-medium); box-shadow: none; }
.page-container.full-width header:not(.landing-header) { left: 0; width: 100%; }

.sidebar-toggle { display: flex; align-items: center; justify-content: center; color: var(--text-secondary); width: 32px; height: 32px; border-radius: var(--radius-small); transition: background 0.2s, color 0.2s; }
.sidebar-toggle:hover { background: var(--tertiary-bg); color: var(--text-primary); }
.sidebar-toggle svg { width: 24px; height: 24px; }

.chat-container { width: 100%; max-width: 100%; margin: 0; display: flex; flex-direction: column; height: 100dvh; background-color: var(--primary-bg); flex-grow: 1; overflow: hidden; }
#mainChatSection { padding-top: 56px; flex-grow: 1; display: flex; flex-direction: column; position: relative; overflow: hidden; height: 100%; }
.controls-container { display: flex; align-items: center; gap: calc(var(--spacing-unit) * 2); }

.custom-model-dropdown { position: relative; min-width: 140px; font-family: var(--font-primary); }
.selected-model { padding: 6px 12px; background-color: var(--primary-bg); border: none; border-radius: var(--radius-medium); color: var(--text-primary); cursor: pointer; transition: background var(--transition-fast); display: flex; flex-direction: row; align-items: center; gap: 8px; }
.selected-model:hover, .custom-model-dropdown.open .selected-model { background-color: var(--tertiary-bg); }
.selected-model:focus, .selected-model:focus-visible { outline: none; background-color: var(--tertiary-bg); }
.selected-model .model-name { font-size: 0.95rem; font-weight: 600; }
.selected-model .model-desc { display: none; } 
.selected-model::after {
    content: '\f078';
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-left: 4px;
}

.model-options { display: none; position: absolute; top: calc(100% + 4px); left: 0; min-width: 220px; width: max-content; background-color: var(--secondary-bg); border: 1px solid var(--border-primary); border-radius: var(--radius-medium); list-style: none; padding: calc(var(--spacing-unit) * 0.5); margin: 0; z-index: 1000; box-shadow: 0 4px 15px var(--shadow-color-medium); }
.custom-model-dropdown.open .model-options { display: block; }
.model-options li { padding: calc(var(--spacing-unit) * 1) calc(var(--spacing-unit) * 1.5); border-radius: var(--radius-small); cursor: pointer; transition: background-color var(--transition-fast); margin: 0; line-height: 1.3; }
.model-options li:hover { background-color: var(--tertiary-bg); }
.model-options li.selected { background-color: var(--accent-primary); color: white; }
.model-options li.selected .model-desc { color: rgba(255, 255, 255, 0.8); }
.model-options .model-name { font-weight: 600; display: block; font-size: 0.9rem; }
.model-options .model-desc { font-size: 0.75rem; color: var(--text-secondary); display: block; }

#chatbox { background: var(--primary-bg); padding: calc(var(--spacing-unit) * 2.5) calc(var(--spacing-unit) * 3); flex-grow: 1; overflow-y: auto; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; position: relative; display: flex; flex-direction: column; overscroll-behavior: contain; }
.empty-chat-placeholder { position: absolute; top: 45%; left: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--text-tertiary); opacity: 1; pointer-events: none; transition: opacity 0.3s ease-out; width: 100%; }
#chatbox.has-messages .empty-chat-placeholder { opacity: 0; }
.empty-chat-placeholder h2 { font-size: 2rem; font-weight: 600; color: var(--text-tertiary); margin: 0; }


/* --- BULLETPROOF FLEX LAYOUT FIX FOR CHAT BUBBLES --- */
.message { 
    display: flex; 
    flex-direction: column; 
    align-items: flex-start; 
    margin: calc(var(--spacing-unit) * 1.25) auto; 
    max-width: 768px; 
    width: 100%; 
    min-width: 0; /* CRITICAL: Allows flex box to respect constraints */
    opacity: 0; 
    transform: translateY(20px); 
    animation: messageFadeIn 0.3s ease-out forwards; 
    position: relative; 
    z-index: 1; 
}
@keyframes messageFadeIn { to { opacity: 1; transform: translateY(0); } }

.message.user { align-items: flex-end; }
.message.bot { align-items: flex-start; }

/* The inner wrapper created via script.js that holds the actual message */
.message > div {
    max-width: 100%;
    min-width: 0; /* CRITICAL: Prevents invisible child from blowing out parent bounds */
}

.message .message-header { display: none; } 

.message-content { 
    padding: calc(var(--spacing-unit) * 1.5) calc(var(--spacing-unit) * 2); 
    border-radius: var(--radius-medium); 
    position: relative; 
    transition: background-color var(--transition-fast); 
    width: auto; 
    max-width: 100%; 
    min-width: 0; /* CRITICAL: Stop text contents from breaking the flex box */
    font-size: 1rem; 
    line-height: 1.7; 
    overflow-wrap: break-word; 
    word-break: break-word; 
    hyphens: auto; 
    box-shadow: none; 
}

/* User Message Color: Dark Gray (in Dark Mode) */
.message.user .message-content { background: #2A2B32; color: #ececf1; border-bottom-right-radius: var(--radius-small); white-space: pre-wrap; }
.light-theme .message.user .message-content { background: #e4e4e7; color: #18181b; }

.message.bot .message-content { background: var(--primary-bg); color: var(--text-primary); border: none; border-bottom-left-radius: var(--radius-small); }
.message.error .message-content { background: var(--error-color); color: #ffffff; border-color: #ef4444; box-shadow: none; }

.message.stopped .message-content { color: var(--text-tertiary); font-style: italic; border: 1px dashed var(--border-primary); background: transparent; }

.message-content p { margin: calc(var(--spacing-unit) * 0.75) 0; }
.message-content p:first-child { margin-top: 0; }
.message-content p:last-child { margin-bottom: 0; }
.message-content h1, .message-content h2, .message-content h3, .message-content h4, .message-content h5, .message-content h6 { margin: calc(var(--spacing-unit) * 3) 0 calc(var(--spacing-unit) * 1.5); font-weight: 600; line-height: 1.4; padding-bottom: 0.3em; border-bottom: 1px solid var(--border-primary); }
.message-content h1 { font-size: 1.5em; } .message-content h2 { font-size: 1.35em; } .message-content h3 { font-size: 1.2em; }
.message-content strong { font-weight: 700; color: inherit; } .message-content em { font-style: italic; color: inherit; }

/* Advanced Code Block Styling */
.code-block-container.enhanced-code { 
    background-color: var(--code-bg); 
    border: 1px solid var(--code-border); 
    border-radius: 8px; 
    margin: calc(var(--spacing-unit) * 2) 0; 
    overflow: hidden; 
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); 
    width: 100%; 
    max-width: 100%; 
    display: flex; 
    flex-direction: column; 
}

.code-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    background-color: var(--code-header-bg); 
    padding: 8px 16px; 
    border-bottom: 1px solid var(--code-border); 
    user-select: none;
}

.language-label { 
    font-family: var(--font-monospace); 
    font-size: 0.8rem; 
    color: var(--code-text); 
    font-weight: 600; 
    text-transform: uppercase; 
    letter-spacing: 0.5px; 
}

.code-controls { 
    display: flex; 
    gap: 8px; 
}

.code-controls button { 
    background: transparent; 
    color: var(--text-secondary); 
    border: none;
    border-radius: 4px; 
    padding: 4px 8px; 
    font-size: 0.8rem; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    line-height: 1; 
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s; 
}

.code-controls button:hover { 
    background-color: rgba(255, 255, 255, 0.1); 
    color: var(--text-primary); 
}

.code-controls button i {
    font-size: 0.9rem;
    margin-right: 0;
}

/* Specific styling for copy/download buttons to have labels on desktop */
@media (min-width: 768px) {
    .code-controls button::after {
        content: attr(data-label);
        margin-left: 6px;
        font-family: var(--font-primary);
        font-weight: 500;
    }
}

.code-wrapper { 
    overflow-x: auto; 
    width: 100%; 
    display: grid; 
}

.code-wrapper pre { 
    margin: 0 !important; 
    padding: 16px !important; 
    background: transparent !important; 
    border: none !important;
    overflow-x: auto;
}

.code-wrapper code { 
    font-family: var(--font-monospace); 
    font-size: 0.9em; 
    line-height: 1.6; 
    white-space: pre; 
}

/* Inline code style */
.message-content code:not(pre code) { 
    background-color: var(--tertiary-bg); 
    color: var(--accent-primary); 
    padding: 0.2em 0.4em; 
    border-radius: var(--radius-small); 
    font-family: var(--font-monospace); 
    font-size: 0.9em; 
    vertical-align: baseline; 
}

.message-content ul, .message-content ol { padding-left: calc(var(--spacing-unit) * 3); margin: var(--spacing-unit) 0; }
.message-content ul ul, .message-content ol ol, .message-content ul ol, .message-content ol ul { margin: 0; }
.message-content li { margin-bottom: 4px; }
.message-content li::marker { color: var(--text-secondary); }

.message-content blockquote { border-left: 4px solid var(--accent-primary); padding: calc(var(--spacing-unit) * 1.5) calc(var(--spacing-unit) * 2); margin: calc(var(--spacing-unit) * 1.5) 0; color: var(--text-secondary); font-style: italic; background-color: var(--tertiary-bg); border-radius: 0 var(--radius-medium) var(--radius-medium) 0; box-shadow: none; }

.message-content hr { border: none; height: 1px; background-color: var(--border-primary); margin: calc(var(--spacing-unit) * 2.5) 0; }


/* --- TABLE SCROLL BOX (OUTER CONTAINER) --- */
.table-container {
    width: 100%;
    max-width: 100%; /* Strictly bound to .message-content */
    overflow-x: auto; /* Allow horizontal scrolling */
    overflow-y: hidden;
    margin: 1.5rem 0;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-large);
    background-color: var(--secondary-bg);
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    display: block; /* Essential for establishing a block formatting context */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on mobile devices */
}

/* CUSTOM SCROLLBAR FOR THE TABLE BOX */
.table-container::-webkit-scrollbar {
    height: 8px;
    display: block; 
}

.table-container::-webkit-scrollbar-track {
    background: transparent;
}

.table-container::-webkit-scrollbar-thumb {
    background: var(--border-secondary);
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* --- INNER TABLE --- */
.message-content table { 
    width: 100%; 
    min-width: 700px; /* Forces scrolling on screens smaller than this */
    border-collapse: collapse; 
    margin: 0; 
    font-size: 0.9em; 
    border: none; 
    display: table; 
}

.message-content th, .message-content td { 
    border: none;
    border-bottom: 1px solid var(--border-primary); 
    padding: 1rem 1.25rem; 
    text-align: left; 
    vertical-align: top;
    white-space: normal; /* Allow cell text to wrap */
    line-height: 1.5;
}

.message-content tr:last-child td {
    border-bottom: none;
}

.message-content th { 
    background-color: var(--tertiary-bg); 
    font-weight: 600; 
    color: var(--text-primary); 
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.85rem;
    white-space: nowrap; /* Keep header labels on one line */
}

.message-content tr:nth-child(even) { 
    background-color: rgba(255, 255, 255, 0.02); 
}
.light-theme .message-content tr:nth-child(even) { 
    background-color: rgba(0, 0, 0, 0.02); 
}


/* --- KATEX / MATH --- */
.katex-display { display: block; margin: 1em 0; color: var(--text-primary); overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.katex-display::-webkit-scrollbar { display: none; }
.katex { font-size: 1.45em; color: inherit; }
.katex-display > .katex { display: inline-block; max-width: 100%; text-align: initial; }
.light-theme .katex { color: var(--text-primary); }

.input-container-wrapper { 
    position: relative; /* Added to keep greeting text correctly anchored */
    width: 100%; 
    max-width: var(--chat-max-width); 
    margin: 0 auto; 
    padding: 0 calc(var(--spacing-unit) * 2) calc(var(--spacing-unit) * 4); 
    display: flex; 
    flex-direction: column; 
    gap: var(--spacing-unit); 
    flex-shrink: 0; 
    transition: transform 0.5s cubic-bezier(0.25, 1, 0.5, 1); 
}

.input-area { display: flex; align-items: flex-end; gap: var(--spacing-unit); padding: var(--spacing-unit); background-color: var(--primary-bg); border: 1px solid var(--border-secondary); border-radius: var(--radius-xl); box-shadow: 0 2px 10px var(--shadow-color-soft); transition: border-color var(--transition-fast), box-shadow var(--transition-medium); }
.input-area:focus-within { border-color: var(--border-secondary); box-shadow: none; outline: none; }

.input-action-btn { flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background-color: transparent; color: var(--text-secondary); font-size: 1.1rem; transition: background-color var(--transition-fast), color var(--transition-fast); margin-bottom: 4px; }
.input-action-btn:hover { background-color: var(--tertiary-bg); color: var(--text-primary); }
#searchToggleBtn.active-search { background-color: var(--accent-primary); color: white; }
#searchToggleBtn.active-search:hover { background-color: var(--accent-primary-hover); }
.input-area textarea { flex: 1; background: transparent; border: none; outline: none; color: var(--text-primary); resize: none; min-height: 24px; max-height: 200px; font-size: 1rem; line-height: 1.5; padding: 8px 4px; scrollbar-width: none; }
.input-area textarea::placeholder { color: var(--text-tertiary); }
.input-area textarea::-webkit-scrollbar { display: none; }
.send-btn { flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background-color: var(--tertiary-bg); color: var(--text-tertiary); font-size: 1.1rem; transition: background-color var(--transition-fast), color var(--transition-fast); margin-bottom: 4px; cursor: not-allowed; }
.send-btn.active { background-color: var(--accent-primary); color: white; cursor: pointer; }
.send-btn.active:hover { background-color: var(--accent-primary-hover); }

.send-btn.stop-btn { background-color: var(--tertiary-bg); color: var(--text-primary); cursor: pointer; }
.send-btn.stop-btn:hover { background-color: var(--border-secondary); }
.send-btn.stop-btn i { font-size: 0.9rem; }

.image-preview-container { 
    display: flex; 
    flex-direction: row; 
    flex-wrap: wrap;
    align-items: center; 
    gap: var(--spacing-unit); 
    padding: 0;
    width: 100%; 
    margin-left: var(--spacing-unit); 
    min-height: 0;
    background: transparent;
    border: none;
    box-shadow: none;
}

.preview-item {
    position: relative;
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    margin-right: 8px;
}

.preview-image {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: var(--radius-medium);
    border: none;
}

.preview-file-card {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: var(--secondary-bg);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-medium);
    padding: 8px 12px;
    max-width: 200px;
    height: 40px;
}

.preview-file-icon {
    color: var(--accent-primary);
    font-size: 1.2rem;
}

.preview-file-name {
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.remove-preview-btn {
    background: var(--tertiary-bg);
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--text-secondary);
    font-size: 0.7rem;
    position: absolute;
    top: -6px;
    right: -6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    cursor: pointer;
    z-index: 2;
}
.remove-preview-btn:hover { background-color: var(--error-color); color: white; }

.image-upload-loader { color: var(--text-secondary); font-size: 0.9rem; display: flex; align-items: center; gap: 8px; }
.image-upload-loader::before { content: ''; width: 20px; height: 20px; border: 2px solid var(--border-primary); border-top-color: var(--accent-primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.input-word-counter { text-align: center; font-size: 0.8rem; color: var(--text-tertiary); padding: 0 calc(var(--spacing-unit) * 2); height: 1.2em; transition: color 0.2s ease; }
.input-word-counter.warning { color: var(--warning-color); }
.input-word-counter.error { color: var(--error-color); font-weight: 600; }
.input-footer { text-align: center; font-size: 0.75rem; color: var(--text-tertiary); padding: 0 calc(var(--spacing-unit) * 2); margin-bottom: 4px;}

.chat-uploaded-image { max-width: 250px; height: auto; border-radius: var(--radius-small); margin-bottom: 0; border: none; box-shadow: none; }

.chat-attachments-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
    width: 100%;
    align-items: flex-end; 
}

.user-file-attachment { 
    background-color: var(--secondary-bg); 
    border-radius: var(--radius-small); 
    padding: 10px 14px; 
    margin-bottom: 0; 
    display: flex; 
    align-items: center; 
    gap: 10px; 
    font-size: 0.9rem; 
    border: 1px solid var(--border-primary); 
    cursor: pointer;
    transition: background 0.2s;
    width: fit-content;
}
.user-file-attachment:hover { background-color: var(--tertiary-bg); }
.user-file-attachment i { font-size: 1.2rem; color: var(--accent-primary); }

.placeholder { display: flex; align-items: center; justify-content: flex-start; }
.typing-indicator { width: auto; display: flex; align-items: center; justify-content: flex-start; margin-left: 0; }
.typing-indicator span {
    width: 12px; height: 12px; background: white; border-radius: 50%;
    animation: singlePulse 1s infinite alternate;
    margin: 0; position: static; opacity: 1;
}
@keyframes singlePulse { 
    0% { opacity: 0.3; transform: scale(0.9); box-shadow: 0 0 0 rgba(255,255,255,0); } 
    100% { opacity: 1; transform: scale(1.1); box-shadow: 0 0 8px rgba(255,255,255,0.5); } 
}

.light-theme .typing-indicator span {
    background: #555; 
    box-shadow: none; 
}
.light-theme .typing-indicator span {
    animation: singlePulseLight 1s infinite alternate;
}
@keyframes singlePulseLight { 
    0% { opacity: 0.3; transform: scale(0.9); } 
    100% { opacity: 1; transform: scale(1.1); } 
}

.custom-modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.7); display: flex; justify-content: center; align-items: center; z-index: 2000; opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease; }
.light-theme .custom-modal-overlay { background-color: rgba(0, 0, 0, 0.4); }
.custom-modal-overlay.show { opacity: 1; visibility: visible; }

#settingsModalOverlay { z-index: 2000; }
#customModalOverlay { z-index: 2100; } 
#loginModalOverlay { z-index: 3000; } 
#fileViewerOverlay { z-index: 2500; }

.custom-modal { 
    background: var(--secondary-bg); /* Solid background */
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-medium); 
    padding: calc(var(--spacing-unit) * 3); 
    max-width: 400px; 
    width: 90%; 
    box-shadow: 0 8px 30px var(--shadow-color-strong); 
    transform: translateY(-20px); 
    transition: transform 0.3s ease; 
    text-align: center; 
}
.custom-modal-overlay.show .custom-modal { transform: translateY(0); }
.custom-modal h3 { font-size: 1.5rem; color: var(--accent-primary); margin-bottom: calc(var(--spacing-unit) * 2); }
.custom-modal p { color: var(--text-primary); margin-bottom: calc(var(--spacing-unit) * 3); line-height: 1.6; }
.custom-modal-buttons { display: flex; justify-content: center; gap: calc(var(--spacing-unit) * 2); }
.custom-modal-buttons button { padding: calc(var(--spacing-unit) * 1) calc(var(--spacing-unit) * 3); border-radius: var(--radius-small); font-weight: 600; transition: transform 0.2s ease, box-shadow 0.2s ease; }
.custom-modal-buttons .confirm-btn { background: var(--accent-primary); color: white; box-shadow: none; border: none; }
.custom-modal-buttons .confirm-btn:hover { transform: translateY(-2px); box-shadow: none; }
.custom-modal-buttons .cancel-btn { background-color: var(--tertiary-bg); color: var(--text-secondary); border: 1px solid var(--border-primary); box-shadow: none; }
.custom-modal-buttons .cancel-btn:hover { background-color: var(--border-secondary); transform: translateY(-2px); box-shadow: none; }

/* Updated Notification Styles */
.custom-notification { 
    background-color: rgba(45, 45, 45, 0.7); /* Dark theme transparent */
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid var(--border-primary); 
    border-radius: 20px; /* Pill shape */
    padding: 8px 12px;
    position: fixed; 
    top: 20px; 
    left: 50%; 
    transform: translateX(-50%) translateY(-100px); 
    opacity: 0; 
    visibility: hidden; 
    z-index: 1500; 
    min-width: auto;
    max-width: 90%; 
    box-shadow: 0 4px 6px rgba(0,0,0,0.2); 
    display: flex; 
    align-items: center; 
    gap: 10px; 
    transition: transform 0.3s ease-out, opacity 0.3s ease-out, visibility 0.3s ease-out; 
}

.light-theme .custom-notification {
    background-color: rgba(255, 255, 255, 0.7); /* Light theme transparent */
    color: #18181b;
    border-color: #e4e4e7;
}

.custom-notification.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }
.custom-notification.success { border-left: 3px solid var(--success-color); }
.custom-notification.error { border-left: 3px solid var(--error-color); }
.custom-notification.info { border-left: 3px solid var(--accent-primary); }
.custom-notification i { font-size: 1rem; } 
.custom-notification.success i { color: var(--success-color); }
.custom-notification.error i { color: var(--error-color); }
.custom-notification.info i { color: var(--accent-primary); }
.custom-notification p { margin: 0; font-size: 0.85rem; color: var(--text-primary); flex-grow: 1; }
.light-theme .custom-notification p { color: #18181b; }

/* Offline Notification */
.offline-notification {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    background-color: rgba(239, 68, 68, 0.7); 
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    color: white;
    border: none;
    border-radius: 20px;
    text-align: center;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
}
.offline-notification.show { display: flex; }

.rename-input { width: 100%; background-color: var(--tertiary-bg); border: 1px solid var(--accent-primary); border-radius: var(--radius-small); padding: 4px 8px; color: var(--text-primary); font-size: inherit; font-family: inherit; outline: none; margin-left: calc(var(--spacing-unit) * 1.5); }


/* ---- FULLY RESPONSIVE SETTINGS MODAL ---- */
.settings-modal { 
    max-width: 750px; 
    width: 90%;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 85vh;
    max-height: 600px;
    background-color: var(--secondary-bg);
    position: relative;
}
.settings-container {
    display: flex;
    flex-direction: row;
    height: 100%;
    overflow: hidden;
}
.settings-sidebar {
    width: 220px;
    background: rgba(0,0,0,0.1);
    border-right: 1px solid var(--border-primary);
    padding: 20px 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    overflow-y: auto;
    flex-shrink: 0;
}
.settings-tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 10px 15px;
    text-align: left;
    cursor: pointer;
    border-radius: var(--radius-small);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    outline: none !important; 
    transition: background-color 0.2s, color 0.2s;
    white-space: nowrap;
}
.settings-tab-btn:hover { background: var(--tertiary-bg); color: var(--text-primary); }
.settings-tab-btn.active { background: var(--accent-primary); color: white; }
.settings-tab-btn i { width: 18px; text-align: center; }

.settings-content {
    flex-grow: 1;
    padding: 30px;
    overflow-y: auto;
    text-align: left;
    position: relative;
}
.settings-tab-pane { display: none; }
.settings-tab-pane.active { display: block; }

.settings-section { margin-bottom: 25px; }
.settings-section h4 { margin-bottom: 10px; color: var(--text-primary); font-size: 1.1rem; font-weight: 600; border-bottom: 1px solid var(--border-primary); padding-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }

.theme-toggle-wrapper { display: flex; align-items: center; }
.theme-switch { position: relative; display: inline-block; width: 50px; height: 26px; }
.theme-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--tertiary-bg); transition: .4s; border-radius: 34px; border: 1px solid var(--border-primary); }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-family: "Font Awesome 5 Free"; font-weight: 900; font-size: 10px; color: #f39c12; }
.light-theme .slider:before { content: "\f185"; transform: translateX(24px); background-color: white; color: #f39c12; }
.dark-theme .slider:before { content: "\f186"; transform: translateX(0); background-color: #343541; color: #f1c40f; }

.settings-input { width: 100%; background-color: rgba(0, 0, 0, 0.5); border: 1px solid var(--border-primary); border-radius: var(--radius-medium); padding: 10px; color: var(--text-primary); margin-bottom: 10px; font-family: inherit; }
.light-theme .settings-input { background-color: rgba(255, 255, 255, 0.6); }
.settings-input:focus { outline: none; border-color: var(--accent-primary); }

.user-info-box { background: var(--tertiary-bg); padding: 15px; border-radius: var(--radius-medium); margin-bottom: 15px; }
.user-info-item { margin-bottom: 8px; font-size: 0.9rem; color: var(--text-secondary); }
.user-info-item strong { color: var(--text-primary); margin-right: 5px; }

.danger-btn { background-color: rgba(239, 68, 68, 0.1); color: var(--error-color); border: 1px solid var(--error-color); padding: 8px 16px; border-radius: var(--radius-small); cursor: pointer; transition: background 0.2s; width: 100%; margin-bottom: 10px; }
.danger-btn:hover { background-color: var(--error-color); color: white; }

.action-btn { background-color: var(--tertiary-bg); color: var(--text-primary); border: 1px solid var(--border-primary); padding: 8px 16px; border-radius: var(--radius-small); cursor: pointer; transition: background 0.2s; width: 100%; margin-bottom: 10px; }
.action-btn:hover { background-color: var(--border-secondary); }

.action-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.close-modal-btn { 
    position: absolute; 
    top: 15px; 
    right: 15px; 
    background: var(--tertiary-bg);
    border: 1px solid var(--border-primary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary); 
    font-size: 1.1rem; 
    cursor: pointer; 
    z-index: 100;
    transition: background-color 0.2s, color 0.2s;
}
.close-modal-btn:hover { color: var(--text-primary); background-color: var(--error-color); border-color: transparent; }

/* Drag and Drop Overlay */
.drag-drop-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.8); z-index: 2000; display: flex; flex-direction: column; align-items: center; justify-content: center; opacity: 0; visibility: hidden; transition: opacity 0.2s ease, visibility 0.2s ease; pointer-events: none; }
.drag-drop-overlay.active { opacity: 1; visibility: visible; pointer-events: all; }
.drag-drop-content { border: 3px dashed var(--accent-primary); border-radius: var(--radius-large); padding: 40px; text-align: center; background-color: var(--secondary-bg); }
.drag-drop-content i { font-size: 4rem; color: var(--accent-primary); margin-bottom: 20px; }
.drag-drop-content h3 { font-size: 1.5rem; color: var(--text-primary); margin-bottom: 10px; }
.drag-drop-content p { color: var(--text-secondary); margin: 0; }

.loading-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: var(--primary-bg); z-index: 9999; display: flex; flex-direction: column; justify-content: center; align-items: center; transition: opacity 0.5s ease, visibility 0.5s ease; }
.loading-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-logo { width: 40px; height: 40px; border: 3px solid var(--accent-primary); border-top-color: transparent; border-radius: 50%; animation: spin 1s linear infinite; }

.premium-login-modal {
    background: var(--secondary-bg); /* Solid */
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    padding: 40px;
    max-width: 480px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
    animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalSlideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.premium-login-modal::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; height: 4px;
    background: var(--gradient-accent);
}
.premium-login-content h2 { font-size: 2rem; margin-bottom: 10px; background: var(--gradient-accent); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-weight: 800; letter-spacing: -0.5px; }
.premium-login-content p { color: var(--text-secondary); font-size: 1.1rem; margin-bottom: 30px; line-height: 1.5; }
.login-features { display: flex; justify-content: space-around; margin-bottom: 35px; text-align: center; }
.feature-item { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-primary); font-size: 0.9rem; font-weight: 500; }
.feature-item i { font-size: 1.5rem; color: var(--accent-primary); background: rgba(16, 163, 127, 0.1); width: 50px; height: 50px; display: flex; align-items: center; justify-content: center; border-radius: 50%; margin-bottom: 5px; }
.premium-login-btn {
    background: var(--gradient-accent);
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    padding: 16px 32px;
    border-radius: var(--radius-full);
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(16, 163, 127, 0.4);
    width: 100%;
    position: relative;
    overflow: hidden;
}
.premium-login-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(16, 163, 127, 0.5); }
.premium-login-btn::after {
    content: ""; position: absolute; top: 0; left: -100%; width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    animation: shine 3s infinite;
}
@keyframes shine { 0% { left: -100%; } 20% { left: 100%; } 100% { left: 100%; } }

/* Message Actions Visibility Logic */
.message-actions { 
    display: flex; 
    gap: 6px; 
    margin-top: 8px; 
    opacity: 0; 
    transition: opacity 0.2s; 
}
.message:hover .message-actions { opacity: 1; }
.message.bot .message-actions { justify-content: flex-start; }
.message.user .message-actions { justify-content: flex-end; }

.message-btn { background: transparent; border: none; color: var(--text-tertiary); cursor: pointer; padding: 0; border-radius: 4px; transition: color 0.2s, background 0.2s; display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; }
.message-btn svg { width: 14px; height: 14px; fill: currentColor; }
.message-btn:hover { color: var(--text-primary); background: var(--tertiary-bg); }

.dark-theme .message-btn { border: 1px solid transparent; }
.dark-theme .message-btn:hover { border-color: rgba(255,255,255,0.2); }

/* UPDATED INLINE EDITOR STYLES */
.inline-editor {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 5px;
}
.inline-editor textarea {
    width: 100%;
    min-width: 300px; /* Ensure wide enough */
    background-color: var(--primary-bg); /* Contrast against bubble */
    border: 1px solid var(--border-primary);
    color: var(--text-primary);
    padding: 12px;
    border-radius: var(--radius-medium);
    resize: vertical;
    min-height: 100px;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.6;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.inline-editor textarea:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.2);
}
.editor-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}
.editor-btn {
    padding: 8px 16px;
    border-radius: var(--radius-medium);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.editor-save {
    background-color: var(--accent-primary);
    color: white;
    border: none;
}
.editor-save:hover {
    background-color: var(--accent-primary-hover);
}
.editor-cancel {
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-primary);
}
.editor-cancel:hover {
    background-color: var(--tertiary-bg);
    color: var(--text-primary);
}

.header-btn-group {
    display: flex;
    align-items: center;
    gap: 8px;
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.header-icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
}
.header-icon-btn:hover { color: var(--text-primary); background: var(--tertiary-bg); }
.header-icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#tempChatBtn { color: var(--text-secondary); }
body.temp-mode #tempChatBtn { color: var(--accent-primary); }
body.temp-mode .custom-model-dropdown { display: none !important; }
body.temp-mode label[for="imageFileInput"] { display: none !important; }
body.temp-mode #searchToggleBtn { display: none !important; }

.greeting-text {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#mainChatSection.start-screen .greeting-text {
    opacity: 1;
}

/* Position Input wrapper perfectly in the middle before chat starts */
#mainChatSection.start-screen .input-container-wrapper {
    transform: translateY(-40vh);
}

#mainChatSection.start-screen #chatbox {
    opacity: 0;
    pointer-events: none;
}

.file-viewer-modal {
    width: 80%;
    max-width: 800px;
    height: 80vh; 
    display: flex;
    flex-direction: column;
    text-align: left;
    padding: 0; 
    border-radius: var(--radius-large);
    overflow: hidden; 
}

.file-viewer-header {
    padding: 15px;
    background: var(--code-header-bg);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.file-viewer-content {
    flex-grow: 1;
    overflow: auto;
    background: var(--code-bg);
    padding: 20px; 
    border-radius: 0;
    font-family: var(--font-monospace);
    font-size: 0.9rem;
    white-space: pre-wrap;
    color: var(--code-text);
    margin: 0;
}

.ai-status-text {
    color: var(--text-tertiary);
    font-size: 0.9rem;
    font-weight: 500;
    font-style: italic;
    background: linear-gradient(90deg, #555 0%, #fff 50%, #555 100%);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer 2s linear infinite;
    display: inline-block;
    margin-left: 0;
}

@keyframes shimmer {
    to {
        background-position: 200% center;
    }
}

.chat-loader {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
}
.chat-loader::after {
    content: '';
    width: 40px;
    height: 40px;
    border: 3px solid var(--accent-primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* MOBILE MEDIA QUERIES */
@media (max-width: 1024px) { 
    :root { --sidebar-width: 240px; --chat-max-width: 90%; } 
    .page-container { margin-left: var(--sidebar-width); width: calc(100% - var(--sidebar-width)); } 
}
@media (max-width: 768px) { 
    :root { --font-size-base: 15px; } 
    .sidebar { transform: translateX(-100%); width: 280px; box-shadow: 5px 0 20px rgba(0,0,0,0.4); z-index: 2000; height: 100dvh; } 
    .sidebar.closed { transform: translateX(-100%); } 
    .sidebar.open { transform: translateX(0); } 
    .sidebar-toggle { display: flex; } 
    header:not(.landing-header) { padding: calc(var(--spacing-unit) * 1) calc(var(--spacing-unit) * 2); left: 0; width: 100%; min-height: 52px; } 
    .controls-container { gap: calc(var(--spacing-unit) * 1.5); } 
    .custom-model-dropdown { min-width: 140px; } 
    #chatbox { padding: var(--spacing-unit) calc(var(--spacing-unit) * 2); padding-bottom: var(--spacing-unit); } 
    .message { max-width: 95%; } 
    .message-actions { opacity: 1; } /* Always visible on mobile */
    .input-container-wrapper { 
        max-width: 100%; 
        padding: var(--spacing-unit); 
        padding-bottom: 10px; 
        background-color: var(--primary-bg); 
        border-top: none; 
        bottom: 0;
        position: sticky;
        z-index: 10;
    } 
    .input-area { box-shadow: none; } 
    .katex { font-size: 1.25em; } 
    .page-container { margin-left: 0; width: 100%; height: 100dvh; }
    .page-container.full-width { margin-left: 0; width: 100%; }
    
    .greeting-text { font-size: 1.5rem; margin-bottom: 15px; }
    
    #mainChatSection.start-screen .input-container-wrapper {
        transform: translateY(-35vh); 
    }

    /* Settings Mobile Overrides */
    .settings-modal { 
        width: 95%; 
        max-width: none;
        height: 85vh; 
        max-height: 85vh; /* Larger max height on mobile */
    }
    .settings-container { 
        flex-direction: column; 
    }
    .settings-sidebar { 
        width: 100%; 
        border-right: none; 
        border-bottom: 1px solid var(--border-primary); 
        padding: 10px; 
        flex-direction: row; 
        overflow-x: auto;
        /* Hide scrollbar visually but allow scroll */
        scrollbar-width: none;
    }
    .settings-sidebar::-webkit-scrollbar { display: none; }
    .settings-tab-btn {
        flex: 0 0 auto; /* Prevent shrinking */
        padding: 8px 12px;
    }
    .settings-content { 
        padding: 20px 15px; 
        padding-top: 25px; 
    }
    .close-modal-btn {
        top: 10px; right: 10px;
    }
}