/* ═══════════════════════════════════════════════════════════════
   htmxRazor Button Component
   BEM:  rhx-button  /  rhx-button__{label,prefix,suffix,spinner}
         rhx-button--{variant}  rhx-button--{appearance}
         rhx-button--{size}     rhx-button--{shape/state}
   ═══════════════════════════════════════════════════════════════ */

/* ── Base ── */
.rhx-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--rhx-space-sm);
  position: relative;
  padding: var(--rhx-space-sm) var(--rhx-space-lg);
  min-height: 2.25rem;
  font-family: var(--rhx-font-family);
  font-size: var(--rhx-font-size-sm);
  font-weight: var(--rhx-font-weight-medium);
  line-height: var(--rhx-line-height-tight);
  text-decoration: none;
  white-space: nowrap;
  vertical-align: middle;
  border: var(--rhx-border-width) solid transparent;
  border-radius: var(--rhx-radius-md);
  cursor: pointer;
  user-select: none;
  transition-property: color, background-color, border-color, box-shadow, opacity;
  transition-duration: var(--rhx-transition-fast);
  transition-timing-function: ease;
}

.rhx-button:focus-visible {
  outline: 2px solid var(--rhx-color-focus-ring);
  outline-offset: 2px;
}

/* ── Inner elements ── */
.rhx-button__label {
  display: inline-flex;
  align-items: center;
}

.rhx-button__prefix,
.rhx-button__suffix {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.rhx-button__spinner {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

/* ══════════════════════════════════════════════════════════════
   SIZES
   ══════════════════════════════════════════════════════════════ */

.rhx-button--small {
  padding: var(--rhx-space-xs) var(--rhx-space-md);
  min-height: 1.75rem;
  font-size: var(--rhx-font-size-xs);
  gap: var(--rhx-space-xs);
}

/* medium is the default — no modifier needed */

.rhx-button--large {
  padding: var(--rhx-space-md) var(--rhx-space-xl);
  min-height: 2.75rem;
  font-size: var(--rhx-font-size-md);
}

/* ══════════════════════════════════════════════════════════════
   SHAPE MODIFIERS
   ══════════════════════════════════════════════════════════════ */

.rhx-button--pill {
  border-radius: var(--rhx-radius-full);
}

.rhx-button--circle {
  border-radius: var(--rhx-radius-full);
  padding: var(--rhx-space-sm);
  aspect-ratio: 1;
  min-height: auto;
}

.rhx-button--circle.rhx-button--small {
  padding: var(--rhx-space-xs);
}

.rhx-button--circle.rhx-button--large {
  padding: var(--rhx-space-md);
}

/* ══════════════════════════════════════════════════════════════
   VARIANT × APPEARANCE:  FILLED  (solid background)
   ══════════════════════════════════════════════════════════════ */

/* ── Neutral Filled ── */
.rhx-button--neutral.rhx-button--filled {
  background: var(--rhx-color-neutral-200);
  color: var(--rhx-color-text);
  border-color: var(--rhx-color-neutral-200);
}
.rhx-button--neutral.rhx-button--filled:hover {
  background: var(--rhx-color-neutral-300);
  border-color: var(--rhx-color-neutral-300);
}
.rhx-button--neutral.rhx-button--filled:active {
  background: var(--rhx-color-neutral-400);
  border-color: var(--rhx-color-neutral-400);
}

/* ── Brand Filled ── */
.rhx-button--brand.rhx-button--filled {
  background: var(--rhx-color-brand-500);
  color: var(--rhx-color-text-inverse);
  border-color: var(--rhx-color-brand-500);
}
.rhx-button--brand.rhx-button--filled:hover {
  background: var(--rhx-color-brand-600);
  border-color: var(--rhx-color-brand-600);
}
.rhx-button--brand.rhx-button--filled:active {
  background: var(--rhx-color-brand-700);
  border-color: var(--rhx-color-brand-700);
}

/* ── Success Filled ── */
.rhx-button--success.rhx-button--filled {
  background: var(--rhx-color-success-500);
  color: var(--rhx-color-text-inverse);
  border-color: var(--rhx-color-success-500);
}
.rhx-button--success.rhx-button--filled:hover {
  background: var(--rhx-color-success-600);
  border-color: var(--rhx-color-success-600);
}
.rhx-button--success.rhx-button--filled:active {
  background: var(--rhx-color-success-700);
  border-color: var(--rhx-color-success-700);
}

/* ── Warning Filled ── */
.rhx-button--warning.rhx-button--filled {
  background: var(--rhx-color-warning-500);
  color: var(--rhx-color-neutral-900);
  border-color: var(--rhx-color-warning-500);
}
.rhx-button--warning.rhx-button--filled:hover {
  background: var(--rhx-color-warning-600);
  border-color: var(--rhx-color-warning-600);
}
.rhx-button--warning.rhx-button--filled:active {
  background: var(--rhx-color-warning-700);
  border-color: var(--rhx-color-warning-700);
}

/* ── Danger Filled ── */
.rhx-button--danger.rhx-button--filled {
  background: var(--rhx-color-danger-500);
  color: var(--rhx-color-text-inverse);
  border-color: var(--rhx-color-danger-500);
}
.rhx-button--danger.rhx-button--filled:hover {
  background: var(--rhx-color-danger-600);
  border-color: var(--rhx-color-danger-600);
}
.rhx-button--danger.rhx-button--filled:active {
  background: var(--rhx-color-danger-700);
  border-color: var(--rhx-color-danger-700);
}

/* ══════════════════════════════════════════════════════════════
   VARIANT × APPEARANCE:  OUTLINED  (transparent bg, visible border)
   ══════════════════════════════════════════════════════════════ */

/* ── Neutral Outlined ── */
.rhx-button--neutral.rhx-button--outlined {
  background: transparent;
  color: var(--rhx-color-text);
  border-color: var(--rhx-color-border);
}
.rhx-button--neutral.rhx-button--outlined:hover {
  background: var(--rhx-color-neutral-100);
  border-color: var(--rhx-color-neutral-400);
}
.rhx-button--neutral.rhx-button--outlined:active {
  background: var(--rhx-color-neutral-200);
}

/* ── Brand Outlined ── */
.rhx-button--brand.rhx-button--outlined {
  background: transparent;
  color: var(--rhx-color-brand-600);
  border-color: var(--rhx-color-brand-500);
}
.rhx-button--brand.rhx-button--outlined:hover {
  background: var(--rhx-color-brand-50);
  border-color: var(--rhx-color-brand-600);
}
.rhx-button--brand.rhx-button--outlined:active {
  background: var(--rhx-color-brand-100);
}

/* ── Success Outlined ── */
.rhx-button--success.rhx-button--outlined {
  background: transparent;
  color: var(--rhx-color-success-600);
  border-color: var(--rhx-color-success-500);
}
.rhx-button--success.rhx-button--outlined:hover {
  background: var(--rhx-color-success-50);
  border-color: var(--rhx-color-success-600);
}
.rhx-button--success.rhx-button--outlined:active {
  background: var(--rhx-color-success-100);
}

/* ── Warning Outlined ── */
.rhx-button--warning.rhx-button--outlined {
  background: transparent;
  color: var(--rhx-color-warning-700);
  border-color: var(--rhx-color-warning-500);
}
.rhx-button--warning.rhx-button--outlined:hover {
  background: var(--rhx-color-warning-50);
  border-color: var(--rhx-color-warning-600);
}
.rhx-button--warning.rhx-button--outlined:active {
  background: var(--rhx-color-warning-100);
}

/* ── Danger Outlined ── */
.rhx-button--danger.rhx-button--outlined {
  background: transparent;
  color: var(--rhx-color-danger-600);
  border-color: var(--rhx-color-danger-500);
}
.rhx-button--danger.rhx-button--outlined:hover {
  background: var(--rhx-color-danger-50);
  border-color: var(--rhx-color-danger-600);
}
.rhx-button--danger.rhx-button--outlined:active {
  background: var(--rhx-color-danger-100);
}

/* ══════════════════════════════════════════════════════════════
   VARIANT × APPEARANCE:  PLAIN  (no bg, no border, text only)
   ══════════════════════════════════════════════════════════════ */

/* ── Neutral Plain ── */
.rhx-button--neutral.rhx-button--plain {
  background: transparent;
  color: var(--rhx-color-text);
  border-color: transparent;
}
.rhx-button--neutral.rhx-button--plain:hover {
  background: var(--rhx-color-neutral-100);
}
.rhx-button--neutral.rhx-button--plain:active {
  background: var(--rhx-color-neutral-200);
}

/* ── Brand Plain ── */
.rhx-button--brand.rhx-button--plain {
  background: transparent;
  color: var(--rhx-color-brand-600);
  border-color: transparent;
}
.rhx-button--brand.rhx-button--plain:hover {
  background: var(--rhx-color-brand-50);
}
.rhx-button--brand.rhx-button--plain:active {
  background: var(--rhx-color-brand-100);
}

/* ── Success Plain ── */
.rhx-button--success.rhx-button--plain {
  background: transparent;
  color: var(--rhx-color-success-600);
  border-color: transparent;
}
.rhx-button--success.rhx-button--plain:hover {
  background: var(--rhx-color-success-50);
}
.rhx-button--success.rhx-button--plain:active {
  background: var(--rhx-color-success-100);
}

/* ── Warning Plain ── */
.rhx-button--warning.rhx-button--plain {
  background: transparent;
  color: var(--rhx-color-warning-700);
  border-color: transparent;
}
.rhx-button--warning.rhx-button--plain:hover {
  background: var(--rhx-color-warning-50);
}
.rhx-button--warning.rhx-button--plain:active {
  background: var(--rhx-color-warning-100);
}

/* ── Danger Plain ── */
.rhx-button--danger.rhx-button--plain {
  background: transparent;
  color: var(--rhx-color-danger-600);
  border-color: transparent;
}
.rhx-button--danger.rhx-button--plain:hover {
  background: var(--rhx-color-danger-50);
}
.rhx-button--danger.rhx-button--plain:active {
  background: var(--rhx-color-danger-100);
}

/* ══════════════════════════════════════════════════════════════
   DARK THEME OVERRIDES
   Raw palette tokens (neutral-100, brand-50, etc.) are not
   remapped in dark mode, so we swap them for darker shades.
   ══════════════════════════════════════════════════════════════ */

/* ── Neutral Filled (dark) ── */
[data-rhx-theme="dark"] .rhx-button--neutral.rhx-button--filled {
  background: var(--rhx-color-neutral-700);
  border-color: var(--rhx-color-neutral-700);
}
[data-rhx-theme="dark"] .rhx-button--neutral.rhx-button--filled:hover {
  background: var(--rhx-color-neutral-600);
  border-color: var(--rhx-color-neutral-600);
}
[data-rhx-theme="dark"] .rhx-button--neutral.rhx-button--filled:active {
  background: var(--rhx-color-neutral-500);
  border-color: var(--rhx-color-neutral-500);
}

/* ── Neutral Outlined (dark) ── */
[data-rhx-theme="dark"] .rhx-button--neutral.rhx-button--outlined:hover {
  background: var(--rhx-color-neutral-800);
  border-color: var(--rhx-color-neutral-500);
}
[data-rhx-theme="dark"] .rhx-button--neutral.rhx-button--outlined:active {
  background: var(--rhx-color-neutral-700);
}

/* ── Brand Outlined (dark) ── */
[data-rhx-theme="dark"] .rhx-button--brand.rhx-button--outlined {
  color: var(--rhx-color-brand-400);
}
[data-rhx-theme="dark"] .rhx-button--brand.rhx-button--outlined:hover {
  background: var(--rhx-color-brand-950);
}
[data-rhx-theme="dark"] .rhx-button--brand.rhx-button--outlined:active {
  background: var(--rhx-color-brand-900);
}

/* ── Success Outlined (dark) ── */
[data-rhx-theme="dark"] .rhx-button--success.rhx-button--outlined {
  color: var(--rhx-color-success-400);
}
[data-rhx-theme="dark"] .rhx-button--success.rhx-button--outlined:hover {
  background: var(--rhx-color-success-950);
}
[data-rhx-theme="dark"] .rhx-button--success.rhx-button--outlined:active {
  background: var(--rhx-color-success-900);
}

/* ── Warning Outlined (dark) ── */
[data-rhx-theme="dark"] .rhx-button--warning.rhx-button--outlined {
  color: var(--rhx-color-warning-400);
}
[data-rhx-theme="dark"] .rhx-button--warning.rhx-button--outlined:hover {
  background: var(--rhx-color-warning-950);
}
[data-rhx-theme="dark"] .rhx-button--warning.rhx-button--outlined:active {
  background: var(--rhx-color-warning-900);
}

/* ── Danger Outlined (dark) ── */
[data-rhx-theme="dark"] .rhx-button--danger.rhx-button--outlined {
  color: var(--rhx-color-danger-400);
}
[data-rhx-theme="dark"] .rhx-button--danger.rhx-button--outlined:hover {
  background: var(--rhx-color-danger-950);
}
[data-rhx-theme="dark"] .rhx-button--danger.rhx-button--outlined:active {
  background: var(--rhx-color-danger-900);
}

/* ── Neutral Plain (dark) ── */
[data-rhx-theme="dark"] .rhx-button--neutral.rhx-button--plain:hover {
  background: var(--rhx-color-neutral-800);
}
[data-rhx-theme="dark"] .rhx-button--neutral.rhx-button--plain:active {
  background: var(--rhx-color-neutral-700);
}

/* ── Brand Plain (dark) ── */
[data-rhx-theme="dark"] .rhx-button--brand.rhx-button--plain {
  color: var(--rhx-color-brand-400);
}
[data-rhx-theme="dark"] .rhx-button--brand.rhx-button--plain:hover {
  background: var(--rhx-color-brand-950);
}
[data-rhx-theme="dark"] .rhx-button--brand.rhx-button--plain:active {
  background: var(--rhx-color-brand-900);
}

/* ── Success Plain (dark) ── */
[data-rhx-theme="dark"] .rhx-button--success.rhx-button--plain {
  color: var(--rhx-color-success-400);
}
[data-rhx-theme="dark"] .rhx-button--success.rhx-button--plain:hover {
  background: var(--rhx-color-success-950);
}
[data-rhx-theme="dark"] .rhx-button--success.rhx-button--plain:active {
  background: var(--rhx-color-success-900);
}

/* ── Warning Plain (dark) ── */
[data-rhx-theme="dark"] .rhx-button--warning.rhx-button--plain {
  color: var(--rhx-color-warning-400);
}
[data-rhx-theme="dark"] .rhx-button--warning.rhx-button--plain:hover {
  background: var(--rhx-color-warning-950);
}
[data-rhx-theme="dark"] .rhx-button--warning.rhx-button--plain:active {
  background: var(--rhx-color-warning-900);
}

/* ── Danger Plain (dark) ── */
[data-rhx-theme="dark"] .rhx-button--danger.rhx-button--plain {
  color: var(--rhx-color-danger-400);
}
[data-rhx-theme="dark"] .rhx-button--danger.rhx-button--plain:hover {
  background: var(--rhx-color-danger-950);
}
[data-rhx-theme="dark"] .rhx-button--danger.rhx-button--plain:active {
  background: var(--rhx-color-danger-900);
}

/* ══════════════════════════════════════════════════════════════
   DISABLED STATE
   ══════════════════════════════════════════════════════════════ */

.rhx-button:disabled,
.rhx-button--disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ══════════════════════════════════════════════════════════════
   LOADING STATE
   ══════════════════════════════════════════════════════════════ */

.rhx-button--loading {
  cursor: wait;
}

.rhx-button--loading .rhx-button__label {
  opacity: 0.4;
}

/* ── Spinner ── */
.rhx-spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: rhx-spin 0.6s linear infinite;
}

.rhx-spinner--current {
  color: currentColor;
}

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

/* ══════════════════════════════════════════════════════════════
   BUTTON GROUP
   ══════════════════════════════════════════════════════════════ */

.rhx-button-group {
  display: inline-flex;
  align-items: stretch;
}

/* Remove internal border radii */
.rhx-button-group > .rhx-button {
  border-radius: 0;
}

/* First child: left radii */
.rhx-button-group > .rhx-button:first-child {
  border-top-left-radius: var(--rhx-radius-md);
  border-bottom-left-radius: var(--rhx-radius-md);
}

/* Last child: right radii */
.rhx-button-group > .rhx-button:last-child {
  border-top-right-radius: var(--rhx-radius-md);
  border-bottom-right-radius: var(--rhx-radius-md);
}

/* Collapse adjacent borders (avoid double-thick borders) */
.rhx-button-group > .rhx-button + .rhx-button {
  margin-left: calc(-1 * var(--rhx-border-width));
}

/* Raise hovered/focused button above its neighbor so its border is visible */
.rhx-button-group > .rhx-button:hover,
.rhx-button-group > .rhx-button:focus-visible,
.rhx-button-group > .rhx-button:active {
  z-index: 1;
  position: relative;
}

/* ══════════════════════════════════════════════════════════════
   REDUCED MOTION
   ══════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .rhx-button {
    transition-duration: 0.01ms;
  }

  .rhx-spinner {
    animation-duration: 1.5s;
  }
}
