/* --- Base & Theming --- */
:root {
    --bg-color: #f0f4f9;
    --sidebar-bg: #eaf1f8;
    --chat-bg: #fff;
    --text-primary: #1f1f1f;
    --text-secondary: #5f6368;
    --header-text: #444746;
    --btn-bg: #dde3ea;
    --btn-hover-bg: #d2d8df;
    --input-bg: #eaf1f8;
    --border-color: #dde3ea;
}

body {
    font-family: 'Google Sans', sans-serif;
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden; /* Prevent body scroll */
}

.app-container {
    display: flex;
    height: 100vh;
}

body.sidebar-collapsed #sidebar {
    width: 0;
    padding: 16px 0;
    overflow: hidden;
}

/* --- Icon Button --- */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background-color 0.2s ease;
}
.icon-btn:hover {
    background-color: var(--btn-hover-bg);
}

/* --- Icon Button --- */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background-color 0.2s ease;
}
.icon-btn:hover {
    background-color: var(--btn-hover-bg);
}

/* --- Sidebar --- */
#sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    flex-shrink: 0; /* 防止侧边栏被压缩 */
    justify-content: space-between;
    transition: width 0.3s ease, padding 0.3s ease;
}

.sidebar-main-content {
    display: flex;
    flex-direction: column;
    padding: 16px 10px 0;
    overflow-y: auto;
}

.sidebar-header {
    padding-bottom: 16px;
    flex-shrink: 0;
}

#new-chat-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background-color: var(--btn-bg);
    color: var(--text-primary);
    border: none;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    cursor: pointer;
    width: auto;
    transition: background-color 0.2s ease;
}

#new-chat-btn:hover {
    background-color: var(--btn-hover-bg);
}

.sidebar-footer {
    padding: 16px 10px;
    flex-shrink: 0;
    border-top: 1px solid var(--border-color);
}

#settings-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
}

#settings-btn:hover {
    background-color: var(--btn-bg);
}

.sidebar-content {
    flex-grow: 1;
    overflow-y: auto;
}

.recent-label {
    font-size: 14px;
    font-weight: 500;
    padding: 16px 10px 8px;
    color: var(--text-secondary);
}

#history-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#history-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    font-size: 14px;
}

#history-list li:hover, #history-list li.active {
    background-color: var(--btn-bg);
}

.history-item-text {
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.delete-chat-btn {
    padding: 4px;
    margin-left: 8px;
    visibility: hidden; /* Hide by default */
}

#history-list li:hover .delete-chat-btn {
    visibility: visible; /* Show on hover */
}
/* --- Main Chat Container --- */
#chat-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative; /* 保持相对定位 */
    background-color: var(--chat-bg);
    max-width: 1000px; /* 增加宽度 */
    margin: 0 auto; /* 居中 */
    min-width: 0; /* 关键：允许 flex item 收缩，防止溢出 */
    overflow: hidden; /* 取消滚动条 */
}

/* --- Header --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px; /* Increased vertical padding */
    color: var(--header-text);
    flex-shrink: 0;
}

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

.model-selector-container {
    display: flex;
    align-items: center;
    gap: 4px; /* Reduce gap to give more space to the select element */
    position: relative;
}

.model-selector-container::after {
    content: 'expand_more';
    font-family: 'Material Symbols Outlined';
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none; /* Allow clicks to pass through to the select element */
    color: var(--text-secondary);
}

#model-select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: transparent;
    border: none;
    font-family: 'Google Sans', sans-serif;
    font-size: 22px;
    font-weight: 500;
    color: var(--header-text);
    padding-right: 28px; /* Increase space for dropdown arrow */
    min-width: 240px; /* Widen to fully display model names */
    cursor: pointer;
}

#model-select:hover {
    color: var(--text-primary);
}

h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 500;
    color: inherit;
}

/* --- Messages Area --- */
#chat-messages {
    flex-grow: 1; /* 关键：让消息区域占据所有可用空间 */
    overflow-y: auto; /* 允许内容滚动 */
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.message {
    display: flex;
    gap: 16px;
    max-width: 100%;
}

.message-icon {
    font-size: 24px;
    margin-top: 4px;
    color: var(--header-text);
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0; /* 关键：允许 flex item 收缩，防止内容溢出 */
    flex-grow: 1;
}

.message-sender {
    font-weight: bold;
    font-size: 16px;
    color: var(--text-primary);
}

.message-text {
    line-height: 3;
    font-size: 16px;
    /*white-space: pre-wrap; /* 保持换行和空格 */
    word-break: break-word; /* 强制长单词换行 */
    color: var(--text-primary);
}
/* Reduce margin between paragraphs in Markdown content */
.message-text p {
    margin-top: 0;
    margin-bottom: 0;
}

.message-actions {
    margin-top: 8px;
    display: flex;
    gap: 8px;
}

.message-actions .icon-btn {
    padding: 4px;
}

.copy-feedback {
    color: #2e7d32;
    font-weight: 500;
}

/* --- Thinking Indicator --- */
.thinking-indicator .message-content .message-text::after {
    content: '▋';
    display: inline-block;
    animation: blink 1s infinite;
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}


/* --- Uploaded Files Preview --- */
#uploaded-files-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 10px;
}

.file-preview-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: var(--input-bg);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 14px;
    max-width: 200px;
}

.file-preview-item .file-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-preview-item .remove-file-btn {
    padding: 2px;
    font-size: 18px;
    line-height: 1;
    margin-left: auto;
}

.dark-theme .file-preview-item {
    background-color: var(--btn-bg);
}

/* --- Input Area --- */
#chat-input-container {
    padding: 0 20px 20px 20px;
    flex-shrink: 0;
}

#chat-input-container .info-text {
    font-size: 12px;
    text-align: center;
    color: #5f6368;
    margin-top: 12px;
}

#chat-input {
    display: flex;
    align-items: flex-end;
    padding: 12px 14px 12px 20px;
    border-radius: 28px;
    background-color: var(--input-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

#upload-file-btn {
    margin-right: 8px;
}

#message {
    background: transparent;
    border: none;
    outline: none;
    flex-grow: 1;
    resize: none;
    font-family: 'Google Sans', sans-serif;
    font-size: 16px;
    line-height: 24px;
    max-height: 200px; /* 限制最大高度 */
    color: var(--text-primary);
}

#message::placeholder {
    color: var(--text-secondary);
}

#mic-btn.recording .material-symbols-outlined {
    color: #d93025;
}

#send-btn {
    margin-left: 4px; /* Space between mic and send */
    color: var(--text-secondary);
}

#send-btn:disabled {
    cursor: not-allowed;
    background-color: transparent;
}

#send-btn:not([disabled]) {
    background-color: #0b57d0;
    color: #fff;
    cursor: pointer;
}

#send-btn:not([disabled]):hover {
    background-color: #0a4cb5;
}

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

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

::-webkit-scrollbar-thumb {
    background-color: #d4d4d4;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: #b3b3b3;
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background-color: #fff;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
}
.modal-content { background-color: var(--chat-bg); }

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

.modal-header h2 {
    margin-top: 0;
    margin-bottom: 0;
    font-size: 20px;
}

.modal-body {
    padding: 8px 24px 24px;
    max-height: 70vh;
    overflow-y: auto;
}

.setting-section {
    margin-top: 24px;
}
.setting-section h3 {
    margin-top: 0;
    margin-bottom: 4px;
}
.setting-section p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 0;
}

.input-group {
    margin: 20px 0;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
}

#api-key-input, #model-select, #theme-select, #voice-select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 16px;
    box-sizing: border-box;
    background-color: var(--input-bg);
    color: var(--text-primary);
}

select:hover {
    border-color: var(--text-secondary);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    text-align: right;
}

#save-settings-btn {
    background-color: #0b57d0;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-family: 'Google Sans', sans-serif;
}

#save-settings-btn:hover {
    background-color: #0a4cb5;
}

/* --- Custom Confirm Dialog --- */
.confirm-dialog {
    max-width: 400px;
}
.confirm-dialog .modal-body {
    padding-top: 24px;
    text-align: center;
    font-size: 16px;
}
.confirm-dialog .modal-footer {
    justify-content: flex-end;
    display: flex;
    gap: 12px;
}
#cancel-btn {
    background-color: var(--btn-bg);
    color: var(--text-primary);
}
#confirm-btn {
    background-color: #d93025;
    color: white;
}

/* --- Dark Theme --- */
.dark-theme {
    --bg-color: #131314;
    --sidebar-bg: #1e1f20;
    --chat-bg: #1e1f20;
    --text-primary: #e3e3e3;
    --text-secondary: #8e8f91;
    --header-text: #e3e3e3;
    --btn-bg: #343541;
    --btn-hover-bg: #40414f;
    --input-bg: #343541;
    --border-color: #40414f;
}

.dark-theme #send-btn:disabled {
    color: var(--text-secondary);
}
.dark-theme #send-btn:not([disabled]) {
    background-color: #88a4d4;
    color: #1e1f20;
}
.dark-theme #send-btn:not([disabled]):hover {
    background-color: #a0b9e0;
}

.dark-theme #save-settings-btn {
    background-color: #88a4d4;
    color: #1e1f20;
}
.dark-theme #send-btn:not([disabled]):hover {
    background-color: #a0b9e0;
}

.dark-theme #cancel-btn {
    background-color: var(--btn-bg);
    color: var(--text-primary);
}
.dark-theme #confirm-btn {
    background-color: #e57373;
    color: #131314;
}
.dark-theme ::-webkit-scrollbar-thumb {
    background-color: #4a4a4a;
}

.dark-theme ::-webkit-scrollbar-thumb:hover {
    background-color: #5f5f5f;
}