* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --sidebar-width: 300px;
    --sidebar-collapsed-width: 60px;
    --primary-color: #111827;
    --secondary-color: #6b7280;
    --accent-color: #3b82f6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --border-color: #e5e7eb;
    --background-color: #ffffff;
    --surface-color: #f9fafb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --hover-color: #f3f4f6;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background: var(--background-color);
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    color: var(--text-primary);
    overflow: hidden;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--background-color);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.loading-content .logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
    margin-bottom: 16px;
    animation: bounce 2s infinite;
    display: block;
}

.loading-text {
    font-size: 16px;
    color: var(--text-secondary);
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-10px); }
    60% { transform: translateY(-5px); }
}

/* Main App Layout */
.app {
    display: flex;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    overflow: hidden;
}

.app.hidden {
    display: none;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--background-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    z-index: 100;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s ease;
}

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

.hamburger {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    position: relative;
    transition: background 0.3s ease;
}

.hamburger::before,
.hamburger::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    transition: transform 0.3s ease;
}

.hamburger::before {
    top: -6px;
}

.hamburger::after {
    top: 6px;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 18px;
}

/* Logo styling for images */
.logo {
    display: block;
    object-fit: contain;
    object-position: center;
}

.logo-section .logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.sidebar.collapsed .logo-section .logo {
    width: 28px;
    height: 28px;
}

.sidebar.collapsed .logo-section .app-name {
    display: none;
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

.nav-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s ease;
    border-radius: 0;
    margin: 0 8px;
    border-radius: 4px;
}

.nav-item:hover {
    background: var(--surface-color);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--border-color);
    color: black;
}

.nav-icon {
    font-size: 18px;
    min-width: 18px;
}

.sidebar.collapsed .nav-text {
    display: none;
}

/* Conversations Section */
.conversations-section {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-height: 0;
}

.conversations-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    margin: 0 8px;
}

.conversations-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

.sidebar.collapsed .conversations-title {
    display: none;
}

.new-conversation-btn {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 24px;
    height: 24px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.new-conversation-btn:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.sidebar.collapsed .new-conversation-btn {
    width: 20px;
    height: 20px;
    font-size: 12px;
}

.conversations-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.conversations-loading {
    padding: 12px 16px;
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
}

.conversations-loading-more {
    padding: 12px 16px;
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-secondary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.conversation-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s ease;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    min-height: 42px;
}

.conversation-item:hover {
    background: var(--hover-color);
    color: var(--text-primary);
}

.conversation-item.active {
    background: var(--accent-color);
    color: white;
}

.conversation-item.active .conversation-delete {
    color: rgba(255, 255, 255, 0.8);
}

.conversation-item.active .conversation-delete:hover {
    color: white;
    background: rgba(255, 255, 255, 0.2);
}

.conversation-icon {
    font-size: 16px;
    min-width: 16px;
    opacity: 0.7;
}

.conversation-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.conversation-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.conversation-meta {
    font-size: 11px;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-delete {
    opacity: 1;
    color: var(--text-secondary);
    background: none;
    border: none;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.2s ease;
}

.conversation-delete:hover {
    background: var(--danger-color);
    color: white;
}

.sidebar.collapsed .conversation-content {
    display: none;
}

.sidebar.collapsed .conversation-delete {
    display: none;
}

.sidebar.collapsed .conversations-section {
    display: none;
}

/* Empty state */
.conversations-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

.conversations-empty .empty-icon {
    font-size: 24px;
    margin-bottom: 8px;
    opacity: 0.5;
}

.conversations-empty .empty-text {
    font-size: 13px;
    line-height: 1.4;
}

/* Sidebar Footer */
.sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding: 16px;
}

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

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface-color);
}

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

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

.user-email {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar.collapsed .user-details {
    display: none;
}

.sign-out-btn {
    width: 100%;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.sign-out-btn:hover {
    background: var(--danger-color);
    color: white;
    border-color: var(--danger-color);
}

.sidebar.collapsed .sign-out-btn span {
    display: none;
}

.sidebar.collapsed .sign-out-btn::after {
    content: '↗';
    font-size: 16px;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: margin-left 0.3s ease;
}

/* Views */
.view {
    display: none;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
}

.view.active {
    display: flex;
    flex-direction: column;
}

/* Chat View */
.chat-container {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    background: var(--surface-color);
    display: flex;
    flex-direction: column;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    position: relative; /* Needed for absolute positioning of centered input */
}

.chat-header {
    padding: 16px 24px;
    background: var(--background-color);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-header-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    background: var(--background-color);
}

/* Mobile menu toggle - hidden by default on desktop */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.mobile-menu-toggle:hover {
    background-color: var(--surface-color);
}

.mobile-menu-toggle svg {
    width: 24px;
    height: 24px;
}

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

.header-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.token-counter-container {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 400;
    opacity: 0.8;
}

.token-counter-container .loading {
    opacity: 0.6;
    font-style: italic;
}

.chat-meta-row {
    display: flex;
    align-items: center;
    padding: 8px 16px 0;
    gap: 12px;
}

.model-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--surface-color);
    padding: 6px 12px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.model-indicator:hover {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--accent-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.model-indicator .model-icon {
    font-size: 14px;
    opacity: 0.8;
}

.model-indicator .model-name {
    font-weight: 500;
    color: var(--text-primary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 24px 48px 24px; /* top right bottom left */
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--background-color);
}

/* Welcome Message */
.welcome-message {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    text-align: center;
}

.welcome-content {
    max-width: 500px;
    padding: 32px;
}

.welcome-content h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.welcome-content p {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}

.welcome-features {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

.feature {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--surface-color);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.feature-icon {
    font-size: 20px;
}

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

.message {
    display: flex;
    gap: 12px;
    line-height: 1.6;
}

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

.message.user .message-content {
    background: var(--surface-color);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 70%;
    font-size: 15px;
}

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

.message.assistant .message-content {
    background: transparent;
    color: var(--text-primary);
    padding: 0;
    max-width: 100%;
    font-size: 15px;
}

/* Enhanced markdown styling for assistant messages */
.message.assistant .message-content h1,
.message.assistant .message-content h2,
.message.assistant .message-content h3,
.message.assistant .message-content h4,
.message.assistant .message-content h5,
.message.assistant .message-content h6 {
    margin: 1.2em 0 0.5em 0;
    font-weight: 600;
    color: var(--text-primary);
}

.message.assistant .message-content h1:first-child,
.message.assistant .message-content h2:first-child,
.message.assistant .message-content h3:first-child,
.message.assistant .message-content h4:first-child,
.message.assistant .message-content h5:first-child,
.message.assistant .message-content h6:first-child {
    margin-top: 0;
}

.message.assistant .message-content h1 { font-size: 1.5em; }
.message.assistant .message-content h2 { font-size: 1.3em; }
.message.assistant .message-content h3 { font-size: 1.2em; }
.message.assistant .message-content h4 { font-size: 1.1em; }

.message.assistant .message-content p {
    margin: 0.8em 0;
    color: var(--text-primary);
}

.message.assistant .message-content p:first-child {
    margin-top: 0;
}

.message.assistant .message-content p:last-child {
    margin-bottom: 0;
}

.message.assistant .message-content ul,
.message.assistant .message-content ol {
    margin: 0.8em 0;
    padding-left: 1.5em;
}

.message.assistant .message-content li {
    margin: 0.4em 0;
    color: var(--text-primary);
}

/* Link styling */
.message.assistant .message-content a {
    color: var(--accent-color);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.message.assistant .message-content a:hover {
    color: #1d4ed8;
}

.message.assistant .message-content a:visited {
    color: #7c3aed;
}

/* Code styling */
.message.assistant .message-content code {
    background: var(--surface-color);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, Inconsolata, 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 0.9em;
    color: var(--danger-color);
    border: 1px solid var(--border-color);
}

.message.assistant .message-content pre {
    background: #f8fafc;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid #e2e8f0;
    margin: 1em 0;
}

.message.assistant .message-content pre code {
    background: none;
    padding: 0;
    border: none;
    font-size: 0.85em;
    color: #1e293b;
}

/* Blockquote styling */
.message.assistant .message-content blockquote {
    border-left: 4px solid var(--border-color);
    padding-left: 16px;
    margin: 1em 0;
    color: var(--text-secondary);
    font-style: italic;
}

/* Table styling */
.message.assistant .message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
    font-size: 0.9em;
}

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

.message.assistant .message-content th {
    background-color: var(--surface-color);
    font-weight: 600;
    color: var(--text-primary);
}

.message.assistant .message-content td {
    color: var(--text-primary);
}

/* Status update styling */
.status-update {
    color: var(--accent-color);
    font-style: italic;
    display: inline-block;
    animation: pulse 1.5s ease-in-out infinite;
}

.thinking {
    color: var(--accent-color);
    font-style: italic;
    display: inline-block;
    animation: pulse 1.5s ease-in-out infinite;
}

.thinking-status {
    color: #6b7280;
    font-style: italic;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(156, 163, 175, 0.1);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.9em;
    animation: thinkingPulse 2s ease-in-out infinite;
}

.thinking-message .message-content {
    opacity: 0.8;
}

@keyframes thinkingPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Web search indicator - OLD STYLE REMOVED */

/* .web-search-icon - OLD STYLE REMOVED */

.message.web-searching {
    position: relative;
}

.message.web-searching::before {
    content: '';
    position: absolute;
    left: -4px;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, #0ea5e9 0%, #38bdf8 100%);
    border-radius: 2px;
    animation: shimmer 1.5s ease-in-out infinite;
}

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

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

/* @keyframes webSearchGlow - REMOVED */

@keyframes shimmer {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

/* Input container styling */
.chat-input-container {
    padding: 16px 24px 32px 24px; /* top right bottom left */
    background: var(--background-color);
}

/* Centered state for new conversations */
.chat-container.new-conversation {
    background: white;
}

.chat-container.new-conversation .chat-input-container {
    position: absolute;
    bottom: auto;
    top: 33%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 800px;
    border: none;
    padding: 0;
    background: transparent;
}

.chat-container.new-conversation .chat-input-wrapper {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: white;
}

.chat-container.new-conversation .chat-input,
.chat-container.new-conversation .chat-controls {
    background: white;
}

.chat-container.new-conversation .chat-messages {
    display: none;
}

/* Position dropdown menus below buttons for new conversations */
.chat-container.new-conversation .tools-menu,
.chat-container.new-conversation .model-menu {
    bottom: auto;
    top: 100%;
    margin-bottom: 0;
    margin-top: 8px;
}

.help-text {
    text-align: center;
    font-size: 32px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 24px;
    opacity: 0.9;
    transition: opacity 0.3s ease-in-out;
}

.chat-container.new-conversation .chat-meta-row {
    justify-content: center;
}

/* New 2-row input wrapper */
.chat-input-wrapper {
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: white;
    overflow: visible; /* Allow dropdowns to show */
}

.chat-input {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 12px;
    border-radius: 12px 12px 0 0; /* Round top corners */
}

.chat-input input[type="text"] {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 8px;
    font-family: inherit;
    font-size: 16px;
    outline: none;
    color: var(--text-primary);
}

.chat-input input[type="text"]::placeholder {
    color: var(--text-secondary);
}

/* Chat controls row */
.chat-controls {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: white;
    position: relative;
    border-radius: 0 0 12px 12px; /* Round bottom corners */
    justify-content: space-between;
}

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

/* Tools button */
.tools-button {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tools-button:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

.tools-button.has-active-tools {
    color: var(--accent-color);
}

.tools-button svg {
    width: 18px;
    height: 18px;
}

.tools-label {
    display: none;
}

@media (min-width: 768px) {
    .tools-label {
        display: inline;
    }
}

/* On smaller screens, adjust spacing */
@media (max-width: 480px) {
    .chat-controls {
        gap: 8px;
        padding: 8px;
    }
    
    /* Make model selector more compact on mobile */
    .model-selector {
        padding: 6px 10px;
        font-size: 13px;
    }
    
    .model-selector .model-icon {
        font-size: 14px;
    }
}

/* Web search indicator */
.web-search-indicator {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 6px;
    background: transparent;
    border: none;
    cursor: default;
}

.web-search-indicator svg {
    width: 20px;
    height: 20px;
}

/* Default state - no web search */
.web-search-indicator.disabled svg {
    stroke: #9ca3af; /* Grey color */
    opacity: 1;
}

/* Active state - web search supported */
.web-search-indicator.active svg {
    stroke: #3b82f6; /* Blue color */
    opacity: 1;
}

/* Tooltip */
.web-search-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    font-size: 12px;
    border-radius: 6px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.web-search-indicator:hover .web-search-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-4px);
}

/* Tooltip arrow */
.web-search-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid rgba(0, 0, 0, 0.9);
}

/* Model selector */
.model-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    white-space: nowrap;
}

.model-selector:hover {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--accent-color);
}

.model-selector .model-icon {
    font-size: 16px;
}

.model-selector .dropdown-arrow {
    width: 14px;
    height: 14px;
    opacity: 0.6;
}

/* Dropdown menus */
.tools-menu,
.model-menu {
    position: absolute;
    bottom: 100%;
    margin-bottom: 8px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 280px;
    max-height: 400px;
    overflow: hidden;
    z-index: 1000;
}

.tools-menu {
    left: 12px;
}

.model-menu {
    right: 12px;
}

.tools-menu-header,
.model-menu-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.02);
}

.tools-menu-header h3,
.model-menu-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.tools-menu-items,
.model-menu-items {
    max-height: 300px;
    overflow-y: auto;
}

/* Integration item */
.integration-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.integration-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.integration-item-info {
    flex: 1;
}

.integration-item-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.integration-item-status {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.toggle-switch.active {
    background: var(--accent-color);
}

.toggle-switch-handle {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.toggle-switch.active .toggle-switch-handle {
    transform: translateX(16px);
}

/* Model item */
.model-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.model-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.model-item.selected {
    background: rgba(59, 130, 246, 0.1);
}

.model-item-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.model-item-check {
    width: 16px;
    height: 16px;
    color: var(--accent-color);
    display: none;
}

.model-item.selected .model-item-check {
    display: block;
}

/* Add integration link */
.tools-menu-footer {
    border-top: 1px solid var(--border-color);
    padding: 8px;
}

.add-integration-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    color: var(--accent-color);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    transition: background 0.2s ease;
}

.add-integration-link:hover {
    background: rgba(59, 130, 246, 0.1);
}

.add-integration-link svg {
    width: 16px;
    height: 16px;
}

.chat-input button {
    background: transparent;
    color: var(--text-primary);
    border: none;
    border-radius: 0;
    padding: 4px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 24px;
    line-height: 1;
    /* Reset iOS button styles */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.chat-input button svg {
    width: 20px;
    height: 20px;
}

.chat-input button .send-arrow-icon {
    width: 40px;
    height: 40px;
    display: block;
    /* Remove filter to show icon in its original color */
}

/* SVG arrow hover effect */
.chat-input button:hover:not(:disabled) .send-arrow-icon circle {
    fill: #6B7280;
}

.chat-input button:hover:not(:disabled) .send-arrow-icon path {
    stroke: white;
}

/* Stop button styling */
.chat-input button .stop-icon {
    width: 40px;
    height: 40px;
    display: block;
}

/* SVG stop button hover effect */
.chat-input button:hover:not(:disabled) .stop-icon circle {
    fill: #6B7280;
}

.chat-input button:hover:not(:disabled) .stop-icon rect {
    fill: white;
}

/* System message styling */
.message.system {
    justify-content: center;
    margin: 16px 0;
}

.message.system .message-content {
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-style: italic;
    padding: 8px 16px;
    border-left: 3px solid var(--border-color);
    max-width: none;
}

.chat-input button:hover:not(:disabled) {
    opacity: 0.7;
    transform: scale(1.1);
}

.chat-input button:disabled {
    cursor: not-allowed;
    opacity: 0.3;
}

.chat-hints {
    text-align: center;
    color: var(--text-secondary);
    font-size: 12px;
    margin-top: 8px;
}

/* Settings View */
.settings-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 24px;
    width: 100%;
    flex: 1;
    overflow-y: auto;
}

.settings-header {
    margin-bottom: 32px;
}

.settings-header h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 8px;
}

.settings-header p {
    color: var(--text-secondary);
    font-size: 16px;
}

.settings-content {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.settings-section {
    background: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
}

.settings-section h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 16px;
}

.settings-section.danger {
    border-color: var(--danger-color);
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settings-group label {
    font-weight: 500;
    color: var(--text-primary);
}

.info-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 8px;
}

.setting-description {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.5;
    margin: 0 0 12px 0;
    padding: 12px;
    background: var(--surface-color);
    border-radius: 8px;
    border-left: 4px solid var(--accent-color);
}

.settings-group input[type="text"],
.settings-group input[type="email"] {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--background-color);
    color: var(--text-primary);
}

.settings-group input[type="text"]:focus,
.settings-group input[type="email"]:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    margin: 0;
}

.settings-group input[type="range"] {
    width: 100%;
}

.range-value {
    font-weight: 500;
    color: var(--accent-color);
}

.settings-group small {
    color: var(--text-secondary);
    font-size: 12px;
}

/* Buttons */
.btn-primary {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.btn-danger:hover {
    background: #dc2626;
}

/* Mobile Styles */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }

    /* Fix for mobile viewport issues */
    body {
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100); /* Fallback for browsers without dvh support */
        height: 100dvh;
        /* Prevent iOS Safari from bouncing */
        position: fixed;
        width: 100%;
        overflow: hidden;
    }

    .app {
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
        height: 100dvh;
    }

    .chat-container {
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
        height: 100dvh;
        /* Ensure the container takes full available space */
        min-height: 0;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
        height: 100dvh;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 200;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 150;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    .main-content {
        width: 100%;
    }

    .chat-header {
        padding: 12px 16px;
    }

    .chat-header h1 {
        font-size: 18px;
        margin: 0;
    }

    .chat-header-main {
        flex-direction: row;
        align-items: center;
        gap: 12px;
    }
    
    .header-left {
        display: flex;
        align-items: center;
        gap: 12px;
        flex: 1;
    }
    
    .header-meta {
        display: none; /* Hide token counter on mobile to save space */
    }

    .chat-messages {
        padding: 16px;
        gap: 16px;
    }

    .message.user .message-content {
        max-width: 85%;
        font-size: 16px;
    }

    .message.assistant .message-content {
        font-size: 16px;
    }

    .chat-input-container {
        padding: 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        /* Ensure input stays visible above mobile keyboards */
        position: sticky;
        bottom: 0;
        background: var(--background-color);
        border-top: 2px solid var(--border-color);
        /* Prevent layout shift when keyboard appears */
        box-sizing: border-box;
    }

    .chat-input textarea {
        /* Prevent zoom on iOS when focusing input */
        font-size: 16px;
    }

    .settings-container {
        padding: 16px;
    }

    .settings-header h1 {
        font-size: 24px;
    }

    .settings-content {
        gap: 24px;
    }

    .settings-section {
        padding: 20px;
    }

    .welcome-content {
        padding: 24px 16px;
    }

    .welcome-features {
        gap: 8px;
    }

    .feature {
        padding: 10px;
    }
    
    .chat-meta-row {
        padding: 8px 12px 0;
    }
    
    .model-indicator {
        font-size: 12px;
        padding: 5px 10px;
    }

    /* Show mobile menu toggle */
    .mobile-menu-toggle {
        display: flex !important;
    }
}

/* Scrollbar styling for webkit browsers */
.chat-messages::-webkit-scrollbar,
.conversations-list::-webkit-scrollbar,
.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.conversations-list::-webkit-scrollbar-track,
.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

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

.chat-messages::-webkit-scrollbar-thumb:hover,
.conversations-list::-webkit-scrollbar-thumb:hover,
.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Loading state */
.loading {
    opacity: 0.6;
}

/* Compact Settings Styles */
.settings-section.compact {
    padding: 16px 20px;
    margin-bottom: 16px;
}

.settings-section.compact h2 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.settings-group.inline {
    flex-direction: row;
    align-items: center;
    gap: 12px;
}

.compact-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease;
}

.compact-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.btn-primary.compact,
.btn-danger.compact {
    padding: 8px 16px;
    font-size: 14px;
    min-width: auto;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--surface-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.btn-icon {
    font-size: 16px;
}

.settings-section.compact .settings-group small {
    color: var(--text-secondary);
    font-size: 12px;
    margin-top: 4px;
}

/* Admin section specific styling */
#admin-section {
    border-color: var(--accent-color);
    background: rgba(59, 130, 246, 0.02);
}

#admin-section h2 {
    color: var(--accent-color);
}

/* Privacy notification animation */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Privacy notification styling */
.privacy-notification {
    animation: slideIn 0.3s ease-out;
}

.privacy-notification details summary {
    outline: none;
    user-select: none;
}

/* Streaming content styles */
.streaming-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.6;
}

.streaming-code {
    border: 1px dashed var(--border-color);
    position: relative;
}

.streaming-code::after {
    content: '...';
    position: absolute;
    bottom: 4px;
    right: 8px;
    color: var(--text-secondary);
    animation: pulse 1s ease-in-out infinite;
}

/* Streaming indicator for incomplete blocks */
.streaming-indicator {
    color: var(--text-secondary);
    font-style: italic;
    animation: pulse 1s ease-in-out infinite;
}

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

/* Token usage display */
.token-usage-summary {
    margin-top: 8px;
    margin-left: 0;
    font-size: 12px;
    color: #6b7280;
    width: 100%;
}

.token-usage-divider {
    border-top: 1px solid #e5e7eb;
    margin: 8px 0 6px 0;
}

.token-usage-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background-color: #f9fafb;
    border-radius: 6px;
}

.token-usage-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.token-usage-text {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
    font-size: 11px;
    color: #6b7280;
    line-height: 1.4;
}

/* Message with token usage wrapper */
.message-with-usage {
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* Toast animations */
@keyframes slideUp {
    from {
        transform: translate(-50%, 100%);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

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

/* User Dropdown Styles */
.user-dropdown-container {
    position: relative;
    display: none; /* Hidden by default, shown on larger screens */
}

.user-dropdown-trigger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.user-dropdown-trigger:hover {
    background-color: var(--hover-color);
}

.header-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.user-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    min-width: 200px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s;
    z-index: 1000;
}

.user-dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-user-info {
    padding: 12px 16px;
}

.dropdown-user-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.dropdown-user-email {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

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

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 0.875rem;
}

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

.dropdown-icon {
    font-size: 16px;
}

.dropdown-sign-out {
    color: var(--danger-color);
}

/* Show dropdown on larger screens only */
@media (min-width: 768px) {
    .user-dropdown-container {
        display: block;
    }
    
    /* Hide sidebar user info and settings on larger screens */
    .sidebar-footer {
        display: none;
    }
}

/* Extend chat container width on larger screens */
@media (min-width: 1024px) {
    .chat-container {
        max-width: 90%;
    }
    
    .chat-container.new-conversation .chat-input-wrapper {
        max-width: 800px;
    }
}

/* Keep original behavior on mobile */
@media (max-width: 767px) {
    .user-dropdown-container {
        display: none;
    }
    
    .sidebar-footer .user-info,
    .sidebar-footer .sign-out-btn {
        display: flex;
    }
}

/* Sarcasm Button Styles */
.sarcasm-button {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.sarcasm-button:hover {
    background: rgba(59, 130, 246, 0.1);
    border-radius: 6px;
}

.sarcasm-button:hover .sarcasm-icon {
    transform: scale(1.1);
}

.sarcasm-icon {
    width: 20px;
    height: 20px;
    transition: transform 0.2s;
    display: inline-block;
}

.sarcasm-tooltip {
    position: absolute;
    bottom: -28px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
}

.sarcasm-button:hover .sarcasm-tooltip {
    opacity: 1;
    visibility: visible;
}

/* Sarcasm Popup Styles */
.sarcasm-popup {
    position: absolute;
    bottom: 100%;
    margin-bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 280px;
    z-index: 1000;
}

/* Arrow pointing down to the button */
.sarcasm-popup::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid var(--border-color);
}

.sarcasm-popup::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-1px);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid var(--surface-color);
}

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

.sarcasm-popup-header h3 {
    margin: 0;
    font-size: 16px;
    color: var(--text-primary);
}

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

.sarcasm-close:hover {
    background: var(--hover-color);
}

.sarcasm-popup-content {
    padding: 20px;
}

.sarcasm-level-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 16px;
}

.sarcasm-level-label {
    font-size: 14px;
    color: var(--text-secondary);
}

.sarcasm-level-value {
    font-size: 32px;
    font-weight: 600;
    color: var(--primary-color);
    min-width: 40px;
    text-align: center;
}

.sarcasm-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
    margin: 16px 0;
}

.sarcasm-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

.sarcasm-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.sarcasm-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: transform 0.2s;
}

.sarcasm-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
}

.sarcasm-scale-labels {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: -8px;
}

.sarcasm-description {
    margin-top: 16px;
    padding: 12px;
    background: var(--hover-color);
    border-radius: 8px;
    text-align: center;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.4;
}

/* Adjust position for new conversation view - popup below button */
.chat-container.new-conversation .sarcasm-popup {
    bottom: auto;
    top: 100%;
    margin-bottom: 0;
    margin-top: 8px;
}

/* Flip arrow for new conversation view - arrow points up */
.chat-container.new-conversation .sarcasm-popup::after {
    top: auto;
    bottom: 100%;
    border-top: none;
    border-bottom: 8px solid var(--border-color);
}

.chat-container.new-conversation .sarcasm-popup::before {
    top: auto;
    bottom: 100%;
    transform: translateX(-50%) translateY(1px);
    border-top: none;
    border-bottom: 8px solid var(--surface-color);
}