/* ==========================================================================
   Component: Button
   .btn base with variants: --primary, --danger, --ghost, --sm, --loading
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1;
  color: var(--text-primary);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
  min-height: 32px;
  position: relative;
  overflow: hidden;
}

/* Micro-interactions */
.btn:hover:not(:disabled) {
  background-color: var(--bg-overlay);
  border-color: var(--text-muted);
  transform: scale(1.02);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ---------------------------------------------------------------------------
   Primary — teal accent
   --------------------------------------------------------------------------- */
.btn--primary {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--text-inverse);
}

.btn--primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn--primary:active:not(:disabled) {
  background-color: var(--accent-active);
  border-color: var(--accent-active);
}

/* ---------------------------------------------------------------------------
   Danger — red
   --------------------------------------------------------------------------- */
.btn--danger {
  background-color: hsl(0, 60%, 18%);
  border-color: hsl(0, 50%, 30%);
  color: hsl(0, 90%, 70%);
}

.btn--danger:hover:not(:disabled) {
  background-color: hsl(0, 60%, 24%);
  border-color: hsl(0, 60%, 40%);
  color: hsl(0, 90%, 78%);
}

.btn--danger:active:not(:disabled) {
  background-color: hsl(0, 60%, 15%);
  border-color: hsl(0, 50%, 30%);
}

/* ---------------------------------------------------------------------------
   Accent — muted accent for secondary actions (reprice)
   --------------------------------------------------------------------------- */
.btn--accent {
  background-color: var(--accent-muted, rgba(0, 200, 180, 0.15));
  border-color: var(--accent, hsl(174, 100%, 39%));
  color: var(--accent, hsl(174, 100%, 39%));
}

.btn--accent:hover:not(:disabled) {
  background-color: var(--accent-subtle, rgba(0, 200, 180, 0.25));
  border-color: var(--accent-hover);
}

.btn--accent:active:not(:disabled) {
  background-color: var(--accent-muted, rgba(0, 200, 180, 0.15));
  border-color: var(--accent);
}

/* ---------------------------------------------------------------------------
   Ghost — transparent bg
   --------------------------------------------------------------------------- */
.btn--ghost {
  background-color: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn--ghost:hover:not(:disabled) {
  background-color: var(--bg-elevated);
  border-color: transparent;
  color: var(--text-primary);
}

.btn--ghost:active:not(:disabled) {
  background-color: var(--bg-overlay);
}

/* ---------------------------------------------------------------------------
   Small size
   --------------------------------------------------------------------------- */
.btn--sm {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  min-height: 24px;
  border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------------------
   Icon-only button
   --------------------------------------------------------------------------- */
.btn--icon {
  padding: var(--space-1);
  min-height: 28px;
  min-width: 28px;
  gap: 0;
}

.btn--icon.btn--sm {
  min-height: 24px;
  min-width: 24px;
}

/* ---------------------------------------------------------------------------
   Loading state with spinner
   --------------------------------------------------------------------------- */
.btn--loading {
  color: transparent !important;
  pointer-events: none;
}

.btn--loading::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--text-primary);
  border-radius: var(--radius-full);
  animation: btn-spin 600ms linear infinite;
}

.btn--primary.btn--loading::after {
  border-color: rgba(0, 0, 0, 0.2);
  border-top-color: var(--text-inverse);
}

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

/* ---------------------------------------------------------------------------
   Monitor Start — compact green icon button
   --------------------------------------------------------------------------- */
.btn--monitor-start {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, hsl(145, 60%, 12%), hsl(145, 50%, 18%));
  border: 1px solid hsl(145, 50%, 28%);
  color: hsl(145, 80%, 65%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn--monitor-start:hover:not(:disabled) {
  background: linear-gradient(135deg, hsl(145, 60%, 18%), hsl(145, 50%, 24%));
  border-color: hsl(145, 55%, 40%);
  color: hsl(145, 90%, 75%);
  box-shadow: 0 0 14px hsla(145, 60%, 45%, 0.35), inset 0 0 8px hsla(145, 60%, 40%, 0.1);
  transform: scale(1.08);
}

.btn--monitor-start:active:not(:disabled) {
  background: linear-gradient(135deg, hsl(145, 60%, 8%), hsl(145, 50%, 14%));
  transform: scale(0.94);
  box-shadow: 0 0 4px hsla(145, 60%, 40%, 0.2);
}

/* ---------------------------------------------------------------------------
   Monitor Stop — compact red icon button
   --------------------------------------------------------------------------- */
.btn--monitor-stop {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, hsl(0, 60%, 12%), hsl(0, 50%, 18%));
  border: 1px solid hsl(0, 50%, 28%);
  color: hsl(0, 80%, 65%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn--monitor-stop:hover:not(:disabled) {
  background: linear-gradient(135deg, hsl(0, 60%, 18%), hsl(0, 50%, 24%));
  border-color: hsl(0, 55%, 40%);
  color: hsl(0, 90%, 75%);
  box-shadow: 0 0 14px hsla(0, 60%, 45%, 0.35), inset 0 0 8px hsla(0, 60%, 40%, 0.1);
  transform: scale(1.08);
}

.btn--monitor-stop:active:not(:disabled) {
  background: linear-gradient(135deg, hsl(0, 60%, 8%), hsl(0, 50%, 14%));
  transform: scale(0.94);
  box-shadow: 0 0 4px hsla(0, 60%, 40%, 0.2);
}

/* ---------------------------------------------------------------------------
   Monitor Active — pulsing glow when monitoring is running
   --------------------------------------------------------------------------- */
.btn--monitor-active {
  animation: monitor-pulse 2s ease-in-out infinite;
}

@keyframes monitor-pulse {
  0%, 100% {
    box-shadow: 0 0 4px hsla(0, 60%, 40%, 0.2);
  }
  50% {
    box-shadow: 0 0 18px hsla(0, 60%, 45%, 0.5), 0 0 6px hsla(0, 60%, 40%, 0.3);
  }
}

/* ---------------------------------------------------------------------------
   Reduced motion
   --------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }

  .btn:hover:not(:disabled),
  .btn:active:not(:disabled) {
    transform: none;
  }

  .btn--loading::after {
    animation: none;
    border-color: rgba(255, 255, 255, 0.5);
    border-top-color: var(--text-primary);
  }

  .btn--monitor-active {
    animation: none;
  }
}
