/* -- Color Picker component ------------------------------------- */

@layer components {
  .color-picker {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid var(--input);
    border-radius: var(--radius-md);
    background: var(--background);
    /* the unsized default IS the ladder's md step (see .input):
       1.75rem swatch + 2×3px block padding + 2px frame = 36px */
    padding: 0.1875rem 0.75rem 0.1875rem 0.25rem;
    box-shadow: var(--shadow-xs);

    & input[type="color"] {
      -webkit-appearance: none;
      appearance: none;
      width: 1.75rem;
      height: 1.75rem;
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      cursor: pointer;
      padding: 0;
      background: none;

      &::-webkit-color-swatch-wrapper {
        padding: 0;
      }
      &::-webkit-color-swatch {
        border: none;
        border-radius: calc(var(--radius-sm) - 1px);
      }
      &::-moz-color-swatch {
        border: none;
        border-radius: calc(var(--radius-sm) - 1px);
      }
    }

    /* the value is meant to be used: one click selects all of it for copy;
       tabular digits keep the width steady while dragging through colours */
    & .color-picker-value {
      font-size: 0.8125rem;
      font-family: var(--font-mono);
      font-variant-numeric: tabular-nums;
      color: var(--muted-foreground);
      white-space: nowrap;
      user-select: all;
    }

    /* optional notation switcher (hex / rgb / hsl / oklch) at the end */
    & .color-picker-format {
      margin-inline-start: auto;
      padding: 0 0 0 0.5rem;
      border: none;
      border-inline-start: 1px solid var(--border);
      background: transparent;
      color: var(--muted-foreground);
      font-size: 0.75rem;
      font-family: var(--font-mono);
      cursor: pointer;

      &:focus-visible {
        outline: 2px solid var(--ring);
        outline-offset: 2px;
        border-radius: var(--radius-sm);
      }
    }

    /* -- Sizes -------------------------------------------------
       Swatch + padding re-derived per step so the TOTAL box height lands
       on the shared input ladder (xs 28 / sm 32 / md 36 / lg 44 / xl 52
       px - md is the typical 2.25rem the other inputs use at md). The UA
       styles form controls border-box, so:
       total = swatch + 2×padding-block + 2px frame:
       xs 20+6+2 · sm 24+6+2 · md 28+6+2 · lg 32+10+2 · xl 40+10+2.
       The unsized default IS md (1.75rem swatch, 0.1875rem block padding = 36px)
       - exactly like .input defaults to the md step. */
    &[data-size="xs"] {
      padding: 0.1875rem 0.5rem;
      gap: 0.375rem;
      & input[type="color"] {
        width: 1.25rem;
        height: 1.25rem;
      }
      & .color-picker-value {
        font-size: 0.6875rem;
      }
    }
    &[data-size="sm"] {
      padding: 0.1875rem 0.625rem;
      gap: 0.375rem;
      & input[type="color"] {
        width: 1.5rem;
        height: 1.5rem;
      }
      & .color-picker-value {
        font-size: 0.75rem;
      }
    }
    &[data-size="md"] {
      padding: 0.1875rem 0.75rem;
      & input[type="color"] {
        width: 1.75rem;
        height: 1.75rem;
      }
      & .color-picker-value {
        font-size: 0.8125rem;
      }
    }
    &[data-size="lg"] {
      padding: 0.3125rem 0.875rem;
      & input[type="color"] {
        width: 2rem;
        height: 2rem;
      }
      & .color-picker-value {
        font-size: 0.875rem;
      }
    }
    &[data-size="xl"] {
      padding: 0.3125rem 1rem;
      gap: 0.625rem;
      & input[type="color"] {
        width: 2.5rem;
        height: 2.5rem;
      }
      & .color-picker-value {
        font-size: 1rem;
      }
    }
  }
}
