@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --page-bg: #F2F2F7;
    --header-bg: rgba(242, 242, 247, 0.85); 
    --menu-bg: rgba(255, 255, 255, 0.85);   
    --input-bg: #FFFFFF;
    --text-color: #000000;
    --border-color: rgba(60, 60, 67, 0.15);
    --model-bubble-bg: #FFFFFF;
    --model-text-color: #000000;
    --user-bubble-bg: #007AFF;
    --user-text-color: #FFFFFF;
    --action-button-color: #8E8E93;
    --settings-hover-bg: rgba(0, 0, 0, 0.05);
    --tooltip-bg: rgba(0, 0, 0, 0.85);
    --tooltip-text-color: #FFFFFF;
    --file-preview-bg: #E5E5EA;
    --file-preview-text: #000000;
    --code-bg: #F2F2F7;
    --code-text: #000000;
    --sidebar-bg: #F9F9FB;
    --sidebar-item-hover: rgba(0,0,0,0.08);
    --sidebar-text: #000000;
    --sidebar-width: 260px;
}

body.dark-mode {
    --page-bg: #1A1A1C;
    --header-bg: rgba(26, 26, 28, 0.85);
    --menu-bg: rgba(28, 28, 30, 0.85);
    --input-bg: #2C2C2E;
    --text-color: #EDEDED;
    --border-color: rgba(84, 84, 88, 0.35);
    --model-bubble-bg: #2C2C2E;
    --model-text-color: #FFFFFF;
    --user-bubble-bg: #0A84FF;
    --user-text-color: #FFFFFF;
    --action-button-color: #98989D;
    --settings-hover-bg: rgba(255, 255, 255, 0.1);
    --tooltip-bg: rgba(255, 255, 255, 0.9);
    --tooltip-text-color: #000000;
    --file-preview-bg: #3A3A3C;
    --file-preview-text: #FFFFFF;
    --code-bg: #1C1C1E;
    --code-text: #FFFFFF;
    --sidebar-bg: #141414;
    --sidebar-item-hover: rgba(255,255,255,0.1);
    --sidebar-text: #EDEDED;
}

html { height: 100%; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--page-bg);
    color: var(--text-color);
    margin: 0;
    display: flex;
    flex-direction: row; 
    height: 100vh;
    overflow: hidden; 
    -webkit-font-smoothing: antialiased;
}

#send-btn svg { display: block; }
.message-actions svg { width: 16px; height: 16px; display: block; }
.settings-label svg { width: 16px; height: 16px; display: block; flex-shrink: 0; }

#sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 0.5px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 200;
    flex-shrink: 0;
    position: relative;
}
body.sidebar-closed #sidebar { width: 60px; }

#sidebar-resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    background-color: transparent;
    z-index: 210;
    transition: background-color 0.2s;
}
#sidebar-resizer:hover, body.is-resizing #sidebar-resizer {
    background-color: var(--action-button-color);
    opacity: 0.5;
}
body.sidebar-closed #sidebar-resizer { display: none; }

.sidebar-controls {
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 8px;
}

#toggle-sidebar-btn {
    background: transparent;
    border: none;
    color: var(--action-button-color);
    cursor: pointer;
    padding: 10px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    transition: background 0.2s;
    width: fit-content;
}
body.sidebar-closed #toggle-sidebar-btn { width: 40px; justify-content: center; }
#toggle-sidebar-btn:hover { background-color: var(--settings-hover-bg); color: var(--text-color); }

#new-chat-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 12px;
    color: var(--text-color);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}
#new-chat-btn:hover { background: var(--settings-hover-bg); }

body.sidebar-closed #new-chat-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: 0; 
    color: var(--action-button-color);
}
body.sidebar-closed #new-chat-btn .new-chat-text { display: none; }
body.sidebar-closed #new-chat-btn:hover { 
    background-color: var(--settings-hover-bg); 
    color: var(--text-color);
    border-radius: 4px; 
}

#history-list { flex: 1; overflow-y: auto; margin-top: 5px; }
body.sidebar-closed #history-list { display: none; }

.history-item-container {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px; border-radius: 6px; color: var(--sidebar-text);
    margin: 0 10px 2px 10px; cursor: pointer;
}
.history-item-container:hover { background-color: var(--sidebar-item-hover); }
.history-item-container.active { background-color: var(--settings-hover-bg); font-weight: 500; }

.history-item-title {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.9rem; flex: 1;
}

.history-item-title-input {
    flex: 1; background: var(--input-bg); color: var(--text-color); 
    border: 1px solid var(--action-button-color); border-radius: 4px; 
    padding: 2px 4px; font-size: 0.9rem; font-family: inherit; outline: none; width: 100%;
}

.history-item-actions {
    display: flex;
    gap: 4px;
    opacity: 0; 
    pointer-events: none;
    transition: opacity 0.2s;
}
.history-item-container:hover .history-item-actions { 
    opacity: 1; 
    pointer-events: auto;
}

.history-item-actions button {
    background: transparent; border: none; color: var(--text-color);
    cursor: pointer; padding: 4px; border-radius: 4px; display: flex; align-items: center; justify-content: center;
}
.history-item-actions button svg { width: 14px; height: 14px; }
.history-item-actions button:hover { background-color: rgba(0,0,0,0.1); }
body.dark-mode .history-item-actions button:hover { background-color: rgba(255,255,255,0.1); }

#main-content { flex: 1; display: flex; flex-direction: column; position: relative; height: 100%; overflow: hidden; }

#menu-btn {
    position: absolute; left: 15px; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer; color: var(--text-color);
    padding: 6px; border-radius: 6px; display: none; 
    align-items: center;
}

#sidebar-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 150;
}

header {
    background-color: var(--header-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-bottom: 0.5px solid var(--border-color); padding: 12px 20px; text-align: center;
    position: absolute; top: 0; left: 0; right: 0; z-index: 100;
}

header h1 { margin: 0; font-size: 1.1rem; font-weight: 600; letter-spacing: -0.02em; }

#chat-container {
    flex: 1; overflow-y: auto; padding: 80px 15px 160px 15px;
    -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; position: relative;
}

#welcome-screen {
    position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%);
    text-align: center; color: var(--text-color); transition: opacity 0.3s ease; width: 100%;
}
#welcome-screen h2 { font-size: 2.2rem; margin-bottom: 8px; font-weight: 700; }
#welcome-screen p { font-size: 1.1rem; color: var(--action-button-color); }
.hidden { opacity: 0 !important; pointer-events: none !important; }

#chat-log {
    max-width: 750px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; 
    gap: 10px; margin-top: auto; margin-bottom: 0; padding-bottom: 0;
}

#scroll-anchor { height: 1px; margin: 0; padding: 0; display: block; }

.message-wrapper { display: flex; width: 100%; position: relative; flex-direction: column; gap: 2px; }
.message-inner { display: flex; flex-direction: column; max-width: 85%; width: max-content; }
.message-wrapper.user { align-items: flex-end; }
.message-wrapper.model { align-items: flex-start; }
.message-wrapper.user .message-inner { align-items: flex-end; }
.message-wrapper.model .message-inner { align-items: flex-start; }

.message-bubble {
    padding: 12px 20px; border-radius: 20px; width: 100%; box-sizing: border-box;
    font-size: 1.05rem; line-height: 1.45; word-wrap: break-word;
}
.message-bubble.model { background-color: var(--model-bubble-bg); color: var(--model-text-color); border-bottom-left-radius: 4px; white-space: normal; }
.message-bubble.user { background-color: var(--user-bubble-bg); color: var(--user-text-color); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.message-bubble.user.editing { background-color: transparent !important; padding: 0 !important; }

.message-bubble.error-bubble { background-color: #FEE2E2; color: #991B1B; border: 1px solid #FCA5A5; }
body.dark-mode .message-bubble.error-bubble { background-color: rgba(127, 29, 29, 0.4); color: #F87171; border: 1px solid rgba(153, 27, 27, 0.5); }

.message-bubble p, .message-bubble ul, .message-bubble ol, .message-bubble pre { margin: 0 0 10px 0; padding: 0; }
.message-bubble > *:last-child { margin-bottom: 0 !important; }
.message-bubble ul, .message-bubble ol { padding-left: 20px; }
.message-bubble li { margin-bottom: 2px; }
.message-bubble.model h1, .message-bubble.model h2, .message-bubble.model h3, .message-bubble.model h4 { margin: 12px 0 6px 0; padding: 0; font-weight: 600; }
.message-bubble.model h1:first-child, .message-bubble.model h2:first-child { margin-top: 0; }
.message-bubble.model h1 { font-size: 1.3em; }
.message-bubble.model h2 { font-size: 1.15em; }
.message-bubble a { color: var(--user-bubble-bg); text-decoration: none; }
.message-bubble.user a { color: #FFFFFF; text-decoration: underline; }
.message-bubble a:hover { text-decoration: underline; }
.message-bubble code { background-color: var(--code-bg); color: var(--code-text); padding: 2px 5px; border-radius: 5px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 0.9em; }
.message-bubble pre { background-color: var(--code-bg); color: var(--code-text); padding: 12px; border-radius: 12px; overflow-x: auto; font-size: 0.85em; margin: 8px 0; white-space: pre; }
.message-bubble pre code { background-color: transparent; padding: 0; }

.katex-error { color: inherit !important; font-family: inherit !important; font-style: inherit !important; font-weight: inherit !important; background: transparent !important; border: none !important; font-size: 1em !important; }
.katex { font-size: 1.1em; }
.katex-display { margin: 0.5em 0 !important; overflow-x: auto; overflow-y: hidden; }

.message-bubble.user img { max-height: 240px; width: auto; height: auto; max-width: 100%; border-radius: 12px; margin-top: 4px; display: block; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.user-file-tag { font-size: 0.85em; background-color: rgba(0,0,0,0.15); padding: 6px 12px; border-radius: 14px; margin-top: 6px; display: inline-block; }

.message-bubble.loading-bubble { 
    display: inline-flex; 
    flex-direction: row; 
    padding: 12px 20px; 
    min-height: 48px; 
    align-items: center; 
    justify-content: center; 
    box-sizing: border-box; 
    gap: 12px;
}
.loading-animation { display: flex; align-items: center; justify-content: center; gap: 4px; height: 24px; }
.loading-animation div { width: 8px; height: 8px; background-color: var(--action-button-color); border-radius: 50%; animation: pulseDots 1.4s infinite ease-in-out both; }
.loading-animation div:nth-child(1) { animation-delay: -0.32s; }
.loading-animation div:nth-child(2) { animation-delay: -0.16s; }
.loading-text { font-size: 0.95rem; opacity: 0.8; font-weight: 500; }

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

.source-grounding-container { margin-top: 12px; border-top: 1px solid var(--border-color); padding-top: 12px; }

.sources-top-row { display: flex; align-items: center; gap: 8px; width: 100%; }

.compact-main-chip { 
    display: flex; align-items: center; gap: 6px; 
    font-size: 0.75rem; font-weight: 500; background: var(--model-bubble-bg); 
    color: var(--text-color) !important; text-decoration: none !important;
    padding: 6px 12px; border-radius: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); 
    border: 1px solid var(--border-color);
    white-space: nowrap; overflow: hidden; transition: transform 0.1s, box-shadow 0.2s;
}
.compact-main-chip:hover { transform: translateY(-1px); box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
.compact-main-chip .truncate { max-width: 160px; overflow: hidden; text-overflow: ellipsis; }

.sources-toggle-pill { 
    display: inline-flex; align-items: center; gap: 4px; height: 32px; box-sizing: border-box;
    padding: 2px 8px 2px 4px; background: rgba(128,128,128,0.1); 
    border-radius: 20px; border: 1px solid var(--border-color); 
    cursor: pointer; transition: background 0.2s; user-select: none;
}
.sources-toggle-pill:hover { background: rgba(128,128,128,0.2); }

.source-icon-stack { display: flex; align-items: center; }
.stacked-icon { 
    width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--model-bubble-bg); 
    background: var(--input-bg); display: flex; align-items: center; justify-content: center; 
    margin-left: -8px; overflow: hidden; 
}
.stacked-icon img { width: 14px; height: 14px; }
.stacked-icon:first-child { margin-left: 0; }
.stacked-more { 
    width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--model-bubble-bg); 
    background: var(--settings-hover-bg); display: flex; align-items: center; justify-content: center; 
    font-size: 0.65rem; font-weight: bold; margin-left: -8px; color: var(--text-color); z-index: 0;
}
.expand-chevron { display: flex; align-items: center; justify-content: center; opacity: 0.5; margin-left: 4px; }
.expand-chevron svg { width: 16px; height: 16px; }

.sources-toggle-pill.close-mode { padding: 4px 10px; font-size: 0.75rem; font-weight: 500; font-family: inherit; color: var(--action-button-color) !important; }
.sources-toggle-pill.close-mode:hover { color: var(--text-color) !important; }
.sources-toggle-pill.close-mode svg { width: 14px; height: 14px; margin-left: 2px; }


.expanded-list { 
    display: flex; flex-wrap: wrap; gap: 6px; 
    background: rgba(128,128,128,0.05); padding: 12px; margin-top: 8px;
    border-radius: 16px; border: 1px solid var(--border-color); 
}
.expanded-source-chip { 
    display: inline-flex; align-items: center; gap: 6px; 
    background: var(--model-bubble-bg); color: inherit !important; text-decoration: none !important; 
    font-size: 0.75rem; padding: 6px 12px; border-radius: 16px; border: 1px solid var(--border-color); 
    font-weight: 500; transition: background 0.2s, transform 0.1s; max-width: 250px; 
}
.expanded-source-chip:hover { background: rgba(128,128,128,0.1); transform: translateY(-1px); box-shadow: 0 2px 6px rgba(0,0,0,0.05); }
.expanded-source-chip .truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.message-meta { width: 100%; margin-top: 6px; }
.message-meta-content { display: flex; justify-content: flex-start; align-items: center; gap: 8px; width: 100%; opacity: 0; transition: opacity 0.2s ease-in-out; padding: 2px 6px; box-sizing: border-box; }
.message-wrapper.user .message-meta-content { justify-content: flex-end; }
.message-inner:hover .message-meta-content { opacity: 1; }

.branch-nav { display: flex; align-items: center; gap: 4px; font-size: 0.75rem; color: var(--action-button-color); user-select: none; font-weight: 500; }
.branch-nav button { background: none; border: none; color: inherit; cursor: pointer; padding: 2px 4px; border-radius: 4px; font-size: 0.8rem; }
.branch-nav button:hover:not(:disabled) { background: var(--settings-hover-bg); color: var(--text-color); }
.branch-nav button:disabled { opacity: 0.3; cursor: not-allowed; }

.message-actions { display: flex; gap: 2px; }
.message-actions button { background: none; border: none; cursor: pointer; color: var(--action-button-color); padding: 6px; display: flex; align-items: center; justify-content: center; border-radius: 6px; }
.message-actions button:hover { background-color: var(--settings-hover-bg); }

.model-badge { margin-left: auto; font-size: 0.7rem; color: var(--action-button-color); font-weight: 500; }

.action-button-wrapper { position: relative; }
.custom-tooltip { 
    position: absolute; 
    bottom: 100%; 
    margin-bottom: 6px; 
    background-color: var(--tooltip-bg); 
    color: var(--tooltip-text-color); 
    padding: 4px 8px; 
    border-radius: 6px; 
    font-size: 0.75rem; 
    font-weight: 500; 
    white-space: nowrap; 
    display: none; 
    z-index: 250;
    pointer-events: none; 
}

.inline-edit-container { display: flex; flex-direction: column; gap: 8px; width: 100%; min-width: 250px; }
.inline-edit-textarea { width: 100%; padding: 12px 20px; border-radius: 20px; border: 1px solid var(--border-color); background: var(--input-bg); color: var(--text-color); font-family: inherit; font-size: 1.05rem; resize: none; overflow-y: hidden; line-height: 1.45; box-sizing: border-box; }
.inline-edit-textarea:focus { outline: none; border-color: var(--action-button-color); }
.inline-edit-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.primary-btn, .secondary-btn { padding: 10px 16px; border-radius: 10px; font-size: 0.95rem; font-weight: 500; font-family: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; box-sizing: border-box; margin: 0; }
.primary-btn { background: var(--user-bubble-bg); color: #FFFFFF; border: none; }
.primary-btn:hover { opacity: 0.9; }
.secondary-btn { background: rgba(0, 0, 0, 0.08); color: var(--text-color); border: 1px solid rgba(0,0,0,0.15); transition: background 0.15s; }
body.dark-mode .secondary-btn { background: rgba(255, 255, 255, 0.12); color: #EDEDED; border: 1px solid rgba(255, 255, 255, 0.25); }
.secondary-btn:hover { background: rgba(0, 0, 0, 0.12); }
body.dark-mode .secondary-btn:hover { background: rgba(255, 255, 255, 0.18); }

.inline-edit-save, .edit-cancel-btn { padding: 8px 14px; font-size: 0.85rem; border-radius: 8px; }

#input-area { 
    position: absolute; 
    bottom: 0; left: 0; right: 0; 
    background: linear-gradient(to top, var(--page-bg) 0%, var(--page-bg) 65px, transparent 110px); 
    padding: 12px 20px 15px 20px; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    gap: 8px; 
    z-index: 100; 
    pointer-events: none; 
}
.input-content-wrapper { width: 100%; max-width: 800px; display: flex; flex-direction: column; gap: 6px; pointer-events: auto; }
#chat-form-container { position: relative; width: 100%; display: flex; justify-content: center; }

.floating-input-container { 
    width: 100%; 
    background-color: rgba(255, 255, 255, 0.4); 
    backdrop-filter: blur(25px) saturate(200%); 
    -webkit-backdrop-filter: blur(25px) saturate(200%); 
    border: 1px solid rgba(255, 255, 255, 0.6); 
    border-radius: 28px; 
    padding: 16px 18px 12px 18px; 
    box-shadow: 0 12px 40px rgba(0,0,0,0.08), inset 0 1px 4px rgba(255, 255, 255, 0.5); 
    display: flex; 
    flex-direction: column; 
}
body.dark-mode .floating-input-container {
    background-color: rgba(30, 30, 32, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 12px 40px rgba(0,0,0,0.3), inset 0 1px 4px rgba(255, 255, 255, 0.05);
}

#chat-query { width: 100%; padding: 0; padding-left: 8px; border-radius: 0; font-size: 1rem; background-color: transparent; color: var(--text-color); border: none; box-sizing: border-box; font-family: inherit; resize: none; overflow-y: auto; min-height: 24px; max-height: 200px; line-height: 1.4; display: block; margin-bottom: 12px; }
#chat-query:focus { outline: none; border-color: transparent; }

.input-controls-row { display: flex; justify-content: space-between; align-items: center; }
.right-controls { display: flex; align-items: center; gap: 8px; }

.web-search-btn { 
    background: transparent; border: none; color: var(--action-button-color); 
    cursor: pointer; padding: 4px; display: flex; align-items: center; justify-content: center; 
    border-radius: 8px; transition: all 0.2s; position: relative; 
}
.web-search-btn:hover { background-color: var(--settings-hover-bg); }
.web-search-btn::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 2px;
    background-color: var(--action-button-color);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
    border-radius: 2px;
    box-shadow: 0 0 0 2px var(--input-bg); 
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}
.web-search-btn.search-disabled::after { opacity: 1; }

.custom-select { position: relative; background-color: rgba(0,0,0,0.05); border: 0.5px solid var(--border-color); border-radius: 8px; color: var(--text-color); font-size: 0.85rem; cursor: pointer; user-select: none; }
body.dark-mode .custom-select { background-color: rgba(255,255,255,0.05); }
.custom-select .select-trigger { display: flex; align-items: center; justify-content: space-between; padding: 0 8px; height: 100%; gap: 8px; }
.custom-select .select-trigger svg { transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1); }
.custom-select.open .select-trigger svg { transform: rotate(180deg); }
.custom-select .options-list { position: absolute; bottom: calc(100% + 6px); top: auto; width: max-content; min-width: 100%; background-color: var(--header-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 0.5px solid var(--border-color); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); display: none; flex-direction: column; z-index: 120; max-height: 200px; overflow-y: auto; padding: 4px; }
.custom-select.open .options-list { display: flex; }
.custom-select .option { padding: 8px 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 8px; transition: background 0.15s; }
.custom-select .option:hover { background-color: var(--settings-hover-bg); }

#custom-model-select { background: transparent; border: none; height: 32px; }
#custom-model-select .select-trigger { padding: 0 4px; color: var(--action-button-color); font-weight: 500; }
#custom-model-select .select-trigger:hover { color: var(--text-color); }
#custom-model-select .options-list { bottom: calc(100% + 8px); right: 0; left: auto; min-width: 180px; }
#custom-history-select { width: 140px; height: 26px; }
#custom-history-select .options-list { top: calc(100% + 4px); bottom: auto; left: 0; }

#send-btn { background-color: var(--user-bubble-bg); border: none; border-radius: 10px; width: 32px; height: 32px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #FFFFFF; transition: opacity 0.2s; }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.settings-wrapper { position: relative; }
#plus-settings-btn { background: none; border: none; border-radius: 10px; width: 32px; height: 32px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--action-button-color); transition: background 0.2s; }
#plus-settings-btn:hover { background-color: var(--settings-hover-bg); color: var(--text-color); }

#settings-menu { display: none; position: absolute; bottom: calc(100% + 8px); left: 0; margin-bottom: 0; background-color: var(--header-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 0.5px solid var(--border-color); border-radius: 14px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); padding: 6px; z-index: 110; min-width: max-content; }
#settings-menu.visible { display: flex; flex-direction: column; gap: 2px; }
.settings-row { display: flex; align-items: center; justify-content: flex-start; height: 34px; padding: 0 10px; gap: 12px; border-radius: 8px; font-size: 0.85rem; color: var(--text-color); box-sizing: border-box; white-space: nowrap; }
.settings-row:hover { background-color: var(--settings-hover-bg); }
.settings-row[role="button"] { cursor: pointer; }
.settings-label { display: flex; align-items: center; gap: 8px; font-weight: 500; flex: 0 0 auto; }

.password-mask { -webkit-text-security: disc; font-family: inherit; }
.settings-input { flex: 0 0 140px; background-color: rgba(0,0,0,0.05); color: var(--text-color); border: 0.5px solid var(--border-color); border-radius: 6px; font-size: 0.85rem; padding: 2px 8px; box-sizing: border-box; font-family: inherit; width: 140px; height: 26px; min-width: 0; }
body.dark-mode .settings-input { background-color: rgba(255,255,255,0.05); }

#file-preview-container { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; padding: 0; }
.file-preview-item { background-color: var(--file-preview-bg); color: var(--file-preview-text); padding: 6px 12px; border-radius: 14px; font-size: 0.85rem; display: flex; align-items: center; gap: 8px; }
.file-preview-item span { max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-preview-item button { background: none; border: none; cursor: pointer; font-size: 1.2rem; line-height: 1; padding: 0; color: var(--file-preview-text); opacity: 0.7;}

#token-display-area { font-size: 0.7rem; color: var(--action-button-color); width: 100%; padding: 10px 8px 0 8px; box-sizing: border-box; display: flex; justify-content: space-between; align-items: center; position: relative; z-index: 10; border-radius: 8px; }
.stats-container { display: flex; align-items: center; }
.clickable-stats { cursor: pointer; opacity: 0.7; transition: opacity 0.2s ease; display: flex; align-items: center; border-radius: 4px; padding: 2px 0; }
.clickable-stats:hover { opacity: 1; }
.stats-info-icon { display: flex; align-items: center; justify-content: center; padding: 0 0 0 6px; }

#global-modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.3); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); z-index: 999; display: flex; justify-content: center; align-items: center; opacity: 1; transition: opacity 0.25s ease-out; }
#global-modal-overlay.hidden { opacity: 0; pointer-events: none; }

.glass-popup { background: var(--header-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 0.5px solid var(--border-color); border-radius: 16px; padding: 24px; box-shadow: 0 12px 48px rgba(0,0,0,0.15); color: var(--text-color); max-width: 400px; width: 90%; display: flex; flex-direction: column; gap: 16px; transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s; transform: scale(1); }
.glass-popup.hidden { display: none !important; transform: scale(0.95); opacity: 0; }
.glass-popup h2 { margin: 0; font-size: 1.25rem; font-weight: 600; }
.glass-popup p { margin: 0; font-size: 0.95rem; line-height: 1.4; opacity: 0.9; }
.glass-popup a { color: var(--user-bubble-bg); text-decoration: none; font-weight: 500; }
.glass-popup a:hover { text-decoration: underline; }
.glass-popup ol, .glass-popup ul { margin: 0; padding-left: 20px; font-size: 0.95rem; line-height: 1.5; opacity: 0.9; }
.glass-popup li { margin-bottom: 6px; }
.stats-list { list-style: none; padding-left: 0 !important; }
.stats-list li { background: var(--settings-hover-bg); padding: 12px; border-radius: 8px; margin-bottom: 8px; }
.stats-desc { font-size: 0.85rem; opacity: 0.8; margin-top: 4px; }
#confirm-message { word-break: break-all; }

#image-modal { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background-color: rgba(0, 0, 0, 0.85); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); z-index: 1000; display: flex; justify-content: center; align-items: center; opacity: 1; transition: opacity 0.25s ease-out; }
#image-modal.hidden { opacity: 0; pointer-events: none; }
#enlarged-image { max-width: 90vw; max-height: 90vh; border-radius: 8px; box-shadow: 0 4px 24px rgba(0,0,0,0.3); object-fit: contain; }
#close-modal { position: absolute; top: 20px; right: 20px; cursor: pointer; padding: 8px; background: rgba(255, 255, 255, 0.2); border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: background 0.2s; }
#close-modal:hover { background: rgba(255, 255, 255, 0.4); }

@media (max-width: 768px) {
    #sidebar { position: fixed; left: -300px; top: 0; bottom: 0; width: 80%; max-width: 300px; transition: left 0.3s ease; }
    body.sidebar-open #sidebar { left: 0; }
    body.sidebar-closed #sidebar { width: 80%; } 
    body.sidebar-open #sidebar-overlay { display: block; }
    #sidebar-resizer { display: none; }
    #menu-btn { display: flex; }
    #toggle-sidebar-btn { display: none; } 
    .history-item-actions { opacity: 1; pointer-events: auto; }
    .message-bubble { max-width: 90%; }
    .message-actions { opacity: 1; }
    body.input-focus-mode header { transform: translateY(-100%); }
    body.input-focus-mode #input-area { padding-top: 8px; padding-bottom: 8px; gap: 5px; }
    body.input-focus-mode #token-display-area { transform: translateY(150%); opacity: 0; pointer-events: none; }
    body.input-focus-mode #chat-container { padding-top: 15px; padding-bottom: 90px; }
    #token-display-area { flex-direction: column; gap: 5px; font-size: 0.65rem; align-items: center; text-align: center; }
}