/* 工作台与每个设置预览共用同一组主题变量。 */
/* 图片配色的顶栏直接使用原图色值，文字和控件使用相应的深浅色。 */
[data-theme="mint"], [data-palette="mint"]       { --source-color: #38ba91; --header-ink: #101014; }
[data-theme="teal"], [data-palette="teal"]       { --source-color: #18947e; --header-ink: #101014; }
[data-theme="sky"], [data-palette="sky"]         { --source-color: #6fcbdd; --header-ink: #101014; }
[data-theme="olive"], [data-palette="olive"]     { --source-color: #66861d; --header-ink: #08090b; }
[data-theme="gold"], [data-palette="gold"]       { --source-color: #eaa822; --header-ink: #101014; }
[data-theme="magenta"], [data-palette="magenta"] { --source-color: #e11665; --header-ink: #fff; --search-tint: #000; }
[data-theme="red"], [data-palette="red"]         { --source-color: #ce0e0d; --header-ink: #fff; --search-tint: #000; }
[data-theme="grape"], [data-palette="grape"]     { --source-color: #311039; --header-ink: #fff; --search-tint: #000; }

:where(html[data-theme], [data-palette]) {
  --theme-header: var(--source-color);
  --theme-accent: color-mix(in srgb, var(--source-color) 53%, #191920);
  --theme-accent-strong: color-mix(in srgb, var(--source-color) 38%, #191920);
  --theme-accent-soft: color-mix(in srgb, var(--source-color) 9%, white);
  --theme-accent-border: color-mix(in srgb, var(--source-color) 42%, #d4d5d8);
  --theme-selected: color-mix(in srgb, var(--source-color) 23%, white);
  --theme-ink: color-mix(in srgb, var(--source-color) 12%, #202024);
  --theme-muted: color-mix(in srgb, var(--source-color) 15%, #505157);
  --theme-line: color-mix(in srgb, var(--source-color) 12%, #e2e2e4);
  --theme-canvas: color-mix(in srgb, var(--source-color) 3%, white);
  --theme-surface: white;
  --theme-sidebar: color-mix(in srgb, var(--source-color) 40%, #24232a);
  --theme-sidebar-deep: color-mix(in srgb, var(--source-color) 29%, #18171e);
  --theme-sidebar-ink: white;
  --theme-sidebar-muted: color-mix(in srgb, var(--source-color) 11%, white);
  --theme-focus: var(--theme-accent);
  --theme-own-bubble: color-mix(in srgb, var(--source-color) 13%, white);
  --theme-own-bubble-ink: var(--theme-ink);
  --theme-tree-wire: color-mix(in srgb, var(--source-color) 38%, #a1a3a8);
  --theme-search: color-mix(in srgb, var(--source-color) 82%, var(--search-tint, white));
  --theme-search-hover: color-mix(in srgb, var(--source-color) 66%, var(--search-tint, white));
}

html[data-theme="plum"],
[data-palette="plum"] {
  --theme-accent: #704078;
  --theme-accent-strong: #542d5d;
  --theme-accent-soft: #f4eef6;
  --theme-accent-border: #d7c5dc;
  --theme-selected: #f0dbf0;
  --theme-ink: #27222a;
  --theme-muted: #6a6470;
  --theme-line: #e2dfe4;
  --theme-canvas: #faf9fb;
  --theme-surface: #fff;
  --theme-header: #321b36;
  --theme-sidebar: #48274c;
  --theme-sidebar-deep: #39203d;
  --theme-sidebar-ink: #f1e7f3;
  --theme-sidebar-muted: #d7bfdc;
  --theme-focus: #9b70a7;
  --theme-own-bubble: #f6eff8;
  --theme-own-bubble-ink: #34253a;
  --theme-tree-wire: #b9a8bd;
  --theme-search: #604663;
  --theme-search-hover: #705773;
}

html[data-theme="ocean"],
[data-palette="ocean"] {
  --theme-accent: #286b96;
  --theme-accent-strong: #174b6d;
  --theme-accent-soft: #e9f4fa;
  --theme-accent-border: #bad6e5;
  --theme-selected: #dceef7;
  --theme-ink: #1c2d3d;
  --theme-muted: #627487;
  --theme-line: #d7e2e9;
  --theme-canvas: #f5f9fb;
  --theme-surface: #fff;
  --theme-header: #15394f;
  --theme-sidebar: #1d4961;
  --theme-sidebar-deep: #15394e;
  --theme-sidebar-ink: #eaf5fa;
  --theme-sidebar-muted: #bfd9e5;
  --theme-focus: #4b98c1;
  --theme-own-bubble: #e7f3f9;
  --theme-own-bubble-ink: #1d4055;
  --theme-tree-wire: #9ebdce;
  --theme-search: #315f78;
  --theme-search-hover: #3b708d;
}

html[data-theme="forest"],
[data-palette="forest"] {
  --theme-accent: #347354;
  --theme-accent-strong: #21543b;
  --theme-accent-soft: #eaf4ed;
  --theme-accent-border: #c1ddc9;
  --theme-selected: #dceee1;
  --theme-ink: #24352b;
  --theme-muted: #68776d;
  --theme-line: #dce5dd;
  --theme-canvas: #f7faf7;
  --theme-surface: #fff;
  --theme-header: #1f3d2d;
  --theme-sidebar: #2c543d;
  --theme-sidebar-deep: #214431;
  --theme-sidebar-ink: #edf6ef;
  --theme-sidebar-muted: #c6dbc9;
  --theme-focus: #62a27a;
  --theme-own-bubble: #e7f2e9;
  --theme-own-bubble-ink: #294733;
  --theme-tree-wire: #a9c5ae;
  --theme-search: #3b634a;
  --theme-search-hover: #477658;
}

html[data-theme="amber"],
[data-palette="amber"] {
  --theme-accent: #895715;
  --theme-accent-strong: #67400c;
  --theme-accent-soft: #fbf2e3;
  --theme-accent-border: #e7d0a6;
  --theme-selected: #f5e7ca;
  --theme-ink: #382f23;
  --theme-muted: #786d5b;
  --theme-line: #e8dfd0;
  --theme-canvas: #fcfaf6;
  --theme-surface: #fff;
  --theme-header: #493416;
  --theme-sidebar: #64491f;
  --theme-sidebar-deep: #4d3819;
  --theme-sidebar-ink: #fbf3e3;
  --theme-sidebar-muted: #e5d1a9;
  --theme-focus: #b27b2d;
  --theme-own-bubble: #f7edd8;
  --theme-own-bubble-ink: #493817;
  --theme-tree-wire: #cbb68d;
  --theme-search: #735527;
  --theme-search-hover: #84632f;
}

html[data-theme="rose"],
[data-palette="rose"] {
  --theme-accent: #a54460;
  --theme-accent-strong: #7b2e47;
  --theme-accent-soft: #faedf1;
  --theme-accent-border: #e8c4d0;
  --theme-selected: #f5dfe7;
  --theme-ink: #38262d;
  --theme-muted: #78646b;
  --theme-line: #eadde1;
  --theme-canvas: #fcf8f9;
  --theme-surface: #fff;
  --theme-header: #4c2635;
  --theme-sidebar: #683548;
  --theme-sidebar-deep: #512a39;
  --theme-sidebar-ink: #fbecf1;
  --theme-sidebar-muted: #e5c5d0;
  --theme-focus: #c66b87;
  --theme-own-bubble: #f7e8ed;
  --theme-own-bubble-ink: #4d2d38;
  --theme-tree-wire: #cbaab6;
  --theme-search: #784356;
  --theme-search-hover: #8c5064;
}

html[data-theme], [data-palette] {
  --blue: var(--theme-accent);
  --ink: var(--theme-ink);
  --muted: var(--theme-muted);
  --line: var(--theme-line);
  --paper: var(--theme-canvas);
  --plum-dark: var(--theme-header);
  --plum-sidebar: var(--theme-sidebar);
  --plum-light: var(--theme-accent-soft);
}

html[data-theme] body {
  color: var(--theme-ink);
  background: var(--theme-canvas);
}

html[data-theme] button:focus-visible,
html[data-theme] a:focus-visible,
html[data-theme] input:focus-visible,
html[data-theme] select:focus-visible,
html[data-theme] textarea:focus-visible,
html[data-theme] [tabindex="0"]:focus-visible {
  outline-color: var(--theme-focus) !important;
}

/* 顶栏、左轨与频道侧栏 */
html[data-theme] #topbar {
  color: var(--header-ink, var(--theme-sidebar-ink));
  background: var(--theme-header);
}
html[data-theme] .snack-brand { color: var(--header-ink, white); }
html[data-theme] .snack-brand span { color: var(--header-ink, #e7d5eb); }
html[data-theme] #topbar .top-icon,
html[data-theme] #topbar .top-login,
html[data-theme] .header-nav { color: var(--header-ink, var(--theme-sidebar-ink)); }
html[data-theme] #topbar .top-icon:hover,
html[data-theme] #topbar .top-login:hover,
html[data-theme] #topbar .search-trigger:hover { background: var(--theme-search-hover); }
html[data-theme] #topbar .search-trigger {
  border-color: color-mix(in srgb, var(--theme-sidebar-ink) 24%, transparent);
  color: var(--header-ink, var(--theme-sidebar-ink));
  background: var(--theme-search);
}
html[data-theme] #topbar .search-trigger kbd {
  border-color: color-mix(in srgb, var(--theme-sidebar-ink) 28%, transparent);
  color: var(--header-ink, var(--theme-sidebar-ink));
  background: color-mix(in srgb, var(--theme-sidebar-ink) 9%, transparent);
}
html[data-theme] #sidebar { color: var(--theme-sidebar-ink); background: var(--theme-sidebar); }
html[data-theme] .app-rail { background: var(--theme-sidebar-deep); }
html[data-theme] .channel-sidebar { color: var(--theme-sidebar-ink); background: var(--theme-sidebar); }
html[data-theme] .rail-item,
html[data-theme] .channel-overview,
html[data-theme] .channel-action,
html[data-theme] .dir-link,
html[data-theme] .room-shortcut { color: var(--theme-sidebar-ink); }
html[data-theme] .rail-item[aria-current="page"] .rail-icon { background: var(--theme-accent); }
html[data-theme] .rail-item:hover .rail-icon,
html[data-theme] .channel-overview:hover,
html[data-theme] .channel-action:hover,
html[data-theme] .channel-heading-toggle:hover,
html[data-theme] .channel-heading-title:hover { background: color-mix(in srgb, var(--theme-sidebar-ink) 11%, transparent); }
html[data-theme] .channel-overview[aria-current="page"],
html[data-theme] .channel-action[aria-current="page"],
html[data-theme] .channel-heading-title[aria-current="page"],
html[data-theme] .dir-link.current,
html[data-theme] .room-shortcut.current {
  color: var(--theme-accent-strong);
  background: var(--theme-selected);
}
html[data-theme] .channel-heading-title,
html[data-theme] .channel-heading-toggle,
html[data-theme] .dir-pad,
html[data-theme] .dir-fold,
html[data-theme] .dir-link svg,
html[data-theme] .room-shortcut span,
html[data-theme] .nav-empty,
html[data-theme] .account-box small { color: var(--theme-sidebar-muted); }
html[data-theme] .channel-workspace { border-color: color-mix(in srgb, var(--theme-sidebar-ink) 15%, transparent); }
html[data-theme] .workspace-tile,
html[data-theme] .side-avatar { color: var(--theme-accent-strong); background: var(--theme-selected); }
html[data-theme] .account-box { border-color: color-mix(in srgb, var(--theme-sidebar-ink) 16%, transparent); }
html[data-theme] .case-pin[aria-pressed="true"],
html[data-theme] .personal-room-row .room-shortcut.current + .case-pin { color: var(--theme-accent); }

/* 页面控件、选中项与管理页 */
html[data-theme] .btn.primary,
html[data-theme] .detail-send-button,
html[data-theme] .detail-reply-send,
html[data-theme] .detail-case-unread,
html[data-theme] .case-lifecycle-approve {
  border-color: var(--theme-accent-strong);
  background: var(--theme-accent);
}
html[data-theme] .btn.primary:hover,
html[data-theme] .detail-send-button:hover:not(:disabled),
html[data-theme] .detail-reply-send:hover:not(:disabled),
html[data-theme] .case-lifecycle-approve:hover:not(:disabled) { background: var(--theme-accent-strong); }
html[data-theme] .segment button[aria-pressed="true"],
html[data-theme] .filter-tabs button[aria-pressed="true"],
html[data-theme] .home-feed-switch button[aria-pressed="true"],
html[data-theme] .home-feed-toggle[aria-expanded="true"] {
  border-color: var(--theme-accent-border);
  color: var(--theme-accent-strong);
  background: var(--theme-accent-soft);
}
html[data-theme] .section-title > svg,
html[data-theme] .text-action,
html[data-theme] .home-view .section-title > svg { color: var(--theme-accent); }
html[data-theme] .panel,
html[data-theme] .people-dialog,
html[data-theme] .detail-dialog-card,
html[data-theme] .detail-status-pop,
html[data-theme] .ws-tree-menu,
html[data-theme] .ws-tree-editor,
html[data-theme] .ws-case-move-dialog { border-color: var(--theme-line); background-color: var(--theme-surface); }
html[data-theme] .panel-bar,
html[data-theme] .inbox-view .filter-tabs,
html[data-theme] .profile-device-row,
html[data-theme] .detail-case-nav > header,
html[data-theme] .detail-room-header,
html[data-theme] .detail-composer { border-color: var(--theme-line); }
html[data-theme] .map-viewport { background-color: var(--theme-canvas); }
html[data-theme] .map-tree { --wire: var(--theme-tree-wire); }
html[data-theme] .map-root { border-color: var(--theme-header); background: var(--theme-sidebar); }
html[data-theme] .node-symbol.root { color: var(--theme-selected); background: var(--theme-accent); }
html[data-theme] .outline-row.is-tree-selected,
html[data-theme] .map-node.is-tree-selected { outline-color: color-mix(in srgb, var(--theme-accent) 34%, transparent); }
html[data-theme] .outline-row.is-tree-selected { background: var(--theme-accent-soft); box-shadow: inset 3px 0 var(--theme-accent); }
html[data-theme] .ws-tree-handle,
html[data-theme] .ws-case-move-button { border-color: var(--theme-accent-border); color: var(--theme-accent); }
html[data-theme] .ws-tree-handle:hover,
html[data-theme] .ws-tree-handle:focus-visible,
html[data-theme] .ws-case-move-button:hover,
html[data-theme] .ws-case-move-button:focus-visible { border-color: var(--theme-accent); color: #fff; background: var(--theme-accent); }
html[data-theme] .ws-tree-preview path { stroke: var(--theme-accent); }
html[data-theme] .ws-tree-action.is-primary { border-color: var(--theme-accent); background: var(--theme-accent); }
html[data-theme] .ws-tree-action.is-primary:hover:not(:disabled) { background: var(--theme-accent-strong); }
html[data-theme] .ws-tree-action:hover:not(:disabled),
html[data-theme] .junction-toggle:hover,
html[data-theme] .junction-toggle:focus-visible,
html[data-theme] .is-folded > .junction-toggle { border-color: var(--theme-accent-border); color: var(--theme-accent-strong); background: var(--theme-accent-soft); }

/* 项目会话列表与聊天区 */
html[data-theme] .detail-case-nav { background: var(--theme-canvas); }
html[data-theme] .detail-case-row.selected,
html[data-theme] .detail-case-open[aria-current="page"] { background: var(--theme-selected); box-shadow: inset 3px 0 var(--theme-accent); }
html[data-theme] .detail-case-open:hover,
html[data-theme] .detail-case-row > .case-pin:hover,
html[data-theme] .detail-people-button:hover { background: var(--theme-accent-soft); }
html[data-theme] .detail-case-kind,
html[data-theme] .detail-message-kind { background: var(--theme-accent-soft); color: var(--theme-accent-strong); }
html[data-theme] .detail-case-unread { color: #fff; }
html[data-theme] .detail-title-edit,
html[data-theme] .detail-room-title h1::before,
html[data-theme] .detail-new-discussion,
html[data-theme] .detail-copy-card,
html[data-theme] .detail-status-pop > button,
html[data-theme] .detail-status-member,
html[data-theme] .detail-track-action:hover,
html[data-theme] .detail-reply-open:hover,
html[data-theme] .detail-upload-button:hover,
html[data-theme] .detail-reply-upload:hover,
html[data-theme] .detail-upload-item > button:hover,
html[data-theme] .detail-expand,
html[data-theme] .detail-retry,
html[data-theme] .detail-welcome-icon,
html[data-theme] .detail-unread-divider { color: var(--theme-accent); }
html[data-theme] .detail-title-edit:hover,
html[data-theme] .detail-new-discussion:hover,
html[data-theme] .detail-upload-button:hover,
html[data-theme] .detail-reply-upload:hover,
html[data-theme] .detail-upload-item > button:hover { background: var(--theme-accent-soft); }
html[data-theme] .detail-new-discussion,
html[data-theme] .detail-compose-box:focus-within,
html[data-theme] .detail-reply-form textarea:focus { border-color: var(--theme-focus); }
html[data-theme] .detail-compose-box:focus-within { box-shadow: 0 0 0 3px color-mix(in srgb, var(--theme-accent) 12%, transparent); }
html[data-theme] .detail-message.is-mine .detail-message-content,
html[data-theme] .detail-message.is-mine .detail-reply-bubble { color: var(--theme-own-bubble-ink); background: var(--theme-own-bubble); }
html[data-theme] .detail-message.is-mine .detail-message-content { border-color: var(--theme-accent-border); }
html[data-theme] .detail-message.is-mine .detail-message-kind { color: var(--theme-accent-strong); background: var(--theme-selected); }
html[data-theme] .detail-avatar { background: var(--theme-accent-soft); color: var(--theme-accent-strong); }
html[data-theme] .detail-message.is-mine .detail-avatar { background: var(--theme-selected); color: var(--theme-accent-strong); }
html[data-theme] .detail-message.is-mine .detail-avatar img,
html[data-theme] .detail-avatar img { border-radius: inherit; }
html[data-theme] .detail-unread-divider::before,
html[data-theme] .detail-unread-divider::after { background: var(--theme-accent-border); }
html[data-theme] .detail-expand { border-color: var(--theme-accent-border); }
html[data-theme] .detail-reply-send { color: #fff; }
html[data-theme] .detail-message.is-mine .detail-message-content a,
html[data-theme] .detail-message-content .detail-card-link { color: var(--theme-accent-strong); }

/* 对话框和通用表单的边框、焦点与按钮保持同一主题。 */
html[data-theme] .detail-status-pop,
html[data-theme] .detail-delete-dialog,
html[data-theme] .case-lifecycle-dialog,
html[data-theme] .ws-case-move-dialog,
html[data-theme] .people-dialog { color: var(--theme-ink); }
html[data-theme] .detail-status-pop button:not(.detail-dialog-danger),
html[data-theme] .detail-dialog-actions button:not(.detail-dialog-danger),
html[data-theme] .case-lifecycle-secondary,
html[data-theme] .ws-case-move-close { border-color: var(--theme-line); color: var(--theme-ink); }
html[data-theme] .detail-status-pop button:not(.detail-dialog-danger):hover,
html[data-theme] .detail-dialog-actions button:not(.detail-dialog-danger):hover,
html[data-theme] .case-lifecycle-secondary:hover:not(:disabled),
html[data-theme] .ws-case-move-close:hover { background: var(--theme-accent-soft); }
html[data-theme] .case-lifecycle-reason-label textarea:focus,
html[data-theme] .ws-tree-editor input:focus-visible,
html[data-theme] .ws-case-move-form select:focus-visible { border-color: var(--theme-focus); }

html[data-theme] .dir-link.current svg,
html[data-theme] .room-shortcut.current span { color: var(--theme-accent-strong); }
html[data-theme] .room-unread,
html[data-theme] .room-shortcut .room-unread { background: var(--theme-selected); color: var(--theme-accent-strong); }
html[data-theme] .personal-room-row .case-pin[aria-pressed="true"] { color: var(--theme-sidebar-ink); }
html[data-theme] .personal-room-row .room-shortcut.current + .case-pin { color: var(--theme-accent-strong); }
html[data-theme] #topbar .header-search-field:focus-within { border-color: var(--theme-focus); }
html[data-theme] .header-search-result.is-active { background: var(--theme-accent-soft); }
html[data-theme] .permissions-page {
  --perm-accent: var(--theme-accent);
  --perm-accent-strong: var(--theme-accent-strong);
  --perm-accent-soft: var(--theme-accent-soft);
  --perm-ink: var(--theme-ink);
  --perm-muted: var(--theme-muted);
}

/* 便签工具栏随主题变化，每张纸仍使用便签自身的颜色。 */
html[data-theme] .notes-primary { background: var(--theme-accent); }
html[data-theme] .notes-primary:hover:not(:disabled) { background: var(--theme-accent-strong); }
html[data-theme] .notes-app { background: var(--theme-canvas); }
html[data-theme] .notes-actions, html[data-theme] .notes-status {
  color: var(--theme-muted); border-color: var(--theme-line); background: var(--theme-surface);
}
html[data-theme] .notes-status strong { color: var(--theme-accent-strong); }

.profile-theme { grid-column: 1; }
.theme-options { display: grid; gap: 18px; padding: 16px; container-type: inline-size; }
.theme-group { min-width: 0; }
.theme-group h3 { margin: 0 0 8px; font-size: 13px; color: var(--theme-muted); }
.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
  gap: 10px;
}
/* 八个取色样本排成两行，侧栏挤窄或在手机上时改成两列。 */
.theme-group + .theme-group .theme-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); --sample-header-height: 12px; }
@container (max-width: 380px) {
  .theme-group + .theme-group .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.theme-option {
  display: grid;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--theme-line);
  border-radius: 8px;
  color: var(--theme-ink);
  background: var(--theme-surface);
  cursor: pointer;
}
.theme-option:hover { border-color: var(--theme-accent); }
.theme-option:has(:checked) { border-color: var(--theme-accent); box-shadow: inset 0 0 0 1px var(--theme-accent); }
.theme-option:has(:focus-visible) { outline: 2px solid var(--theme-focus); outline-offset: 2px; }
.theme-sample {
  position: relative; display: block; height: 36px; border-radius: 4px;
  background: linear-gradient(var(--theme-header) 0 0) top/100% var(--sample-header-height, 7px) no-repeat,
    linear-gradient(to right, var(--theme-sidebar) 26%, var(--theme-accent-soft) 26%);
}
.theme-sample::after {
  content: ''; position: absolute; top: 15px; left: 35%; width: 40%; height: 5px;
  border-radius: 2px; background: var(--theme-accent); box-shadow: 0 8px var(--theme-accent-border);
}
.theme-caption { display: flex; align-items: center; justify-content: center; gap: 5px; font-size: 13px; white-space: nowrap; }
.theme-caption input { flex: none; width: 14px; height: 14px; margin: 0; accent-color: var(--theme-accent); }
.theme-feedback { margin: 0; padding: 0 16px 14px; color: #a52f3d; }

