/* Applied only for explicitly chosen groups after the base theme is installed.
   :root + data-theme outrank dark selectors whose :is() includes nested controls,
   without changing shared preset variables or other groups. */

/* Outer surfaces never set inherited text colors on the cards they contain. */
html:root[data-theme][data-appearance-background] :is(.messenger,.workspace,.feature-workspace,.powerview-panel,.powerview-cards){background:var(--appearance-background-bg)}
html:root[data-theme][data-appearance-background] :is(.powerview-header,.powerview-footer){background:var(--appearance-background-bg);color:var(--appearance-background-fg);border-color:var(--appearance-background-line)}
html:root[data-theme][data-appearance-background] :is(.powerview-heading h2,.pw-empty h3){color:var(--appearance-background-fg)}
html:root[data-theme][data-appearance-background] :is(.powerview-count,.pw-empty,.pw-empty p){color:var(--appearance-background-muted)}
html:root[data-theme][data-appearance-background] .feature-workspace>.feature-heading :is(h1,.eyebrow){color:var(--appearance-background-fg)}
html:root[data-theme][data-appearance-background] .feature-workspace>.feature-heading p:not(.eyebrow),
html:root[data-theme][data-appearance-background] #feature-content>.feature-empty{color:var(--appearance-background-muted)}
html:root[data-theme][data-appearance-background] .feature-workspace>#feature-feedback{color:var(--appearance-background-success)}
html:root[data-theme][data-appearance-background] .feature-workspace>#feature-feedback.is-error{color:var(--appearance-background-error)!important}
html:root[data-theme][data-appearance-background] :is(.powerview-header button,.powerview-footer #powerview-more){background:var(--appearance-background-hover);color:var(--appearance-background-fg);border-color:var(--appearance-background-line)}
html:root[data-theme][data-appearance-background] .powerview-header #powerview-single{background:transparent;color:var(--appearance-background-fg)}
html:root[data-theme][data-appearance-background] :is(.powerview-header button,.powerview-footer #powerview-more):hover:not(:disabled){background:var(--appearance-background-hover);color:var(--appearance-background-fg);border-color:var(--appearance-background-fg)}
html:root[data-theme][data-appearance-background] :is(.powerview-header button,.powerview-footer #powerview-more):focus-visible{outline:2px solid var(--appearance-background-focus);outline-offset:2px;box-shadow:0 0 0 2px var(--appearance-background-bg)}

/* Navigation, including the compact connection/status strip. */
html:root[data-theme][data-appearance-navigation] :is(.menu-rail,.topbar){background:var(--appearance-navigation-bg);color:var(--appearance-navigation-fg);border-color:var(--appearance-navigation-line)}
html:root[data-theme][data-appearance-navigation] :is(.rail-brand,.topbar .device-picker select){color:var(--appearance-navigation-fg)}
html:root[data-theme][data-appearance-navigation] .rail-brand .brand-mark{background:var(--appearance-navigation-hover);color:var(--appearance-navigation-fg)}
html:root[data-theme][data-appearance-navigation] .topbar .device-picker select{background:var(--appearance-navigation-bg);border-color:var(--appearance-navigation-line);color-scheme:normal}
html:root[data-theme][data-appearance-navigation] :is(.topbar .device-picker label,.topbar .device-status,.topbar .current-user,.topbar .sync-status,.topbar .device-battery){color:var(--appearance-navigation-muted)}
html:root[data-theme][data-appearance-navigation] .menu-rail .nav-button:not(.active):not([aria-current=page]){background:transparent;color:var(--appearance-navigation-fg)}
html:root[data-theme][data-appearance-navigation] .menu-rail .nav-button:not(.active):not([aria-current=page]):hover{background:var(--appearance-navigation-hover);color:var(--appearance-navigation-fg)}
html:root[data-theme][data-appearance-navigation]:not([data-appearance-accent]) .menu-rail :is(.nav-button.active,.nav-button[aria-current=page]){background:var(--appearance-navigation-hover);color:var(--appearance-navigation-fg);box-shadow:inset 3px 0 var(--appearance-navigation-fg)}
html:root[data-theme][data-appearance-navigation] :is(.topbar .refresh-button,.topbar #appearance-settings){background:var(--appearance-navigation-hover);color:var(--appearance-navigation-fg);border-color:var(--appearance-navigation-line)}
html:root[data-theme][data-appearance-navigation] :is(.topbar .refresh-button,.topbar #appearance-settings):hover{background:var(--appearance-navigation-bg);color:var(--appearance-navigation-fg);border-color:var(--appearance-navigation-fg)}
html:root[data-theme][data-appearance-navigation] .topbar :is(.status-online,.realtime-status[data-mode=connected]){color:var(--appearance-navigation-success)}
html:root[data-theme][data-appearance-navigation] .topbar :is(.status-offline,.realtime-status:not([data-mode=connected]):not([data-mode=unavailable])){color:var(--appearance-navigation-warning)}
html:root[data-theme][data-appearance-navigation] .topbar .realtime-status[data-mode=unavailable]{color:var(--appearance-navigation-error)}
html:root[data-theme][data-appearance-navigation] :is(.menu-rail,.topbar) :is(button,select):focus-visible{outline:2px solid var(--appearance-navigation-focus);outline-offset:2px;box-shadow:0 0 0 2px var(--appearance-navigation-bg)}

/* Card headings and the background behind messages; bubble contents stay owned
   by the incoming/outgoing groups, including when those groups are unset. */
html:root[data-theme][data-appearance-conversation] :is(.thread-panel,.messages,.pw-card){background:var(--appearance-conversation-bg);border-color:var(--appearance-conversation-line)}
html:root[data-theme][data-appearance-conversation] :is(.thread-header,.conversation-workflow,.pw-card-header,.pw-card-controls,.pw-more-content,.pw-history-controls){background:var(--appearance-conversation-bg);color:var(--appearance-conversation-fg);border-color:var(--appearance-conversation-line)}
html:root[data-theme][data-appearance-conversation] :is(.thread-header h2,.thread-header .eyebrow,.pw-card-title,.group-message-sender,.empty h3){color:var(--appearance-conversation-fg)}
html:root[data-theme][data-appearance-conversation] :is(.pw-card-address,.timeline-order,.pw-empty-timeline,.pw-placeholder-text,.messages .message-meta,.messages .message-type,.empty p){color:var(--appearance-conversation-muted)}
html:root[data-theme][data-appearance-conversation] :is(.conversation-workflow,.pw-card-controls) :is(.workflow-summary,.workflow-summary>span:first-child,.workflow-feedback,.pw-more-content>span,.pw-more-content>p){color:var(--appearance-conversation-muted)}
html:root[data-theme][data-appearance-conversation] :is(.conversation-workflow,.pw-card-controls) .workflow-summary>.workflow-unread{color:var(--appearance-conversation-success)}
html:root[data-theme][data-appearance-conversation] :is(.thread-header,.conversation-workflow,.pw-card-header,.pw-more-content,.pw-history-controls) :is(button,select,summary,.feature-labels,.lease-note,.sms-badge){background:var(--appearance-conversation-bg);color:var(--appearance-conversation-fg);border-color:var(--appearance-conversation-line)}
html:root[data-theme][data-appearance-conversation] :is(.thread-header,.conversation-workflow,.pw-card-header,.pw-more-content,.pw-history-controls) :is(button,summary):hover:not(:disabled),
html:root[data-theme][data-appearance-conversation] .pw-more[open]>summary{background:var(--appearance-conversation-hover);color:var(--appearance-conversation-fg);border-color:var(--appearance-conversation-line)}
html:root[data-theme][data-appearance-conversation] :is(.thread-header,.conversation-workflow,.pw-card-header,.pw-more-content,.pw-history-controls) :is(button,select,summary):focus-visible,
html:root[data-theme][data-appearance-conversation] .messages:focus-visible{outline:2px solid var(--appearance-conversation-focus);outline-offset:-2px;box-shadow:inset 0 0 0 2px var(--appearance-conversation-bg)}
html:root[data-theme][data-appearance-conversation] .messages :is(.message-status.failed,.message-error){color:var(--appearance-conversation-error)}
html:root[data-theme][data-appearance-conversation] .messages .message-status.unknown{color:var(--appearance-conversation-warning)}
html:root[data-theme][data-appearance-conversation] :is(.conversation-workflow,.pw-card-controls) .is-error{color:var(--appearance-conversation-error)!important}

/* Inbound and outbound bubbles do not recolor the separate timestamps, status
   text, photos or the background behind the bubble. */
html:root[data-theme][data-appearance-incoming] .message.inbound .message-body,
html:root[data-theme][data-appearance-incoming] .message.inbound .message-attachments button{background:var(--appearance-incoming-bg);color:var(--appearance-incoming-fg);border-color:var(--appearance-incoming-line)}
html:root[data-theme][data-appearance-incoming] .message.inbound :is(.attachment-caption,.attachment-preview-status){color:var(--appearance-incoming-fg)}
html:root[data-theme][data-appearance-incoming] .message.inbound .attachment-thumbnail{background:var(--appearance-incoming-hover);color:var(--appearance-incoming-muted)}
html:root[data-theme][data-appearance-incoming] .message.inbound :is(.message-body a,.message-attachments button):focus-visible{outline:2px solid var(--appearance-incoming-focus);outline-offset:2px;box-shadow:0 0 0 2px var(--appearance-incoming-bg)}
html:root[data-theme][data-appearance-outgoing] .message.outbound .message-body,
html:root[data-theme][data-appearance-outgoing] .message.outbound .message-attachments button{background:var(--appearance-outgoing-bg);color:var(--appearance-outgoing-fg);border-color:var(--appearance-outgoing-line)}
html:root[data-theme][data-appearance-outgoing] .message.outbound :is(.attachment-caption,.attachment-preview-status){color:var(--appearance-outgoing-fg)}
html:root[data-theme][data-appearance-outgoing] .message.outbound .attachment-thumbnail{background:var(--appearance-outgoing-hover);color:var(--appearance-outgoing-muted)}
html:root[data-theme][data-appearance-outgoing] .message.outbound :is(.message-body a,.message-attachments button):focus-visible{outline:2px solid var(--appearance-outgoing-focus);outline-offset:2px;box-shadow:0 0 0 2px var(--appearance-outgoing-bg)}

/* Compose surfaces and their secondary tools. Primary send buttons are owned
   by accent and are deliberately absent from these button selectors. */
html:root[data-theme][data-appearance-composer] :is(.compose,.pw-compose,.pw-input-row){background:var(--appearance-composer-bg);color:var(--appearance-composer-fg);border-color:var(--appearance-composer-line)}
html:root[data-theme][data-appearance-composer] :is(.compose,.pw-compose) :is(input,textarea,select){background:var(--appearance-composer-bg);color:var(--appearance-composer-fg);border-color:var(--appearance-composer-line);color-scheme:normal}
html:root[data-theme][data-appearance-composer] :is(.compose,.pw-compose) :is(input,textarea)::placeholder{color:var(--appearance-composer-muted);opacity:1}
html:root[data-theme][data-appearance-composer] :is(.compose,.pw-compose) :is(.compose-heading,.compose-heading span,.compose-shortcut,.draft-status,.feature-help,.pw-character-count,.pw-sender){color:var(--appearance-composer-muted)}
html:root[data-theme][data-appearance-composer] :is(.compose,.pw-compose) :is(.pw-tool-button,.compose-tool-row button,.attachment-chip,.rcs-reply-by-number){background:var(--appearance-composer-bg);color:var(--appearance-composer-fg);border-color:var(--appearance-composer-line)}
html:root[data-theme][data-appearance-composer] :is(.compose,.pw-compose) :is(.pw-tool-button,.compose-tool-row button,.attachment-chip,.rcs-reply-by-number):hover:not(:disabled),
html:root[data-theme][data-appearance-composer] .pw-tool-button:is([aria-expanded=true],[aria-pressed=true]){background:var(--appearance-composer-hover);color:var(--appearance-composer-fg);border-color:var(--appearance-composer-fg)}
html:root[data-theme][data-appearance-composer] :is(.compose,.pw-compose) :is(input,textarea,select,.pw-tool-button,.compose-tool-row button,.attachment-chip,.rcs-reply-by-number):focus-visible{outline:2px solid var(--appearance-composer-focus);outline-offset:2px;box-shadow:0 0 0 2px var(--appearance-composer-bg)}
html:root[data-theme][data-appearance-composer] .pw-input-row:focus-within{border-color:var(--appearance-composer-focus);box-shadow:0 0 0 1px var(--appearance-composer-focus)}
html:root[data-theme][data-appearance-composer] :is(.compose,.pw-compose) .send-feedback{color:var(--appearance-composer-success)}
html:root[data-theme][data-appearance-composer] :is(.compose,.pw-compose) :is(.reply-notice,.draft-conflict){background:var(--appearance-composer-hover);color:var(--appearance-composer-warning);border-color:var(--appearance-composer-line)}
html:root[data-theme][data-appearance-composer] :is(.compose,.pw-compose) .is-error{color:var(--appearance-composer-error)!important}

/* Accent comes last so it wins for the selected item inside another surface. */
html:root[data-theme][data-appearance-accent] :is(#send-button,.pw-send,#new-message,.nav-button.active,.nav-button[aria-current=page],.conversation.active){background:var(--appearance-accent-bg);color:var(--appearance-accent-fg);border-color:var(--appearance-accent-line);filter:none}
html:root[data-theme][data-appearance-accent] :is(#send-button,.pw-send,#new-message,.nav-button.active,.nav-button[aria-current=page],.conversation.active):hover:not(:disabled){background:var(--appearance-accent-hover);color:var(--appearance-accent-fg);border-color:var(--appearance-accent-line)}
html:root[data-theme][data-appearance-accent] :is(#send-button,.pw-send,#new-message):disabled{background:var(--appearance-accent-bg);color:var(--appearance-accent-muted);opacity:1}
html:root[data-theme][data-appearance-accent] .conversation.active .conversation-number{color:var(--appearance-accent-fg)}
html:root[data-theme][data-appearance-accent] .conversation.active :is(.conversation-time,.conversation-preview){color:var(--appearance-accent-muted)}
html:root[data-theme][data-appearance-accent] .conversation.active :is(.unread-badge,.assignee-badge){background:var(--appearance-accent-hover);color:var(--appearance-accent-fg)}
html:root[data-theme][data-appearance-accent] :is(#send-button,.pw-send,#new-message,.nav-button.active,.nav-button[aria-current=page],.conversation.active):focus-visible{outline:2px solid var(--appearance-accent-focus);outline-offset:2px;box-shadow:0 0 0 2px var(--appearance-accent-bg)}
