:root {
  color-scheme: light;
  --theme-bg: #f5f7fa;
  --theme-surface: #ffffff;
  --theme-surface-muted: #fafafa;
  --theme-text: #333333;
  --theme-text-muted: #666666;
  --theme-line: #e6e8ed;
  --theme-primary: #409eff;
  --theme-focus: #1d4ed8;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --theme-bg: #12161f;
  --theme-surface: #1b2230;
  --theme-surface-muted: #202938;
  --theme-text: #f3f6fb;
  --theme-text-muted: #b7c0cf;
  --theme-line: #344052;
  --theme-primary: #79a7ff;
  --theme-focus: #a9c5ff;
  --theme-success: #8be0b1;
  --theme-warning: #ffd08a;
  --theme-danger: #ff9e9a;
  --chat-hint: #b7c0cf;
}
/* Light mode deliberately uses the original page styles. */
html[data-theme="dark"], html[data-theme="dark"] body { background-color: var(--theme-bg); color: var(--theme-text); }
html[data-theme="dark"] :is(.card, .auth-card, .modal-content, .modal-box, .message-item, .reply-item, .task-item, .page-btn, .form-control, .navbar, .nav-menu, .chat-container, .sidebar-tabs, .sidebar-top, .chat-main-header, .chat-input-area, .conv-menu, .call-card, .load-history-btn) { background-color: var(--theme-surface); color: var(--theme-text); border-color: var(--theme-line); }
html[data-theme="dark"] :is(.chat-sidebar, .chat-messages, .chat-empty-state, .pwd-overlay, .load-history-bar, .progress-item, .fw-preview, .fw-tab, .msg-voice, .file-preview-item, .fold-entry, .burn-toggle, .btn-cancel) { background: var(--theme-surface-muted); color: var(--theme-text); border-color: var(--theme-line); }
html[data-theme="dark"] :is(.card-title, .task-title, .item-name, .sidebar-title, .conv-item .conv-name, .friend-list-item .f-name, .fw-preview-text, .fw-row-name, .fw-result-title, .fw-fail-name, .call-peer, .conv-menu .cm-item) { color: var(--theme-text); }
html[data-theme="dark"] :is(.footer, .message-time, .task-meta, .empty-state, .form-group label, .message-info, .progress-time, .item-preview, .item-time, .msg-time, .msg-sender-name, .conv-item .conv-preview, .conv-item .conv-time, .friend-list-item .f-sub, .hint, .fw-row-sub, .fw-status, .fw-empty, .fw-loading, .call-status, .chat-date-split, .voice-hint, .modal-box label, .read-more, .header-icon-btn, .sidebar-icon-btn, .friend-tab, .tool-btn, .msg-voice .voice-dur) { color: var(--theme-text-muted); }
html[data-theme="dark"] :is(input, textarea, select) { color: var(--theme-text); background-color: var(--theme-surface); border-color: var(--theme-line); }
html[data-theme="dark"] ::placeholder { color: var(--theme-text-muted); opacity: 1; }
html[data-theme="dark"] :is(.card-header, .message-detail-header, .message-detail-content, .message-actions, .replies-section, .conv-item, .fw-row, .fw-list, .friend-tabs, .friend-list-item, .member-row, .member-checklist) { border-color: var(--theme-line); }
html[data-theme="dark"] :is(.conv-item.active, .conv-item:hover, .fw-row.checked, .fw-row:hover, .conv-menu .cm-item:hover) { background: #202e4a; }
html[data-theme="dark"] .msg-row:not(.self) .msg-bubble { background: var(--theme-surface); color: var(--theme-text); }
html[data-theme="dark"] .msg-row.self .msg-bubble { background: #153a2a; color: #e0f8ea; }
html[data-theme="dark"] :is(.badge-primary, .direction-badge, .msg-file-attach) { background: #202e4a; color: var(--theme-primary); }
html[data-theme="dark"] :is(.badge-success, .read-flag.read, .call-timer) { color: var(--theme-success); }
html[data-theme="dark"] .badge-success { background: #153a2a; }
html[data-theme="dark"] .badge-warning { background: #49351a; color: var(--theme-warning); }
html[data-theme="dark"] :is(.badge-danger, .badge-urgency, .burn-banner, .burn-toggle.on, .voice-bar, .load-history-retry) { background: #48252a; color: var(--theme-danger); border-color: #865159; }
html[data-theme="dark"] :is(.fw-fail-reason, .conv-menu .cm-item.danger, .pwd-overlay .err, .voice-time) { color: var(--theme-danger); }
html[data-theme="dark"] :is(.msg-skeleton-avatar, .msg-skeleton-bubble) { background: linear-gradient(90deg, #202938 25%, #2a3445 37%, #202938 63%); background-size: 400% 100%; }
html[data-theme="dark"] :is(.user-table, .reset-pwd-modal .modal-box, .btn-sm) { background: var(--theme-surface); color: var(--theme-text); border-color: var(--theme-line); }
html[data-theme="dark"] :is(.user-table th, .badge-no-pwd) { background: var(--theme-surface-muted); color: var(--theme-text-muted); }
html[data-theme="dark"] :is(.user-table th, .user-table td, .tab-header, .tab-header-group, .header-icon-btn, .sidebar-icon-btn, .fw-check) { border-color: var(--theme-line); }
html[data-theme="dark"] :is(.user-table tr:hover, .contact-item:hover, .contact-item.active, .group-item:hover, .group-item.active, .tool-btn:hover, .fold-entry:hover, .sidebar-icon-btn:hover, .conv-menu-btn:hover, .load-history-btn:hover, .load-history-btn:active) { background: #202e4a; }
html[data-theme="dark"] :is(.sidebar-tab, .tab-header, .tab-header-group span, .group-tags, .chat-main-header .sub, .read-flag.sent, .conv-empty, .fold-arrow, .conv-menu .cm-item .cm-ico) { color: var(--theme-text-muted); }
html[data-theme="dark"] :is(.sidebar-tab.active, .sidebar-tab:hover, .friend-tab.active, .msg-file-attach a, .header-icon-btn:hover, .sidebar-icon-btn:hover, .conv-menu .cm-item.primary .cm-ico) { color: var(--theme-primary); border-color: var(--theme-primary); }
html[data-theme="dark"] :is(.conv-item .conv-tag, .conv-item .conv-tag.group-tag) { color: #9bb9ff; border-color: #536b95; }
html[data-theme="dark"] .conv-menu .cm-sep { background: var(--theme-line); }
html[data-theme="dark"] :is(.badge-active, .btn-success) { background: #153a2a; color: var(--theme-success); }
html[data-theme="dark"] :is(.badge-inactive, .btn-sm.btn-danger, .modal-box .btn-danger, .conv-menu .cm-item.danger:hover, .load-history-retry:hover) { background: #48252a; color: var(--theme-danger); border-color: #865159; }
html[data-theme="dark"] :is(.badge-admin, .btn-warn) { background: #49351a; color: var(--theme-warning); }
html[data-theme="dark"] .group-tags .lock { color: var(--theme-warning); }
html[data-theme="dark"] :is(.conv-menu .cm-item.danger .cm-ico, .file-preview-item button) { color: var(--theme-danger); }
html[data-theme="dark"] .fw-tab.active { background: #202e4a; color: #9bb9ff; border-color: #536b95; }
html[data-theme="dark"] .send-btn:disabled { background: #40547e; color: #f3f6fb; }
html[data-theme="dark"] .msg-row .msg-bubble.system { background: transparent; color: var(--theme-text-muted); }
html[data-theme="dark"] :is(.card, .chat-container, .modal-box, .user-table, .admin-header) :is([style*="color:#999"], [style*="color: #999"], [style*="color:#666"], [style*="color: #666"], [style*="color:#c0c4cc"], [style*="color: #909399"]) { color: var(--theme-text-muted) !important; }
html[data-theme="dark"] .card [style*="color: #303133"] { color: var(--theme-text) !important; }
html[data-theme="dark"] :is(.card, .modal-box) :is([style*="color: #409eff"], [style*="color:#1677ff"]) { color: var(--theme-primary) !important; }
html[data-theme="dark"] :is(.card, .user-table) :is([style*="color: #67c23a"], [style*="color:#27ae60"]) { color: var(--theme-success) !important; }
html[data-theme="dark"] :is(.card, .modal-box) :is([style*="color: #e6a23c"], [style*="color:#f39c12"]) { color: var(--theme-warning) !important; }
html[data-theme="dark"] :is(.card, .modal-box, .user-table) :is([style*="color: #f56c6c"], [style*="color:#ff4d4f"], [style*="color:#e74c3c"]) { color: var(--theme-danger) !important; }
html[data-theme="dark"] .card [style*="background: #fef0f0"] { background: #48252a !important; }
html[data-theme="dark"] .card [style*="border: 1px solid #e4e7ed"] { border-color: var(--theme-line) !important; }
html[data-theme="dark"] #qrFallback { background: var(--theme-surface-muted) !important; }
html[data-theme="dark"] .modal-box button[style*="background:#ddd"] { background: var(--theme-surface-muted) !important; color: var(--theme-text) !important; }
html[data-theme="dark"] .alert-success { background: #153a2a; color: var(--theme-success); border-color: #496956; }
html[data-theme="dark"] :is(.alert-error, .alert-danger) { background: #48252a; color: var(--theme-danger); border-color: #865159; }
html[data-theme="dark"] .alert-warning { background: #49351a; color: var(--theme-warning); }
html[data-theme="dark"] .alert-info { background: #202e4a; color: var(--theme-primary); }
.theme-toggle { min-height: 40px; padding: 8px 12px; border: 1px solid currentColor; border-radius: 999px; background: transparent; color: inherit; cursor: pointer; font: inherit; }
.site-header .theme-toggle { color: var(--header-fg); white-space: nowrap; }
.theme-toggle:focus-visible, button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--theme-focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; } }
