/*
 * Copyright 2021 The Chromium Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* https://github.com/bgrins/spectrum */

:host {
  width: 232px;
  height: 319px;
  user-select: none;
  overflow: hidden;
}

/* stylelint-disable-next-line selector-pseudo-class-no-unknown */
:selection {
  background-color: var(--sys-color-tonal-container);
  color: var(--sys-color-on-tonal-container);
}

.spectrum-color {
  position: relative;
  width: 232px;
  height: 127px;
  border-radius: 2px 2px 0 0;
  overflow: hidden;
  flex: none;
  touch-action: none;
}

.spectrum-dragger,
.spectrum-slider {
  user-select: none;
}

.spectrum-dragger {
  border-radius: 12px;
  height: 12px;
  width: 12px;
  border: 1px solid var(--sys-color-surface);
  cursor: move;
  z-index: 1;
  position: absolute;
  top: 0;
  left: 0;
  background: var(--sys-color-inverse-surface);
  box-shadow: var(--drop-shadow);
}

.spectrum-slider {
  position: absolute;
  top: -1px;
  cursor: ew-resize;
  width: 13px;
  height: 13px;
  border-radius: 13px;
  background-color: var(--sys-color-neutral-container);
  box-shadow: var(--drop-shadow);
}

.spectrum-color:focus .spectrum-dragger {
  border: 1px solid var(--sys-color-state-focus-ring);
}

.spectrum-tools {
  position: relative;
  height: 110px;
  width: 100%;
  flex: none;
}

.spectrum-hue {
  top: 16px;
  /* stylelint-disable-next-line plugin/use_theme_colors, declaration-property-value-no-unknown */
  background: linear-gradient(to left in hsl longer hue, #f00 0 100%);
}

.spectrum-hue.display-p3 {
  /* stylelint-disable-next-line declaration-property-value-no-unknown */
  background: linear-gradient(
    to left in hsl longer hue,
    color(display-p3 1 0 0) 0 100%
  );
}

.spectrum-alpha {
  top: 35px;
  background-image: var(--image-file-checker);
  background-size: 12px 11px;
}

.spectrum-alpha-background {
  height: 100%;
  border-radius: 2px;
}

.spectrum-hue,
.spectrum-alpha {
  position: absolute;
  left: 86px;
  width: 130px;
  height: 11px;
  border-radius: 2px;
  touch-action: none;
}

.spectrum-hue:focus-visible .spectrum-slider,
.spectrum-alpha:focus-visible .spectrum-slider {
  border: 1px solid var(--sys-color-state-focus-ring);
  width: 14px;
  height: 14px;
  border-radius: 14px;
}

.spectrum-sat,
.-theme-preserve {
  /* stylelint-disable-next-line plugin/use_theme_colors */
  background-image: linear-gradient(to right, #fff, rgb(204 154 129 / 0%));
}

.spectrum-val,
.-theme-preserve {
  /* stylelint-disable-next-line plugin/use_theme_colors */
  background-image: linear-gradient(to top, #000, rgb(204 154 129 / 0%));
}

.spectrum-contrast-details {
  position: relative;
  background-color: var(--sys-color-cdt-base-container);
  width: 100%;
  height: 83px;
  top: 0;
  font-size: 13px;
  color: var(--sys-color-on-surface);
  border-top: 1px solid var(--sys-color-divider);
  line-height: initial;
  overflow: hidden;
  flex: none;
}

.spectrum-contrast-details.collapsed {
  height: 36px;
  flex: none;
}

.spectrum-contrast-details devtools-toolbar.expand {
  position: absolute;
  right: 6px;
  top: 6px;
  margin: 0;
}

.spectrum-contrast-details.visible {
  display: initial;
}

.spectrum-contrast-details div.container {
  margin: 10px;
}

.spectrum-contrast-details .expanded-details {
  display: flex;
  margin: 12px 12px 0 4px;
}

.spectrum-contrast-details.collapsed .expanded-details {
  display: none;
}

.contrast-pass-fail {
  margin-left: 0.5em;
  display: flex;
  align-items: center;
}

.contrast-choose-bg-color {
  margin: 8px 0 0 5px;
  font-style: italic;
}

.spectrum-contrast-details .contrast-choose-bg-color,
.spectrum-contrast-details .contrast-thresholds {
  width: 150px;
}

.contrast-threshold:first-child {
  margin-bottom: 5px;
}

.contrast-fix-button {
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  margin: 0 0 0 10px;
  background: 0;
  width: 12px;
  height: 12px;
  border: 1px solid var(--sys-color-neutral-outline);
  display: inline-block;
  position: relative;
}

.contrast-fix-button::after {
  content: ' ';
  width: 13px;
  height: 13px;
  background-image: var(--image-file-refresh);
  background-size: contain;
  position: absolute;
  left: 5.5px;
  top: 3.5px;
  background-color: var(--sys-color-cdt-base-container);
  border-radius: 50%;
}

.contrast-fix-button:hover,
.contrast-fix-button:focus {
  border: 1px solid var(--sys-color-state-focus-ring);
  transform: scale(1.2);
}

.contrast-link-label {
  cursor: pointer;
}

.contrast-link-label:hover {
  text-decoration: underline;
}

.spectrum-contrast-details .background-color {
  position: absolute;
  flex: none;
  right: 12px;
}

.spectrum-eye-dropper {
  width: 32px;
  height: 24px;
  position: relative;
  left: 8px;
  top: 17px;
  cursor: pointer;
}

.spectrum-contrast-details .spectrum-eye-dropper {
  top: 2px;
  right: 34px;
  position: absolute;
  left: auto;
}

.contrast-details-value {
  color: var(--sys-color-on-surface);
  margin: 1px 5px;
  user-select: text;
}

.contrast-pass-fail devtools-icon {
  margin-left: 5px;
}

.contrast-details-value devtools-icon {
  display: none;
  margin-left: 5px;
  color: var(--sys-color-on-surface);
}

.spectrum-contrast-details .toolbar-state-on devtools-icon {
  color: var(--sys-color-token-subtle);
}

devtools-icon.clear {
  transform: scale(0.7);
  color: var(--icon-error);
}

devtools-icon.checkmark,
devtools-icon.check-double {
  color: var(--icon-checkmark-green);
}

.spectrum-contrast-details .contrast-details-value.contrast-unknown {
  background-color: var(--sys-color-cdt-base-container);
  color: var(--sys-color-on-surface);
  width: 3em;
  text-align: center;
}

.contrast-details-value .clear,
.contrast-details-value .checkmark,
.contrast-details-value .check-double {
  cursor: pointer;
  vertical-align: -5px;
}

.spectrum-contrast-details.contrast-fail .contrast-details-value .clear,
.contrast-details-value.contrast-aa .checkmark,
.contrast-details-value.contrast-aaa .check-double {
  display: inline-block;
}

.swatch {
  width: 32px;
  height: 32px;
  margin: 0;
  position: absolute;
  top: 15px;
  left: 44px;
  background-image: var(--image-file-checker);
  border-radius: 16px;
}

.swatch-inner,
.swatch-overlay {
  position: absolute;
  width: 100%;
  height: 100%;
  display: inline-block;
  border-radius: 16px;
}

.swatch-inner-white {
  border: 1px solid var(--sys-color-neutral-outline);
}

.swatch-overlay {
  cursor: pointer;
  opacity: 0%;
  padding: 4px;
}

.swatch-overlay:hover,
.swatch-overlay:focus-visible {
  background-color: var(--color-background-inverted-opacity-30);
  opacity: 100%;
}

.swatch-overlay:active {
  background-color: var(--color-background-inverted-opacity-50);
}

devtools-icon.copy-color-icon {
  color: var(--sys-color-cdt-base-container);
  margin-top: 2px;
  margin-left: 2px;
}

.spectrum-text {
  position: absolute;
  top: 60px;
  left: 16px;
}

.spectrum-text-value {
  display: inline-block;
  width: 40px;
  overflow: hidden;
  text-align: center;
  margin-right: 6px;
  line-height: 20px;
  padding: 0;
  color: var(--sys-color-on-surface);
  border: 1px solid var(--sys-color-neutral-outline);
  white-space: nowrap;
}

.spectrum-text-label {
  letter-spacing: 39.5px;
  margin-top: 8px;
  display: block;
  color: var(--sys-color-state-disabled);
  margin-left: 16px;
  width: 174px;
}

.spectrum-text-hex > .spectrum-text-value {
  width: 178px;
}

.spectrum-text-hex > .spectrum-text-label {
  letter-spacing: normal;
  margin-left: 0;
  text-align: center;
}

.spectrum-switcher {
  border-radius: 2px;
  height: 20px;
  width: 20px;
  padding: 2px;
  border: none;
  background: none;
  margin: 0;
}

.spectrum-display-switcher {
  top: 72px;
  position: absolute;
  right: 10px;
}

.spectrum-switcher:hover {
  background-color: var(--sys-color-state-hover-on-subtle);
}

.spectrum-switcher:focus-visible {
  background-color: var(--sys-color-state-focus-highlight);
}

.spectrum-palette-container {
  border-top: 1px solid var(--sys-color-divider);
  position: relative;
  width: 100%;
  padding: 6px 24px 6px 6px;
  display: flex;
  flex-wrap: wrap;
}

.spectrum-palette {
  display: flex;
  flex-wrap: wrap;
  width: 198px;
}

.spectrum-palette-color {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border-radius: 2px;
  margin: 6px;
  cursor: pointer;
  position: relative;
  border: 1px solid var(--sys-color-divider);
  background-position: -1px !important; /* stylelint-disable-line declaration-no-important */
  z-index: 14;
}

.spectrum-palette-color-shadow {
  position: absolute;
  opacity: 0%;
  margin: 0;
  top: -5px;
  left: 3px;
  border: 0;
  border-radius: 1px;
  width: 11px;
  height: 11px;
}

.spectrum-palette-color:hover:not(.spectrum-shades-shown)
  > .spectrum-palette-color-shadow,
.spectrum-palette-color:focus:not(.spectrum-shades-shown)
  > .spectrum-palette-color-shadow {
  opacity: 20%;
}

.spectrum-palette-color:hover:not(.spectrum-shades-shown)
  > .spectrum-palette-color-shadow:first-child,
.spectrum-palette-color:focus:not(.spectrum-shades-shown)
  > .spectrum-palette-color-shadow:first-child {
  opacity: 60%;
  top: -3px;
  left: 1px;
}

.palette-color-shades {
  position: absolute;
  background-color: var(--sys-color-cdt-base-container);
  height: 228px;
  width: 28px;
  box-shadow: var(--drop-shadow);
  z-index: 14;
  border-radius: 2px;
  transform-origin: 0 228px;
  margin-top: 16px;
  margin-left: -8px;
}

.spectrum-palette > .spectrum-palette-color.spectrum-shades-shown {
  z-index: 15;
}

.palette-color-shades > .spectrum-palette-color {
  margin: 8px 0 0;
  margin-left: 8px;
  width: 12px;
}

.spectrum-palette > .spectrum-palette-color {
  transition: transform 100ms cubic-bezier(0, 0, 0.2, 1);
  will-change: transform;
  z-index: 13;
}

.palette-preview > .spectrum-palette-color {
  margin-top: 1px;
}

.spectrum-palette > .spectrum-palette-color.empty-color {
  border-color: transparent;
}

.spectrum-palette-color:not(.has-material-shades):focus {
  border: 1px solid var(--sys-color-state-focus-ring);
  transform: scale(1.4);
}

.palette-color-shades > .spectrum-palette-color:not(.empty-color):hover,
.spectrum-palette
  > .spectrum-palette-color:not(.empty-color, .has-material-shades):hover {
  transform: scale(1.15);
}

.add-color-toolbar {
  margin-left: -3px;
  margin-top: -1px;
}

.spectrum-palette-switcher {
  right: 10px;
  top: 0;
  margin-top: 9px;
  position: absolute;
}

.palette-panel {
  width: 100%;
  position: absolute;
  top: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--sys-color-cdt-base-container);
  z-index: 14;
  transition: transform 200ms cubic-bezier(0, 0, 0.2, 1), visibility 0s 200ms;
  border-top: 1px solid var(--sys-color-divider);
  visibility: hidden;
}

.palette-panel-showing > .palette-panel {
  transform: translateY(-100%);
  transition-delay: 0s;
  visibility: visible;
}

.palette-panel > devtools-toolbar {
  position: absolute;
  right: 6px;
  top: 6px;
}

.palette-panel > div {
  flex: 0 0 38px;
  border-bottom: 1px solid var(--sys-color-divider);
  padding: 12px;
  line-height: 14px;
  color: var(--sys-color-on-surface);
}

.palette-panel > div.palette-title {
  font-size: 14px;
  line-height: 16px;
  color: var(--sys-color-on-surface);
  flex-basis: 40px;
}

div.palette-preview {
  display: flex;
  cursor: pointer;
}

.palette-preview-title {
  flex: 0 0 84px;
}

.palette-preview:focus-visible,
.palette-preview:hover {
  background-color: var(--sys-color-state-hover-on-subtle);
}

.spectrum-overlay {
  z-index: 13;
  visibility: hidden;
  /* stylelint-disable-next-line plugin/use_theme_colors */
  background-color: hsl(0deg 0% 0% / 50%);
  /* See: crbug.com/1152736 for color variable migration. */
  opacity: 0%;
  transition: opacity 100ms cubic-bezier(0, 0, 0.2, 1), visibility 0s 100ms;
}

.palette-panel-showing > .spectrum-overlay {
  transition-delay: 0s;
  visibility: visible;
  opacity: 100%;
}

.spectrum-contrast-container {
  width: 100%;
  height: 100%;
}

.spectrum-contrast-line,
:host-context(.theme-with-dark-background) .spectrum-contrast-line {
  fill: none;
  stroke: #fff; /* stylelint-disable-line plugin/use_theme_colors */
  opacity: 70%;
  stroke-width: 1.5px;
}

.delete-color-toolbar {
  position: absolute;
  right: 0;
  top: 0;
  background-color: var(--sys-color-cdt-base-container);
  visibility: hidden;
  z-index: 3;
  width: 36px;
  display: flex;
  align-items: center;
  padding-left: 4px;
  bottom: 2px;
  border-bottom-right-radius: 2px;
}

@keyframes showDeleteToolbar {
  from {
    opacity: 0%;
  }

  to {
    opacity: 100%;
  }
}

.delete-color-toolbar.dragging {
  visibility: visible;
  animation: showDeleteToolbar 100ms 150ms cubic-bezier(0, 0, 0.2, 1) backwards;
}

.delete-color-toolbar-active {
  background-color: var(--sys-color-state-hover-on-subtle);
  color: var(--sys-color-cdt-base-container);
}

.swatch.contrast {
  width: 30px;
  height: 30px;
  position: absolute;
  top: 0;
  right: 0;
  left: auto;
  background-image: var(--image-file-checker);
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.swatch.contrast .swatch-overlay {
  padding: 0;
}

.background-color .text-preview {
  color: var(--sys-color-inverse-surface);
  font-size: 16px;
  position: relative;
  padding-bottom: 2px;
}

.swatch.contrast devtools-icon {
  margin: -2px;
}

.no-contrast-info-available {
  border-top: 1px solid var(--sys-color-divider);
  position: relative;
  width: 100%;
  padding: 10px;
  justify-content: center;
  display: flex;
  flex-wrap: wrap;
}

@media (forced-colors: active) {
  :host {
    border: 1px solid canvastext !important; /* stylelint-disable-line declaration-no-important */
  }

  .spectrum-color {
    forced-color-adjust: none;
  }

  .spectrum-switcher:hover,
  .spectrum-switcher:focus-visible {
    forced-color-adjust: none;
    background-color: Highlight !important; /* stylelint-disable-line declaration-no-important */
  }

  :host-context(.theme-with-dark-background) .spectrum-switcher {
    filter: unset;
  }

  .spectrum-switcher:hover svg,
  .spectrum-switcher:focus-visible svg {
    fill: HighlightText;
  }

  .swatch {
    forced-color-adjust: none;
  }

  .swatch-inner,
  .swatch-overlay,
  .swatch-inner-white {
    border: 1px solid ButtonText;
  }

  .swatch-overlay:hover,
  .swatch-overlay:focus-visible {
    background-color: canvas !important; /* stylelint-disable-line declaration-no-important */
  }

  .spectrum-slider {
    forced-color-adjust: none;
    background-color: ButtonText !important; /* stylelint-disable-line declaration-no-important */
    box-shadow: 0 1px 4px 0 ButtonFace !important; /* stylelint-disable-line declaration-no-important */
  }
}
