:root {
    --bg-dark: #1a1a1a;
    --bg-side: #242424;
    --bg-input: #2d2d2d;
    --accent: #007acc;
    --accent-hover: #005a9e;
    --text-main: #d4d4d4;
    --text-dim: #888;
    --border: #3a3a3a;
    --success: #4caf50;
    --danger: #e74c3c;
    --warning: #f39c12;
    --info: #3498db;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    height: 100dvh;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    margin: 0;
    display: flex;
    overflow: hidden;
}

.app-container {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
}

/* ========== 顶部通知容器 ========== */
.notice-container {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.top-notice {
    background: rgba(0, 122, 204, 0.95);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.3s ease;
    pointer-events: auto;
    max-width: 90vw;
    text-align: center;
}

.top-notice.show {
    opacity: 1;
    transform: translateY(0);
}

.top-notice.hide {
    opacity: 0;
    transform: translateY(-20px);
}

/* ========== 移动端顶栏 ========== */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: var(--bg-side);
    border-bottom: 1px solid var(--border);
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    z-index: 100;
}

.mobile-header button {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.3rem;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.2s;
}

.mobile-header button:active {
    background: rgba(255,255,255,0.1);
}

.header-actions {
    display: flex;
    gap: 4px;
}

.header-btn {
    font-size: 1.1rem !important;
}

.current-chat-title {
    font-size: 0.95rem;
    font-weight: 600;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.current-chat-title:hover {
    background: rgba(255,255,255,0.1);
}

/* ========== 侧边栏通用 ========== */
.sidebar {
    background-color: var(--bg-side);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 15px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--accent);
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.sidebar-scroll h3 {
    font-size: 0.8rem;
    margin: 20px 0 10px 0;
    color: var(--accent);
}

.sidebar-scroll h3:first-child {
    margin-top: 0;
}

.sidebar-footer {
    padding: 15px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ========== 隐私徽章 ========== */
.privacy-badge {
    text-align: center;
    font-size: 0.7rem;
    color: var(--success);
    padding: 6px 10px;
    background: rgba(76, 175, 80, 0.1);
    border: 1px solid rgba(76, 175, 80, 0.2);
    border-radius: 6px;
    cursor: help;
}

/* ========== 会话列表侧边栏 ========== */
.sessions-sidebar {
    width: 260px;
    min-width: 260px; /* 已修改：固定最小宽度 */
    max-width: 260px; /* 已修改：固定最大宽度 */
    flex-shrink: 0;   /* 已修改：禁止 flex 挤压收缩 */
}

.new-chat-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.new-chat-btn:hover {
    background: var(--accent-hover);
}

.session-search-box {
    padding: 10px 15px;
    border-bottom: 1px solid var(--border);
}

.session-search-box input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 6px;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.session-search-box input:focus {
    border-color: var(--accent);
}

.sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.session-item {
    display: flex;
    align-items: center;
    padding: 12px;
    margin-bottom: 6px;
    background: var(--bg-input);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    gap: 8px;
}

.session-item:hover {
    background: #383838;
}

.session-item.active {
    background: var(--accent);
    color: white;
}

.session-item.hidden {
    display: none;
}

.session-item .session-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
}

.session-item .session-meta {
    font-size: 0.7rem;
    color: var(--text-dim);
    flex-shrink: 0;
}

.session-item.active .session-meta {
    color: rgba(255,255,255,0.7);
}

.session-item .session-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--danger);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px 8px;
    transition: opacity 0.2s;
    border-radius: 4px;
    flex-shrink: 0;
}

.session-item:hover .session-delete {
    opacity: 1;
}

.session-item.active .session-delete {
    color: rgba(255,255,255,0.8);
}

.session-item.active .session-delete:hover {
    color: white;
}

.toggle-config-btn {
    width: 100%;
    padding: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.toggle-config-btn:hover {
    background: #383838;
}

/* ========== 配置侧边栏 ========== */
.config-sidebar {
    width: 320px;
    min-width: 280px;
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    transform: translateX(100%);
    z-index: 200;
    border-left: 1px solid var(--border);
    border-right: none;
}

.config-sidebar.open {
    transform: translateX(0);
}

.close-config-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.2s;
}

.close-config-btn:hover {
    color: var(--text-main);
}

/* ========== 隐私与安全框 ========== */
.privacy-box {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    font-size: 0.8rem;
    line-height: 1.6;
}

.privacy-box p {
    margin: 0 0 8px 0;
    color: var(--text-main);
}

.privacy-box p:last-of-type {
    margin-bottom: 12px;
}

.privacy-box strong {
    color: var(--success);
}

.danger-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    margin-top: 4px;
}

.danger-btn:hover {
    background: var(--danger);
    color: white;
}

/* ========== 测试连接按钮 ========== */
.test-api-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--success);
    color: var(--success);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    margin-top: 4px;
}

.test-api-btn:hover {
    background: var(--success);
    color: white;
}

.test-api-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========== 调试日志面板 ========== */
.debug-panel {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 35vh;
    max-height: 300px;
    background: #0d1117;
    border-top: 2px solid var(--accent);
    z-index: 250;
    flex-direction: column;
}

.debug-panel.active {
    display: flex;
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    background: #161b22;
    border-bottom: 1px solid #30363d;
    flex-shrink: 0;
}

.debug-header h3 {
    margin: 0;
    font-size: 0.85rem;
    color: var(--accent);
}

.debug-actions {
    display: flex;
    gap: 8px;
}

.debug-action-btn {
    padding: 4px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 4px;
    font-size: 0.7rem;
    cursor: pointer;
    transition: background 0.2s;
}

.debug-action-btn:hover {
    background: #383838;
}

.debug-close-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px 8px;
}

.debug-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.7rem;
    line-height: 1.5;
}

.debug-entry {
    margin-bottom: 6px;
    padding: 5px 8px;
    background: #21262d;
    border-radius: 4px;
    border-left: 3px solid var(--text-dim);
}

.debug-entry.info {
    border-left-color: var(--info);
}

.debug-entry.success {
    border-left-color: var(--success);
}

.debug-entry.warning {
    border-left-color: var(--warning);
}

.debug-entry.error {
    border-left-color: var(--danger);
}

.debug-time {
    color: var(--text-dim);
    margin-right: 8px;
}

.debug-type {
    font-weight: 600;
    margin-right: 8px;
    text-transform: uppercase;
    font-size: 0.6rem;
}

.debug-entry.info .debug-type { color: var(--info); }
.debug-entry.success .debug-type { color: var(--success); }
.debug-entry.warning .debug-type { color: var(--warning); }
.debug-entry.error .debug-type { color: var(--danger); }

.debug-message {
    color: var(--text-main);
    word-break: break-all;
}

.debug-details {
    margin-top: 4px;
    padding: 4px 6px;
    background: #0d1117;
    border-radius: 3px;
    color: #8b949e;
    white-space: pre-wrap;
    max-height: 100px;
    overflow-y: auto;
    font-size: 0.65rem;
}

/* ========== 搜索面板 ========== */
.search-panel {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-dark);
    z-index: 250;
    flex-direction: column;
}

.search-panel.active {
    display: flex;
}

.search-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    background: var(--bg-side);
    border-bottom: 1px solid var(--border);
}

.search-input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0 12px;
    transition: border-color 0.2s;
}

.search-input-wrapper:focus-within {
    border-color: var(--accent);
}

.search-icon {
    font-size: 1rem;
    margin-right: 8px;
    opacity: 0.6;
}

.search-input-wrapper input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-main);
    padding: 10px 0;
    font-size: 1rem;
    outline: none;
}

.search-clear-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.search-input-wrapper input:not(:placeholder-shown) + .search-clear-btn {
    opacity: 1;
}

.search-close-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.95rem;
    cursor: pointer;
    padding: 8px 12px;
    white-space: nowrap;
}

.search-results {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.search-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-dim);
    text-align: center;
}

.search-placeholder-icon {
    font-size: 3rem;
    margin-bottom: 15px;
    opacity: 0.5;
}

.search-placeholder p {
    margin: 0;
    font-size: 0.9rem;
}

.search-result-item {
    background: var(--bg-side);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 15px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.search-result-item:hover {
    border-color: var(--accent);
    background: #2a2a2a;
}

.search-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.search-result-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent);
}

.search-result-meta {
    font-size: 0.75rem;
    color: var(--text-dim);
}

.search-result-content {
    font-size: 0.85rem;
    color: var(--text-main);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.search-result-content mark {
    background: var(--warning);
    color: #000;
    padding: 0 2px;
    border-radius: 2px;
}

.search-no-results {
    text-align: center;
    color: var(--text-dim);
    padding: 40px 20px;
}

.search-no-results-icon {
    font-size: 3rem;
    margin-bottom: 15px;
    opacity: 0.5;
}

/* ========== 预设/API管理器 ========== */
.preset-manager {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}

.preset-select {
    flex: 1;
    padding: 8px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
}

.preset-select:focus {
    border-color: var(--accent);
}

.preset-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.preset-btn.add {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.preset-btn.add:hover {
    background: #45a049;
}

.preset-btn.delete {
    background: var(--bg-input);
    color: var(--text-dim);
}

.preset-btn.delete:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.save-preset-btn {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    border: none;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    margin-top: 8px;
    transition: background 0.2s;
}

.save-preset-btn:hover {
    background: var(--accent-hover);
}

.config-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.config-group label {
    font-size: 0.75rem;
    color: var(--text-dim);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.config-group label span {
    color: var(--accent);
    font-weight: 600;
    font-family: 'Consolas', monospace;
}

.config-hint {
    font-size: 0.7rem;
    color: var(--text-dim);
    opacity: 0.8;
}

.checkbox-label {
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px !important;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.checkbox-label span {
    color: var(--text-main) !important;
    font-weight: normal !important;
    font-family: inherit !important;
}

.config-group input[type="text"],
.config-group input[type="password"],
.config-group input[type="number"],
.config-group textarea,
.config-group select {
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: #fff;
    border-radius: 6px;
    outline: none;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

.config-group input:focus,
.config-group textarea:focus,
.config-group select:focus {
    border-color: var(--accent);
}

.config-group textarea {
    resize: vertical;
    min-height: 80px;
    font-family: inherit;
    line-height: 1.5;
}

.config-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #444;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.config-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

/* ========== 模型输入组 ========== */
.model-input-group {
    display: flex;
    gap: 6px;
}

.model-input-group input {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: #fff;
    border-radius: 6px;
    outline: none;
    font-size: 0.9rem;
    transition: border-color 0.2s;
    min-width: 0;
}

.model-input-group input:focus {
    border-color: var(--accent);
}

.fetch-models-btn {
    width: 42px;
    height: 42px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.fetch-models-btn:hover {
    background: #383838;
    border-color: var(--accent);
}

.fetch-models-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.fetch-models-btn.loading {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.model-select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
}

.model-select:focus {
    border-color: var(--accent);
}

.model-count {
    font-size: 0.7rem;
    color: var(--success);
    font-weight: normal;
}

/* ========== 统计和信息框 ========== */
.stats-box {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    flex: 1;
}

.stat-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent);
    font-family: 'Consolas', monospace;
}

.stat-unit {
    font-size: 0.7rem;
    color: #666;
}

.info-box {
    font-size: 0.8rem;
    background: var(--bg-input);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.info-box ul {
    margin: 0;
    padding-left: 0;
    list-style: none;
}

.info-box li {
    padding: 4px 0;
}

.info-box code {
    background: #444;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8em;
    color: var(--accent);
}

.info-tip {
    margin: 10px 0 0 0;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.75rem;
}

/* ========== 遮罩层 ========== */
.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
}

.overlay.active {
    display: block;
}

/* ========== 主内容区 ========== */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    min-width: 0;
}

.chat-window {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    will-change: scroll-position;
}

/* ========== 欢迎页 ========== */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    color: var(--text-dim);
    padding: 40px 20px;
}

.welcome-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

.welcome-screen h2 {
    margin: 0 0 10px 0;
    color: var(--text-main);
    font-size: 1.3rem;
}

.welcome-screen p {
    margin: 0 0 30px 0;
    font-size: 0.9rem;
}

.welcome-tips {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tip-item {
    background: var(--bg-input);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--text-main);
}

/* ========== 消息气泡 ========== */
.message {
    position: relative;
    max-width: 85%;
    padding: 12px 16px;
    padding-top: 24px;
    border-radius: 12px;
    line-height: 1.7;
    word-wrap: break-word;
    transition: all 0.2s ease;
    cursor: default;
    contain: layout style;
}

.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #005a9e, #007acc);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: #2d2d2d;
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message.hidden-msg {
    opacity: 0.7;
    border-style: dashed !important;
}

.message.hidden-msg .content {
    opacity: 0.85;
}

.message.highlight {
    animation: highlightPulse 2s ease;
}

@keyframes highlightPulse {
    0%, 100% { box-shadow: none; }
    25%, 75% { box-shadow: 0 0 0 3px var(--warning); }
}

.message.selectable {
    cursor: pointer;
}

.message.selectable:hover {
    transform: scale(1.01);
}

.message.selected {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.message.selected::after {
    content: '✓';
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: bold;
}

.msg-edit-btn {
    position: absolute;
    top: 2px;
    right: 8px;
    width: 26px;
    height: 26px;
    background: var(--bg-side);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    z-index: 10;
}

.message:hover .msg-edit-btn {
    opacity: 1;
}

.msg-edit-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
}

/* 消息元数据 - 放在消息内部顶部 */
.message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.65rem;
    color: #888;
    margin-bottom: 6px;
    margin-top: -8px;
}

.floor-num {
    background: rgba(255,255,255,0.1);
    padding: 1px 6px;
    border-radius: 3px;
}

.token-count {
    color: #777;
    font-family: 'Consolas', monospace;
}

/* 隐藏标记 - 简洁的文字标签 */
.hidden-tag {
    display: inline-block;
    padding: 1px 8px;
    font-size: 0.65rem;
    color: var(--warning);
    background: rgba(243, 156, 18, 0.15);
    border: 1px solid rgba(243, 156, 18, 0.3);
    border-radius: 10px;
    line-height: 1.4;
    font-weight: 500;
}

/* 正在思考指示器 */
.typing-indicator {
    color: #666;
    font-style: italic;
}

.message .content {
    user-select: text;
    -webkit-user-select: text;
}

/* ========== Markdown 样式 ========== */
.message .content p {
    margin: 0 0 10px 0;
}

.message .content p:last-child {
    margin-bottom: 0;
}

.message .content h1,
.message .content h2,
.message .content h3,
.message .content h4,
.message .content h5,
.message .content h6 {
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.4;
}

.message .content h1 { font-size: 1.4em; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.message .content h2 { font-size: 1.25em; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.message .content h3 { font-size: 1.1em; }
.message .content h4 { font-size: 1em; }

.message .content ul,
.message .content ol {
    margin: 10px 0;
    padding-left: 24px;
}

.message .content li {
    margin: 4px 0;
}

.message .content blockquote {
    margin: 10px 0;
    padding: 10px 15px;
    border-left: 4px solid var(--accent);
    background: rgba(0,122,204,0.1);
    border-radius: 0 6px 6px 0;
}

.message .content blockquote p {
    margin: 0;
}

.message .content code {
    background: rgba(255,255,255,0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.message .content pre {
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    overflow: visible;
}

.message .content pre code {
    display: block;
    padding: 14px;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 0 0 8px 8px;
    overflow-x: auto;
    font-size: 0.85em;
    line-height: 1.5;
}

.message .content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.9em;
}

.message .content th,
.message .content td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}

.message .content th {
    background: rgba(255,255,255,0.05);
    font-weight: 600;
}

.message .content tr:nth-child(even) {
    background: rgba(255,255,255,0.02);
}

.message .content a {
    color: var(--accent);
    text-decoration: none;
}

.message .content a:hover {
    text-decoration: underline;
}

.message .content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

.message .content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 8px 0;
}

.message .content strong {
    font-weight: 600;
    color: #fff;
}

.message .content em {
    font-style: italic;
    color: #b0b0b0;
}

.message.user .content code {
    background: rgba(255,255,255,0.2);
}

.message.user .content pre code {
    background: rgba(0,0,0,0.3);
    border-color: rgba(255,255,255,0.2);
}

.message.user .content blockquote {
    border-left-color: rgba(255,255,255,0.5);
    background: rgba(255,255,255,0.1);
}

.message.user .content th,
.message.user .content td {
    border-color: rgba(255,255,255,0.3);
}

.message.user .content th {
    background: rgba(255,255,255,0.1);
}

.message.user .content strong {
    color: #fff;
}

.message.user .content a {
    color: #8fd4ff;
}

.message.user .message-meta {
    color: rgba(255,255,255,0.5);
}

.message.user .floor-num {
    background: rgba(255,255,255,0.15);
}

.message.user .token-count {
    color: rgba(255,255,255,0.4);
}

.message.user .hidden-tag {
    background: rgba(243, 156, 18, 0.25);
    border-color: rgba(243, 156, 18, 0.4);
    color: #ffd280;
}

.message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.message-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s;
    object-fit: cover;
}

.message-image:hover {
    transform: scale(1.02);
}

/* ========== 代码块折叠功能 ========== */
.code-block-wrapper {
    position: relative;
    margin: 12px 0;
}

.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: #161b22;
    border: 1px solid #30363d;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}

.code-block-header:hover {
    background: #1c2128;
}

.code-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.code-toggle-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.7rem;
    cursor: pointer;
    padding: 2px 4px;
    transition: transform 0.2s;
}

.code-block-lang {
    color: var(--text-dim);
    text-transform: uppercase;
}

.code-copy-btn {
    background: #484f58;
    color: #c9d1d9;
    border: none;
    padding: 4px 10px;
    font-size: 0.7rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.code-copy-btn:hover {
    background: #6e7681;
}

.code-block-wrapper pre {
    margin: 0 !important;
    max-height: 500px;
    overflow: auto;
    transition: max-height 0.3s ease;
}

.code-block-wrapper.collapsed pre {
    max-height: 0;
    overflow: hidden;
    padding: 0 !important;
}

.code-block-wrapper.collapsed .code-block-header {
    border-radius: 8px;
    border-bottom: 1px solid #30363d;
}

.code-block-wrapper.collapsed pre code {
    padding: 0;
    border: none;
}

/* ========== 选择模式操作栏 ========== */
.selection-bar {
    display: none;
    padding: 12px 15px;
    background: var(--bg-side);
    border-top: 1px solid var(--border);
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.selection-bar.active {
    display: flex;
}

.selection-count {
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 600;
}

.selection-actions {
    display: flex;
    gap: 8px;
}

.sel-btn {
    padding: 8px 14px;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.sel-btn.show-btn {
    background: var(--success);
    color: white;
}

.sel-btn.hide-btn {
    background: var(--warning);
    color: white;
}

.sel-btn.delete-btn {
    background: var(--danger);
    color: white;
}

.sel-btn.cancel-btn {
    background: var(--bg-input);
    color: var(--text-main);
}

.sel-btn:hover:not(:disabled) {
    filter: brightness(1.1);
}

.sel-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========== 图片预览栏 ========== */
.image-preview-bar {
    display: none;
    padding: 10px 15px;
    background: var(--bg-side);
    border-top: 1px solid var(--border);
}

.image-preview-bar.active {
    display: block;
}

.image-preview-list {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 5px;
}

.image-preview-item {
    position: relative;
    flex-shrink: 0;
}

.image-preview-thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid var(--border);
}

.image-preview-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========== 输入区 ========== */
.input-area {
    padding: 12px 15px;
    padding-bottom: calc(12px + var(--safe-bottom));
    background: var(--bg-side);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.input-area.hidden {
    display: none;
}

.input-side-buttons {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    transition: flex-direction 0.2s;
}

.input-side-buttons.vertical {
    flex-direction: column;
}

.side-btn {
    padding: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.2s;
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.side-btn:hover {
    background: #383838;
}

.side-btn.active,
#select-mode-btn.active {
    background: var(--accent);
    border-color: var(--accent);
}

#image-btn.has-images {
    background: var(--success);
    border-color: var(--success);
}

#message-input {
    flex-grow: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: white;
    padding: 12px 14px;
    border-radius: 8px;
    resize: none;
    font-size: 1rem;
    line-height: 1.5;
    outline: none;
    max-height: 120px;
    font-family: inherit;
    min-width: 0;
}

#message-input:focus {
    border-color: var(--accent);
}

.input-area.expanded #message-input {
    flex-grow: 1;
}

#send-button {
    padding: 12px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

#send-button:hover {
    background: var(--accent-hover);
}

#send-button:disabled {
    background: #444;
    color: #777;
    cursor: not-allowed;
}

#send-button.hidden {
    display: none;
}

.stop-btn {
    padding: 12px 20px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.stop-btn:hover {
    background: #c0392b;
}

.stop-btn.hidden {
    display: none;
}

/* ========== 自定义弹窗 ========== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 300;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-box {
    background: var(--bg-side);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    max-width: 360px;
    width: 90%;
    text-align: center;
}

.modal-box p {
    margin: 0 0 20px 0;
    font-size: 0.95rem;
    line-height: 1.5;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.modal-btn {
    padding: 10px 24px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.modal-btn.cancel {
    background: var(--bg-input);
    color: var(--text-main);
}

.modal-btn.cancel:hover {
    background: #383838;
}

.modal-btn.confirm {
    background: var(--danger);
    color: white;
}

.modal-btn.confirm:hover {
    background: #c0392b;
}

/* ========== 右键菜单 ========== */
.context-menu {
    display: none;
    position: fixed;
    background: var(--bg-side);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 0;
    min-width: 150px;
    z-index: 400;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.context-menu.active {
    display: block;
}

.context-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
}

.context-item:hover {
    background: var(--bg-input);
}

.context-item.hidden {
    display: none;
}

/* ========== 重命名弹窗 ========== */
.rename-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 300;
    align-items: center;
    justify-content: center;
}

.rename-modal.active {
    display: flex;
}

.rename-box {
    background: var(--bg-side);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    max-width: 320px;
    width: 90%;
}

.rename-box h3 {
    margin: 0 0 16px 0;
    font-size: 1rem;
    color: var(--accent);
}

.rename-box input {
    width: 100%;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: white;
    border-radius: 6px;
    font-size: 0.95rem;
    outline: none;
    margin-bottom: 16px;
}

.rename-box input:focus {
    border-color: var(--accent);
}

.rename-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.rename-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.rename-btn.cancel {
    background: var(--bg-input);
    color: var(--text-main);
}

.rename-btn.confirm {
    background: var(--accent);
    color: white;
}

.rename-btn:hover {
    filter: brightness(1.1);
}

/* ========== 编辑消息弹窗 ========== */
.edit-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 300;
    align-items: center;
    justify-content: center;
}

.edit-modal.active {
    display: flex;
}

.edit-box {
    background: var(--bg-side);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
}

.edit-box h3 {
    margin: 0 0 16px 0;
    font-size: 1rem;
    color: var(--accent);
}

.edit-box textarea {
    width: 100%;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: white;
    border-radius: 6px;
    font-size: 0.95rem;
    outline: none;
    resize: vertical;
    min-height: 120px;
    font-family: inherit;
    line-height: 1.5;
}

.edit-box textarea:focus {
    border-color: var(--accent);
}

.edit-options {
    margin: 12px 0 16px 0;
}

.edit-option {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-dim);
    cursor: pointer;
}

.edit-option input[type="checkbox"] {
    margin-top: 2px;
    accent-color: var(--accent);
}

.edit-option span {
    line-height: 1.4;
}

.edit-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.edit-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.edit-btn.cancel {
    background: var(--bg-input);
    color: var(--text-main);
}

.edit-btn.confirm {
    background: var(--accent);
    color: white;
}

.edit-btn:hover {
    filter: brightness(1.1);
}

/* ========== 新建弹窗 ========== */
.create-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 300;
    align-items: center;
    justify-content: center;
}

.create-modal.active {
    display: flex;
}

.create-box {
    background: var(--bg-side);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    max-width: 320px;
    width: 90%;
}

.create-box h3 {
    margin: 0 0 16px 0;
    font-size: 1rem;
    color: var(--accent);
}

.create-box input {
    width: 100%;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: white;
    border-radius: 6px;
    font-size: 0.95rem;
    outline: none;
    margin-bottom: 16px;
}

.create-box input:focus {
    border-color: var(--accent);
}

.create-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.create-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.create-btn.cancel {
    background: var(--bg-input);
    color: var(--text-main);
}

.create-btn.confirm {
    background: var(--success);
    color: white;
}

.create-btn:hover {
    filter: brightness(1.1);
}

/* ========== 图片查看器 ========== */
.image-viewer {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 500;
    align-items: center;
    justify-content: center;
}

.image-viewer.active {
    display: flex;
}

.image-viewer-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    font-size: 1.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.image-viewer-close:hover {
    background: rgba(255,255,255,0.2);
}

#image-viewer-img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 8px;
}

/* ========== 滚动条 ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

/* ========== 移动端适配 ========== */
@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    .sessions-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        min-width: 280px; /* 移动端同样保持固定 */
        max-width: 280px;
        transform: translateX(-100%);
        z-index: 200;
    }

    .sessions-sidebar.open {
        transform: translateX(0);
    }

    .config-sidebar {
        max-width: 85vw;
    }

    .main-content {
        padding-top: 50px;
    }

    .chat-window {
        padding: 15px;
        gap: 14px;
    }

    .message {
        max-width: 90%;
        padding: 10px 14px;
        padding-top: 22px;
    }

    .msg-edit-btn {
        opacity: 1;
    }

    .input-area {
        padding: 10px;
        padding-bottom: calc(10px + var(--safe-bottom));
    }

    #message-input {
        padding: 10px 12px;
        font-size: 16px;
    }

    #send-button,
    .stop-btn {
        padding: 10px 16px;
    }

    .session-item .session-delete {
        opacity: 1;
    }

    .selection-bar {
        flex-wrap: wrap;
    }

    .selection-actions {
        flex-wrap: wrap;
    }

    .sel-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .edit-box {
        max-width: 95%;
    }

    .message-image {
        max-width: 150px;
        max-height: 150px;
    }

    .debug-panel {
        height: 30vh;
        max-height: 200px;
    }

    .notice-container {
        top: 55px;
    }

    .modal-box {
        max-width: 90%;
    }
}

/* ========== 超小屏幕适配 ========== */
@media (max-width: 380px) {
    .input-side-buttons {
        flex-direction: column;
    }

    .side-btn {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }

    #send-button,
    .stop-btn {
        padding: 10px 12px;
        font-size: 0.8rem;
    }

    .selection-actions {
        gap: 4px;
    }

    .sel-btn {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
}

/* ========== 大屏幕适配 ========== */
@media (min-width: 1200px) {
    .message {
        max-width: 70%;
    }

    .chat-window {
        padding: 30px 40px;
    }
}

@media (min-width: 1600px) {
    .message {
        max-width: 60%;
    }

    .chat-window {
        padding: 30px 60px;
    }
}