/* NO raw hex/rgba/rem values — use var(--token) from base/variables.css */
/* ========================================
   BUTTONS
   ========================================
   The one place a <button> gets its look -- GitHub Primer's button set:
   variants default (no class; .secondary names it), .primary, .danger and
   .invisible; sizes .btn-sm, medium (no class) and .btn-lg; the icon buttons
   .btn-icon-delete, .btn-icon-move, .btn-icon-dismiss and .btn-icon-plain; and .segment, a
   segmented control's button. Other stylesheets place a button (margin, size,
   flex, position, animation) but give it no look of their own:
   tests/test_frontend_code_rules.py -k shared_components refuses one. */

button {
  padding: var(--spacing-xs) var(--spacing-md);
  font-family: var(--font-ui);
  font-size: var(--font-size-sm);
  border-radius: var(--radius-sm);
  border: var(--line-width-thin) solid var(--color-border);
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  cursor: pointer;
  font-weight: var(--font-weight-semibold);
  transition: all var(--transition-fast);
  box-shadow: none;
}

/* A disabled button shows no hover or pressed look. :where() adds no
   specificity, so a component's own :hover still wins over these. */
button:hover:not(:where(:disabled, [aria-disabled="true"])) {
  background: var(--color-accent-tint-strong);
  border-color: var(--color-accent-primary);
  transform: none;
  box-shadow: none;
}

button:active:not(:where(:disabled, [aria-disabled="true"])) {
  background: var(--color-border);
  transform: translateY(0);
}

button.primary {
  border-color: var(--color-accent-primary);
  background: linear-gradient(var(--angle-accent-gradient), var(--color-accent-primary) 0%, var(--color-accent-dark) 100%);
  color: var(--color-bg-primary);
  box-shadow: var(--shadow-accent);
}

button.primary:hover:not(:where(:disabled, [aria-disabled="true"])) {
  background: linear-gradient(var(--angle-accent-gradient), var(--color-accent-hover) 0%, var(--color-accent-primary) 100%);
  transform: translateY(var(--hover-lift-sm));
  box-shadow: var(--shadow-accent-hover);
}

button.primary:active:not(:where(:disabled, [aria-disabled="true"])) {
  background: var(--color-accent-dark);
  transform: translateY(0);
}

button.secondary {
  border-color: var(--color-border);
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  box-shadow: none;
}

button.secondary:hover:not(:where(:disabled, [aria-disabled="true"])) {
  background: var(--color-accent-tint-strong);
  border-color: var(--color-accent-primary);
  transform: none;
  box-shadow: none;
}

button.secondary:active:not(:where(:disabled, [aria-disabled="true"])) {
  background: var(--color-border);
}

/* A destructive action: red text at rest, a red fill under the pointer. */
button.danger {
  border-color: var(--color-error-border);
  background: var(--color-bg-tertiary);
  color: var(--color-error-text);
}

button.danger:hover:not(:where(:disabled, [aria-disabled="true"])) {
  background: var(--color-error-solid);
  border-color: var(--color-error-solid);
  color: var(--color-text-on-accent);
  box-shadow: var(--shadow-error);
}

button.danger:active:not(:where(:disabled, [aria-disabled="true"])) {
  background: var(--color-error-solid-hover);
  border-color: var(--color-error-solid-hover);
}

/* A minimal action beside the content it acts on: no fill or border at rest. */
button.invisible {
  border-color: transparent;
  background: transparent;
  color: var(--color-text-secondary);
}

button.invisible:hover:not(:where(:disabled, [aria-disabled="true"])) {
  border-color: transparent;
  background: var(--color-accent-tint);
  color: var(--color-accent-primary);
}

button.invisible:active:not(:where(:disabled, [aria-disabled="true"])) {
  background: var(--color-accent-tint-strong);
}

/* Sizes. Medium is the default; small for an action inside a card, row or
   toolbar; large for a page's one main action and its tabs. */
button.btn-sm {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: var(--font-size-xs);
}

button.btn-lg {
  padding: var(--spacing-sm) var(--spacing-lg);
  font-size: var(--font-size-lg);
}

/* A segmented control's button: one of a set of mutually exclusive options --
   tabs, steps, a view switch. The selected one is marked by its ARIA state,
   which a screen reader announces too. */
button.segment {
  border-color: var(--color-border-subtle);
  background: transparent;
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-normal);
}

button.segment:hover:not(:where(:disabled, [aria-disabled="true"])) {
  border-color: var(--color-border);
  background: var(--color-accent-tint);
  color: var(--color-text-primary);
}

button.segment[aria-selected="true"],
button.segment[aria-pressed="true"] {
  border-color: var(--color-accent-primary);
  background: var(--color-accent-tint-faint);
  color: var(--color-accent-primary);
  font-weight: var(--font-weight-semibold);
}

/* An icon glyph inside a button, beside its label. */
button .btn-icon {
  font-size: var(--font-size-xl);
}

/* Icon-only delete button — transparent bg, error color text, no border */
button.btn-icon-delete {
  background: none;
  border: none;
  color: var(--color-error);
  padding: 0 var(--spacing-xs);
  font-size: var(--font-size-lg);
  font-weight: bold;
  line-height: var(--line-height-none);
  opacity: var(--opacity-muted);
  box-shadow: none;
}

button.btn-icon-delete:hover:not(:where(:disabled, [aria-disabled="true"])) {
  background: none;
  border-color: transparent;
  color: var(--color-error-solid);
  opacity: 1;
}

button.btn-icon-delete:active:not(:where(:disabled, [aria-disabled="true"])) {
  background: none;
  color: var(--color-error-solid-hover);
}

/* Icon-only move/insert buttons -- btn-icon-delete's transparent, borderless
   pattern in a neutral colour, since these actions destroy nothing. Used by
   the editor's event list and the wizard's chain cards. */
button.btn-icon-move {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  padding: 0 var(--spacing-2xs);
  font-size: var(--font-size-xs);
  line-height: var(--line-height-none);
  opacity: var(--opacity-muted);
  box-shadow: none;
}

button.btn-icon-move:hover:not(:where(:disabled, [aria-disabled="true"])) {
  background: none;
  border-color: transparent;
  color: var(--color-accent-primary);
  opacity: 1;
}

button.btn-icon-move:active:not(:where(:disabled, [aria-disabled="true"])) {
  background: none;
  color: var(--color-accent-hover);
}

/* Icon buttons with a glyph alone (Primer's IconButton): at least the smallest
   pointer target (WCAG 2.2 2.5.8), the glyph centred in it -- a minimum size,
   so a larger glyph still grows the target. .btn-icon-dismiss closes a message,
   a notice, a status line or a filter, in the colour of the text it closes and
   faint until pointed at or focused; .btn-icon-plain is any other icon action
   (a notice's "i"), in its text's colour at full strength. */
button.btn-icon-dismiss,
button.btn-icon-plain {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-inline-size: var(--target-size-min);
  min-block-size: var(--target-size-min);
  background: none;
  border: none;
  color: inherit;
  padding: 0;
  font-size: var(--font-size-lg);
  line-height: var(--line-height-none);
  box-shadow: none;
}

button.btn-icon-dismiss {
  opacity: var(--opacity-subtle);
}

button.btn-icon-dismiss:hover:not(:where(:disabled, [aria-disabled="true"])),
button.btn-icon-dismiss:active:not(:where(:disabled, [aria-disabled="true"])) {
  background: none;
  border-color: transparent;
  opacity: 1;
}

button.btn-icon-dismiss:focus-visible:not(:where(:disabled, [aria-disabled="true"])) {
  opacity: 1;
}

button.btn-icon-plain:hover:not(:where(:disabled, [aria-disabled="true"])),
button.btn-icon-plain:active:not(:where(:disabled, [aria-disabled="true"])) {
  background: var(--color-accent-tint);
  border-color: transparent;
}

/* A navigation entry (Primer's NavList item), on a button or a link: a full-width
   row with no fill at rest, a bar on its leading edge that turns teal under the
   pointer, and the entry the user is on -- marked aria-current (WAI-ARIA 1.2),
   which a screen reader announces -- tinted with a teal bar and accent text.
   .nav-item-sub is an entry of a sub-list (smaller, indented, secondary text);
   .nav-item-action an action at the head of a list (accent text, a divider
   above it). A container places an entry through two settings, never by a look
   property of its own: --nav-item-padding-inline (its side padding) and
   --nav-item-bar-start / --nav-item-bar-end (the bar's width on the leading or
   the bottom edge, for a row of tiles). */
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  width: 100%;
  padding: var(--spacing-md) var(--nav-item-padding-inline, var(--spacing-lg));
  background: none;
  border: none;
  border-left: var(--nav-item-bar-start, var(--line-width-accent)) solid transparent;
  border-bottom: var(--nav-item-bar-end, 0) solid transparent;
  border-radius: var(--radius-sm);
  color: var(--color-text-primary);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-medium);
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: none;
}

/* Under the pointer only the leading bar turns teal: button:hover colours every
   edge, and in a row of tiles the bottom bar marks the current entry alone. */
.nav-item:hover:not(:where(:disabled, [aria-disabled="true"])) {
  background: var(--color-accent-tint);
  border-left-color: var(--color-accent-primary);
  border-bottom-color: transparent;
  transform: none;
  box-shadow: none;
}

.nav-item[aria-current]:not([aria-current="false"]) {
  background: var(--color-accent-tint-strong);
  border-left-color: var(--color-accent-primary);
  border-bottom-color: var(--color-accent-primary);
  color: var(--color-accent-hover);
}

.nav-item-sub {
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--nav-item-padding-inline, var(--spacing-lg)) var(--spacing-sm) var(--spacing-2xl);
  color: var(--color-text-secondary);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
}

.nav-item-sub:hover:not(:where(:disabled, [aria-disabled="true"])) {
  color: var(--color-text-primary);
}

.nav-item-action {
  color: var(--color-accent-primary);
  font-weight: var(--font-weight-semibold);
  border-top: var(--line-width-thin) solid var(--color-border-subtle);
  padding-bottom: var(--spacing-md);
}

/* The divider stays a divider under the pointer: button:hover colours every edge. */
.nav-item-action:hover:not(:where(:disabled, [aria-disabled="true"])) {
  color: var(--color-accent-hover);
  border-top-color: var(--color-border-subtle);
}

/* Disabled, after every variant: an icon button's resting opacity yields to the
   one disabled opacity too. */
button:disabled {
  opacity: var(--opacity-disabled);
  cursor: not-allowed;
  transform: none;
}

/* A control that cannot act now but says why in its tooltip (aria-disabled
   keeps it focusable and hoverable; a disabled button shows no tooltip). Its
   hover and pressed looks are gated off with the disabled button's. */
button[aria-disabled="true"] {
  opacity: var(--opacity-disabled);
  cursor: not-allowed;
  color: var(--color-text-secondary);
}

.is-loading {
  position: relative;
  opacity: var(--opacity-muted);
}

/* Token Estimation Buttons */
.button-with-token-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.button-with-token-icon .button-text {
  flex: 1;
}

.button-with-token-icon .token-icon {
  font-size: inherit; /* match button text size — prevents height inflation */
  line-height: var(--line-height-none);
  opacity: var(--opacity-muted);
  transition: opacity var(--transition-fast);
}

.button-with-token-icon:hover .token-icon {
  opacity: 1;
}

.token-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: var(--spacing-sm);
  padding: var(--spacing-xs) var(--spacing-md);
  background-color: var(--color-bg-secondary);
  color: var(--color-text-primary);
  font-size: var(--font-size-base);
  white-space: nowrap;
  border-radius: var(--radius-sm);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-fast), visibility var(--transition-fast);
  pointer-events: none;
  z-index: var(--z-index-overlay);
}

.token-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: var(--tooltip-arrow-size) solid transparent;
  border-top-color: var(--color-bg-secondary);
}

.button-with-token-icon:hover .token-tooltip {
  opacity: 1;
  visibility: visible;
}

.token-tooltip:empty::before {
  content: '—';
}

/* Template pill row layout */
.template-pill-wrapper {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  margin-bottom: var(--spacing-xs);
}

.template-pill-wrapper .template-pill {
  flex: 1;
}
