/* Selection emphasis stays local. Never filter a dialog ancestor or a photo.
   Existing state owns selection; leaving it restores the normal presentation. */
:root { --hds-selection-accent: #a78bfa; }
html:not(.dark-mode) { --hds-selection-accent: #805ad5; }

/* Explicit project-library modes also focus before the first checkbox is ticked. */
#hdsLanding:has(#hdsSelToggle.active) .hds-filterbar-tools,
#hbLanding:has(#hbSelToggle.active) .hds-library-tools,
#yuQueuePane:has(.yu-select-all) .yu-bulk-select-row,
#yuQueuePane:has(.yu-select-all) .yu-selection-bar,
#yuDrivePane:has(.yu-drive-select:checked:not(:disabled)) .yu-drive-footer,
.cat-wrap.hds-selection-focus .cat-actions,
.hds-chk-tools:has(.hds-asset-select-action:not([hidden])),
.hds-sync-match-editor:has(.hds-match-cards input:checked) .hds-match-bulk,
#epRefDialog.has-selection .ep-ref-dialog-actions {
  border-radius: 9px;
  background: color-mix(in srgb, var(--hds-selection-accent) 12%, transparent);
  outline: 1px solid color-mix(in srgb, var(--hds-selection-accent) 48%, transparent);
  outline-offset: 2px;
  padding: 8px 10px;
  box-sizing: border-box;
}

/* Only secondary leaves are subdued: errors, live controls and titles retain contrast. */
#hdsLanding:has(#hdsSelToggle.active) :is(#hdsStats,.hds-mini-stages,.pt-mode,.pt-origin),
#hbLanding:has(#hbSelToggle.active) :is(#hbStats,.hb-type-cell>div,.hb-flow-cell>div,.hb-progress-cell>div),
#yuQueuePane:has(.yu-select-all) .yu-job:not(.needs-attention) .yu-jmeta,
#yuDrivePane:has(.yu-drive-select:checked:not(:disabled)) .yu-library-row[data-needs-review="false"] .yu-media-status,
.cat-wrap.hds-selection-focus :is(#catStats,.cat-tags,.cat-bar),
.hds-chk-tools:has(.hds-asset-select-action:not([hidden])) > :is(.hds-provider-gallery-size,.hds-provider-gallery-toggle) {
  filter: grayscale(1);
  opacity: .55;
}

#hdsLanding:has(#hdsSelToggle.active) [data-delivery-overview],
#hbLanding:has(#hbSelToggle.active) [data-delivery-overview],
#hdsLanding:has(#hdsSelToggle.active) .hds-landing-actions > button,
#hbLanding:has(#hbSelToggle.active) .hds-landing-actions > button,
.cat-wrap.hds-selection-focus :is(#catRebuild,#catSuggest),
.hds-sync-match-editor:has(.hds-match-cards input:checked) .hds-sync-review > button {
  filter: grayscale(1);
  opacity: .6;
}
/* Secondary actions remain usable and regain emphasis on keyboard/pointer focus. */
#hdsLanding [data-delivery-overview]:is(:hover,:focus-visible),
#hbLanding [data-delivery-overview]:is(:hover,:focus-visible),
#hdsLanding .hds-landing-actions > button:is(:hover,:focus-visible),
#hbLanding .hds-landing-actions > button:is(:hover,:focus-visible),
.cat-wrap :is(#catRebuild,#catSuggest):is(:hover,:focus-visible),
.hds-sync-match-editor .hds-sync-review > button:is(:hover,:focus-visible) {
  filter: none;
  opacity: 1;
}

#hdsProjGrid .hds-trow:has(.hds-proj-check:checked) > td,
#hbProjGrid .hb-trow:has(.hb-proj-check:checked) > td,
#catGrid .cat-trow.sel > td {
  background: color-mix(in srgb, var(--hds-selection-accent) 11%, transparent);
}
#hdsProjGrid .hds-trow:has(.hds-proj-check:checked) > td:first-child,
#hbProjGrid .hb-trow:has(.hb-proj-check:checked) > td:first-child,
#catGrid .cat-trow.sel > td:first-child {
  box-shadow: inset 3px 0 var(--hds-selection-accent);
}
#yuDriveRows .yu-library-row:has(.yu-drive-select:checked:not(:disabled)),
#yuJobs .yu-job.selected,
#catGrid :is(.cat-card,.cat-row).sel,
.hds-sync-match-editor .hds-match-cards .hds-sync-review:has(input:checked),
#epRefDialog .ep-ref-import-item:has(input:checked) {
  background: color-mix(in srgb, var(--hds-selection-accent) 10%, transparent);
  box-shadow: inset 3px 0 var(--hds-selection-accent);
}
.cat-wrap.hds-selection-focus #catRemix {
  border-color: var(--hds-selection-accent);
  background: color-mix(in srgb, var(--hds-selection-accent) 22%, var(--card-bg,#252528));
  font-weight: 700;
}
:is(#hdsProjGrid,#hbProjGrid,#catGrid,#yuDriveRows,#yuJobs,.hds-match-cards) input[type=checkbox] {
  accent-color: var(--hds-selection-accent);
}
/* No opacity on containers: selected photos and open comparisons stay readable. */
.hds-chk-tools:has(.hds-asset-select-action:not([hidden])) {
  flex-wrap: wrap;
  gap: 6px;
}
@media (max-width: 640px) {
  #hdsLanding:has(#hdsSelToggle.active) .hds-filterbar-tools,
  #hbLanding:has(#hbSelToggle.active) .hds-library-tools,
  #yuQueuePane:has(.yu-select-all) .yu-bulk-select-row {
    flex-wrap: wrap;
    min-width: 0;
    max-width: 100%;
  }
}

/* Action hierarchy: filled primary, outlined secondary, quiet exit, red delete.
   Use actual disabled state so busy/unavailable actions never appear actionable. */
#hbStatusCard.hb-selecting #hbBulkActions {
  background: color-mix(in srgb,var(--hb-accent) 9%,var(--hb-bg));
  border-color: color-mix(in srgb,var(--hb-accent) 55%,var(--hb-line));
}
#hbStatusCard.hb-selecting #hbBulkCount { color:var(--hb-accent); }
#hbBulkActions .hb-bulk-secondary :is(button,select):not(:disabled),
#hdsLanding:has(#hdsSelToggle.active) #hdsSelAll,
#hbLanding:has(#hbSelToggle.active) #hbSelAll,
#yuQueuePane:has(.yu-select-all) :is(.yu-bulk-select-row,.yu-selection-bar,.yu-selection-editor) select,
.hds-chk-tools .hds-asset-select-action:not([hidden]),
.hds-sync-match-editor .hds-match-bulk button:first-child {
  background: var(--input-bg,var(--card-bg,#252528));
  border: 1px solid var(--border-color,#56515f);
  color: var(--text-primary,#f4f1ff);
  font-weight: 500;
  filter: none;
  opacity: 1;
  box-shadow: none;
}
#hbBulkActions #hbBulkExport:not(:disabled),
#yuQueuePane:has(.yu-row-select:checked) .yu-selection-editor button[onclick^="yuApply"]:not(:disabled),
#yuDrivePane:has(.yu-drive-select:checked:not(:disabled)) #yuImportSelected:not(:disabled),
.cat-wrap.hds-selection-focus #catRemix:not(:disabled),
.hds-sync-match-editor .hds-match-bulk button:last-child:not(:disabled),
#epRefDialog #epRefCopySelected:not(:disabled) {
  background: #7134db;
  border-color: #9063df;
  color: #fff;
  opacity: 1;
  filter: none;
  font-weight: 700;
  box-shadow: 0 2px 5px #7134db20;
}
#hdsLanding #hdsSelDelete:not(:disabled),
#hbLanding #hbSelDelete:not(:disabled),
.hds-chk-tools .hds-asset-delete-selected:not([hidden]):not(:disabled) {
  background: #ad334b;
  border-color: #d6687e;
  color: #fff;
  opacity: 1;
  filter: none;
  font-weight: 700;
}
#hbBulkActions #hbBulkClear,
#hdsLanding:has(#hdsSelToggle.active) #hdsSelToggle,
#hbLanding:has(#hbSelToggle.active) #hbSelToggle,
#yuQueuePane :is(.yu-selection-cancel,.yu-selection-done),
#yuDrivePane #yuInboxClearSelection,
.hds-chk-tools .hds-asset-select-action[onclick="hdsSetAssetSelectionMode(false)"],
#epRefDialog #epRefDialogCancel {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted,#aaa);
  font-weight: 500;
  box-shadow: none;
}
:is(#hbBulkActions,#hdsLanding,#hbLanding,.hds-chk-tools,.hds-match-bulk,#epRefDialog,.yu-selection-editor,.yu-drive-footer) :is(button,select):disabled,
#catRemix:disabled {
  opacity: .4;
  filter: grayscale(1);
  box-shadow: none;
}

/* Background information must also lose its semantic colors in selection mode.
   Target leaves, never rows/containers that include checkboxes or dialogs. */
#hbLanding:has(#hbSelToggle.active) :is(.hb-delivery-cell .hds-delivery-button,.hb-status-cell > div),
#hdsLanding:has(#hdsSelToggle.active) :is(.hds-delivery-button,.hds-history-badge),
#yuQueuePane:has(.yu-select-all) .yu-job :is(.yu-uploaded,.yu-project-origin,.yu-jdot,.yu-badge),
.cat-wrap.hds-selection-focus :is(.cat-origin-remix,.cat-uploaded,.cat-readiness,.cat-ok,.cat-no) {
  filter: grayscale(1);
  opacity: .6;
}
/* Header leaves remain readable; popovers retain their own colors and stacking. */
.hb-wrap:has(#hbLanding #hbSelToggle.active) > .page-header :is(.page-title,.hsg-trigger,.hds-upload-sync > button,.hds-upload-sync-details > summary),
.hds-wrap:has(#hdsLanding #hdsSelToggle.active) > .page-header :is(.page-title,.hsg-trigger,.hds-upload-sync > button,.hds-upload-sync-details > summary) {
  filter: grayscale(1);
  opacity: .6;
}
