/* ============================================================
   v6 Button polish layer
   ============================================================
   Refines the existing .btn / .btn-primary / .btn-secondary /
   .btn-ghost / .btn-accent / .btn-danger / .btn-lg / .btn-sm /
   .btn-icon-sm / .btn-icon-only classes from style-v2.css with:

   - Tighter type/spacing rhythm
   - Crisp visible focus ring (keyboard a11y)
   - Smooth hover + active motion
   - Disabled + loading states
   - Icon-left / icon-only sizing rules that work with v6 SVG icons

   No HTML changes required — markup keeps the v5 class names.
*/

@layer v6-components {

  /* ============================================================
     Base — applies to every .btn regardless of variant
     ============================================================ */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;

    height: var(--control-h-md, 30px);
    padding: 0 12px;

    font-family: var(--font-sans, system-ui, sans-serif);
    font-size: var(--text-sm, 13px);
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.01em;
    white-space: nowrap;
    user-select: none;

    border: 1px solid transparent;
    border-radius: var(--radius-md, 6px);
    cursor: pointer;

    transition:
      background-color var(--duration-fast, 120ms) var(--ease-out-quart, ease-out),
      border-color var(--duration-fast, 120ms) var(--ease-out-quart, ease-out),
      color var(--duration-fast, 120ms) var(--ease-out-quart, ease-out),
      transform var(--duration-instant, 50ms) var(--ease-out-quart, ease-out),
      box-shadow var(--duration-fast, 120ms) var(--ease-out-quart, ease-out);

    -webkit-tap-highlight-color: transparent;
  }
  .btn:active:not(:disabled) {
    transform: translateY(1px);
  }
  .btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--surface-200, #111113), 0 0 0 4px var(--accent-primary, #8b5cf6);
  }
  .btn:disabled,
  .btn[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
  }

  /* ============================================================
     Sizes — height + padding + font tweaks
     ============================================================ */
  .btn.btn-sm {
    height: var(--control-h-sm, 24px);
    padding: 0 8px;
    font-size: var(--text-xs, 12px);
  }
  .btn.btn-lg {
    height: var(--control-h-lg, 36px);
    padding: 0 16px;
    font-size: var(--text-base, 14px);
    border-radius: var(--radius-lg, 8px);
  }

  /* ============================================================
     Icon-only — square aspect, no text gap
     ============================================================ */
  .btn.btn-icon-only {
    width: var(--control-h-md, 30px);
    padding: 0;
    gap: 0;
  }
  .btn.btn-sm.btn-icon-only {
    width: var(--control-h-sm, 24px);
  }
  .btn.btn-lg.btn-icon-only {
    width: var(--control-h-lg, 36px);
  }

  /* When a button has both an icon and text, slim the left padding by 2px so
     the icon reads as part of the label (Ableton-style tight rhythm). */
  .btn .icon + .btn-text,
  .btn .icon + span:not(.btn-text) {
    /* no extra margin needed; .btn's flex gap handles it */
  }

  /* ============================================================
     Primary — saturated brand accent
     ============================================================ */
  .btn.btn-primary {
    background: var(--accent-primary, #8b5cf6);
    color: #ffffff;
    border-color: var(--accent-primary, #8b5cf6);
  }
  .btn.btn-primary:hover:not(:disabled) {
    background: var(--accent-primary-dim, #7c3aed);
    border-color: var(--accent-primary-dim, #7c3aed);
  }

  /* ============================================================
     Secondary — quiet, panel-tone surface
     ============================================================ */
  .btn.btn-secondary {
    background: var(--surface-500, #27272b);
    color: var(--text-primary, #fafafa);
    border-color: var(--v6-border, rgba(255, 255, 255, 0.08));
  }
  .btn.btn-secondary:hover:not(:disabled) {
    background: var(--surface-600, #303036);
    border-color: var(--v6-border-strong, rgba(255, 255, 255, 0.14));
  }

  /* ============================================================
     Ghost — transparent, hover reveals
     ============================================================ */
  .btn.btn-ghost {
    background: transparent;
    color: var(--text-secondary, #a1a1aa);
    border-color: transparent;
  }
  .btn.btn-ghost:hover:not(:disabled) {
    background: var(--surface-500, #27272b);
    color: var(--text-primary, #fafafa);
  }

  /* ============================================================
     Accent — gradient CTA (Generate / Refine / etc.)
     ============================================================ */
  .btn.btn-accent {
    background: var(--grad-accent, linear-gradient(135deg, #a78bfa, #ec4899));
    color: #ffffff;
    border-color: transparent;
    box-shadow: var(--shadow-1, 0 1px 2px rgba(0,0,0,0.4));
  }
  .btn.btn-accent:hover:not(:disabled) {
    filter: brightness(1.08);
    box-shadow: var(--glow-accent, 0 0 24px rgba(139, 92, 246, 0.3)), var(--shadow-1, 0 1px 2px rgba(0,0,0,0.4));
  }

  /* ============================================================
     Danger — destructive actions
     ============================================================ */
  .btn.btn-danger {
    background: transparent;
    color: var(--accent-danger, #ef4444);
    border-color: rgba(239, 68, 68, 0.30);
  }
  .btn.btn-danger:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.10);
    border-color: rgba(239, 68, 68, 0.55);
  }

  /* ============================================================
     Loading state — `.btn[data-loading]` or `.btn--loading`
     Shows a subtle spinner glyph in place of the icon.
     JS factory toggles `data-loading` attribute.
     ============================================================ */
  .btn[data-loading],
  .btn.btn--loading {
    position: relative;
    cursor: progress;
    color: transparent !important;
  }
  .btn[data-loading]::after,
  .btn.btn--loading::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: v6-btn-spin 0.7s linear infinite;
    color: var(--text-primary, #fafafa);
  }
  @keyframes v6-btn-spin {
    to { transform: rotate(360deg); }
  }

  /* ============================================================
     Small icon-only legacy class — already used heavily
     (.btn-icon-sm without .btn prefix). Polish its hover.
     ============================================================ */
  .btn-icon-sm {
    transition:
      background-color var(--duration-fast, 120ms) var(--ease-out-quart, ease-out),
      color var(--duration-fast, 120ms) var(--ease-out-quart, ease-out),
      border-color var(--duration-fast, 120ms) var(--ease-out-quart, ease-out);
  }
  .btn-icon-sm:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--surface-200, #111113), 0 0 0 4px var(--accent-primary, #8b5cf6);
  }
}
