/* Own the component states, including mouse focus after pointer leave.
 * Only paint properties are forced: host themes retain no button/link colours,
 * while component layout, typography and native control behaviour stay intact.
 * Keep state colours in variables so selected, danger and mail states survive.
 */
:is(.pool-portal, .pool-login-screen, .pool-performance-widget, .cip-admin) :where(button, input[type="button"], input[type="submit"], input[type="reset"], a) {
  --pool-control-bg: var(--pool-control-surface, rgba(255, 255, 255, .035));
  --pool-control-ink: var(--pool-text);
  --pool-control-border: var(--pool-line-strong);
  --pool-control-hover-bg: var(--pool-cyan-soft);
  --pool-control-hover-ink: var(--pool-accent-ink, var(--pool-cyan));
  --pool-control-hover-border: var(--pool-cyan);
  background: var(--pool-control-bg) !important;
  color: var(--pool-control-ink) !important;
  border-color: var(--pool-control-border) !important;
  box-shadow: none !important;
  text-shadow: none !important;
  text-decoration: none !important;
}

/* Ordinary links and small icon actions start without a filled surface. */
:is(.pool-portal, .pool-login-screen, .pool-performance-widget, .cip-admin) a,
.pool-portal :is(.pool-icon-button, .pool-notification-button, .pool-icon-dismiss, .pool-modal__close, .pool-ap__dialog-head > button, .pool-lead-contact-card__actions button),
.pool-portal .pool-portalbar :is(button, a),
.pool-performance-widget :is(.pool-intent-group-toggle, th button) {
  --pool-control-bg: transparent;
  --pool-control-border: transparent;
}
:is(.pool-portal, .pool-login-screen, .pool-performance-widget, .cip-admin) a {
  --pool-control-ink: var(--pool-accent-ink, var(--pool-cyan));
  --pool-control-hover-bg: transparent;
}
.pool-portal .pool-portalbar a,
.pool-portal .pool-lead-contact-card a { --pool-control-ink: var(--pool-text); }
.pool-portal .pool-portalbar a { --pool-control-hover-bg: var(--pool-cyan-soft); }
.pool-portal :is(.pool-icon-dismiss, .pool-modal__close, .pool-inline-edit, .pool-inline-editor__cancel, .pool-ap__dialog-head > button, .pool-lead-contact-card__actions button),
.pool-performance-widget th button { --pool-control-ink: var(--pool-muted); }
.pool-portal :is(.pool-inline-editor__save),
.pool-performance-widget .pool-intent-group-toggle { --pool-control-ink: var(--pool-accent-ink, var(--pool-cyan)); }

/* Primary actions must remain cyan when focused by a mouse click. */
:is(.pool-portal, .pool-login-screen, .pool-performance-widget, .cip-admin) :is(.pool-primary-action, input[type="submit"], .button-primary) {
  --pool-control-bg: var(--pool-cyan);
  --pool-control-ink: #071014;
  --pool-control-border: var(--pool-cyan);
  --pool-control-hover-bg: #30d8fd;
  --pool-control-hover-ink: #071014;
  --pool-control-hover-border: #30d8fd;
}
.pool-portal .pool-lead-accordion__summary {
  --pool-control-bg: transparent;
  --pool-control-border: transparent;
  --pool-control-hover-ink: var(--pool-text);
  --pool-control-hover-border: transparent;
}
.pool-portal :is(.pool-danger-action, .pool-lead-archive-action, [data-lead-contact-delete]),
.cip-admin .pool-danger-action {
  --pool-control-bg: rgba(255, 79, 98, .08);
  --pool-control-ink: var(--pool-red);
  --pool-control-border: var(--pool-red);
  --pool-control-hover-bg: rgba(255, 79, 98, .16);
  --pool-control-hover-ink: var(--pool-red);
  --pool-control-hover-border: var(--pool-red);
}

/* Persistent selections are independent of :focus / :hover. */
.pool-portal :is([data-portal-tab].is-active, .pool-filter-toggle.is-active, .pool-filter-toggle[aria-expanded="true"], .pool-range-filter button.is-active, .pool-person-filter button.is-active, .pool-icon-button[aria-expanded="true"], .pool-notification-button[aria-expanded="true"]),
.pool-performance-widget :is(.pool-range-filter button.is-active, .pool-person-filter button.is-active, .pool-row-actions button.is-active, .pool-intent-group-toggle[aria-expanded="true"]),
.cip-admin .nav-tab-active {
  --pool-control-bg: var(--pool-cyan-soft);
  --pool-control-ink: var(--pool-accent-ink, var(--pool-cyan));
  --pool-control-border: var(--pool-cyan);
}
.pool-performance-widget .pool-row-actions :is([data-intent-action="junk"], [data-intent-action="spam"]).is-active {
  --pool-control-bg: rgba(255, 79, 98, .12);
  --pool-control-ink: var(--pool-red);
  --pool-control-border: var(--pool-red);
  --pool-control-hover-bg: rgba(255, 79, 98, .2);
  --pool-control-hover-ink: var(--pool-red);
  --pool-control-hover-border: var(--pool-red);
}
.pool-performance-widget .pool-row-actions [data-intent-action="convert"].is-active,
.pool-performance-widget .pool-notify-intent[data-notice-status="sent"] {
  --pool-control-bg: rgba(255, 197, 61, .08);
  --pool-control-ink: var(--pool-amber);
  --pool-control-border: var(--pool-amber);
  --pool-control-hover-bg: rgba(255, 197, 61, .16);
  --pool-control-hover-ink: var(--pool-amber);
  --pool-control-hover-border: var(--pool-amber);
}
.pool-performance-widget .pool-notify-intent:is([data-notice-status="responded"], [data-notice-status="answered"]) {
  --pool-control-bg: rgba(84, 226, 150, .08);
  --pool-control-ink: var(--pool-green);
  --pool-control-border: var(--pool-green);
  --pool-control-hover-bg: rgba(84, 226, 150, .16);
  --pool-control-hover-ink: var(--pool-green);
  --pool-control-hover-border: var(--pool-green);
}
.pool-performance-widget .pool-intent-group-toggle {
  --pool-control-bg: var(--pool-control-surface, rgba(255, 255, 255, .035));
  --pool-control-ink: var(--pool-text);
  --pool-control-border: var(--pool-line-strong);
  --pool-control-hover-ink: var(--pool-text);
}

/* Hover must not stick on touch screens or recolour disabled actions. */
@media (hover: hover) and (pointer: fine) {
  :is(.pool-portal, .pool-login-screen, .pool-performance-widget, .cip-admin) :is(button, input[type="button"], input[type="submit"], input[type="reset"], a):not(:disabled):not([aria-disabled="true"]):hover {
    background: var(--pool-control-hover-bg) !important;
    color: var(--pool-control-hover-ink) !important;
    border-color: var(--pool-control-hover-border) !important;
  }
}
:is(.pool-portal, .pool-login-screen, .pool-performance-widget, .cip-admin) :is(button, input[type="button"], input[type="submit"], input[type="reset"], a):not(:disabled):not([aria-disabled="true"]):is(:active, :focus-visible) {
  background: var(--pool-control-hover-bg) !important;
  color: var(--pool-control-hover-ink) !important;
  border-color: var(--pool-control-hover-border) !important;
}
:is(.pool-portal, .pool-login-screen, .pool-performance-widget, .cip-admin) :is(button, input, select, textarea, a, [tabindex]):focus-visible {
  outline: 2px solid var(--pool-accent-ink, var(--pool-cyan)) !important;
  outline-offset: 3px !important;
}
.pool-portal .pool-lead-accordion__summary:focus-visible { outline-offset: -3px !important; }
:is(.pool-portal, .pool-login-screen, .pool-performance-widget, .cip-admin) :is(button, input[type="button"], input[type="submit"], input[type="reset"], a):focus:not(:focus-visible) {
  outline: none !important;
}
:is(.pool-portal, .pool-login-screen, .pool-performance-widget, .cip-admin) :is(button, input):disabled {
  opacity: .65;
  cursor: not-allowed !important;
}

/* GeneratePress also repaints text fields on focus. Keep their own surface. */
:is(.pool-portal, .pool-login-screen, .pool-performance-widget, .cip-admin) :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="hidden"]), select, textarea) {
  background: var(--pool-field-bg, #eef2f4) !important;
  color: var(--pool-field-ink, #161a1d) !important;
  border-color: var(--pool-field-border, var(--pool-line-strong)) !important;
  box-shadow: none !important;
}
:is(.pool-portal, .pool-login-screen, .pool-performance-widget, .cip-admin) :is(input, select, textarea):focus {
  --pool-field-border: var(--pool-cyan);
}
.pool-ap, .pool-audit, .pool-login-screen { --pool-field-bg: var(--pool-ink); --pool-field-ink: var(--pool-text); }

/* SweetAlert mounts outside its caller. Its low-specificity :where() rules
   otherwise lose to GeneratePress button:focus. Keep each dialog's configured
   CSS colour variables (including red confirmations), not one global colour. */
body:has(.pool-portal, .pool-performance-widget, .cip-admin) .swal2-popup .swal2-confirm {
  background: var(--swal2-confirm-button-background-color, #01cefa) !important;
  color: #071014 !important;
}
body:has(.pool-portal, .pool-performance-widget, .cip-admin) .swal2-popup .swal2-cancel {
  background: var(--swal2-cancel-button-background-color, #4d555b) !important;
  color: #fff !important;
}
body:has(.pool-portal, .pool-performance-widget, .cip-admin) .swal2-popup .swal2-deny {
  background: var(--swal2-deny-button-background-color, #dc3741) !important;
  color: #fff !important;
}
@media (hover: hover) and (pointer: fine) {
  body:has(.pool-portal, .pool-performance-widget, .cip-admin) .swal2-popup .swal2-styled:not(:disabled):hover { filter: brightness(1.08); }
}
body:has(.pool-portal, .pool-performance-widget, .cip-admin) .swal2-popup .swal2-styled:not(:disabled):active { filter: brightness(.94); }
body:has(.pool-portal, .pool-performance-widget, .cip-admin) .swal2-popup .swal2-styled:focus {
  box-shadow: none !important;
  outline: 2px solid var(--pool-accent-ink, var(--pool-cyan, #01cefa)) !important;
  outline-offset: 3px;
}
body:has(.pool-portal, .pool-performance-widget, .cip-admin) .swal2-popup .swal2-styled:focus:not(:focus-visible) { outline: none !important; }
