/* static/brand/rules.css — the brand book's shared rules for client pages.
 *
 * THE ONE PLACE in this repo that draws a keyboard focus ring or a dialog
 * backdrop on a client page. Every client shell loads it
 * (templates/booking/_shell.html, templates/partials/brand_public_head.html,
 * templates/partials/brand_standalone_head.html for the script-free Brunner
 * pages, and the few standalone client templates); no other client stylesheet or
 * template may write an outline colour, width or offset, or a backdrop
 * colour. tests/test_brand_focus_rules.py enforces that, and
 * tests/browser/test_focus_ring.py checks the result in a real browser.
 *
 * Values come only from the generated brand tokens in
 * static/brand/tokens.css: --brand-focus-width, --brand-focus-color,
 * --brand-focus-offset, --brand-focus-offset-edge, --brand-scrim.
 *
 * Brand book (~/Projects/tate-brand, tokens.json, Stanley 2026-11-18):
 *
 *   rules.focusShapes  One ring, one colour, one width, two shapes.
 *                      OFFSET (4px out) on things you press: buttons, links,
 *                      dropdowns (a native <select> included), option cards,
 *                      checkboxes and radios.
 *                      EDGE (0: the ring hugs the field's own edge) on things
 *                      you type in, because a text field shows its ring on
 *                      every click and must not sit over the figures. Nothing
 *                      is drawn inside the field, there is never a second
 *                      ring, and the field's border stays visible inside the
 *                      ring so an invalid field keeps its error edge.
 *   rules.scrim        A dialog dims the page behind it with the scrim (the
 *                      canvas at 72%). Nothing else uses it.
 *   rules.noThemingThroughHas
 *                      Nothing here uses :has(): browsers from before 2023
 *                      drop the whole rule. A card that rings for the control
 *                      inside it gets a class from static/brand/focus-card.js.
 *
 * The declarations are !important on purpose. The booking shell loads a
 * vendored kit with about thirty focus rules of its own and the public pages
 * load the staff UI kit, whose fields remove their outline; one rule has to
 * win over all of them wherever it is loaded.
 */

/* ── Shape 1, offset: everything a keyboard can reach ─────────────────────── */
:focus-visible {
  outline: var(--brand-focus-width) solid var(--brand-focus-color) !important;
  outline-offset: var(--brand-focus-offset) !important;
}

/* ── Shape 2, edge: things you type in ────────────────────────────────────
   Plain :focus, not :focus-visible: a text field rings on a click too (every
   current browser already treats it that way), and a browser that does not
   know :focus-visible still shows the ring. The list is positive, so an
   input type nobody listed keeps the offset ring rather than none.
   No shadow on a focused field: a glow would be a second ring. */
input:not([type]):focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="url"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
input[type="month"]:focus,
input[type="week"]:focus,
input[type="time"]:focus,
input[type="datetime-local"]:focus,
textarea:focus,
[contenteditable=""]:focus,
[contenteditable="true"]:focus {
  outline: var(--brand-focus-width) solid var(--brand-focus-color) !important;
  outline-offset: var(--brand-focus-offset-edge) !important;
  box-shadow: none !important;
}

/* ── A card that holds its own radio or tick box ──────────────────────────
   The ring belongs on the card, not on the small control inside it.
   static/brand/focus-card.js puts .is-focus-ring on the card while its
   control has keyboard focus (and .brand-focus-js on <html> once it runs).
   If the script has not run, the control keeps the offset ring above; a card
   whose control is visually hidden rings whenever focus is inside it. */
.is-focus-ring {
  outline: var(--brand-focus-width) solid var(--brand-focus-color) !important;
  outline-offset: var(--brand-focus-offset) !important;
}
.is-focus-ring input:focus-visible,
.is-focus-ring input:focus,
.is-focus-ring ~ input:focus-visible,
.is-focus-ring ~ input:focus { outline: none !important; }
html:not(.brand-focus-js) .bk-about-check:focus-within,
html:not(.brand-focus-js) [data-focus-card]:focus-within {
  outline: var(--brand-focus-width) solid var(--brand-focus-color) !important;
  outline-offset: var(--brand-focus-offset) !important;
}

/* ── No ring: a heading a script moves focus to ───────────────────────────
   A page moves focus to a heading after a step change so a screen reader
   announces it. A heading is not a control, so it never shows the ring
   (Stanley, 2026-11-19). */
h1[tabindex="-1"]:focus,
h2[tabindex="-1"]:focus,
h3[tabindex="-1"]:focus,
h4[tabindex="-1"]:focus,
h1[tabindex="-1"]:focus-visible,
h2[tabindex="-1"]:focus-visible,
h3[tabindex="-1"]:focus-visible,
h4[tabindex="-1"]:focus-visible { outline: none !important; }

/* ── Scrim: what a dialog dims the page with ──────────────────────────────
   .brand-scrim is the full-page layer behind a dialog built from a <div>;
   ::backdrop covers a native <dialog>. */
.brand-scrim,
dialog::backdrop {
  background: var(--brand-scrim) !important;
}
