/* A contact form on a raised card under a dithered band of the accent. Each
   field checks itself when you leave it, and the card shows a confirmation in
   place once the message is sent. */
.dh-contact {
  container: dh-contact / inline-size;
  display: grid;
  grid-template-columns: minmax(0, 440px);
  justify-content: center;
  padding: 56px 20px;
  background: var(--dh-bg, #f7f7f6);
  color: var(--dh-fg, #171717);
  font-family: inherit;
  font-size: 13px;
  line-height: 20px;
  text-align: left;
}

.dh-contact *,
.dh-contact *::before,
.dh-contact *::after {
  box-sizing: border-box;
}

/* Honeypot: invisible para personas, rellenado por bots. */
.dh-contact-hp {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* The form and the confirmation share one grid cell, so the card keeps its
   size when one takes the place of the other. */
.dh-contact-card {
  --accent: var(--dh-accent, #2563ff);
  --line: color-mix(in srgb, var(--dh-fg, #171717) 9%, transparent);
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  border-radius: 14px;
  background: var(--dh-raised, #fff);
  box-shadow:
    0 0 0 1px var(--line),
    0 1px 2px color-mix(in srgb, var(--dh-fg, #171717) 10%, transparent);
}

.dh-contact-top {
  height: 76px;
  padding: 18px 20px;
  background: linear-gradient(120deg, var(--link, #3291ff) 0%, #7c3aed 52%, #ff6a3d 100%);
  color: #fff;
  -webkit-mask-image: linear-gradient(#000 46%, transparent), radial-gradient(circle, #000 1.3px, transparent 1.6px);
  mask-image: linear-gradient(#000 46%, transparent), radial-gradient(circle, #000 1.3px, transparent 1.6px);
  -webkit-mask-size: auto, 5px 5px;
  mask-size: auto, 5px 5px;
}

.dh-contact-top svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.dh-contact-body,
.dh-contact-done {
  grid-area: 2 / 1;
  min-width: 0;
}

.dh-contact :is(h2, p) {
  margin: 0;
}

.dh-contact h2 {
  padding: 0 20px;
  font-size: 16px;
  font-weight: 500;
  line-height: 24px;
  letter-spacing: -0.02em;
}

.dh-contact-lead {
  margin-top: 2px !important;
  padding: 0 20px;
  color: var(--dh-muted, #5c5c5c);
}

.dh-contact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 8px;
  padding: 16px 20px 4px;
}

.dh-contact-field {
  display: grid;
  min-width: 0;
}

.dh-contact-wide {
  grid-column: 1 / -1;
}

.dh-contact-field label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
  color: var(--dh-muted, #5c5c5c);
  font-size: 11px;
  line-height: 16px;
}

.dh-contact-count {
  color: var(--dh-faint, #8a8a8a);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.dh-contact-field :is(input, textarea) {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: var(--dh-well, #ededeb);
  color: inherit;
  font: inherit;
  outline: none;
  transition: box-shadow 150ms var(--ease);
}

.dh-contact-field textarea {
  display: block;
  height: auto;
  min-height: 84px;
  padding: 6px 10px;
  resize: vertical;
}

.dh-contact-field ::placeholder {
  color: var(--dh-faint, #8a8a8a);
}

.dh-contact-field :is(input, textarea):focus-visible {
  box-shadow: 0 0 0 2px var(--dh-faint, #8a8a8a);
}

.dh-contact-field [aria-invalid="true"] {
  box-shadow: 0 0 0 1px #d92d20;
}

.dh-contact-field [aria-invalid="true"]:focus-visible {
  box-shadow:
    0 0 0 1px #d92d20,
    0 0 0 3px color-mix(in srgb, #d92d20 30%, transparent);
}

/* The message line keeps its height when empty, so nothing jumps. */
.dh-contact-field small {
  min-height: 16px;
  margin: 3px 0 4px;
  color: color-mix(in srgb, #d92d20 82%, var(--dh-fg, #171717));
  font-size: 11px;
  line-height: 16px;
}

/* The foot is a quiet strip: a note on the left, the one action on the right. */
.dh-contact-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 10px 20px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--dh-fg, #171717) 3%, var(--dh-raised, #fff));
}

.dh-contact-foot p {
  color: var(--dh-muted, #5c5c5c);
  font-size: 12px;
}

.dh-contact :is(.dh-contact-send, .dh-contact-again) {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  letter-spacing: -0.01em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 150ms var(--ease),
    opacity 150ms var(--ease);
}

.dh-contact :is(.dh-contact-send, .dh-contact-again):active {
  transform: scale(0.97);
}

.dh-contact :is(.dh-contact-send, .dh-contact-again):focus-visible {
  outline: 2px solid var(--dh-faint, #8a8a8a);
  outline-offset: 2px;
}

.dh-contact-send {
  min-width: 112px;
  background: linear-gradient(color-mix(in srgb, var(--accent) 84%, #fff), var(--accent));
  color: var(--dh-on-accent, #fff);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.3),
    0 0 0 1px color-mix(in srgb, var(--accent) 78%, #000),
    0 1px 2px color-mix(in srgb, var(--dh-fg, #171717) 22%, transparent);
}

/* While sending, the label gives way to a spinner and "Sending…". */
.dh-contact-send i {
  display: none;
  width: 12px;
  height: 12px;
  border: 1.5px solid color-mix(in srgb, currentColor 30%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: dh-contact-spin 0.7s linear infinite;
}

.dh-contact-card[data-state="busy"] .dh-contact-send {
  opacity: 0.7;
  pointer-events: none;
}

.dh-contact-card[data-state="busy"] .dh-contact-send i {
  display: block;
}

.dh-contact-card[data-state="done"] .dh-contact-body {
  visibility: hidden;
}

.dh-contact-done {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2px;
  padding: 0 20px 20px;
  text-align: center;
  animation: dh-contact-in 280ms var(--ease) both;
}

.dh-contact-done[hidden] {
  display: none;
}

/* The tick sits in a small tinted tile, like an app icon. */
.dh-contact-done svg {
  width: 36px;
  height: 36px;
  margin-bottom: 10px;
  padding: 8px;
  border-radius: 10px;
  background: color-mix(in srgb, #1fa750 12%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #1fa750 18%, transparent);
  fill: #1fa750;
}

.dh-contact-done h2 {
  outline: none;
}

.dh-contact-done p {
  max-width: 300px;
  color: var(--dh-muted, #5c5c5c);
}

.dh-contact-done p span {
  color: var(--dh-fg, #171717);
  overflow-wrap: anywhere;
}

.dh-contact-again {
  margin-top: 16px;
  background: var(--dh-raised, #fff);
  color: inherit;
  box-shadow:
    0 0 0 1px var(--line),
    0 1px 2px color-mix(in srgb, var(--dh-fg, #171717) 10%, transparent);
}

/* In a narrow space the fields stack and grow to a thumb's height. */
@container dh-contact (max-width: 440px) {
  .dh-contact {
    padding: 16px 12px;
  }

  .dh-contact-grid {
    grid-template-columns: 1fr;
  }

  .dh-contact-field :is(input, textarea) {
    font-size: 16px;
  }

  .dh-contact-field input,
  .dh-contact :is(.dh-contact-send, .dh-contact-again) {
    height: 44px;
  }

  .dh-contact-foot {
    flex-direction: column-reverse;
    align-items: stretch;
    padding: 12px 20px;
    text-align: center;
  }
}

@keyframes dh-contact-spin {
  to {
    rotate: 1turn;
  }
}

@keyframes dh-contact-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
    filter: blur(4px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .dh-contact-done {
    animation: dh-contact-fade 200ms both;
  }

  .dh-contact :is(.dh-contact-send, .dh-contact-again) {
    transition: none;
  }
}

@keyframes dh-contact-fade {
  from {
    opacity: 0;
  }
}
