/* =============================================================================
   Unified button system — additive, non-breaking
   -----------------------------------------------------------------------------
   Usage:
     Apply BOTH .btn and a variant, e.g.
       <button class="btn btn--primary">…</button>
       <button class="btn btn--ghost btn--sm">…</button>
       <button class="btn btn--danger btn--icon" aria-label="delete">
         <i class="fa-solid fa-trash"></i>
       </button>
   Scope:
     - Does NOT override Bootstrap's .btn-primary / .btn-outline-* classes.
     - Existing Bootstrap buttons keep their current look.
     - New UI should prefer .btn + .btn--* so that every variant consumes
       the central --color-* tokens.
   ========================================================================== */

/* ---- Base --------------------------------------------------------------- */
.btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  box-sizing: border-box;
  min-height: var(--tap-target-min);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-600);
  line-height: var(--line-height-tight);
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);
}

.btn:focus {
  outline: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.btn:active:not(:disabled):not([aria-disabled="true"]) {
  transform: translateY(1px);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

/* Loading state (spinner)
   Apply aria-busy="true" and optionally wrap label in <span class="btn__label">
   so only the label gets hidden while the spinner shows. */
.btn[aria-busy="true"] {
  position: relative;
  cursor: progress;
  color: transparent !important;
}

.btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  inline-size: 1.1em;
  block-size: 1.1em;
  margin-block-start: -0.55em;
  margin-inline-start: -0.55em;
  border-radius: var(--radius-pill);
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: var(--color-text);
  animation: btn-spin 0.7s linear infinite;
}

.btn--primary[aria-busy="true"]::after,
.btn--danger[aria-busy="true"]::after,
.btn--success[aria-busy="true"]::after {
  color: var(--color-text-on-brand);
}

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

@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }
  .btn:active:not(:disabled):not([aria-disabled="true"]) {
    transform: none;
  }
  .btn[aria-busy="true"]::after {
    animation-duration: 1.5s;
  }
}

/* ---- Variants ---------------------------------------------------------- */

/* Primary — filled brand */
.btn--primary {
  background: var(--color-brand);
  border-color: var(--color-brand);
  color: var(--color-text-on-brand);
}
.btn--primary:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--color-brand-hover);
  border-color: var(--color-brand-hover);
  color: var(--color-text-on-brand);
}
.btn--primary:active:not(:disabled):not([aria-disabled="true"]) {
  background: var(--color-brand-strong);
  border-color: var(--color-brand-strong);
}

/* Secondary — tonal soft brand */
.btn--secondary {
  background: var(--color-brand-soft);
  border-color: transparent;
  color: var(--color-brand-hover);
}
.btn--secondary:hover:not(:disabled):not([aria-disabled="true"]) {
  background: rgba(var(--color-brand-rgb), 0.18);
  color: var(--color-brand-strong);
}

/* Ghost — transparent, reveals bg on hover */
.btn--ghost {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn--ghost:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--color-surface-muted);
  border-color: var(--color-border-strong);
}

/* Danger — filled destructive */
.btn--danger {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: var(--color-text-on-brand);
}
.btn--danger:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--color-danger-strong);
  border-color: var(--color-danger-strong);
}
.btn--danger:focus-visible {
  box-shadow: var(--shadow-focus-danger);
}

/* Success — filled positive */
.btn--success {
  background: var(--color-success);
  border-color: var(--color-success);
  color: var(--color-text-on-brand);
}
.btn--success:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--color-success-strong);
  border-color: var(--color-success-strong);
}

/* Link — inline anchor-style button */
.btn--link {
  background: transparent;
  border-color: transparent;
  color: var(--color-brand);
  min-height: auto;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.btn--link:hover:not(:disabled):not([aria-disabled="true"]) {
  color: var(--color-brand-hover);
}

/* ---- Sizes ------------------------------------------------------------- */
.btn--sm {
  min-height: 36px;
  padding: var(--space-1) var(--space-3);
  font-size: var(--font-size-xs);
  border-radius: var(--radius-sm);
}

.btn--md {
  /* default — matches .btn base */
}

.btn--lg {
  min-height: 52px;
  padding: var(--space-3) var(--space-6);
  font-size: var(--font-size-md);
  border-radius: var(--radius-lg);
}

/* ---- Icon button (square) --------------------------------------------- */
.btn--icon {
  inline-size: var(--tap-target-min);
  block-size: var(--tap-target-min);
  padding: 0;
  gap: 0;
}
.btn--icon.btn--sm {
  inline-size: 36px;
  block-size: 36px;
}
.btn--icon.btn--lg {
  inline-size: 52px;
  block-size: 52px;
}

/* ---- Icon helpers ----------------------------------------------------- */
.btn__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  font-size: 1em;
  line-height: 1;
}

/* Full-width helper — use instead of Bootstrap w-100 so it stays in scope. */
.btn--block {
  display: flex;
  inline-size: 100%;
}

/* ---- Button group ----------------------------------------------------- */
.btn-stack {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.btn-stack--tight {
  gap: var(--space-1);
}
