/* ============================================================================
 * COMPONENT — Button
 * ----------------------------------------------------------------------------
 * Renderer: shared/components/button.php
 *
 * Four variants and no more. Every extra variant is another decision at every
 * call site and another thing to keep consistent; four covers an entire
 * application.
 *   primary  the one action this screen is for
 *   subtle   secondary actions sitting next to a primary
 *   ghost    tertiary, inside toolbars and cards
 *   danger   destructive, and only ever after a confirmation
 * ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
  block-size: 40px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}

.btn:hover { text-decoration: none; }

.btn:disabled,
.btn.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

/* -- variants ------------------------------------------------------------- */

.btn--primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-on);
  box-shadow: var(--sh-1);
}

.btn--primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  color: var(--brand-on);
}

.btn--primary:active {
  background: var(--brand-active);
  border-color: var(--brand-active);
}

.btn--subtle {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--ink);
}

.btn--subtle:hover {
  background: var(--surface-sunken);
  border-color: var(--border-strong);
  color: var(--ink);
}

.btn--ghost {
  background: transparent;
  color: var(--ink-soft);
}

.btn--ghost:hover {
  background: var(--surface-sunken);
  color: var(--ink);
}

.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--n-0);
}

.btn--danger:hover {
  filter: brightness(0.93);
  color: var(--n-0);
}

/* -- sizes ---------------------------------------------------------------- */

.btn--sm {
  block-size: 32px;
  padding-inline: var(--sp-3);
  font-size: var(--fs-sm);
  border-radius: var(--r-sm);
}

.btn--lg {
  block-size: 48px;
  padding-inline: var(--sp-6);
  font-size: var(--fs-md);
}

/* Square, for an icon with no label. The accessible name comes from the
   sr-only span the renderer emits — never leave one without a label. */
.btn--icon {
  inline-size: 40px;
  padding: 0;
}

.btn--icon.btn--sm { inline-size: 32px; }
.btn--icon.btn--lg { inline-size: 48px; }

/* Full width — the default shape for a form's submit button on a phone. */
.btn--block {
  display: flex;
  inline-size: 100%;
}

/* -- loading -------------------------------------------------------------- */

.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  inline-size: 16px;
  block-size: 16px;
  border: 2px solid currentColor;
  border-block-start-color: transparent;
  border-radius: var(--r-full);
  color: var(--brand-on);
  animation: btn-spin 620ms linear infinite;
}

.btn--subtle.is-loading::after,
.btn--ghost.is-loading::after { color: var(--ink); }

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* A "Back" button's chevron points the way the reader came from. The icon set
   draws one chevron pointing forward; .icon--back would have to be on the icon
   itself, and the button component owns the icon — so the flip is applied from
   the button instead. */
.btn--back .icon {
  transform: scaleX(-1);
}

[dir="rtl"] .btn--back .icon {
  transform: none;
}
