/* ==========================================================================
   Color picker — moey.js turns <input class="form-control form-color"> into a
   text field with a swatch; the swatch opens a flat picker panel.

   <input class="form-control form-color" value="#2563eb" name="brand">
   data-moey-format="hex|rgb|hsl" · data-moey-alpha (opacity slider) ·
   data-moey-swatches="#000, #fff, …" (or "false") — all on the input.
   ========================================================================== */

/* Swatch inside the field */
.form-adorn > .color-swatch.adorn-start { inset-inline-start: .4375rem; }
.form-adorn:has(> .color-swatch) > .form-control { padding-inline-start: 2.375rem; font-variant-numeric: tabular-nums; }
.color-swatch {
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  cursor: pointer;
  background: linear-gradient(var(--mo-color-value, transparent), var(--mo-color-value, transparent)), var(--mo-checker);
  border: 0;
  border-radius: calc(var(--mo-radius-control) - .25rem);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--mo-fg-body) 14%, transparent);   /* so white still reads */
}
.color-swatch:focus-visible { outline: var(--mo-focus-ring-width) solid var(--mo-theme-focus-ring); outline-offset: 1px; }
.color-swatch:disabled { cursor: not-allowed; opacity: .5; }

:root { --mo-checker: repeating-conic-gradient(color-mix(in oklab, var(--mo-fg-body) 12%, transparent) 0 25%, transparent 0 50%) 0 0 / 8px 8px; }

/* Panel */
.color-panel:not(:popover-open) { display: none; }   /* closed = gone (see menu.css) */
.color-panel {
  --mo-color-hue: 0;
  position: fixed;
  inset: auto;
  display: grid;
  gap: .75rem;
  width: 15.5rem;
  padding: .75rem;
  margin: 0;
  color: var(--mo-fg-body);
  background: var(--mo-bg-raised);
  border: 0;
  border-radius: var(--mo-radius-overlay);
  box-shadow: var(--mo-shadow-overlay);
}

/* Saturation × brightness area */
.color-area {
  position: relative;
  height: 9.5rem;
  cursor: crosshair;
  touch-action: none;
  background:
    linear-gradient(to top, #000, transparent),
    linear-gradient(to right, #fff, hsl(var(--mo-color-hue) 100% 50%));
  border-radius: calc(var(--mo-radius-overlay) - .375rem);
  outline: 0;
}
.color-thumb {
  position: absolute;
  width: 1rem;
  height: 1rem;
  pointer-events: none;
  background: var(--mo-color-solid);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px oklch(0% 0 0 / .2), 0 1px 3px oklch(0% 0 0 / .3);
  translate: -50% -50%;
}
.color-area:focus-visible .color-thumb { box-shadow: 0 0 0 1px oklch(0% 0 0 / .2), 0 0 0 4px var(--mo-theme-focus-ring); }

.color-row { display: flex; gap: .625rem; align-items: center; }
.color-sliders { display: grid; flex: 1; gap: .625rem; }
.color-preview {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  background: linear-gradient(var(--mo-color-value), var(--mo-color-value)), var(--mo-checker);
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--mo-fg-body) 14%, transparent);
}

/* Hue & opacity sliders (native ranges: keyboard for free) */
.color-slider {
  --mo-color-track: linear-gradient(to right, red, #ff0, lime, cyan, blue, #f0f, red);
  width: 100%;
  height: .75rem;
  margin: 0;
  cursor: pointer;
  background: var(--mo-color-track);
  border-radius: var(--mo-radius-pill);
  appearance: none;
}
.color-slider.is-alpha { --mo-color-track: linear-gradient(to right, transparent, var(--mo-color-solid)), var(--mo-checker); }
.color-slider::-webkit-slider-thumb {
  width: .875rem;
  height: .875rem;
  background: transparent;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px oklch(0% 0 0 / .25), 0 1px 3px oklch(0% 0 0 / .3);
  appearance: none;
}
.color-slider::-moz-range-thumb {
  width: .625rem;
  height: .625rem;
  background: transparent;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px oklch(0% 0 0 / .25), 0 1px 3px oklch(0% 0 0 / .3);
}
.color-slider:focus-visible { outline: 0; }
.color-slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 1px oklch(0% 0 0 / .2), 0 0 0 4px var(--mo-theme-focus-ring); }
.color-slider:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 1px oklch(0% 0 0 / .2), 0 0 0 4px var(--mo-theme-focus-ring); }

/* Value field + format + eyedropper */
.color-field { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; }
.color-format {
  flex-shrink: 0;
  min-width: 2.75rem;
  height: var(--mo-control-height-sm);
  padding: 0 .5rem;
  font: inherit;
  font-size: .6875rem;
  font-weight: var(--mo-font-weight-semibold);
  color: var(--mo-fg-2);
  letter-spacing: .04em;
  cursor: pointer;
  background: color-mix(in oklab, var(--mo-fg-body) 6%, transparent);
  border: 0;
  border-radius: var(--mo-radius-control);
}
.color-format:hover { color: var(--mo-fg-body); background: color-mix(in oklab, var(--mo-fg-body) 10%, transparent); }
.color-eyedropper {
  flex-shrink: 0;
  width: var(--mo-control-height-sm);
  height: var(--mo-control-height-sm);
  padding: 0;
  cursor: pointer;
  background: color-mix(in oklab, var(--mo-fg-body) 6%, transparent);
  border: 0;
  border-radius: var(--mo-radius-control);
}
.color-eyedropper::before {
  display: block;
  width: 1rem;
  height: 1rem;
  margin: auto;
  content: "";
  background: var(--mo-fg-2);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m2 22 1-1h3l9-9'/%3E%3Cpath d='M3 21v-3l9-9'/%3E%3Cpath d='m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3l.4.4Z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.color-eyedropper:hover { background: color-mix(in oklab, var(--mo-fg-body) 10%, transparent); }
.color-eyedropper:hover::before { background: var(--mo-fg-body); }
:is(.color-format, .color-eyedropper):focus-visible { outline: var(--mo-focus-ring-width) solid var(--mo-theme-focus-ring); outline-offset: 1px; }

/* Preset swatches */
.color-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(1.375rem, 1fr)); gap: .375rem; }
.color-swatches:empty { display: none; }
.color-swatches > button {
  aspect-ratio: 1;
  padding: 0;
  cursor: pointer;
  background: linear-gradient(var(--c), var(--c)), var(--mo-checker);
  border: 0;
  border-radius: calc(var(--mo-radius-control) - .25rem);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--mo-fg-body) 10%, transparent);
  transition: scale var(--mo-duration) var(--mo-ease);
}
.color-swatches > button:hover { scale: 1.12; }
.color-swatches > button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--mo-bg-raised), 0 0 0 4px var(--c); }
.color-swatches > button:focus-visible { outline: var(--mo-focus-ring-width) solid var(--mo-theme-focus-ring); outline-offset: 2px; }

@media (prefers-reduced-motion: no-preference) {
  .color-panel {
    transform-origin: var(--mo-menu-origin, top left);
    transition: opacity .12s var(--mo-ease), scale .12s var(--mo-ease), overlay .12s allow-discrete, display .12s allow-discrete;
  }
  .color-panel:not(:popover-open) { opacity: 0; scale: .96; }
  @starting-style { .color-panel:popover-open { opacity: 0; scale: .96; } }
}
