/* Redwood controls — buttons, the buttonset (segmented control), the toolbar
 * and badges.
 *
 * Like redwood-cards.css this adds no color and no scale step. Values were read
 * out of the JET 21.0.0 Redwood theme (oj-redwood-min.css: --oj-button-*,
 * --oj-badge-*, --oj-toolbar-*; identical at 19.0.0) and the core-pack theme
 * that ships beside it (oraclejet-preact Theme-redwood/theme.css:
 * --oj-c-base-button-variants-*, Badge, ButtonLabelLayout), and mapped onto
 * the --rw-* names. Where the two disagree the core pack wins, because oj-c-*
 * is what the JET Cookbook now marks as the replacement for each legacy
 * element. The raw lengths are structural: a 1px border, the badge's
 * status-dot diameter, and the -1px overlap that joins a buttonset.
 *
 * Load after redwood-tokens.css (and redwood-dark.css if you use it).
 *
 *   <button class="rw-btn">Cancel</button>                     outlined
 *   <button class="rw-btn rw-btn-primary">Post invoice</button>
 *   <button class="rw-btn rw-btn-solid rw-btn-sm">Filter</button>
 *   <button class="rw-btn rw-btn-borderless rw-btn-icon" aria-label="Close"><svg/></button>
 *
 *   <div class="rw-buttonset" role="group" aria-label="Period">
 *     <button class="rw-btn" aria-pressed="true">Month</button>
 *     <button class="rw-btn" aria-pressed="false">Quarter</button>
 *   </div>
 *
 *   <span class="rw-badge rw-badge-success rw-badge-subtle">Paid</span>
 *
 * Readings, and where each is rounded onto a token:
 *
 *   Button     2.75rem high (11x), 2.25rem small (9x); 1rem from text to edge
 *              at both sizes; body-sm at 600; radius md; icons 1.5rem, 1.25rem
 *              small. Icon to text is .625rem in the theme — half a step — and
 *              is rounded here to 2x, the small button's own value.
 *   Outlined   transparent, 1px border-enabled. Disabled border is
 *              text-disabled (the legacy reading; the core pack's .2 alpha has
 *              no token).
 *   Solid      a neutral-190 .08 fill, which is --rw-bg-hover exactly.
 *   Borderless transparent until hovered.
 *   States     the core pack draws hover and active as overlays layered on
 *              the base fill (--oj-c-overlay-hover .08, -active .16). That is
 *              the card pattern: a background-image over the background-color,
 *              so a solid button under the pointer is darker than at rest
 *              rather than swapped to a second fill. Disabled fills are
 *              neutral-190 at .04 in Oracle's theme; that alpha has no token
 *              and is rounded to --rw-bg-muted (neutral-20, which is what .04
 *              composites to on white).
 *   Selected   bg-selected, border-selected, text-primary — the same pair as
 *              a selected card, row or item. Never brand text, never a fill of
 *              its own.
 *   Danger     danger-120 with white ink (--oj-c-surface-danger-strong).
 *
 * What people get wrong:
 *
 *   The primary button. Oracle's call-to-action chroming is neutral-170 with
 *   hover 160 and active 150. This file keeps the house rule from
 *   STYLE-GUIDE §5 — brand-110, hover brand-120, active brand-130 — and the
 *   disagreement is recorded in §10 Known gaps. One primary per region.
 *
 *   Buttons are not pills and are not uppercase. Radius md, sentence case.
 *
 *   Badges are pills. The theme gives the badge a radius of half its height
 *   (.75rem on a 1.5rem badge), the one rounded-end shape in Redwood. It is
 *   drawn as calc(height / 2) here, so the small badge follows.
 *
 *   Badge text is weight 400, sentence case, body-sm. Not 600, not uppercase,
 *   not letter-spaced.
 *
 *   A subtle badge is a -60 status step at .4 alpha in Oracle's theme. On white
 *   that composites to the -40 step exactly for danger and warning and within
 *   a few units for success and info, so the subtle fill here is the opaque -40
 *   step with neutral-190 ink. A solid neutral badge is neutral-100 in the
 *   theme, which gives white text 4.54:1 at body-sm; it is stepped to
 *   neutral-110 (5.41:1) for the reason §5 gives brand-110 over brand-100.
 *
 *   A badge carries its own ground. Solid and subtle status badges are fixed
 *   ramp pairs, so they read the same on a light or a dark page and need no
 *   dark rule; only the neutral subtle badge is an overlay and follows the
 *   theme. Never color a badge by mixing an alpha of your own.
 *
 *   Color alone never carries the status. The badge says "Overdue"; a status
 *   dot sits next to a label, not instead of one.
 *
 *   Tabs switch views; a buttonset makes an exclusive choice or filters within
 *   one view. A buttonset whose items change the whole page is a tab bar.
 *
 * (c) Oracle. Internal brand asset — see NOTICE. */

:root {
  --rw-btn-height: var(--rw-space-11x);
  --rw-btn-icon-size: var(--rw-space-6x);
  --rw-badge-height: var(--rw-space-6x);
}

/* ── Button ───────────────────────────────────────────────────────────────── */

.rw-btn {
  box-sizing: border-box;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--rw-space-2x);
  min-height: var(--rw-btn-height);
  margin: 0;
  padding: 0 var(--rw-space-4x);
  border: 1px solid var(--rw-border-enabled);
  border-radius: var(--rw-radius-md);
  background-color: transparent;
  background-image: none;
  color: var(--rw-text-primary);
  font: inherit;
  font-size: var(--rw-body-sm-size);
  line-height: var(--rw-body-sm-lh);
  font-weight: 600;
  text-decoration: none;
  text-transform: none;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.rw-btn > svg,
.rw-btn > .rw-ico {
  flex-shrink: 0;
  width: var(--rw-btn-icon-size);
  height: var(--rw-btn-icon-size);
  font-size: var(--rw-btn-icon-size);
}

.rw-btn:hover { background-image: linear-gradient(var(--rw-bg-hover), var(--rw-bg-hover)); }
.rw-btn:active { background-image: linear-gradient(var(--rw-bg-active), var(--rw-bg-active)); }

.rw-btn:focus-visible {
  outline: 2px solid var(--rw-focus-ring);
  outline-offset: 2px;
}

.rw-btn-sm {
  --rw-btn-height: var(--rw-space-9x);
  --rw-btn-icon-size: var(--rw-space-5x);
}

/* Opt in for longer action labels in narrow cards and translated surfaces. */
.rw-btn-wrap {
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  padding-block: var(--rw-space-2x);
}

/* Icon only: square, and the label goes in aria-label (Oracle shows it as the
   tooltip). */
.rw-btn-icon {
  min-width: var(--rw-btn-height);
  padding: 0;
}

.rw-btn-solid {
  border-color: transparent;
  background-color: var(--rw-bg-hover);
}

.rw-btn-borderless { border-color: transparent; }

.rw-btn-primary {
  border-color: transparent;
  background-color: var(--rw-brand-110);
  color: var(--rw-text-on-brand);
}
.rw-btn-primary:hover { background-image: none; background-color: var(--rw-brand-120); }
.rw-btn-primary:active { background-image: none; background-color: var(--rw-brand-130); }

.rw-btn-danger {
  border-color: transparent;
  background-color: var(--rw-danger-120);
  color: var(--rw-neutral-0);
}
.rw-btn-danger:hover { background-image: none; background-color: var(--rw-danger-130); }
.rw-btn-danger:active { background-image: none; background-color: var(--rw-danger-140); }

/* Selected: a toggle button, or the chosen item of a buttonset. Hover stacks
   over the selection, as on a card. */
.rw-btn[aria-pressed="true"],
.rw-btn[aria-checked="true"],
.rw-btn.rw-selected {
  border-color: var(--rw-border-selected);
  background-color: var(--rw-bg-selected);
  color: var(--rw-text-primary);
}

.rw-btn:disabled,
.rw-btn[aria-disabled="true"] {
  cursor: default;
  background-image: none;
  color: var(--rw-text-disabled);
}
.rw-btn:not(.rw-btn-solid, .rw-btn-borderless, .rw-btn-primary, .rw-btn-danger):disabled,
.rw-btn:not(.rw-btn-solid, .rw-btn-borderless, .rw-btn-primary, .rw-btn-danger)[aria-disabled="true"] {
  border-color: var(--rw-text-disabled);
}
.rw-btn:is(.rw-btn-solid, .rw-btn-primary, .rw-btn-danger):is(:disabled, [aria-disabled="true"]) {
  background-color: var(--rw-bg-muted);
}

/* ── Buttonset (segmented control) ────────────────────────────────────────── */

/* Outlined buttons joined into one control: square inner corners, one shared
   1px separator (each item overlaps the next by its border), and the selected
   item raised so its full selected border shows on every side. */
.rw-buttonset {
  display: inline-flex;
  align-items: stretch;
  max-width: 100%;
}

.rw-buttonset > .rw-btn {
  border-radius: 0;
  margin: 0;
  margin-inline-end: -1px;
}

.rw-buttonset > .rw-btn:not(:first-child) { border-inline-start-color: transparent; }
.rw-buttonset > .rw-btn:first-child {
  border-start-start-radius: var(--rw-radius-md);
  border-end-start-radius: var(--rw-radius-md);
}
.rw-buttonset > .rw-btn:last-child {
  margin-inline-end: 0;
  border-start-end-radius: var(--rw-radius-md);
  border-end-end-radius: var(--rw-radius-md);
}

.rw-buttonset > .rw-btn:is([aria-pressed="true"], [aria-checked="true"], .rw-selected) {
  z-index: 1;
  border-color: var(--rw-border-selected);
}

/* Items touch, so the ring goes inside, as on a tab. */
.rw-buttonset > .rw-btn:focus-visible { z-index: 2; outline: none; }
.rw-buttonset > .rw-btn:focus-visible::after {
  content: "";
  position: absolute;
  inset: 1px;
  pointer-events: none;
  outline: dotted 1px var(--rw-focus-ring);
}

/* ── Toolbar ──────────────────────────────────────────────────────────────── */

/* A strip of controls: .5rem between buttons (--oj-toolbar-button-margin),
   separators with .5rem either side. One tab stop is the JET behaviour; that is
   script, not style. */
.rw-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--rw-space-2x);
}

.rw-toolbar-sep {
  align-self: stretch;
  width: 1px;
  margin: 0 var(--rw-space-2x);
  background: var(--rw-divider);
}

/* ── Badge ────────────────────────────────────────────────────────────────── */

.rw-badge {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--rw-badge-height);
  min-width: var(--rw-badge-height);
  padding: 0 var(--rw-space-3x);
  border-radius: calc(var(--rw-badge-height) / 2);
  background: var(--rw-neutral-110);
  color: var(--rw-neutral-0);
  font-size: var(--rw-body-sm-size);
  line-height: var(--rw-badge-height);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
  vertical-align: middle;
}

.rw-badge-sm {
  --rw-badge-height: var(--rw-space-5x);
  padding: 0 var(--rw-space-2x);
  font-size: var(--rw-body-2xs-size);
}

/* A longer status keeps its words visible as the available width shrinks. */
.rw-badge-wrap {
  min-width: 0;
  max-width: 100%;
  height: auto;
  min-height: var(--rw-badge-height);
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: var(--rw-body-sm-lh);
  padding-block: var(--rw-space-1x);
  text-align: start;
}

.rw-badge-danger  { background: var(--rw-danger-120); }
.rw-badge-warning { background: var(--rw-warning-120); }
.rw-badge-success { background: var(--rw-success-120); }
.rw-badge-info    { background: var(--rw-info-120); }

.rw-badge-subtle                   { background: var(--rw-bg-hover); color: var(--rw-text-primary); }
.rw-badge-subtle.rw-badge-danger   { background: var(--rw-danger-40);  color: var(--rw-neutral-190); }
.rw-badge-subtle.rw-badge-warning  { background: var(--rw-warning-40); color: var(--rw-neutral-190); }
.rw-badge-subtle.rw-badge-success  { background: var(--rw-success-40); color: var(--rw-neutral-190); }
.rw-badge-subtle.rw-badge-info     { background: var(--rw-info-40);    color: var(--rw-neutral-190); }

/* End badge: flush against the end edge of a card, so its end corners square. */
.rw-badge-end {
  border-start-end-radius: 0;
  border-end-end-radius: 0;
}

/* Status dot: the badge reduced to a .625rem circle (.375rem small) in the solid
   status color. Always next to a text label. */
.rw-badge-status {
  height: auto;
  min-width: 0;
  padding: 0;
  gap: var(--rw-space-2x);
  border-radius: 0;
  background: transparent;
  color: inherit;
  line-height: inherit;
}
.rw-badge-status::before {
  content: "";
  flex-shrink: 0;
  width: .625rem;
  height: .625rem;
  border-radius: 50%;
  background: var(--rw-neutral-100);
}
.rw-badge-status.rw-badge-sm::before { width: .375rem; height: .375rem; }
.rw-badge-status.rw-badge-danger::before  { background: var(--rw-danger-120); }
.rw-badge-status.rw-badge-warning::before { background: var(--rw-warning-120); }
.rw-badge-status.rw-badge-success::before { background: var(--rw-success-120); }
.rw-badge-status.rw-badge-info::before    { background: var(--rw-info-120); }

/* ── Windows high contrast ────────────────────────────────────────────────── */

@media (forced-colors: active) {
  .rw-btn { border-color: ButtonText; }
  .rw-btn:is(:disabled, [aria-disabled="true"]) { border-color: GrayText; color: GrayText; }
  .rw-btn:is([aria-pressed="true"], [aria-checked="true"], .rw-selected) {
    border-color: Highlight;
    outline: 2px solid Highlight;
    outline-offset: -3px;
  }
  .rw-btn:focus-visible { outline-color: Highlight; }
  .rw-buttonset > .rw-btn:focus-visible::after { outline-color: Highlight; }
  .rw-badge:not(.rw-badge-status) { border: 1px solid CanvasText; }
  .rw-badge-status::before { background: CanvasText; }
}
