/* ==========================================================================
   Component: button  →  snippets/button.liquid + assets/component-button.css
   Figma 1057-1626 (button component sheet).

   Three styles, each with a resting and a hover state:
     .button--primary    #080808 surface, inverse label
     .button--secondary  white surface, primary label  (default if no style is set)
     .button--tertiary   no surface — a text link with the arrow, underlined on hover

   Markup is always [dot icon] [label] [arrow icon]:
     <a class="button button--secondary" href="#">
       {% render 'icon-dot' %}<span>SHOP MEN’S</span>{% render 'icon-arrow-up-right' %}
     </a>

   Resting state shows the dot on the left and keeps the arrow's slot closed; on hover or keyboard
   focus the dot scales to 0, the label glides left into the freed space, and the arrow scales up
   from 0 on the right. The outgoing icon leaves at once and the incoming one arrives
   --button-icon-delay later, in both directions. The two slots collapse and expand by the same
   amount, so the button's width never changes and nothing around it moves.
   .button--swap-slide drops the scaling and slides the icons in and out instead.
   Tertiary keeps its arrow in place; add .button--swap to give it the same dot/arrow swap. A swap
   button without a dot rests with the arrow's slot closed and opens it on hover.

   Sizes: default 40px / 16px padding / 16px icon · .button--lg 42 / 20 / 18.
   ========================================================================== */
.button {
  --button-height: 40px;
  --button-padding-x: 16px;
  --button-icon-size: 16px;
  --button-gap: 4px;
  /* how far an icon shifts to leave the row: its own width plus the flex gap */
  --button-collapse: calc(-1 * (var(--button-icon-size) + var(--button-gap)));
  --button-motion: 260ms var(--ease-out);          /* the slot opening and closing: moves the label */
  --button-icon-motion: 200ms var(--ease-out);     /* the icon scaling in and out */
  --button-icon-delay: 80ms;                       /* the incoming icon waits for the outgoing one */

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--button-gap);
  height: var(--button-height);
  padding: 0 var(--button-padding-x);
  overflow: hidden; /* clips whichever icon is currently outside the box */
  border: 1px solid var(--color-white);
  border-radius: var(--radius-sm);
  background: var(--color-white);
  color: var(--color-text-primary);
  font-size: var(--text-body-s-size);
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  transition: background-color var(--duration-fast) ease, color var(--duration-fast) ease,
    border-color var(--duration-fast) ease;
}

.button .icon {
  width: var(--button-icon-size);
  height: var(--button-icon-size);
  transition: margin var(--button-motion), opacity var(--button-icon-motion),
    transform var(--button-icon-motion);
}

/* Leading dot: full size at rest, scales away on hover. Coming back, it waits for the arrow. */
.button > .icon:first-child {
  margin-left: 0;
  opacity: 1;
  transform: scale(1);
  transition-delay: 0s, var(--button-icon-delay), var(--button-icon-delay);
}

/* Trailing arrow: slot closed and scaled to nothing at rest */
.button > .icon:last-child {
  margin-right: var(--button-collapse);
  opacity: 0;
  transform: scale(0);
  transition-delay: 0s;
}

.button:hover > .icon:first-child,
.button:focus-visible > .icon:first-child {
  margin-left: var(--button-collapse);
  opacity: 0;
  transform: scale(0);
  transition-delay: 0s;
}

.button:hover > .icon:last-child,
.button:focus-visible > .icon:last-child {
  margin-right: 0;
  opacity: 1;
  transform: scale(1);
  transition-delay: 0s, var(--button-icon-delay), var(--button-icon-delay);
}

/* Alternative: slide the icons instead of scaling them (the first pass at this swap) */
.button--swap-slide > .icon:first-child,
.button--swap-slide > .icon:last-child,
.button--swap-slide:hover > .icon:first-child,
.button--swap-slide:hover > .icon:last-child,
.button--swap-slide:focus-visible > .icon:first-child,
.button--swap-slide:focus-visible > .icon:last-child {
  transform: none;
  transition-delay: 0s;
}

/* Styles */
.button--primary {
  border-color: var(--color-surface-primary);
  background: var(--color-surface-primary);
  color: var(--color-text-inverse);
}

.button--secondary {
  border-color: var(--color-white);
  background: var(--color-white);
  color: var(--color-text-primary);
}

.button--tertiary {
  height: auto;
  padding: 0;
  overflow: visible;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--color-text-primary);
}

/* The link style keeps its arrow: nothing to swap, so the hover is the underline */
.button--tertiary:not(.button--swap) > .icon:last-child,
.button--tertiary:not(.button--swap):hover > .icon:last-child,
.button--tertiary:not(.button--swap):focus-visible > .icon:last-child {
  margin-right: 0;
  opacity: 1;
  transform: none;
  transition-delay: 0s;
}

/* .button--swap: the solid styles' dot/arrow swap in the link style (hero text links, View All).
   Clipped like the solid buttons, so the icons scale in and out inside the box. */
.button--tertiary.button--swap {
  overflow: hidden;
}

.button--tertiary:hover {
  border-bottom-color: currentColor;
}

/* Sizes */
.button--lg {
  --button-height: 42px;
  --button-padding-x: 20px;
  --button-icon-size: 18px;
}

/* Disabled — Figma "Disable" text token on the muted surface */
.button:disabled,
.button[aria-disabled="true"] {
  border-color: var(--color-surface-secondary);
  background: var(--color-surface-secondary);
  color: var(--color-text-disabled);
  cursor: default;
  pointer-events: none;
}

.button--tertiary:disabled,
.button--tertiary[aria-disabled="true"] {
  border-color: transparent;
  background: none;
}

.button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .button,
  .button .icon {
    transition: none;
  }
}
