/*
 * Button and icon button.
 *   <button class="lv-button" type="button">Label</button>
 *   modifiers: lv-button--primary (the one main action on a screen: ink fill), lv-button--quiet
 *   (no fill, for toolbars), lv-button--small. Loading: aria-busy="true" (label stays, spinner
 *   replaces the icon so the width never jumps). Disabled: the disabled attribute, or
 *   aria-disabled="true" on a link styled as a button.
 *   <button class="lv-icon-button" type="button" aria-label="Close"><svg class="icon">…</svg></button>
 */
@layer components {
  .lv-button {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    min-height: 36px; padding: var(--space-2) var(--space-3);
    border: 0; border-radius: var(--radius-control);
    background: var(--surface-sunk); color: var(--text);
    font-size: var(--text-ui); font-weight: var(--weight-medium); line-height: 1; white-space: nowrap;
    transition: background-color var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
  }
  .lv-button .icon { width: 16px; height: 16px; }
  .lv-button:hover { background: var(--surface-hover); color: var(--text); }
  .lv-button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  /* A press compresses slightly, so the click is acknowledged before the action finishes. */
  .lv-button:active:not(:disabled, [aria-disabled="true"], [aria-busy="true"]) { transform: scale(var(--press-scale)); }

  .lv-button--primary { background: var(--selection); color: var(--text-inverse); }
  .lv-button--primary:hover { background: var(--text-secondary); color: var(--text-inverse); }
  .lv-button--quiet { background: transparent; color: var(--text-secondary); }
  .lv-button--quiet:hover { background: var(--surface-hover); }
  .lv-button--small { min-height: 30px; padding: var(--space-1-5) var(--space-2-5); font-size: var(--text-s); }
  .lv-button--small .icon { width: 14px; height: 14px; }

  .lv-button:is(:disabled, [aria-disabled="true"]) { opacity: .5; cursor: not-allowed; pointer-events: none; }

  /* Loading: a ring spinner drawn with borders, so no extra markup or icon is needed. */
  .lv-button[aria-busy="true"] { cursor: progress; }
  .lv-button[aria-busy="true"]::before {
    content: ''; width: 14px; height: 14px; flex-shrink: 0; border-radius: 50%;
    border: 2px solid currentColor; border-right-color: transparent; animation: lv-spin .8s linear infinite;
  }
  .lv-button[aria-busy="true"] > .icon { display: none; }

  .lv-icon-button {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 32px; height: 32px; border-radius: var(--radius-control); color: var(--text-muted);
    transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
  }
  .lv-icon-button .icon { width: 18px; height: 18px; }
  .lv-icon-button:hover { background: var(--surface-hover); color: var(--text); }
  .lv-icon-button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  .lv-icon-button:active:not(:disabled) { transform: scale(var(--press-scale)); }
  /* A toggled icon button (e.g. the chart's info button while its definition is open). */
  .lv-icon-button[aria-pressed="true"], .lv-icon-button[aria-expanded="true"] { background: var(--selection-soft); color: var(--text); }
  .lv-icon-button:disabled { opacity: .45; cursor: not-allowed; }
  .lv-icon-button[aria-busy="true"] > .icon { animation: lv-spin 1s linear infinite; }
  /* Touch targets: 44px is the smallest a fingertip hits reliably. */
  @media (pointer: coarse) { .lv-button { min-height: 44px; } .lv-icon-button { width: 44px; height: 44px; } }

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