/* Shared interaction baseline, loaded by every module and the sign-in shadow root.
   Native mobile tap highlights can outlive the tap and cover a newly opened dialog.
   This inherited property covers nested icons, clickable rows and new controls too. */
:root, :host { -webkit-tap-highlight-color: transparent; }

/* Touch feedback belongs to the pressed control, inside the page's stacking order.
   Keep each module's coloured :active backgrounds; this adds a small tonal change
   for controls without their own pressed style. No overlay, timer or layout shift. */
@media (any-pointer: coarse) {
  :where(button, a[href], summary, [role="button"], [role="link"], [role="tab"],
    input[type="button"], input[type="submit"], input[type="reset"]):where(:active):not(:disabled, [aria-disabled="true"]) {
    filter: brightness(.94);
  }
}

/* Keep focus targets and keyboard behaviour intact; automatic focus on a title
   or panel should not look like a selected control. */
:root { --ag-focus-colour: #59754F; }
body.admin-app { --ag-focus-colour: #64748B; }

body :is(h1,h2,h3,h4,h5,h6,[role="heading"],[role="tabpanel"],[role="alert"],dialog):focus {
  outline: none !important;
  box-shadow: none !important;
}

/* Safari can apply :focus-visible to a newly opened dialog's controls after a
   pointer click. Track the input method instead of removing focus or tab stops. */
html[data-ag-input="pointer"] body :focus:not([aria-invalid="true"]):not(.is-invalid),
html[data-ag-input="pointer"] body :focus::before,
html[data-ag-input="pointer"] body :focus::after {
  outline: none !important;
}
html[data-ag-input="pointer"] body :is(button,a,summary,input,select,textarea,[role="button"],[role="tab"]):focus:not([aria-invalid="true"]):not(.is-invalid) {
  box-shadow: none !important;
}
/* Composite fields and checkbox/switch visuals draw their ring on a wrapper. */
html[data-ag-input="pointer"] body :is(.input-wrap,.money-input,.datetime-input-shell,.setup-row,.optimizer-batch-option,.oad-option-fields label):focus-within,
html[data-ag-input="pointer"] body :is(input:focus + span,input:focus + .harvest-admin-completion-box,input:focus + .hc-switch,input:focus + .dc-switch),
html[data-ag-input="pointer"] body :is(.toggle-switch:has(input:focus) .toggle-track,.od-land-choice label:has(input:focus)) {
  outline: none !important;
  box-shadow: none !important;
}

/* A restrained, theme-matched ring appears only while navigating controls. */
html[data-ag-input="keyboard"] body :is(button,a[href],summary,input[type="checkbox"],input[type="radio"],input[type="range"],select,[role="button"],[role="tab"],[tabindex]):focus-visible:not(:is(h1,h2,h3,h4,h5,h6,[role="heading"],[role="tabpanel"],[role="alert"],dialog)) {
  outline: 2px solid var(--ag-focus-colour) !important;
  outline-offset: 2px;
}
/* The catalogue's phone link uses its entire row as the keyboard/touch target. */
@media(max-width:700px) {
  html[data-ag-input="keyboard"] body .cat-name button.btn:focus-visible { outline: none !important; }
  html[data-ag-input="keyboard"] body .cat-name button.btn:focus-visible::after { outline: 2px solid var(--ag-focus-colour) !important; outline-offset: -2px; }
}
@media(forced-colors:active) {
  :root, body.admin-app { --ag-focus-colour: Highlight; }
}
