@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
@import '/assets/f47cf25678047dc1d0c5372c25b330b4ffdf35604610caa62c68ff9ad26b877e/components/color-picker/color-picker.css';
@import '/assets/f47cf25678047dc1d0c5372c25b330b4ffdf35604610caa62c68ff9ad26b877e/components/popover/popover.css';

@layer cinder.components {
  /* ========================================
 * COLOR FIELD
 * ======================================== */

  /* The field's own height, which Input sets on its private height: the md control step, or the lg
     step under the comfortable density. The swatch's width is derived from it so it stays square;
     its height comes from the slot itself, so the inset stays even whatever the height. */
  .cinder-color-field {
    display: contents;
    --_cinder-color-field-height: var(--cinder-control-height-md);
    --_cinder-color-field-inset: var(--cinder-space-1);
  }

  .cinder-color-field:where([data-density='comfortable'] *) {
    --_cinder-color-field-height: var(--cinder-control-height-lg);
  }

  /* Input's interactive trailing slot pads its inline sides by `--cinder-space-1` and centres its
     content; the swatch stretches to the slot's height less the same space above and below, so it
     sits the same distance from the field's edge on all three sides. No border, no face: the
     colour is the control. */
  .cinder-color-field__swatch-button {
    display: block;
    flex: 0 0 auto;
    align-self: stretch;
    box-sizing: border-box;
    inline-size: calc(
      var(--_cinder-color-field-height) - 2px - 2 * var(--_cinder-color-field-inset)
    );
    margin-block: var(--_cinder-color-field-inset);
    padding: 0;
    border: 0;
    border-radius: var(--cinder-radius-sm);
    background: transparent;
    cursor: pointer;
    appearance: none;
  }

  .cinder-color-field__swatch-button:disabled {
    cursor: not-allowed;
  }

  .cinder-color-field__swatch-button:focus-visible {
    outline: var(--cinder-ring-width) solid var(--cinder-ring-color);
    outline-offset: 1px;
  }

  .cinder-color-field__swatch {
    display: block;
    box-sizing: border-box;
    inline-size: 100%;
    block-size: 100%;
    border-radius: inherit;
    background-color: var(--cinder-color-field-swatch, transparent);
    pointer-events: none;
  }

  .cinder-color-field__swatch[data-cinder-empty] {
    /* "No color" affordance: a diagonal hatch reads as "nothing selected"
     without being mistaken for an intentionally transparent color. */
    background-color: transparent;
    background-image: linear-gradient(
      135deg,
      transparent 0%,
      transparent 45%,
      var(--cinder-border) 45%,
      var(--cinder-border) 55%,
      transparent 55%,
      transparent 100%
    );
    background-size: 6px 6px;
  }

  .cinder-color-field__swatch[data-cinder-alpha]:not([data-cinder-empty]) {
    /* structural-pattern: transparency checkerboard so partially-transparent
     * swatches stay visible while following the shared checker tokens. */
    background-color: var(--cinder-checker-base);
    background-image:
      linear-gradient(
        var(--cinder-color-field-swatch, transparent),
        var(--cinder-color-field-swatch, transparent)
      ),
      linear-gradient(45deg, var(--cinder-checker-tile) 25%, transparent 25%),
      linear-gradient(-45deg, var(--cinder-checker-tile) 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, var(--cinder-checker-tile) 75%),
      linear-gradient(-45deg, transparent 75%, var(--cinder-checker-tile) 75%);
    background-size:
      auto,
      6px 6px,
      6px 6px,
      6px 6px,
      6px 6px;
    background-position:
      0 0,
      0 0,
      0 3px,
      3px -3px,
      -3px 0;
  }

  /*
 * Forced-colors mode strips background gradients to system tokens, which
 * flattens the swatch's checker pattern and makes empty / partial-alpha
 * states indistinguishable from opaque ones. Fall back to border styles so
 * the state remains visible.
 */
  @media (forced-colors: active) {
    .cinder-color-field__swatch {
      forced-color-adjust: none;
      border: 1px solid CanvasText;
      background-color: ButtonFace;
    }

    .cinder-color-field__swatch-button:focus-visible {
      outline-color: Highlight;
    }

    .cinder-color-field__swatch[data-cinder-empty] {
      background-image: none;
      border-style: dashed;
    }

    .cinder-color-field__swatch[data-cinder-alpha]:not([data-cinder-empty]) {
      background-image: none;
      border-style: dotted;
    }
  }
}
