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

:root {
    /* Enhanced modern light theme with better color harmony */
    --bg-gradient-from: #ffffff;
    --bg-gradient-to: #f8fafc;
    --bg-surface: #ffffff;
    --bg-sidebar: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --muted: #f8fafc;
    --primary: #6366f1;          /* Beautiful indigo */
    --primary-light: #8b5cf6;    /* Purple accent */
    --primary-dark: #4f46e5;     /* Darker indigo */
    --primary-shadow: rgba(99, 102, 241, 0.15);
    --accent: #06b6d4;           /* Cyan accent */
    --accent-light: #22d3ee;
    --danger: #f43f5e;           /* Rose red */
    --success: #059669;          /* Emerald green */
    --warning: #f59e0b;          /* Amber */
    --shadow: rgba(0, 0, 0, 0.05);
    --shadow-lg: rgba(0, 0, 0, 0.10);
}

.dark {
    --bg-gradient-from: #0f172a;
    --bg-gradient-to: #1e293b;
    --bg-surface: #0f172a;
    --bg-sidebar: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --border-light: #475569;
    --muted: #1e293b;
    --primary: #8b5cf6;          /* Purple primary in dark */
    --primary-light: #a78bfa;    /* Lighter purple */
    --primary-dark: #7c3aed;     /* Darker purple */
    --primary-shadow: rgba(139, 92, 246, 0.25);
    --accent: #06b6d4;           /* Cyan accent */
    --accent-light: #22d3ee;
    --danger: #f43f5e;           /* Rose red */
    --success: #10b981;          /* Emerald green */
    --warning: #fbbf24;          /* Brighter amber for dark mode */
    --shadow: rgba(0, 0, 0, 0.25);
    --shadow-lg: rgba(0, 0, 0, 0.40);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-from) 0%, var(--bg-gradient-to) 100%);
    min-height: 100vh;
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    font-size: 16px;
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

/* Sectioned layout: full-page sections instead of boxed containers */
.app-shell { 
    display: grid; 
    grid-template-columns: 280px 1fr; 
    height: 100vh; 
    background: linear-gradient(135deg, var(--bg-gradient-from) 0%, var(--bg-gradient-to) 100%);
}

.sidebar { 
    display: flex; 
    flex-direction: column; 
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    box-shadow: 2px 0 12px var(--shadow);
}

.main { 
    display: grid; 
    grid-template-rows: auto 1fr auto; 
    background: var(--bg-surface);
    overflow: hidden;
    position: relative;
}

.topbar { 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    padding: 16px 24px; 
    border-bottom: 1px solid var(--border); 
    background: var(--bg-surface);
    box-shadow: 0 1px 3px var(--shadow);
}

.brand { 
    display: flex; 
    align-items: center; 
    gap: 8px; 
    font-weight: 500; 
    font-size: 17px;
    color: var(--text-primary);
}

.brand .title { 
    font-size: 17px; 
    color: var(--text-primary);
    font-weight: 500;
}

.status { 
    display: flex; 
    gap: 12px; 
    align-items: center; 
    font-size: 14px; 
    color: var(--text-secondary); 
}

.thread { 
    padding: 20px 24px; 
    overflow-y: auto; 
    background: var(--bg-surface);
    position: relative;
    min-height: 0;
}

.composer { 
    border-top: 1px solid var(--border); 
    background: var(--bg-surface);
    padding: 18px 24px; 
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 -2px 12px var(--shadow);
}
/* Redesigned composer for better layout */
.voice-bar { 
    display: flex; 
    align-items: center; 
    gap: 16px; 
}

.voice-controls-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.voice-controls-right {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}


/* Input row: now only one child (input-wrapper) */
.input-row {
    display: flex;
    align-items: flex-end;
    gap: 0;
}

/* Input with buttons inside */
.input-with-buttons {
    position: relative;
    display: flex;
    flex: 1;
    align-items: stretch;
}

.input-with-buttons textarea {
    width: 100%;
    padding-right: 78px; /* space for both buttons (32px + 32px + gaps) */
}

.input-buttons {
    position: absolute;
    top: 50%;
    right: 8px;
    display: flex;
    gap: 6px;
    transform: translateY(-50%);
    z-index: 2;
}

.inside-input.mic-button, .inside-input.send-button {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    border-radius: 6px;
    font-size: 14px;
    margin: 0;
    box-shadow: 0 1px 4px var(--primary-shadow);
}

.inside-input.mic-button {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
}

.inside-input.send-button {
    background: var(--bg-surface);
    color: var(--text-secondary); /* Use secondary text color for better contrast */
    border: 1px solid var(--border);
}

.inside-input.send-button i {
    color: #475569 !important; /* Dark gray icon in light mode - easier on the eyes */
}

.inside-input.mic-button:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--primary-shadow);
}

.inside-input.send-button:hover {
    background: var(--muted);
    color: var(--text-primary);
    border-color: var(--primary-light);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--primary-shadow);
}

.inside-input.send-button:hover i {
    color: var(--text-primary) !important; /* Darker on hover for better visibility */
}

/* Improve contrast for dark theme */
.dark .inside-input.send-button {
    background: var(--muted);
    color: #fff;
    border-color: var(--border);
}

.dark .inside-input.send-button i {
    color: #fff !important; /* White icon in dark mode */
}

.dark .inside-input.send-button:hover {
    background: var(--bg-sidebar);
    color: #fff;
    border-color: var(--primary-light);
}

.dark .inside-input.send-button:hover i {
    color: #fff !important; /* Keep white icon on hover in dark mode */
}

/* Remove old mic/send button from outside input */
#micButton:not(.inside-input),
#sendButton:not(.inside-input) {
    display: none !important;
}

.composer-controls { 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    gap: 16px; 
    flex-wrap: wrap; 
}

.toggle { 
    display: inline-flex; 
    align-items: center; 
    gap: 6px; 
    color: var(--text-secondary); 
    font-size: 14px;
    font-weight: 400;
}

/* Sidebar internals with professional styling */
.sidebar-header { 
    padding: 20px 18px; 
    border-bottom: 1px solid var(--border); 
    background: var(--bg-sidebar);
}

.sidebar-header .brand {
    display: flex; 
    align-items: center; 
    gap: 8px; 
    font-weight: 500; 
    font-size: 15px;
    color: var(--text-primary);
}

.sidebar-footer { 
    margin-top: auto; 
    padding: 18px; 
    border-top: 1px solid var(--border); 
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    gap: 12px; 
}

.chatlist { 
    overflow-y: auto; 
    overflow-x: hidden; 
    padding: 12px 8px; 
    display: flex;
    flex-direction: column;
    gap: 6px; 
}

.chatlist-item { 
    display: grid; 
    grid-template-columns: 1fr auto; 
    align-items: center; 
    gap: 12px; 
    padding: 10px 12px; 
    border-radius: 8px; 
    background: transparent;
    border: none;
    cursor: pointer; 
    transition: background-color 0.2s ease; 
    min-width: 0; 
}

.chatlist-item:hover { 
    background: var(--muted); 
}

.chatlist-item.active { 
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    box-shadow: 0 2px 12px var(--primary-shadow);
}

.chatlist-item.active .title { color: white; }
.chatlist-item.active .meta { color: rgba(255,255,255,0.8); }

/* Remove the older complex hover state */
.chatlist-item.active { border-color: var(--primary); }

/* Active chat hover - keep the active styling */
.chatlist-item.active:hover { 
    background: var(--primary); 
    color: white;
}
.chatlist-item.active:hover .title { color: white; }
.chatlist-item.active:hover .meta { color: rgba(255,255,255,0.8); }
.chatlist-item.active:hover .icon-button { 
    color: white; 
    background: rgba(255,255,255,0.15); 
}
.chatlist-item.active:hover .icon-button:hover { 
    background: rgba(255,255,255,0.25); 
}

/* Active chat icon buttons */
.chatlist-item.active .icon-button { 
    color: white; 
    background: rgba(255,255,255,0.15); 
}
.chatlist-item.active .icon-button:hover { 
    background: rgba(255,255,255,0.25); 
}
.chatlist-item .title { font-weight: 500; font-size: 15px; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chatlist-item .meta { color: var(--text-secondary); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chatlist-item .info { min-width: 0; }
.chatlist-item .actions { display: flex; gap: 6px; }
.chatlist-item .icon-button { width: 32px; height: 32px; }
.primary-button.full { 
    width: 100%; 
    display: inline-flex; 
    align-items: center; 
    justify-content: center; 
    gap: 8px; 
    padding: 10px 16px;
    font-weight: 500;
    font-size: 15px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px var(--primary-shadow);
}

.primary-button.full:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--primary-shadow);
}

.ghost { 
    border: 1px solid var(--border); 
    background: transparent; 
    color: var(--text-secondary); 
    padding: 8px 12px; 
    border-radius: 6px; 
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.ghost:hover { 
    color: var(--text-primary);
    background: var(--muted);
}

.ghost.danger { 
    color: var(--danger); 
    border-color: rgba(220, 38, 38, 0.3);
}

.ghost.danger:hover { 
    background: rgba(220, 38, 38, 0.05);
    border-color: var(--danger);
}

.sidebar-controls { 
    display: flex; 
    align-items: center; 
    gap: 10px; 
}

.sidebar-controls .spacer { 
    flex: 1; 
}

.icon-button { 
    border: none; 
    background: transparent; 
    color: var(--text-secondary); 
    width: 32px; 
    height: 32px; 
    border-radius: 6px; 
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-button:hover { 
    background: var(--muted); 
    color: var(--text-primary);
}

.dark .icon-button { 
    background: transparent; 
    color: var(--text-secondary);
}

.dark .icon-button:hover { 
    background: var(--muted); 
    color: var(--text-primary);
}

/* legacy .header/.chat-container removed in favor of topbar/main layout */


.scroll-bottom-chat {
    position: absolute;
    bottom: 200px;
    right: 40px;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 100;
    pointer-events: auto;
    font-size: 14px;
}

.scroll-bottom-chat.show {
    display: flex;
}

.scroll-bottom-chat:hover {
    background: var(--muted);
    color: var(--text-primary);
}

/* Dark mode scroll button */
.dark .scroll-bottom-chat {
    background: var(--muted);
    border-color: var(--border);
    color: var(--text-secondary);
}

.dark .scroll-bottom-chat:hover {
    background: var(--bg-sidebar);
    border-color: var(--text-secondary);
}

/* Mobile positioning for scroll button */
@media (max-width: 820px) {
    .scroll-bottom-chat {
        bottom: 120px;
        right: 20px;
        width: 34px;
        height: 34px;
        font-size: 0.85rem;
    }
}

@media (max-width: 640px) {
    .scroll-bottom-chat {
        bottom: 100px;
        right: 16px;
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .scroll-bottom-chat {
        bottom: 90px;
        right: 12px;
        width: 30px;
        height: 30px;
    }
}

.stop-speaking-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px var(--shadow);
}

.stop-speaking-btn {
    background: var(--bg-surface);
    color: #f87171;
}

.stop-speaking-btn:hover {
    background: rgba(248, 113, 113, 0.1);
    color: #ef4444;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(248, 113, 113, 0.2);
}


.chat-messages, .thread { /* alias to maintain legacy selector */ min-height: 0; }
.thread { min-height: 0; }

.message {
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease-in;
}

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

.message-content i {
    font-size: 1.2rem;
    margin-top: 6px;
}

.user-message .message-content {
    flex-direction: row-reverse;
    justify-content: flex-start;
    padding-right: 4px;
}

.user-message .message-content i {
    color: var(--primary);
}

.assistant-message .message-content i {
    color: var(--primary-2);
}

.text {
    background: var(--muted);
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 85%;
    word-wrap: break-word;
    line-height: 1.6;
    position: relative;
    font-size: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.user-message .text {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Dark mode user message - keep original blue gradient */
.dark .user-message .text {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    border: none;
    box-shadow: 0 2px 8px var(--primary-shadow);
}

/* Copy button container to avoid overlaying text */
.assistant-message .text { padding-right: 48px; }

/* New copy button style for assistant response */


.assistant-message .copy-btn.bottom-right {
    position: absolute;
    top: auto;
    bottom: 10px;
    right: 10px;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: #f4f4f5;
    color: #6b7280;
    border: 1px solid #e5e7eb;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: background 0.15s, color 0.15s, border 0.15s, opacity 0.18s;
    z-index: 2;
    padding: 0;
}
.assistant-message .text:hover .copy-btn.bottom-right,
.assistant-message .copy-btn.bottom-right:focus {
    opacity: 1;
    pointer-events: auto;
}
.assistant-message .copy-btn.bottom-right:hover {
    background: #e5e7eb;
    color: #333;
    border: 1px solid #cbd5e1;
}
.dark .assistant-message .copy-btn.bottom-right {
    background: #23272f;
    color: #cbd5e1;
    border: 1px solid #334155;
}
.dark .assistant-message .copy-btn.bottom-right:hover {
    background: #2d323c;
    color: #fff;
    border: 1px solid #475569;
}

/* Adjust icon position inside the copy button */
.assistant-message .copy-btn.bottom-right i {
    position: relative;
    top: -2px; /* Move the icon slightly upward */
}

/* Reduce the size of the copy button icon */
.assistant-message .copy-btn.bottom-right i {
    font-size: 0.85rem; /* Make the icon smaller */
}

/* Remove old copy-actions style */
.copy-actions { display: none !important; }

/* Markdown formatting styles */
.text h1, .text h2, .text h3, .text h4 {
    margin: 16px 0 8px 0;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

.text h1:first-child, .text h2:first-child, 
.text h3:first-child, .text h4:first-child {
    margin-top: 0;
}

.text h1 {
    font-size: 1.5em;
    border-bottom: 2px solid var(--border);
    padding-bottom: 8px;
}

.text h2 {
    font-size: 1.3em;
}

.text h3 {
    font-size: 1.2em;
}

.text h4 {
    font-size: 1.1em;
}

.text hr {
    margin: 20px 0;
    border: none;
    height: 1px;
    background: var(--border);
    opacity: 0.6;
}

.text p {
    margin: 0 0 12px 0;
    line-height: 1.6;
}

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

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

.text em {
    font-style: italic;
    color: var(--text-secondary);
}


/* Inline code only (not code blocks) */
.text code:not(pre code) {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 15px;
}

.dark .text code:not(pre code) {
    background: rgba(255, 255, 255, 0.08);
}

/* Code block styling */
.text pre {
    background: #f5f7fa;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    padding: 18px 18px 18px 18px;
    margin: 18px 0;
    overflow-x: auto;
    font-size: 15px;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    max-width: 100%;
}
.text pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 15px;
    color: #222;
    display: block;
    white-space: pre;
}
.dark .text pre {
    background: #181f2a;
    border: 1.5px solid #334155;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}
.dark .text pre code {
    color: #e2e8f0;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 15px;
}

.text ul {
    margin: 8px 0;
    padding-left: 20px;
    list-style-type: disc;
}

.text ol {
    margin: 8px 0;
    padding-left: 20px;
    list-style-type: decimal;
}

/* Ensure continuous numbering for consecutive ordered lists */
.text ol + ol {
    counter-reset: none;
}

.text ul ul {
    margin: 4px 0;
    padding-left: 20px;
    list-style-type: circle;
}

.text ol ol {
    margin: 4px 0;
    padding-left: 20px;
    list-style-type: lower-alpha;
}

.text ul ul ul {
    list-style-type: square;
}

.text ol ol ol {
    list-style-type: lower-roman;
}

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

.text br {
    line-height: 1.2;
}

.text table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 15px;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.text table th,
.text table td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

.text table th {
    background: var(--muted);
    font-weight: 600;
    color: var(--text-primary);
}

.text table tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}

.dark .text table tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.text table tr:hover {
    background: rgba(0, 0, 0, 0.04);
}

.dark .text table tr:hover {
    background: rgba(255, 255, 255, 0.04);
}

.message-time {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
    text-align: right;
    opacity: 0.8;
}

.user-message .message-time {
    text-align: left;
}

.brand p { color: var(--text-secondary); opacity: 0.9; }
.icon-button { border: 0; background: rgba(0,0,0,0.06); color: var(--text-primary); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; }
.icon-button:hover { background: rgba(0,0,0,0.12); }
.dark .icon-button { background: rgba(255,255,255,0.15); color: #fff; }
.dark .icon-button:hover { background: rgba(255,255,255,0.25); }

/* Input Container */
.input-container { /* replaced by .composer */ display: contents; }

.voice-controls, .voice-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 6px;
}

.voice-controls-right {
    display: flex;
    align-items: center;
    gap: 10px;
}



/* Professional button and input styling */
.mic-button {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px var(--primary-shadow);
}

.mic-button:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--primary-shadow);
}

.mic-button.listening {
    background: linear-gradient(135deg, var(--danger) 0%, #f87171 100%);
    animation: pulse 1.5s ease-in-out infinite;
    box-shadow: 0 2px 8px rgba(244, 63, 94, 0.3);
}

.mic-button.processing {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
    animation: pulse 2s ease-in-out infinite;
    box-shadow: 0 2px 8px rgba(6, 182, 212, 0.3);
}

.voice-status {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 400;
    min-width: 100px;
}

.stop-speaking-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px var(--shadow);
    border: 1px solid var(--border);
}

.stop-speaking-btn:hover {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
    border-color: var(--danger);
    transform: translateY(-1px);
}

#messageInput {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 16px;
    resize: vertical;
    font-family: inherit;
    transition: border-color 0.2s ease;
    background: var(--bg-surface);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 40px;
    max-height: 120px;
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-shadow);
}

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

.dark #messageInput {
    background: var(--muted);
    border-color: var(--border);
    color: var(--text-primary);
}

.dark #messageInput:focus {
    border-color: var(--primary);
    background: var(--bg-surface);
}

.send-button {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    align-self: flex-end;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px var(--primary-shadow);
}

.send-button i {
    color: #fff !important; /* White icon for gradient button */
    font-size: 16px !important;
    opacity: 1 !important;
}

.send-button:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--primary-shadow);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.text-input-container, .input-row {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

#messageInput {
    flex: 1;
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 15px;
    font-size: 1rem;
    resize: vertical;
    font-family: inherit;
    transition: border-color 0.3s ease;
    background: var(--bg-surface);
    color: var(--text-primary);
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary);
}

.dark #messageInput {
    background: rgba(15, 23, 42, 0.8);
    border-color: rgba(71, 85, 105, 0.3);
    color: #e2e8f0;
}

.dark #messageInput:focus {
    border-color: var(--primary);
    background: rgba(15, 23, 42, 0.9);
}

.controls, .composer-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.voice-settings {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.voice-settings label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.voice-settings input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

.clear-button {
    padding: 8px 16px;
    border: 2px solid var(--danger);
    border-radius: 8px;
    background: transparent;
    color: var(--danger);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.clear-button:hover {
    background: var(--danger);
    color: #fff;
}

.connection-status.connected {
    color: var(--accent);
}

.connection-status.disconnected {
    color: var(--danger);
}

.speech-support.supported {
    color: var(--accent);
}

.speech-support.not-supported {
    color: var(--danger);
}

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

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s ease-in-out infinite;
}

.loading-text {
    color: white;
    margin-top: 16px;
    font-size: 14px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0% { 
        opacity: 1; 
    }
    50% { 
        opacity: 0.7; 
    }
    100% { 
        opacity: 1; 
    }
}

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

/* Hide mobile elements on desktop */
.mobile-menu-btn {
    display: none;
}

.mobile-overlay {
    display: none;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .app-shell { grid-template-columns: 280px 1fr; }
}

@media (max-width: 1024px) {
    .app-shell { grid-template-columns: 260px 1fr; }
}

/* Mobile-specific improvements */
@media (max-width: 820px) {
    html, body {
        overflow-x: hidden;
        width: 100%;
        max-width: 100vw;
        -webkit-overflow-scrolling: touch;
    }
    
    .app-shell { 
        grid-template-columns: 1fr; 
        height: 100vh;
        height: 100dvh; /* For newer browsers that support dynamic viewport */
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    .main {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        min-height: 0;
    }
    
    .thread {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 20px 18px;
        padding-bottom: 30px;
        -webkit-overflow-scrolling: touch;
    }
    
    .composer {
        flex-shrink: 0;
        background: var(--bg-surface);
        border-top: 1px solid var(--border);
        box-shadow: 0 -2px 8px var(--shadow);
    }
    
    .sidebar { 
        position: fixed; 
        z-index: 50; 
        inset: 0 auto 0 0; 
        width: 85vw; 
        max-width: 300px; 
        transform: translateX(-100%); 
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); 
        border-right: 1px solid var(--border); 
        border-radius: 0;
        backdrop-filter: blur(8px);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }
    .sidebar.show { transform: translateX(0); }
    
    /* Mobile overlay */
    .mobile-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 40;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    .mobile-overlay.show {
        opacity: 1;
        pointer-events: all;
    }
    
    /* Add hamburger menu button */
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border: none;
        background: none;
        color: var(--text-primary);
        cursor: pointer;
        border-radius: 8px;
        transition: background-color 0.2s ease;
    }
    
    .mobile-menu-btn:hover {
        background: var(--muted);
    }
    
    .topbar {
        padding: 12px 16px;
        display: flex;
        align-items: center;
        gap: 12px;
    }
    
    .composer {
        padding: 16px;
        gap: 12px;
    }
    
    /* Hide extra composer controls on mobile to remove unwanted section between thread and composer */
    .composer-controls {
        display: none !important;
    }
    
    /* Simplified voice bar for mobile */
    .voice-bar {
        flex-wrap: wrap;
        gap: 10px;
        justify-content: center;
    }
    
    .input-row {
        flex-direction: row;
        gap: 12px;
        align-items: flex-end;
    }
    
    .input-wrapper {
        flex: 1;
    }
    
    .input-with-buttons {
        width: 100%;
    }
    
    .send-button {
        align-self: flex-end;
        height: 40px;
        min-width: 40px;
        font-size: 1rem;
    }
    
    .message {
        margin-bottom: 28px;
    }
    
    .message-content {
        gap: 10px;
    }
    
    .message .text {
        max-width: 85%;
        font-size: 0.95rem;
        line-height: 1.6;
        padding: 16px 18px;
        margin-right: 12px;
        border-radius: 16px;
    }
    
    /* Ensure user messages also have proper spacing */
    .user-message .message-content {
        padding-right: 4px;
    }
    
    .user-message .text {
        margin-right: 0;
        margin-left: 12px;
    }
    
    /* Hide suggestion chips on mobile */
    .suggestions {
        display: none !important;
    }
    
    /* Fix table overflow on mobile */
    .text table {
        font-size: 0.85em;
    }
    
    .text table th,
    .text table td {
        padding: 6px 8px;
        font-size: 0.85rem;
    }
}

@media (max-width: 640px) {
    .thread {
        padding: 18px 20px;
        padding-bottom: 25px;
    }
    
    .topbar {
        padding: 12px 18px;
    }
    
    .composer {
        padding: 16px 20px;
        gap: 14px;
        background: var(--bg-surface);
        border-top: 1px solid var(--border);
        box-shadow: 0 -2px 8px var(--shadow);
    }
    
    .message-content {
        gap: 10px;
    }
    
    .voice-controls-left,
    .voice-controls-right {
        gap: 8px;
        flex-wrap: wrap;
    }
    
    .mic-button {
        width: 44px;
        height: 44px;
        font-size: 1.1rem;
    }
    
    .send-button {
        height: 44px;
        min-width: 44px;
    }
    
    #messageInput {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 46px;
        line-height: 1.5;
        border-radius: 12px;
        padding: 14px 16px;
    }
    
    .message .text {
        max-width: 88%;
        font-size: 0.92rem;
        padding: 14px 16px;
        margin-right: 12px;
        border-radius: 14px;
        line-height: 1.6;
    }
    
    /* Ensure user messages also have proper spacing */
    .user-message .message-content {
        padding-right: 6px;
    }
    
    .user-message .text {
        margin-right: 0;
        margin-left: 12px;
    }
    
    .brand .title {
        font-size: 1.1rem;
    }
    
    .chatlist-item {
        padding: 10px 12px;
        font-size: 0.9rem;
    }
    
    .connection-status {
        font-size: 0.8rem;
    }
    
    /* Ensure suggestions are hidden */
    .suggestions {
        display: none !important;
    }
    
    /* Better table handling on small screens */
    .text table {
        font-size: 0.8em;
        max-width: 100%;
    }
    
    .text table th,
    .text table td {
        padding: 4px 6px;
        font-size: 0.8rem;
        min-width: 60px;
    }
}

@media (max-width: 480px) {
    .html, body {
        overflow-x: hidden !important;
        width: 100vw;
        max-width: 100vw;
    }
    
    /* Remove fixed positioning for composer to prevent overlay */
    .composer {
        position: relative;
        bottom: auto;
        left: auto;
        width: 100%;
        z-index: auto;
        padding: 10px 12px;
        background: var(--bg-surface);
        border-top: 1px solid var(--border);
        box-shadow: 0 -2px 8px var(--shadow);
    }
    
    .sidebar {
        z-index: 1100; /* Ensure sidebar appears above other content */
    }
    
    .thread {
        padding: 8px 12px;
        padding-bottom: 20px; /* Add bottom padding to prevent content cutoff */
        overflow-y: auto;
    }
    
    .topbar {
        padding: 8px 12px;
    }
    
    .thread {
        padding: 16px 20px;
        padding-bottom: 25px;
    }
    
    .topbar {
        padding: 10px 16px;
    }
    
    .message-content {
        gap: 8px;
    }
    
    .voice-bar {
        gap: 10px;
        justify-content: space-between;
        margin-bottom: 10px;
    }
    
    .input-row {
        gap: 10px;
        align-items: flex-end;
    }
    
    .mic-button,
    .send-button {
        width: 42px;
        height: 42px;
        font-size: 1rem;
        flex-shrink: 0;
    }
    
    .inside-input.mic-button {
        width: 30px;
        height: 30px;
        font-size: 0.85rem;
    }
    
    #messageInput {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 42px;
        line-height: 1.5;
        border-radius: 10px;
        padding: 12px 14px;
        padding-right: 78px; /* Space for both mic and send buttons */
    }
    
    .message .text {
        max-width: 85%;
        font-size: 0.9rem;
        padding: 12px 15px;
        margin-right: 14px;
        border-radius: 12px;
        line-height: 1.6;
    }
    
    /* Ensure user messages also have proper spacing */
    .user-message .message-content {
        padding-right: 6px;
    }
    
    .user-message .text {
        margin-right: 0;
        margin-left: 14px;
    }
    
    .brand {
        gap: 8px;
    }
    
    .brand .title {
        font-size: 1rem;
    }
    
    .sidebar {
        width: 90vw;
        max-width: 280px;
    }
    
    /* Hide suggestions on smallest screens */
    .suggestions {
        display: none !important;
    }
    
    /* Optimize tables for very small screens */
    .text table {
        font-size: 0.75em;
    }
    
    .text table th,
    .text table td {
        padding: 3px 5px;
        font-size: 0.75rem;
        min-width: 50px;
    }
}

/* Landscape orientation optimizations */
@media (max-height: 600px) and (orientation: landscape) {
    .composer {
        padding: 8px 16px;
        gap: 8px;
    }
    
    .thread {
        padding: 8px 16px;
    }
    
    .topbar {
        padding: 6px 16px;
    }
    
    .mic-button,
    .send-button {
        height: 36px;
        min-width: 36px;
    }
    
    #messageInput {
        min-height: 36px;
        padding: 8px 12px;
    }
}

/* Typing indicator */
.typing-indicator { 
    position: absolute;
    bottom: 20px;
    left: 24px;
    display: none; 
    padding: 8px 16px; 
    background: var(--bg-surface);
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow);
    z-index: 10;
}
.typing-indicator.show { display: block; }
.typing-indicator span { 
    display: inline-block; 
    width: 8px; 
    height: 8px; 
    margin: 0 2px; 
    background: var(--primary); 
    border-radius: 50%; 
    opacity: 0.6; 
    animation: bounce 1.2s infinite; 
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0.8); } 40% { transform: scale(1); } }

/* Mobile typing indicator positioning */
@media (max-width: 820px) {
    .typing-indicator {
        bottom: 16px;
        left: 16px;
        padding: 6px 12px;
    }
}

@media (max-width: 640px) {
    .typing-indicator {
        bottom: 16px;
        left: 16px;
        padding: 6px 12px;
    }
}

@media (max-width: 480px) {
    .typing-indicator {
        bottom: 16px;
        left: 12px;
        padding: 5px 10px;
    }
    
    .typing-indicator span {
        width: 6px;
        height: 6px;
    }
}

/* Suggestions */
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { border: 1px solid var(--border); background: var(--bg-surface); color: var(--text-secondary); padding: 6px 12px; border-radius: 16px; cursor: pointer; transition: all 0.2s ease; font-size: 12px; }
.chip:hover { border-color: var(--primary); color: var(--text-primary); }

/* Buttons now integrated into voice-controls bar */

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
    transition: background 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Dark mode scrollbar */
.dark ::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.3);
}

.dark ::-webkit-scrollbar-thumb {
    background: rgba(71, 85, 105, 0.4);
}

.dark ::-webkit-scrollbar-thumb:hover {
    background: rgba(71, 85, 105, 0.6);
}

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: none; align-items: center; justify-content: center; padding: 24px; z-index: 2000; }
.modal.show { display: flex; }
.modal-content { width: min(480px, 92vw); background: var(--bg-surface); color: var(--text-primary); border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 20px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; padding: 16px 20px; border-top: 1px solid var(--border); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; }
.primary-button, .secondary-button { padding: 8px 16px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-surface); color: var(--text-primary); cursor: pointer; font-size: 13px; }
.primary-button { background: var(--primary); color: white; border: none; }

/* Make Save button in settings modal black in light mode, especially for mobile */
@media (max-width: 600px) {
    .modal-footer .primary-button {
        color: var(--text-primary) !important;
        background: var(--muted) !important;
        border: 1px solid var(--border);
        box-shadow: none;
    }
}

/* Also ensure in all light mode (desktop/mobile) it's black on white */
.modal-footer .primary-button {
    color: var(--text-primary) !important;
    background: var(--muted) !important;
    border: 1px solid var(--border);
    box-shadow: none;
}

/* But keep white text in dark mode */
.dark .modal-footer .primary-button {
    color: #fff !important;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%) !important;
    border: none;
}