/* User refinement, 2026-10-17: focus stays inside the existing surface.
 * Keep ordinary borders, selected/semantic fills and destination highlights.
 * Important only prevents legacy/lazy scoped outlines from returning. */
:is(:focus, :focus-visible, :focus-within),
label:has(input:is([type="checkbox"], [type="radio"]):focus-visible),
input:is([type="checkbox"], [type="radio"]):focus-visible + span {
  outline: none !important;
}

/* Only actions receive a wash. Text fields and editors keep their own surface,
 * including transparent children of search/composer frames. A generic tabindex
 * can belong to an entire panel; it must never paint a focus-sized rectangle. */
:is(button, a[href], summary, [role="button"], [role="link"], [role="menuitem"], [role="tab"], [role="option"], input:is([type="button"], [type="submit"], [type="reset"], [type="checkbox"], [type="radio"])):focus-visible,
input:is([type="checkbox"], [type="radio"]):focus-visible + span {
  box-shadow: inset 0 0 0 100vmax color-mix(in srgb, currentColor 12%, transparent) !important;
}

/* Standalone fields use their existing border. Borderless nested editors keep
 * their frame's focus treatment; invalid fields retain their semantic colour. */
:where(input, textarea, select):focus-visible:where(:not([aria-invalid="true"], :user-invalid, .has-error *)) {
  border-color: var(--ink-2, var(--ink, #3f5f4d));
}

/* Message navigation owns its timed glow; keyboard focus remains a quiet wash. */
#app .message-row:focus-visible:not(.search-target) {
  background-color: color-mix(in srgb, var(--ink-2) 12%, transparent);
}

@media (forced-colors: active) {
  :is(button, a[href], input, textarea, select, summary, [tabindex], [contenteditable="true"]):focus-visible:not(dialog):not(.message-row):not(.search-target),
  #app .message-row:focus-visible:not(.search-target),
  label:has(input:is([type="checkbox"], [type="radio"]):focus-visible),
  input:is([type="checkbox"], [type="radio"]):focus-visible + span {
    box-shadow: none !important;
    background-color: Highlight !important;
    color: HighlightText !important;
    caret-color: HighlightText !important;
  }
  /* Keep Chromium from remapping the caret/placeholder away from this system fill. */
  :is(input, textarea):focus-visible { forced-color-adjust: none; }
  :is(input, textarea):focus-visible::placeholder { color: HighlightText !important; opacity: 1; }
  /* Preserve the navigation destination marker in the user's contrast mode. */
  #app .message-row.search-target { outline: 1px solid Highlight !important; }
}
