/*
 * Shared demo primitives (generic looks reused across multiple demos).
 *
 * Each demo's demo.css holds only that component's own styling; the generic
 * classes used across components are defined here exactly once. This structurally
 * prevents drift from hand-copying into each demo (e.g. forgetting a button style).
 *
 * These are published as code on the "shared styles" page (/foundation) alongside
 * variables.css, so users can copy them verbatim when taking a demo into their app.
 *
 * ---------------------------------------------------------------------------
 * State vocabulary — one meaning per visual device, across every demo.
 *
 *   hover           fill only (`background`). Never an accent outline: the pointer
 *                   merely passing over a control must not read as reaching it.
 *   state           accent `border-color` — "this control is engaged": a menu that
 *                   is open, an option that is selected, a page that is current.
 *   keyboard focus  accent ring (`outline`) via `:focus-visible`.
 *
 * The state border and the focus ring are two accent lines, so a control that is
 * both must show only one: state rules carry `:not(:focus-visible)` and the ring
 * wins. Controls that take a state border sit on `border: 1px solid transparent`
 * at rest, so gaining one never reflows the layout.
 * ---------------------------------------------------------------------------
 */

/* Demo trigger / action button (the same plain button look as the dialog etc. demos). */
.demo-trigger {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: 0.375rem;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
}

/* Hover fills; it never draws an outline. The accent belongs to focus, so a pointer
   passing over a launcher does not read the same as reaching it by keyboard. */
.demo-trigger:hover {
  background: var(--surface-subtle);
}

/* Open state: the launcher of an expanded menu / panel takes the accent border, so
   "open" stays distinguishable from "hovered". Yielding to `:focus-visible` keeps
   the border and the ring from stacking into a doubled frame. */
.demo-trigger[aria-expanded="true"]:not(:focus-visible) {
  border-color: var(--accent);
}

.demo-trigger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/*
 * A top-level item of a horizontal bar (a menubar's top item, a navigation menu's
 * trigger). Flat rather than boxed: it rests on a transparent border so the open
 * state's accent never resizes the bar, and the ring is inset so it is not clipped
 * by the bar's own padding.
 */
.demo-baritem {
  /* Flex rather than the anchor's default inline flow, so a link, a button and a
     square chevron sitting side by side in the bar all come out the same height. */
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.75rem;
  border: 1px solid transparent;
  border-radius: 0.375rem;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.demo-baritem:hover {
  background: var(--surface-subtle);
}

/* An open bar item must not read as merely hovered, so it takes the surface change
   *and* the accent border — and yields the border to the ring under keyboard focus. */
.demo-baritem[aria-expanded="true"] {
  background: var(--surface-subtle);
}

.demo-baritem[aria-expanded="true"]:not(:focus-visible) {
  border-color: var(--accent);
}

.demo-baritem:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/*
 * A row inside a menu or list popup (menu items, menu links, list options).
 *
 * Focus and hover can be true of different rows at once — the library moves focus
 * to the *active* row while the pointer may rest on another — so both fill, and the
 * active one adds the accent border on top. Rows rest on a transparent border so
 * that addition never reflows the popup.
 */
.demo-menuitem {
  display: block;
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 0.25rem;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}

.demo-menuitem:hover,
.demo-menuitem:focus {
  /* Both the fill and the text colour are stated: the highlight token follows the
     theme, so the row keeps its contrast in light and dark alike. */
  background: var(--color-primary-soft);
  color: var(--color-text);
}

/* Pointer-driven focus (opening a menu focuses its first row without a ring) shows
   the state border; keyboard focus shows the ring below instead. */
.demo-menuitem:focus:not(:focus-visible),
.demo-menuitem[aria-selected="true"]:not(:focus-visible),
.demo-menuitem[aria-current]:not(:focus-visible) {
  border-color: var(--accent);
}

.demo-menuitem:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* A disabled row keeps its place in the menu but takes no state at all. */
.demo-menuitem[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

.demo-menuitem[aria-disabled="true"]:hover {
  background: transparent;
}

/* The affirmative action of a pair (a dialog's confirm next to its cancel): filled
   with the accent so the default choice reads first. */
.demo-trigger--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--white);
}

/* Stated after `.demo-trigger:hover` so the accent fill survives the pointer; the
   fill only deepens, staying inside the "hover fills" rule. */
.demo-trigger--primary:hover {
  border-color: var(--accent-700);
  background: var(--accent-700);
}

/* Disabled state (e.g. a live-counter trigger while its subscription is
   unconfirmed): mirrors the reduced-affordance look without relying on the
   browser default, which varies per engine. */
.demo-trigger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.demo-trigger:disabled:hover {
  background: var(--bg);
}

/* The label row of a demo's width slider — a control that shrinks the demo's container
   so a size-driven behavior (banking items, collapsing a trail) can be watched happening
   instead of only being described. */
.demo-width-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-text-muted);
}

/* Demo text inputs (input[type=text/search/...] / textarea). Same plain border and
   radius as the trigger button, unifying the look across the input demos (input_mask /
   auto_submit / nested_form / reset_before_cache, etc.) in one place. Each demo.css
   adds only its state selectors (e.g. [data-mask-complete] / [data-auto-submit-pending]);
   the base look stays here to prevent drift from hand-copying. */
.demo-input {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: 0.375rem;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.demo-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Card surface (background, border, radius, padding, shadow). A shared surface so
   the calendar / date_range_picker demos sit in the same framing. Per-demo layout
   like width / display stays in each demo.css (only the surface is centralized here,
   to prevent drift from hand-copying). */
.demo-card {
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

/* Visually hidden but still read by screen readers (used for accessible labels, etc.). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
