/*
 * Buttons — primary, secondary, icon, add
 *
 * States: default, hover, focus, disabled, loading
 */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  border-radius: var(--radius-md);
  border: var(--border-width) solid transparent;
  min-height: 40px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

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

/* No hover state — accent and accent-hover are too close to distinguish visually.
   The dark teal reads as interactive on its own; focus ring handles keyboard. */

/* Secondary */
.btn-secondary {
  background: var(--color-bg-surface);
  color: var(--color-text-primary);
  border-color: var(--color-border-strong);
}

.btn-secondary:hover {
  background: var(--color-bg-muted);
}

/* Ghost — transparent on dark backgrounds (e.g. shell top bar) */
.btn-ghost {
  background: transparent;
  color: rgb(255 255 255 / 0.7);
  border-color: rgb(255 255 255 / 0.2);
}

.btn-ghost:hover {
  background: rgb(255 255 255 / 0.1);
  color: var(--color-text-inverse);
}

/* Icon button — compact, square */
.btn-icon {
  padding: var(--space-2);
  min-height: 40px;
  min-width: 40px;
  background: transparent;
  color: var(--color-text-secondary);
  border-color: transparent;
}

.btn-icon:hover {
  background: var(--color-bg-muted);
  color: var(--color-text-primary);
}

/* Add button — dashed border, full width */
.btn-add {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: transparent;
  color: var(--color-text-secondary);
  border: var(--border-width) dashed var(--color-border-strong);
}

.btn-add:hover {
  background: var(--color-bg-muted);
  color: var(--color-text-primary);
  border-color: var(--color-accent);
}

/* Disabled — works on any variant */
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Loading — add .btn-loading alongside variant class */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: var(--radius-full);
  animation: btn-spin 0.5s linear infinite;
}

.btn-primary.btn-loading::after {
  border-color: var(--color-text-inverse);
  border-right-color: transparent;
}

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

/* Link — styled as inline text link, for use inside forms and tight layouts */
.btn-link {
  background: none;
  border: none;
  padding: 0;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  text-decoration: underline;
  min-height: 0;
}

.btn-link:hover {
  color: var(--color-text-primary);
}

/* Small variant */
.btn-sm {
  min-height: 32px;
  padding: var(--space-1) var(--space-3);
  font-size: var(--font-size-xs);
}

/*
 * Menu trigger — adds a trailing chevron after the label, signalling that
 * the button opens a menu/modal. Combine with a variant (e.g. .btn-ghost)
 * for the surface treatment. Truncates long labels with ellipsis on narrow
 * viewports so the chevron stays visible.
 *
 * Usage:
 *   <button class="btn btn-ghost btn-menu">{{ label }}</button>
 */
.btn-menu {
  max-width: 100%;
}

.btn-menu > .btn-menu-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.btn-menu::after {
  content: "";
  flex-shrink: 0;
  width: 12px;
  height: 12px;
  background: currentColor;
  /* Chevron-down — sized to fit a 12px box at 1.5px stroke. */
  mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='3,4.5 6,7.5 9,4.5'/></svg>");
  mask-repeat: no-repeat;
  mask-position: center;
  mask-size: contain;
  opacity: 0.6;
  transition: opacity var(--transition-fast);
}

.btn-menu:hover::after {
  opacity: 1;
}

@media (max-width: 640px) {
  .btn-menu {
    max-width: 12rem;
  }
}
