:root {
    --bg-main: #f8f9fb;
    --bg-panel: #ffffff;
    --bg-input: #f0f2f5;
    
    --text-main: #111418;
    --text-secondary: #4a5568;
    --text-muted: #8ca3ba;
    
    --brand-accent: #0f172a;
    --brand-hover: #1e293b;
    --brand-light: #f1f5f9;
    --brand-danger: #ef4444;
    --brand-warning: #f59e0b;
    
    --border-light: rgba(0, 0, 0, 0.06);
    --border-subtle: rgba(0, 0, 0, 0.1);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
    
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.02);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.05);
    --shadow-lg: 0 12px 24px rgba(0,0,0,0.08);
    --shadow-floating: 0 16px 32px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.02);
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Plus Jakarta Sans', sans-serif; -webkit-tap-highlight-color: transparent; }
body { background: var(--bg-main); color: var(--text-main); display: flex; height: 100vh; height: 100dvh; height: calc(var(--vh, 1vh) * 100); overflow: hidden; font-size: 15px; }

h1, h2, h3, h4, h5, h6 { font-family: 'Playfair Display', serif; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

/* Typography */
.text-h1 { font-size: 2rem; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.text-body { font-size: 15px; line-height: 1.6; color: var(--text-secondary); }

/* Sidebar */
.sidebar { margin-left: 0; transition: margin-left 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1); 
    width: 280px;
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-light);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    z-index: 50;
    flex-shrink: 0;
}
.sidebar-header {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 16px;
    letter-spacing: -0.01em;
}
.btn-new-chat {
    margin: 0 16px 16px;
    padding: 12px 16px;
    background: var(--brand-accent);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.2);
}
.btn-new-chat:hover {
    background: var(--brand-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.3);
}
.btn-new-chat:active {
    transform: translateY(1px);
}

.sidebar-history {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.history-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.2s, color 0.2s;
}
.history-item:hover {
    background: var(--bg-main);
    color: var(--text-main);
}
.history-item.active {
    background: var(--brand-light);
    color: var(--brand-accent);
    font-weight: 500;
}
.history-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 8px 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.04em; }
.btn-clear-all { color: var(--text-muted); cursor: pointer; text-transform: none; font-weight: 500; transition: color 0.2s; }
.btn-clear-all:hover { color: var(--brand-danger); }

.sidebar-footer {
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 12px;
}
.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--brand-light);
    color: var(--brand-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}
.user-info-box {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.user-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-sub { font-size: 12px; color: var(--text-muted); }
.btn-power {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-power:hover { background: var(--bg-main); color: var(--text-main); }
.btn-login-register {
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-login-register:hover { background: var(--bg-main); }

/* Main Area */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-main);
    width: 100%;
}
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 40px 20px 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    scroll-behavior: smooth;
}

.welcome-center {
    margin: auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 500px;
    animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.welcome-center img { width: 48px; height: 48px; border-radius: 12px; box-shadow: var(--shadow-sm); }
.welcome-center h1 { color: var(--text-main); }
.welcome-center p { color: var(--text-secondary); font-size: 16px; }

/* Messages Area */
#chatMessages {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}
.message-wrapper { display: flex; width: 100%; flex-direction: column; opacity: 0; animation: msgFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
@keyframes msgFade { to { opacity: 1; } }

.user-message {
    align-self: flex-end;
    background: var(--bg-panel);
    padding: 14px 20px;
    border-radius: 20px 20px 4px 20px;
    font-size: 15px;
    max-width: 80%;
    line-height: 1.6;
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
}
.bot-message {
    display: flex;
    gap: 16px;
    max-width: 100%;
    width: 100%;
}
.bot-avatar {
    width: 32px; height: 32px; flex-shrink: 0;
}
.bot-avatar img { width: 100%; height: 100%; border-radius: 8px; object-fit: contain; }
.bot-content-wrapper { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.bot-content { font-size: 15px; line-height: 1.7; color: var(--text-main); }
.msg-actions { display: flex; gap: 8px; margin-top: 4px; opacity: 0; transition: opacity 0.2s; }
.message-wrapper:hover .msg-actions { opacity: 1; }
.action-btn { background: transparent; border: none; cursor: pointer; color: var(--text-muted); display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 8px; border-radius: var(--radius-sm); transition: background 0.2s, color 0.2s; }
.action-btn:hover { background: rgba(0,0,0,0.05); color: var(--text-main); }
.action-btn.copied { color: #10b981; }

.chat-attachment-container { margin-bottom: 12px; }
.chat-img-preview { max-width: 240px; border-radius: var(--radius-md); box-shadow: var(--shadow-sm); border: 1px solid var(--border-light); }
.chat-file-pill { display: inline-flex; align-items: center; gap: 8px; background: var(--bg-main); border: 1px solid var(--border-light); padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; color: var(--text-secondary); box-shadow: var(--shadow-sm); }

/* Input Dock */
.input-dock {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 24px 24px calc(24px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to top, var(--bg-main) 70%, transparent);
    display: flex;
    justify-content: center;
    pointer-events: none;
    z-index: 40;
}
.input-dock-wrapper {
    width: 100%;
    max-width: 800px;
    background: color-mix(in srgb, var(--bg-panel) 75%, transparent);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    box-shadow: var(--shadow-floating);
    display: flex;
    flex-direction: column;
    pointer-events: auto;
    transition: border-color 0.2s, box-shadow 0.2s;
    position: relative;
    padding: 12px 16px;
}
.input-dock-wrapper.focused {
    border-color: rgba(15, 23, 42, 0.3);
    box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.05), var(--shadow-floating);
}

.file-preview-bar {
    display: none;
    padding: 0 8px 12px;
    border-bottom: 1px solid var(--border-light);
    margin-bottom: 8px;
}
.file-preview-bar.active { display: flex; }
.file-preview-pill {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-input);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    max-width: 200px;
}
.file-preview-icon { width: 24px; height: 24px; border-radius: 4px; object-fit: cover; }
.file-preview-name { font-size: 13px; font-weight: 500; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.btn-remove-file {
    position: absolute; top: -8px; right: -8px;
    width: 24px; height: 24px;
    background: var(--brand-accent); color: white;
    border-radius: 50%; border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; box-shadow: var(--shadow-sm);
}

.chat-input {
    width: 100%;
    border: none;
    background: transparent;
    resize: none;
    padding: 8px 8px;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-main);
    outline: none;
    max-height: 200px;
    overflow-y: auto;
}
.chat-input::placeholder { color: var(--text-muted); }

.input-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 0 4px;
}
.tools-left, .tools-right { display: flex; align-items: center; gap: 8px; }
.tool-btn {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: none; border-radius: var(--radius-md);
    color: var(--text-muted); cursor: pointer; transition: background 0.2s, color 0.2s;
}
.tool-btn:hover { background: var(--bg-input); color: var(--text-main); }

.btn-send-wrapper { position: relative; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; }
.btn-send, .btn-stop {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    border: none; border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: transform 0.2s, opacity 0.2s;
}
.btn-send {
    background: var(--brand-accent); color: white;
}
.btn-send:hover:not(:disabled) { transform: scale(1.05); }
.btn-send:disabled { background: var(--bg-input); color: var(--text-muted); cursor: not-allowed; }
.btn-send.hidden { opacity: 0; pointer-events: none; visibility: hidden; transform: scale(0.8); }

.btn-stop {
    background: var(--bg-input); color: var(--brand-accent);
    opacity: 0; pointer-events: none; transform: scale(0.8);
}
.btn-stop.active { opacity: 1; pointer-events: auto; transform: scale(1); }
.btn-stop:hover { background: #e2e8f0; }

/* Dropdowns */
.dropdown-menu {
    position: absolute;
    bottom: calc(100% + 12px);
    background: color-mix(in srgb, var(--bg-panel) 75%, transparent);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-floating);
    padding: 8px;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 0.2s, transform 0.2s;
}
.dropdown-menu.active { opacity: 1; pointer-events: auto; transform: translateY(0); }
.dropdown-header { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); padding: 8px 12px; }
.dropdown-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 14px; font-weight: 500;
    transition: background 0.2s; color: var(--text-main);
    gap: 12px;
}
.dropdown-item:hover { background: var(--bg-input); }
.dropdown-item.selected { background: var(--brand-light); color: var(--brand-accent); }
.model-badge { font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: 600; text-transform: uppercase; }
.badge-fast { background: #dbeafe; color: #1e40af; }
.badge-image-only { background: #f3f4f6; color: #4b5563; }
.badge-reasoning { background: #fce7f3; color: #be185d; }

/* Modals */
.auth-overlay {
    position: fixed; inset: 0; background: rgba(255,255,255,0.7); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center; z-index: 2000;
    opacity: 0; animation: modalFadeIn 0.3s forwards;
}
@keyframes modalFadeIn { to { opacity: 1; } }
.auth-modal {
    background: color-mix(in srgb, var(--bg-panel) 85%, transparent);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    width: 100%; max-width: 400px;
    border-radius: var(--radius-xl); padding: 32px; max-height: 90vh; overflow-y: auto; margin: 0 16px;
    box-shadow: var(--shadow-floating); position: relative;
    border: 1px solid rgba(0,0,0,0.05);
    transform: translateY(20px); animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes modalSlideUp { to { transform: translateY(0); } }
.auth-close {
    position: absolute; top: 20px; right: 20px;
    background: transparent; border: none; color: var(--text-muted); cursor: pointer;
    width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
    border-radius: 50%; transition: background 0.2s;
}
.auth-close:hover { background: var(--bg-input); }
.auth-title { font-family: 'Playfair Display', serif; font-size: 28px; font-weight: 600; margin-bottom: 24px; text-align: center; }

.auth-tabs { display: flex; gap: 8px; margin-bottom: 24px; background: var(--bg-input); padding: 4px; border-radius: var(--radius-md); }
.auth-tab {
    flex: 1; text-align: center; padding: 10px; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 14px; font-weight: 600; color: var(--text-secondary); transition: all 0.2s;
}
.auth-tab.active { background: var(--bg-panel); color: var(--text-main); box-shadow: var(--shadow-sm); }

.auth-input-group { margin-bottom: 16px; }
.auth-input-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.auth-input-group input {
    width: 100%; padding: 12px 16px; border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md); font-size: 15px; background: var(--bg-main);
    transition: border-color 0.2s; outline: none;
}
.auth-input-group input:focus { border-color: var(--brand-accent); }

.auth-btn {
    width: 100%; padding: 14px; border: none; border-radius: var(--radius-md);
    background: var(--brand-accent); color: white; font-size: 15px; font-weight: 600;
    cursor: pointer; transition: transform 0.2s, background 0.2s; margin-top: 8px;
}
.auth-btn:hover { background: var(--brand-hover); transform: translateY(-1px); }

/* Custom Confirm Overlay */
.custom-confirm-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 3000; }
.custom-confirm-box { background: color-mix(in srgb, var(--bg-panel) 85%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); padding: 24px; border-radius: var(--radius-lg); box-shadow: var(--shadow-floating); max-width: 320px; width: 90%; text-align: center; animation: modalSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.custom-confirm-msg { font-size: 16px; font-weight: 500; margin-bottom: 24px; color: var(--text-main); }
.custom-confirm-btns { display: flex; gap: 12px; }
.custom-confirm-btn { flex: 1; padding: 12px; border: none; border-radius: var(--radius-md); font-weight: 600; cursor: pointer; font-size: 14px; transition: background 0.2s; }
.custom-confirm-btn.cancel { background: var(--bg-input); color: var(--text-secondary); }
.custom-confirm-btn.cancel:hover { background: #e2e8f0; }
.custom-confirm-btn.confirm { background: var(--brand-danger); color: white; }
.custom-confirm-btn.confirm:hover { background: #dc2626; }

/* Image Preview Modal */
.image-preview-modal {
    position: fixed; inset: 0; z-index: 5000;
    background: rgba(0,0,0,0.85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
.image-preview-modal.active {
    opacity: 1; pointer-events: auto; display: flex !important;
}
.image-preview-topbar {
    position: absolute; top: 0; left: 0; right: 0;
    padding: 16px 24px; display: flex; justify-content: flex-end; gap: 16px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 100%);
}
.preview-btn {
    background: rgba(255,255,255,0.2); border: none; border-radius: 50%;
    width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
    color: white; cursor: pointer; backdrop-filter: blur(4px); transition: background 0.2s, transform 0.2s;
}
.preview-btn:hover { background: rgba(255,255,255,0.3); transform: scale(1.05); }
#imagePreviewFull {
    max-width: 90vw; max-height: 85vh; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transform: scale(0.95); transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    object-fit: contain;
}
.image-preview-modal.active #imagePreviewFull { transform: scale(1); }

/* Memory Modal Enhancements */
.memory-modal { max-width: 600px; padding: 0; overflow: hidden; }
.memory-header { background: var(--bg-main); padding: 32px 32px 24px; display: flex; align-items: flex-start; gap: 20px; border-bottom: 1px solid var(--border-light); }
.memory-icon-wrapper { width: 48px; height: 48px; background: var(--bg-panel); border-radius: 12px; display: flex; align-items: center; justify-content: center; color: var(--brand-accent); box-shadow: var(--shadow-sm); }
.memory-title { font-family: 'Playfair Display', serif; font-size: 24px; margin-bottom: 4px; }
.memory-subtitle { color: var(--text-secondary); font-size: 14px; }
.memory-section { padding: 24px 32px; border-bottom: 1px solid var(--border-light); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.toggle-label { display: flex; align-items: center; justify-content: space-between; width: 100%; cursor: pointer; }
.toggle-text { display: flex; flex-direction: column; gap: 4px; }
.toggle-title { font-weight: 600; font-size: 15px; }
.toggle-description { font-size: 13px; color: var(--text-muted); }
.toggle-switch { position: relative; width: 44px; height: 24px; }
.toggle-input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e1; transition: .3s; border-radius: 24px; }
.toggle-slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; box-shadow: var(--shadow-sm); }
.toggle-input:checked + .toggle-slider { background-color: var(--brand-accent); }
.toggle-input:checked + .toggle-slider:before { transform: translateX(20px); }

.memory-content-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.header-left { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.section-icon { width: 18px; height: 18px; color: var(--text-muted); }
.btn-memory-action { background: transparent; border: none; font-size: 13px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius-sm); transition: background 0.2s; }
.btn-delete { color: var(--brand-danger); }
.btn-delete:hover { background: #fef2f2; }
.memory-textarea { width: 100%; height: 160px; padding: 16px; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); font-size: 14px; line-height: 1.6; resize: none; outline: none; transition: border-color 0.2s; background: var(--bg-main); color: var(--text-main); }
.memory-textarea:focus { border-color: var(--brand-accent); }
.memory-hint { margin-top: 12px; font-size: 12px; color: var(--text-muted); display: flex; align-items: flex-start; gap: 6px; line-height: 1.4; }
.memory-actions { padding: 20px 32px; background: var(--bg-main); display: flex; justify-content: flex-end; }
.btn-save { background: var(--brand-accent); color: white; padding: 10px 20px; border-radius: var(--radius-md); }
.btn-save:hover { background: var(--brand-hover); }
.memory-message { text-align: center; padding: 12px; font-size: 13px; font-weight: 500; }

/* Code blocks & Markdown */
.bot-content pre {
    background: var(--brand-accent) !important;
    padding: 16px;
    border-radius: var(--radius-md);
    margin: 16px 0;
    overflow-x: auto;
    font-size: 14px;
    border: 1px solid rgba(255,255,255,0.1);
}
.bot-content code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9em;
}
.bot-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
}
.bot-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    display: block;
    overflow-x: auto;
}
.bot-content th, .bot-content td {
    border: 1px solid var(--border-light);
    padding: 8px 12px;
    text-align: left;
}
.bot-content th {
    background: var(--bg-input);
    font-weight: 600;
}
.code-block-wrapper {
    margin: 16px 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--brand-accent);
    border: 1px solid rgba(255,255,255,0.1);
}
.code-header {
    background: rgba(255,255,255,0.05);
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 12px;
    font-weight: 600;
    color: rgba(255,255,255,0.7);
    font-family: 'JetBrains Mono', monospace;
}
.code-copy-btn {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    transition: color 0.2s;
}
.code-copy-btn:hover { color: white; }
.bot-content pre { margin: 0; border-radius: 0 0 var(--radius-md) var(--radius-md); border: none; }

.btn-scroll-bottom {
    position: absolute;
    bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    right: 50%;
    transform: translateX(50%) translateY(20px);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--bg-panel) 80%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    color: var(--text-secondary);
    z-index: 30;
}
.btn-scroll-bottom.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(50%) translateY(0);
}
.btn-scroll-bottom:hover { color: var(--text-main); background: var(--bg-main); }

/* Utilities */
.hidden-input { display: none; }
.loc-toast {
    background: var(--brand-accent);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-floating);
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Mobile Overrides */
.btn-menu {
    position: fixed; top: calc(16px + env(safe-area-inset-top, 0px)); left: 16px; z-index: 40;
    background: color-mix(in srgb, var(--bg-panel) 80%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; cursor: pointer; color: var(--text-main);
}
@media (min-width: 901px) {
    .btn-menu { display: none; }
    .sidebar.collapsed { margin-left: -280px; }
}
@media (max-width: 900px) {
    .btn-menu { display: flex; }
    .sidebar { position: fixed; left: 0; top: 0; height: 100vh; height: 100dvh; height: calc(var(--vh, 1vh) * 100); transform: translateX(0); margin-left: 0 !important; z-index: 50; background: color-mix(in srgb, var(--bg-panel) 85%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
    .sidebar.collapsed { transform: translateX(-100%); }
    .main-area { width: 100%; }
    .mobile-overlay {
        position: fixed; inset: 0; background: rgba(0,0,0,0.3); backdrop-filter: blur(2px);
        z-index: 45; opacity: 0; pointer-events: none; transition: opacity 0.3s;
    }
    .mobile-overlay.active { opacity: 1; pointer-events: auto; }
    .user-message { max-width: 90%; }
    .chat-container { padding: calc(60px + env(safe-area-inset-top, 0px)) 16px calc(120px + env(safe-area-inset-bottom, 0px)); }
    .input-dock { padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px)); }
    #chatMessages { gap: 20px; }
}
@media (max-width: 600px) {
    .dropdown-menu {
        position: fixed;
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
        left: 16px !important;
        right: 16px !important;
        width: auto !important;
        min-width: 0 !important;
        transform: translateY(10px) scale(0.98);
        transform-origin: bottom center;
    }
    .dropdown-menu.active {
        transform: translateY(0) scale(1);
    }
}

.history-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.btn-delete-chat {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s ease;
    margin-left: auto;
}
.history-item:hover .btn-delete-chat {
    opacity: 1;
}
.btn-delete-chat:hover {
    background: #fee2e2;
    color: #dc2626;
}

@media (max-width: 768px) {
    .btn-delete-chat {
        opacity: 1;
    }
}
.auth-modal::-webkit-scrollbar {
    width: 6px;
}
.auth-modal::-webkit-scrollbar-track {
    background: transparent;
}
.auth-modal::-webkit-scrollbar-thumb {
    background-color: var(--border-light);
    border-radius: 10px;
}
@media (max-width: 768px) {
    .auth-modal {
        padding: 24px;
        margin: 0 16px;
    }
}

/* AI Thinking Process UI */
.qwen-think-box {
    margin: 16px 0;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--bg-main);
    overflow: hidden;
    transition: all 0.3s ease;
}

.qwen-think-box summary {
    padding: 12px 16px;
    background: var(--bg-panel);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid transparent;
}

.qwen-think-box summary::-webkit-details-marker {
    display: none;
}

.qwen-think-box[open] summary {
    border-bottom-color: var(--border-light);
}

.qwen-think-box summary .arrow {
    transition: transform 0.3s ease;
}

.qwen-think-box[open] summary .arrow {
    transform: rotate(180deg);
}

.qwen-think-content {
    padding: 16px;
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.6;
    border-left: 2px solid var(--border-light);
    margin: 0 16px 16px;
}

.qwen-think-content p {
    margin-bottom: 8px;
}
.qwen-think-content p:last-child {
    margin-bottom: 0;
}

/* Code Canvas UI */
.canvas-area {
    width: 50vw;
    max-width: 800px;
    background: var(--bg-panel);
    border-left: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    z-index: 40;
    flex-shrink: 0;
}

.canvas-area.collapsed {
    width: 0;
    opacity: 0;
    border-left: none;
    pointer-events: none;
}

.canvas-header {
    height: calc(64px + env(safe-area-inset-top, 0px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: env(safe-area-inset-top, 0px) 20px 0 20px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-main);
}

.canvas-title {
    display: flex;
    align-items: center;
    font-weight: 600;
    color: var(--text-main);
}

.btn-close-canvas {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
}

.btn-close-canvas:hover {
    background: var(--bg-input);
    color: var(--text-main);
}

.canvas-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 24px calc(24px + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 1024px) {
    .canvas-area {
        position: fixed;
        right: 0;
        top: 0;
        height: 100vh;
        height: 100dvh;
        height: calc(var(--vh, 1vh) * 100);
        width: 100vw;
        max-width: none;
    }
}
.btn-open-canvas-inline:hover {
    background: var(--brand-hover) !important;
}

.btn-toggle-canvas {
    position: fixed;
    top: calc(16px + env(safe-area-inset-top, 0px));
    right: 16px;
    background: color-mix(in srgb, var(--bg-panel) 80%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-light);
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    z-index: 35;
    transition: all 0.2s;
}
.btn-toggle-canvas:hover {
    background: var(--bg-input);
}
@media (max-width: 900px) {
    .btn-toggle-canvas {
        top: calc(16px + env(safe-area-inset-top, 0px));
        right: 16px;
    }
}
