/**
 * ColorPicker Styles
 * @countermeasure/web-components
 *
 * Color picker with saturation/brightness canvas, hue slider, and preset swatches.
 */

/* ============================================================================
   CONTAINER
   ============================================================================ */
.cmm-color-picker {
  position: relative;
  display: inline-block;
}

/* ============================================================================
   PREVIEW SWATCH
   ============================================================================ */
.cmm-color-picker__swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 2px solid hsl(var(--border));
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    border-color var(--transition-fast) ease,
    box-shadow var(--transition-fast) ease;
}

.cmm-color-picker__swatch:hover {
  border-color: hsl(var(--foreground));
}

.cmm-color-picker__swatch:focus-visible {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
}

/* ============================================================================
   POPOVER PANEL
   ============================================================================ */
.cmm-color-picker__panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 50;
  width: 272px;
  padding: 0.75rem;
  background-color: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md); /* was rgba(0,0,0,0.15) elevation shadow */
}

/* ============================================================================
   SATURATION / BRIGHTNESS CANVAS
   ============================================================================ */
.cmm-color-picker__saturation-wrap {
  position: relative;
  width: 100%;
  margin-bottom: 0.625rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.cmm-color-picker__saturation {
  display: block;
  width: 100%;
  height: 160px;
  cursor: crosshair;
  border-radius: var(--radius-sm);
}

/* ============================================================================
   SLIDERS (HUE + ALPHA)
   ============================================================================ */
.cmm-color-picker__sliders {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.625rem;
}

.cmm-color-picker__hue-wrap,
.cmm-color-picker__alpha-wrap {
  position: relative;
  width: 100%;
  border-radius: 9999px;
  overflow: hidden;
}

.cmm-color-picker__hue,
.cmm-color-picker__alpha {
  display: block;
  width: 100%;
  height: 14px;
  cursor: pointer;
  border-radius: 9999px;
}

/* Checkerboard background behind alpha slider */
.cmm-color-picker__alpha-wrap {
  background-image:
    linear-gradient(45deg, hsl(var(--muted)) 25%, transparent 25%),
    linear-gradient(-45deg, hsl(var(--muted)) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, hsl(var(--muted)) 75%),
    linear-gradient(-45deg, transparent 75%, hsl(var(--muted)) 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
}

/* ============================================================================
   INPUT FIELDS ROW
   ============================================================================ */
.cmm-color-picker__inputs {
  display: flex;
  gap: 0.375rem;
  margin-bottom: 0.5rem;
}

.cmm-color-picker__input-group {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  flex: 1;
  min-width: 0;
}

.cmm-color-picker__input-label {
  font-size: 0.625rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cmm-color-picker__input {
  width: 100%;
  height: 1.75rem;
  padding: 0 0.375rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: monospace;
  font-size: 0.75rem;
  text-align: center;
  transition: border-color var(--transition-fast) ease;
}

.cmm-color-picker__input:focus {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: -1px;
  border-color: hsl(var(--primary));
}

.cmm-color-picker__input--hex {
  flex: 2;
}

.cmm-color-picker__input--num {
  flex: 1;
}

/* Hide number input spinners */
.cmm-color-picker__input--num::-webkit-inner-spin-button,
.cmm-color-picker__input--num::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.cmm-color-picker__input--num {
  -moz-appearance: textfield;
}

/* ============================================================================
   ACTIONS ROW
   ============================================================================ */
.cmm-color-picker__actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.cmm-color-picker__copy {
  padding: 0.25rem 0.625rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-size: 0.75rem;
  cursor: pointer;
  transition:
    background-color var(--transition-fast) ease,
    border-color var(--transition-fast) ease;
}

.cmm-color-picker__copy:hover {
  background-color: hsl(var(--accent));
  border-color: hsl(var(--foreground));
}

.cmm-color-picker__copy:focus-visible {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
}

/* ============================================================================
   PRESET SWATCHES GRID
   ============================================================================ */
.cmm-color-picker__presets {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.25rem;
}

.cmm-color-picker__preset {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    border-color var(--transition-fast) ease,
    transform var(--transition-fast) ease;
}

.cmm-color-picker__preset:hover {
  border-color: hsl(var(--foreground));
  transform: scale(1.15);
}

.cmm-color-picker__preset:focus-visible {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 1px;
}
