.color-presets {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--border-muted, #cbd5e1);
  border-radius: 1rem;
  background: transparent;
  color: var(--text-color);
}

.color-presets__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.color-presets__header span,
.color-preset-card__meta strong,
.color-presets__legacy strong {
  display: block;
  font-weight: 600;
}

.color-presets__header small,
.color-preset-card__meta small,
.color-presets__legacy small {
  display: block;
  color: var(--text-muted, #6b7280);
  font-size: 0.8rem;
}

.color-presets__toggle {
  appearance: none;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border-muted, #cbd5e1);
  border-radius: 999px;
  background: var(--team-primary-surface);
  color: var(--team-on-primary);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.color-presets__toggle:hover {
  border-color: var(--team-link-hover);
}

.color-presets__toggle:focus-visible,
.color-preset-card:focus-visible {
  outline: 3px solid var(--team-focus-ring);
  outline-offset: 2px;
}

.color-presets[data-collapsed='true'] .color-presets__grid {
  display: none;
}

.color-presets__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
  gap: 0.75rem;
}

.color-presets--compact .color-presets__grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
}

.color-preset-card {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem;
  overflow: visible;
  border: 1px solid var(--border-muted, #cbd5e1);
  border-radius: 1rem;
  background: var(--inner-container-background);
  color: var(--text-color);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.color-preset-card:hover {
  z-index: 50;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.color-preset-card.is-active {
  border-color: var(--preset-primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--preset-primary) 25%, transparent);
}

.color-preset-card__swatch {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  width: 58px;
  height: 52px;
  overflow: hidden;
  border: 1px solid var(--preset-soft-border);
  border-radius: 0.75rem;
}

.color-preset-card__swatch-primary {
  background: var(--preset-primary);
}

.color-preset-card__swatch-link {
  background: var(--preset-link-dark);
}

.color-preset-card__swatch-soft {
  background: var(--preset-soft-background);
}

.color-preset-card__semantic-preview {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem;
  border: 1px solid var(--preset-soft-border);
  border-radius: 0.6rem;
  background: var(--preset-soft-background);
}

.color-preset-card__preview-button {
  height: 1.1rem;
  border-radius: 0.3rem;
  background: var(--preset-primary);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--preset-on-primary) 35%, transparent);
}

.color-preset-card__preview-link {
  height: 0.2rem;
  border-radius: 999px;
}

.color-preset-card__preview-link--light {
  background: var(--preset-link-light);
}

.color-preset-card__preview-link--dark {
  padding: 0.35rem 0;
  background: var(--preset-link-dark);
  box-shadow: 0 0 0 0.2rem #1c2128;
}

.color-preset-card__preview-badge {
  height: 0.7rem;
  border: 1px solid var(--preset-soft-border);
  border-radius: 999px;
  background: var(--preset-soft-background);
}

.color-preset-card__preview-focus {
  height: 0.9rem;
  border: 3px solid var(--preset-focus);
  border-radius: 0.25rem;
}

.color-presets__legacy {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px dashed var(--border-muted, #cbd5e1);
  border-radius: 0.75rem;
  background: var(--inner-container-background);
}

.color-presets__legacy-swatch {
  width: 2.75rem;
  height: 2.25rem;
  flex: 0 0 auto;
  border: 1px solid var(--border-muted, #cbd5e1);
  border-radius: 0.5rem;
  background: linear-gradient(135deg, var(--legacy-primary) 0 65%, var(--legacy-contrast) 65% 100%);
}

.color-preset-card__preview {
  position: absolute;
  left: 50%;
  top: -8px;
  width: min(540px, calc(100vw - 2rem));
  height: 300px;
  padding: 0;
  overflow: hidden;
  visibility: hidden;
  border: 1px solid var(--border-muted, #cbd5e1);
  border-radius: 12px;
  background: var(--inner-container-background);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -100%);
}

.color-preset-card:hover .color-preset-card__preview,
.color-preset-card:focus-visible .color-preset-card__preview {
  visibility: visible;
  opacity: 1;
}

.color-preset-card__preview[data-loading='true'] {
  visibility: hidden;
  opacity: 0;
}

.color-preset-card__preview iframe {
  display: block;
  width: 1800px;
  height: 1000px;
  border: 0;
  border-radius: 12px;
  pointer-events: none;
  transform: scale(0.3);
  transform-origin: top left;
}

@media (max-width: 700px) {
  .color-presets__header {
    align-items: flex-start;
    flex-direction: column;
  }

  .color-presets__toggle {
    width: 100%;
  }

  .color-preset-card__preview {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .color-preset-card {
    transition: none;
  }
}
