/* Warm dark palette from docs/Sidekick Dark Mode Entwurf. The layout marker also
   covers provider-rendered dialogs; leaving MainLayout automatically restores light tokens. */
:root:has(.sidekick-theme[data-mode="dark"]) {
    color-scheme: dark;
    --paper-bg: #26231f;
    --paper-surface: #302c27;
    --paper-border: #423d35;
    --paper-ink: #ece6da;
    --paper-ink-light: #a59c8d;
    --paper-shadow: 0 1px 3px rgba(0,0,0,.25);
    --sk-dark-sidebar: #2b2823;
    --sk-dark-raised: #2e2b26;
    --sk-dark-input: #312d28;
    --sk-dark-subtle: #35312b;
    --sk-dark-hover: #38342e;
    --sk-dark-control-border: #4a443b;
    --sk-dark-strong-border: #4e483e;
    --sk-dark-body: #e3dccf;
    --sk-dark-strong: #f7f2e8;
    --sk-dark-muted: #b0a796;
    --sk-dark-faint: #9e9587;
    --sk-dark-accent: #a78bfa;
    --sk-dark-accent-hover: #b79af7;
    --sk-dark-accent-text: #bca6f7;
    --sk-dark-accent-contrast: #26231f;
    --sk-dark-active-text: #c4b2ff;
    --sk-dark-active-bg: #3e3448;
    --sk-dark-active-row: #3d3442;
    --sk-dark-accent-border: #5a4b72;
    --sk-map-accent: #9cc7ee;
    --sk-map-tip-bg: var(--paper-surface);
    --sk-map-tip-border: var(--sk-dark-control-border);
    --sk-map-tip-shadow: 0 6px 20px rgba(0,0,0,.3);
    --suite-primary: #bca6f7;
    --suite-primary-light: #c4b2ff;
    --suite-primary-dark: #a78bfa;
    --suite-primary-translucent: #a78bfa14;
    --suite-secondary-translucent: #4a443b;
}

:root:has(.sidekick-theme[data-mode="dark"][data-privacy="true"]) {
    --sk-dark-accent: #827d75;
    --sk-dark-accent-hover: #9a958d;
    --sk-dark-accent-text: #b0ada8;
    --sk-dark-accent-contrast: #fff;
    --sk-dark-active-text: #ece6da;
    --sk-dark-active-bg: #423e38;
    --sk-dark-active-row: #3e3b35;
    --sk-dark-accent-border: #665e52;
    --sk-map-accent: #cec6b8;
    --suite-primary: #b0ada8;
    --suite-primary-light: #cec6b8;
    --suite-primary-dark: #9a958d;
    --suite-primary-translucent: #b0ada814;
}

/* Shared artifact chrome, including static Chat Map captures. Component fallbacks
   preserve light colors; these tokens never change geometry or artifact content. */
:root:has(.sidekick-theme[data-mode="dark"], .chat-render-root[data-render-theme="dark"]) {
    --sk-artifact-surface: var(--paper-surface);
    --sk-artifact-title: var(--paper-ink);
    --sk-artifact-text: var(--paper-ink);
    --sk-artifact-muted: #b0a796;
    --sk-artifact-border: var(--paper-border);
    --sk-artifact-accent: var(--sk-dark-accent-text, #bca6f7);
    --sk-artifact-stripe: #78668f;
    --sk-artifact-success: #86c4a0;
    --sk-artifact-presentation: #f2a28b;
    --sk-visual-muted: var(--paper-ink-light);
}
/* Spreadsheet artifact: muted sage instead of the saturated status green, including its
   success-colored chip and filled download button (dark ink on sage). */
:is(.sidekick-theme[data-mode="dark"], .chat-render-root[data-render-theme="dark"]) .sk-excel-artifact {
    --mud-palette-success: #86c4a0;
    --mud-palette-success-rgb: 134,196,160;
    --mud-palette-success-darken: #9acfb0;
    --mud-palette-success-text: #26231f;
    --mud-palette-success-hover: rgba(134,196,160,.08);
}

/* Mud's automatic darkening makes lavender hover states saturated again. Keep
   filled actions soft and use the brighter foreground only on unfilled controls. */
:root:has(.sidekick-theme[data-mode="dark"]:not([data-privacy="true"])) {
    --mud-palette-primary-darken: #b79af7;
}
html:has(.sidekick-theme[data-mode="dark"]) :is(.mud-primary-text,.mud-button-text-primary,.mud-button-outlined-primary):not(:disabled):not(.mud-disabled) {
    color: var(--sk-dark-accent-text) !important;
}
:root:has(.sidekick-theme[data-mode="dark"][data-privacy="true"]) {
    --sk-artifact-stripe: #786f63;
}

/* Global selectors intentionally reach MudBlazor children and portaled content. */
html:has(.sidekick-theme[data-mode="dark"]) body { background:var(--paper-bg); color:var(--paper-ink); scrollbar-color:var(--sk-dark-strong-border) transparent; }
.sidekick-theme[data-mode="dark"] .sk-topbar { --sk-topbar-bg:#1f1c18; border-bottom:1px solid #3b372f; color:#ece6da; }
.sidekick-theme[data-mode="dark"] .sk-topbar-brand { color:#f5f0e6; }
.sidekick-theme[data-mode="dark"] .sk-topbar-env { background:#4a3a1c; color:#f2c161; }
.sidekick-theme[data-mode="dark"] :is(.sk-topbar-crumb,.sk-topbar-conn,.sk-topbar-iconbtn) { color:var(--sk-dark-muted); }
.sidekick-theme[data-mode="dark"] .sk-topbar-title { color:var(--paper-ink); }
.sidekick-theme[data-mode="dark"] .sk-topbar-sep { color:#6e6558; }
.sidekick-theme[data-mode="dark"] .sk-topbar-avatar { background:#575046; color:var(--paper-ink); box-shadow:0 0 0 1px #665e52; }
.sidekick-theme[data-mode="dark"] .sk-topbar-conn:not([data-sk-connection]) .sk-topbar-dot,
.sidekick-theme[data-mode="dark"] .sk-topbar-conn[data-sk-connection="connected"] .sk-topbar-dot { background:#34d399; }

.sidekick-theme[data-mode="dark"] :is(.sk-drawer-root,.sk-sidebar,.sidekick-sidebar-resizer) { background:var(--sk-dark-sidebar); }
.sidekick-theme[data-mode="dark"] .sk-drawer-switch { background:var(--sk-dark-subtle); }
.sidekick-theme[data-mode="dark"] .sk-drawer-seg.is-active { background:#47423a; color:var(--sk-dark-active-text); }
.sidekick-theme[data-mode="dark"] :is(.sk-sidebar-pinned,.sk-sidebar-search .mud-input-outlined) { background:var(--sk-dark-input); }
.sidekick-theme[data-mode="dark"] .sk-sidebar-search .mud-input-outlined-border { border-color:var(--sk-dark-control-border); }
.sidekick-theme[data-mode="dark"] :is(.sk-pinned-count,.sk-browse-btn) { background:var(--sk-dark-subtle); }
.sidekick-theme[data-mode="dark"] .sk-compact-task:hover { background:var(--sk-dark-hover); }
.sidekick-theme[data-mode="dark"] .sk-compact-task.is-active { background:var(--sk-dark-active-row); }
.sidekick-theme[data-mode="dark"] .sk-task-provider { color:var(--suite-primary); border-color:var(--sk-dark-accent-border); }
.sidekick-theme[data-mode="dark"] :is(.sk-task-group,.sk-task-time) { color:var(--sk-dark-faint); }
.sidekick-theme[data-mode="dark"] .sk-compact-task.is-active .sk-task-time { color:var(--sk-dark-muted); }
.sidekick-theme[data-mode="dark"] .sk-new-task { background:var(--sk-dark-accent); color:var(--sk-dark-accent-contrast); }
.sidekick-theme[data-mode="dark"] .sk-new-task:hover { background:var(--sk-dark-accent-hover); }

/* Browse tasks dialog (portaled): its toolbar, cards and tag input paint fixed light colors.
   Tag chips keep their pastel per-tag colors with dark ink; provider badges get the dark-mode hues. */
html:has(.sidekick-theme[data-mode="dark"]) .task-browser-toolbar { background:var(--paper-surface); border-bottom-color:var(--paper-border); }
html:has(.sidekick-theme[data-mode="dark"]) :is(.task-browser-toolbar__tags-label,.task-browser-empty) { color:var(--sk-dark-muted); }
html:has(.sidekick-theme[data-mode="dark"]) .task-item--flexible { background:var(--sk-dark-raised); border-color:var(--paper-border); }
html:has(.sidekick-theme[data-mode="dark"]) .task-item--flexible:hover { background:var(--sk-dark-hover); border-color:var(--sk-dark-accent-border); box-shadow:0 1px 3px rgba(0,0,0,.3); }
html:has(.sidekick-theme[data-mode="dark"]) .task-item--flexible.selected { border-color:var(--sk-dark-accent-text); }
html:has(.sidekick-theme[data-mode="dark"]) .task-item__footer { border-top-color:var(--paper-border); }
html:has(.sidekick-theme[data-mode="dark"]) .tpb-line,
html:has(.sidekick-theme[data-mode="dark"]) .tpb-snippet { color:var(--sk-dark-body); }
html:has(.sidekick-theme[data-mode="dark"]) .tpb-snippet mark { background:var(--sk-dark-active-bg); }
html:has(.sidekick-theme[data-mode="dark"]) .tpb-badge { color:var(--sk-dark-accent-text); }
html:has(.sidekick-theme[data-mode="dark"]) .tag-editor__input { color:var(--paper-ink); }
html:has(.sidekick-theme[data-mode="dark"]) .tag-editor:focus-within { border-color:var(--sk-dark-accent-text); }
html:has(.sidekick-theme[data-mode="dark"]) .tag-editor__error { color:#f28b82; }
/* Task outline hover card (sidebar and Browse tasks): topic chips use the light navy accent like the Chat Map. */
html:has(.sidekick-theme[data-mode="dark"]) .tot-chip { background:var(--sk-dark-subtle); border-color:var(--sk-dark-control-border); color:var(--sk-map-accent); }
html:has(.sidekick-theme[data-mode="dark"]) .tot-stale { color:#f2c161; }
html:has(.sidekick-theme[data-mode="dark"]) .provider-badge { background:color-mix(in srgb, currentColor 16%, transparent); }
html:has(.sidekick-theme[data-mode="dark"]) .provider-badge.provider-anthropic { color:var(--sk-dark-active-text); }
html:has(.sidekick-theme[data-mode="dark"]) .provider-badge:is(.provider-openai,.provider-default) { color:#9cc7ee; }
html:has(.sidekick-theme[data-mode="dark"]) .provider-badge.provider-gemini { color:#9db7ff; }
html:has(.sidekick-theme[data-mode="dark"]) .provider-badge.provider-dsgvo { color:#70cec4; }

/* Chat Map chrome only: tile images retain their separate render palette. The
   global map tokens also reach the JS tooltip mounted directly under body. */
.sidekick-theme[data-mode="dark"] [data-semantic-map] { --sk-navy:var(--sk-map-accent); }
.sidekick-theme[data-mode="dark"] .sk-ov-status { color:var(--sk-dark-muted); }
.sidekick-theme[data-mode="dark"] :is(.sk-ov-chip,.sk-ov-drift-pill,.sk-ov-hit-tag) { background:var(--sk-dark-subtle); }
.sidekick-theme[data-mode="dark"] .sk-ov-drift-pill { box-shadow:inset 0 0 0 1px var(--sk-dark-control-border); }
.sidekick-theme[data-mode="dark"] :is(.sk-ov-chip-more,.sk-ov-drift-pill:hover,.sk-ov-label:hover,.sk-ov-hit:hover) { background:var(--sk-dark-hover); }
.sidekick-theme[data-mode="dark"] .sk-ov-viewport { background:color-mix(in srgb, var(--sk-map-accent) 10%, transparent); }
.sidekick-theme[data-mode="dark"] :is(.sk-ov-dot,.sk-ov-rail-span) { background:color-mix(in srgb, var(--sk-topic-color, #767676) 75%, white); }
.sidekick-theme[data-mode="dark"] .sk-ov-auto .mud-switch-base:not(.mud-checked) { color:var(--sk-dark-muted); }
.sidekick-theme[data-mode="dark"] .sidekick-tabs > .mud-tabs-tabbar { background:var(--paper-bg); }
.sidekick-theme[data-mode="dark"] .sidekick-tabs > .mud-tabs-tabbar .mud-tab-slider { background:var(--sk-dark-accent); }
.sidekick-theme[data-mode="dark"] .thread-new-floating .thread-new-button { background:var(--sk-dark-raised); border-color:var(--sk-dark-control-border); color:#cec6b8; }

.sidekick-theme[data-mode="dark"] .user-turn--flat .user-message { background:var(--sk-dark-subtle); border-color:var(--sk-dark-control-border); color:var(--paper-ink); }
.sidekick-theme[data-mode="dark"] .segment-content { color:var(--sk-dark-body); }
.sidekick-theme[data-mode="dark"] .segment-content :is(strong,b,h1,h2,h3,h4) { color:var(--sk-dark-strong); }
.sidekick-theme[data-mode="dark"] .sidekick-composer { background:var(--paper-surface); border-color:var(--sk-dark-strong-border); box-shadow:0 -12px 40px rgba(0,0,0,.3); }
.sidekick-theme[data-mode="dark"] .sidekick-composer:focus-within { border-color:var(--sk-dark-accent-text); }
.sidekick-theme[data-mode="dark"] :is(.composer-mode-segments,.composer-option-button,.composer-icon-button,.settings-pill) { border-color:var(--sk-dark-control-border); }
.sidekick-theme[data-mode="dark"] :is(.composer-mode-button--active,.composer-option-button--active) { background:var(--sk-dark-active-bg); color:var(--sk-dark-active-text); border-color:var(--sk-dark-accent-border); }
.sidekick-theme[data-mode="dark"] .composer-run:not(:disabled) { background:var(--sk-dark-accent); color:var(--sk-dark-accent-contrast); }
.sidekick-theme[data-mode="dark"] .composer-run:not(:disabled):hover { background:var(--sk-dark-accent-hover); }
.sidekick-theme[data-mode="dark"] .composer-run:disabled { background:var(--paper-border); color:var(--sk-dark-faint); opacity:1; }
.sidekick-theme[data-mode="dark"] .composer-key-hint,
.sidekick-theme[data-mode="dark"] textarea::placeholder,
.sidekick-theme[data-mode="dark"] input::placeholder { color:var(--sk-dark-faint); opacity:1; }
/* Readability floor (WCAG AA): light-mode fades and brand hues that drop below 4.5:1 text / 3:1 icons
   on the warm dark surfaces. Unfilled lavender text uses the brighter accent like other unfilled actions. */
.sidekick-theme[data-mode="dark"] .personal-memory-control button[aria-pressed=true] { color:var(--sk-dark-accent-text); }
.sidekick-theme[data-mode="dark"] :is(.token-hint--ok,.token-hint--warn) { opacity:.75; }
.sidekick-theme[data-mode="dark"] .js-counter .js-counter__icon--info { color:#9db7ff; }
html:has(.sidekick-theme[data-mode="dark"]) :is(.task-item--flexible .meta-date,.task-item--flexible .type-label) { opacity:1; }

/* The corpus panel predates the paper theme and has its own local token scope. The hover card
   redeclares the light tokens on itself, so it is listed here too. */
.sidekick-theme[data-mode="dark"] :is(.ac-rail,.ac-panel,.ac-toggle,.ac-backdrop,.ac-hover-panel) {
    --ac-brand:var(--sk-dark-accent-text);
    --ac-surface:var(--paper-surface);
    --ac-surface-muted:var(--sk-dark-raised);
    --ac-divider:var(--paper-border);
    --ac-divider-soft:var(--paper-border);
    --ac-border:var(--sk-dark-control-border);
    --ac-text-muted:var(--paper-ink-light);
    --ac-text-faint:var(--sk-dark-faint);
    --ac-danger-bg:#492d2a;
    --ac-danger-fg:#f28b82;
    --ac-danger-border:#70413c;
}
.sidekick-theme[data-mode="dark"] .ac-rail-badge { background:var(--sk-dark-active-bg); color:var(--sk-dark-active-text); }
.sidekick-theme[data-mode="dark"] .ac-rail-badge-num { color:var(--sk-dark-active-text); }
.sidekick-theme[data-mode="dark"] .ac-rail--enforced { background:var(--sk-dark-active-bg); }
.sidekick-theme[data-mode="dark"] .ac-hover-open:not(:disabled) { background:var(--sk-dark-accent); border-color:var(--sk-dark-accent); color:var(--sk-dark-accent-contrast); }
.sidekick-theme[data-mode="dark"] .ac-hover-open:hover:not(:disabled) { background:var(--sk-dark-accent-hover); border-color:var(--sk-dark-accent-hover); }
.sidekick-theme[data-mode="dark"] :is(.sk-recap-pending,.sk-recap-chip) { background:var(--sk-dark-raised); border-color:var(--sk-dark-control-border); color:var(--paper-ink); }

/* Readable legacy rendered markdown, including code/table descendants. Exports use a
   separate layout without the marker, so retain their original corporate palette. */
html:has(.sidekick-theme[data-mode="dark"]) :is(.agent-answer p,.agent-answer li,.agent-answer td,.agent-message-text) { color:var(--sk-dark-body); }
html:has(.sidekick-theme[data-mode="dark"]) .agent-answer :is(strong,b,h1,h2,h3,h4,h5,h6,th):not(.sk-data-grid *) { color:var(--sk-dark-strong); }
html:has(.sidekick-theme[data-mode="dark"]) .agent-answer a:not(.mud-button-root) { color:var(--suite-primary); }
html:has(.sidekick-theme[data-mode="dark"]) .agent-answer :is(pre,code,thead):not(.sk-data-grid *) { background:var(--sk-dark-input); color:var(--paper-ink); text-shadow:none; }
html:has(.sidekick-theme[data-mode="dark"]) .agent-answer :is(tr,th,td,thead) { border-color:var(--paper-border); }
html:has(.sidekick-theme[data-mode="dark"]) .agent-answer tbody tr:hover { background:var(--sk-dark-hover); }
html:has(.sidekick-theme[data-mode="dark"]) .e-content { background:var(--paper-surface); color:var(--sk-dark-body) !important; }

.sidekick-theme[data-mode="dark"] .sk-data-grid .e-grid,
.sidekick-theme[data-mode="dark"] .sk-data-grid .e-grid :is(.e-content,.e-rowcell,.e-pager) { background:var(--paper-surface); color:var(--paper-ink); border-color:var(--paper-border); }
.sidekick-theme[data-mode="dark"] .sk-data-grid .e-grid .e-altrow .e-rowcell { background:var(--sk-dark-subtle); }
.sidekick-theme[data-mode="dark"] .sk-data-grid .e-grid .e-row:hover .e-rowcell { background:var(--sk-dark-hover); }
.sidekick-theme[data-mode="dark"] .sk-data-grid .e-grid .e-gridcontent,
.sidekick-theme[data-mode="dark"] .sk-data-grid .e-grid .e-gridcontent .e-table {
    background-color: var(--paper-surface);
}
/* Header cells and resize grips carry separate light borders in the grid theme.
   Keep their widths and the CI header color; recolor only the seams and backing. */
.sidekick-theme[data-mode="dark"] .sk-data-grid .e-grid .e-gridheader,
.sidekick-theme[data-mode="dark"] .sk-data-grid .e-grid .e-gridheader :is(.e-headercontent,.e-table,.e-headercell,.e-rhandler,.e-rsuppress) {
    border-color: var(--paper-border);
}
/* The generic answer-table rule paints thead cream; it can show through the
   rounded/clipped header table even when every visible cell is CI-colored. */
.sidekick-theme[data-mode="dark"] .sk-data-grid .e-grid .e-gridheader :is(.e-headercontent,.e-table,thead) {
    background-color: var(--sk-grid-header-bg, #00386A);
}
/* Welcome back bookmark card: tinted with the dark accent tokens (grey in privacy mode). */
.sidekick-theme[data-mode="dark"] .sk-recap { --rc-paper:var(--sk-dark-active-row); --rc-line:var(--sk-dark-accent-border); --rc-ribbon:var(--sk-dark-accent); --rc-title:var(--sk-dark-active-text); --rc-note-rule:var(--sk-dark-accent-border); --rc-inlay:var(--sk-dark-raised); --rc-action:var(--sk-dark-accent-text); --rc-hover:var(--sk-dark-hover); }

/* Citation hues retain their source identity with readable dark-mode ink. */
.sidekick-theme[data-mode="dark"] { --citation-contrast:#fff; }

/* Citation previews contain generated HTML with inline light table colors.
   Override those colors only in the interactive dark viewer, not in exports. */
.sidekick-theme[data-mode="dark"] .citation-popover-card,
.sidekick-theme[data-mode="dark"] .citation-popover-card :is(.tooltip-title,.content-text,.content-column h6) {
    color: var(--paper-ink);
}
.sidekick-theme[data-mode="dark"] .citation-popover-card .tooltip-subtitle {
    color: var(--mud-palette-text-secondary);
}
.sidekick-theme[data-mode="dark"] .show-document-dialog .citation-panel {
    background: var(--paper-surface);
    color: var(--paper-ink);
    border-color: var(--paper-border);
}
.sidekick-theme[data-mode="dark"] .show-document-dialog :is(.citation-panel-header,.citation-section-label,.citation-section-text) {
    color: var(--paper-ink);
}
.sidekick-theme[data-mode="dark"] .show-document-dialog .citation-panel-title {
    color: var(--mud-palette-text-secondary);
}
.sidekick-theme[data-mode="dark"] .show-document-dialog :is(.citation-panel-header,.citation-panel-title,.citation-section,.citation-section-label) {
    border-color: var(--paper-border);
}
.sidekick-theme[data-mode="dark"] .show-document-dialog .citation-panel-content::-webkit-scrollbar-track {
    background: var(--paper-surface);
}
.sidekick-theme[data-mode="dark"] .show-document-dialog .citation-panel-content::-webkit-scrollbar-thumb {
    background: var(--sk-dark-strong-border);
}
.sidekick-theme[data-mode="dark"] .show-document-dialog .citation-panel-content::-webkit-scrollbar-thumb:hover {
    background: var(--sk-dark-muted);
}
.sidekick-theme[data-mode="dark"] :is(.citation-popover-card,.show-document-dialog .citation-panel) table {
    background-color: var(--paper-surface) !important;
    color: var(--paper-ink) !important;
}
.sidekick-theme[data-mode="dark"] :is(.citation-popover-card,.show-document-dialog .citation-panel) :is(table,thead,tbody,tr,th,td) {
    border-color: var(--paper-border) !important;
}
.sidekick-theme[data-mode="dark"] :is(.citation-popover-card,.show-document-dialog .citation-panel) :is(th,td) {
    color: var(--paper-ink) !important;
    background-color: transparent !important;
}
.sidekick-theme[data-mode="dark"] :is(.citation-popover-card,.show-document-dialog .citation-panel) tbody tr {
    background-color: var(--paper-surface) !important;
}
.sidekick-theme[data-mode="dark"] :is(.citation-popover-card,.show-document-dialog .citation-panel) tbody tr:nth-child(even) {
    background-color: var(--sk-dark-raised) !important;
}
.sidekick-theme[data-mode="dark"] :is(.citation-popover-card,.show-document-dialog .citation-panel) :is(thead,thead tr) {
    background-color: var(--sk-dark-subtle) !important;
}

/* File drag feedback keeps the light overlay's geometry, opacity and blur. */
.sidekick-theme[data-mode="dark"] .sk-drop-overlay {
    background: color-mix(in srgb, var(--paper-surface) 92%, transparent);
    border-color: var(--mud-palette-primary);
    color: var(--paper-ink);
}
.sidekick-theme[data-mode="dark"] .sk-drop-zone--images {
    color: var(--mud-palette-success);
    border-color: currentColor;
}
.sidekick-theme[data-mode="dark"] .sk-drop-zone--documents {
    color: var(--mud-palette-info);
    border-color: currentColor;
}
.sidekick-theme[data-mode="dark"] :is(.sk-drop-zone-hint,.sk-drop-zone-or,.sk-drop-footer) {
    color: var(--mud-palette-text-secondary);
    opacity: 1;
}

/* Syncfusion's Bootstrap theme supplies light toolbar/footer colors independently
   of the editable content. Keep editor chrome on the shared dark Paper surface. */
.sidekick-theme[data-mode="dark"] .e-richtexteditor,
.sidekick-theme[data-mode="dark"] .e-richtexteditor :is(.e-rte-toolbar,.e-toolbar-items,.e-toolbar-extended,.e-rte-content,.e-rte-srctextarea) {
    background-color: var(--paper-surface) !important;
    border-color: var(--paper-border) !important;
    color: var(--paper-ink) !important;
}
.sidekick-theme[data-mode="dark"] .e-richtexteditor :is(.e-tbar-btn,.e-toolbar-item .e-icons,.e-rte-dropdown-btn,.e-rte-dropdown-btn .e-icons) {
    background-color: transparent !important;
    color: var(--paper-ink) !important;
}
.sidekick-theme[data-mode="dark"] .e-richtexteditor :is(.e-tbar-btn:hover,.e-tbar-btn:focus,.e-rte-dropdown-btn:hover,.e-rte-dropdown-btn:focus) {
    background-color: var(--sk-dark-hover) !important;
}
.sidekick-theme[data-mode="dark"] .e-richtexteditor .e-toolbar-item.e-active .e-tbar-btn {
    background-color: var(--sk-dark-active-bg) !important;
    color: var(--sk-dark-active-text) !important;
}
.sidekick-theme[data-mode="dark"] .e-richtexteditor .e-toolbar-item.e-active .e-icons {
    color: var(--sk-dark-active-text) !important;
}
.sidekick-theme[data-mode="dark"] .e-richtexteditor :is(.e-rte-character-count,.e-rte-resize-handle,.e-toolbar-item.e-overlay .e-icons) {
    color: var(--sk-dark-muted) !important;
}
.sidekick-theme[data-mode="dark"] .e-richtexteditor .e-toolbar-item.e-separator {
    border-color: var(--paper-border) !important;
}

/* Knowledge owns its layout, but shares the app's dark semantic color roles.
   Root matching also covers dialogs/popovers rendered outside the layout subtree. */
html:has(.sidekick-theme[data-mode="dark"]) :is(.knowledge-home,.knowledge-dialog,.knowledge-popover) {
    --kb-ink: var(--paper-ink);
    --kb-body: var(--sk-dark-body);
    --kb-secondary: var(--sk-dark-muted);
    --kb-muted: var(--sk-dark-muted);
    --kb-soft-icon: var(--sk-dark-muted);
    --kb-separator: var(--sk-dark-muted);
    --kb-icon: var(--sk-dark-accent-text);
    --kb-accent: var(--sk-dark-accent-text);
    --kb-legacy-link: var(--sk-dark-accent-text);
    --kb-action: var(--mud-palette-primary);
    --kb-action-hover: var(--mud-palette-primary-darken);
    --kb-action-ink: var(--mud-palette-primary-text);
    --kb-focus: var(--sk-dark-accent-text);
    --kb-tint: var(--sk-dark-active-bg);
    --kb-setup-bg: var(--sk-dark-active-bg);
    --kb-row-selected: var(--sk-dark-active-bg);
    --kb-citation-bg: var(--sk-dark-active-bg);
    --kb-selection-bg: var(--sk-dark-active-bg);
    --kb-selection-ink: var(--sk-dark-active-text);
    --kb-link-border: var(--sk-dark-accent-border);
    --kb-setup-border: var(--sk-dark-accent-border);
    --kb-selected-border: var(--sk-dark-accent-border);
    --kb-border: var(--paper-border);
    --kb-control-border: var(--sk-dark-control-border);
    --kb-strong-border: var(--sk-dark-strong-border);
    --kb-subtle: var(--paper-border);
    --kb-surface: var(--paper-surface);
    --kb-control: var(--sk-dark-input);
    --kb-hover: var(--sk-dark-hover);
    --kb-success: var(--mud-palette-success);
    --kb-success-bg: color-mix(in srgb, var(--mud-palette-success) 8%, var(--paper-surface));
    --kb-success-border: color-mix(in srgb, var(--mud-palette-success) 30%, var(--paper-border));
    --kb-warning: var(--mud-palette-warning);
    --kb-warning-bg: color-mix(in srgb, var(--mud-palette-warning) 8%, var(--paper-surface));
    --kb-error: var(--mud-palette-error);
    --kb-error-bg: color-mix(in srgb, var(--mud-palette-error) 8%, var(--paper-surface));
    --kb-error-border: color-mix(in srgb, var(--mud-palette-error) 30%, var(--paper-border));
    /* Undo the local light-only Mud primary override; inherit the active palette. */
    --mud-palette-primary: inherit;
    --mud-palette-primary-text: inherit;
}

/* Category accents need lighter foregrounds on charcoal. Keep the existing RGB
   tint/border treatment and all light-mode colors; memory retains its light wiki styling. */
.sidekick-theme[data-mode="dark"] .ld-card--mcp {
    --ld-card-accent: #70cec4;
    --ld-card-accent-rgb: 112, 206, 196;
}
.sidekick-theme[data-mode="dark"] .ld-card--wiki {
    --ld-card-accent: #b8a2f2;
    --ld-card-accent-rgb: 184, 162, 242;
}
.sidekick-theme[data-mode="dark"] .ld-card--memory {
    --ld-card-accent: #e7ba7a;
    --ld-card-accent-rgb: 231, 186, 122;
}
/* Memory box under an answer (PersonalMemorySaved): the same warm memory gold as the memory card.
   Gold is a category accent and stays in privacy mode; muted text uses the dark TextSecondary (about 7:1). */
.sidekick-theme[data-mode="dark"] .memory-box {
    --mb-accent: #e7ba7a;
    --mb-accent-text: #e7ba7a;
    --mb-muted: var(--mud-palette-text-secondary);
    --mb-tint: color-mix(in srgb, #e7ba7a 5%, var(--paper-bg));
    --mb-badge: color-mix(in srgb, #e7ba7a 15%, transparent);
    --mb-neutral: color-mix(in srgb, var(--sk-dark-control-border) 55%, transparent);
}
