/* HeyHi design system: popups (<dialog class="dialog">) and the contact form inside shared/_contact_dialog.
 * A dialog is a white sheet over the dimmed page, cast like a menu (--shadow-pop), headed as the house heads things: a
 * mono label, the title in the serif, a line under it. Its fields are 48px boxes edged in a line that keeps 3:1, its
 * notes are mono where they're metadata, and the form's one action is amber, for a message and a waitlist alike. It opens as menus do, with a short fade and settle from
 * @starting-style, and leaves quicker; on phones it's a sheet that rises from the bottom of the screen. Joining a
 * waitlist (.is-waitlist) is the same sheet, narrower, with a name and an email. Problems are shown as the product
 * cards show them, with amber, ink and a mark, never red. */

/* The edge of a field you type in: a warm grey that keeps 3:1 against white (3.3:1) and paper (3.0:1), as a form's
   fields need, where --line-strong would be 1.7:1. Ghost buttons keep the softer line, since their labels say what they
   are. The AI widget's message box uses it too (40_assistant.css). */
:root { --field-line: #948C82; }

.dialog {
  width: min(600px, calc(100% - 2 * var(--space-4))); max-width: none; max-height: calc(100dvh - 2 * var(--space-4));
  margin: auto; padding: 0; border: 0; overflow: visible;
  background: transparent; color: var(--ink);
  transition:
    opacity var(--dur-ui) var(--ease-out), transform var(--dur-ui) var(--ease-out),
    overlay var(--dur-ui) allow-discrete, display var(--dur-ui) allow-discrete;
}
.dialog.is-waitlist { width: min(480px, calc(100% - 2 * var(--space-4))); }
@starting-style {
  .dialog[open] { opacity: 0; transform: translateY(-6px) scale(0.985); }
}
/* Closing, it eases away quicker than it came */
.dialog:not([open]) {
  opacity: 0; transform: translateY(-4px) scale(0.99);
  transition-duration: var(--dur-fast); transition-timing-function: var(--ease-in);
}

.dialog::backdrop {
  background-color: color-mix(in srgb, var(--c-night) 44%, transparent);
  transition: background-color var(--dur-ui) var(--ease-out), overlay var(--dur-ui) allow-discrete, display var(--dur-ui) allow-discrete;
}
@starting-style {
  .dialog[open]::backdrop { background-color: transparent; }
}
.dialog:not([open])::backdrop { background-color: transparent; }

/* The panel scrolls when the screen is short; the <dialog> around it has no padding, so a click on the dialog
   itself is a click on the backdrop (dialogs#closeOnBackdrop). */
.dialog-panel {
  position: relative; max-height: calc(100dvh - 2 * var(--space-4)); overflow-y: auto; overscroll-behavior: contain;
  padding: clamp(24px, 4.4vw, 40px);
  border-radius: var(--radius-lg); background: var(--c-white); box-shadow: var(--shadow-pop);
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}

/* The head: the label beside the close button, the title under them, then the line */
.dialog-head {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "kicker close" "title title";
  align-items: center; gap: var(--space-3) var(--space-4);
}
.dialog-kicker { grid-area: kicker; }
.dialog-title {
  grid-area: title; max-width: 15em;
  font-size: min(var(--text-heading), 2.5rem); line-height: var(--leading-heading); letter-spacing: var(--tracking-heading);
}
/* Round and outlined in a hairline, as the header's menu button is */
.dialog-close {
  grid-area: close; display: grid; place-items: center; width: 44px; height: 44px; margin: -6px -10px -6px 0; padding: 0;
  border-radius: 50%; border: 1px solid var(--line-strong); background: transparent; color: var(--ink); cursor: pointer;
  transition: background-color var(--dur-fast), border-color var(--dur-fast);
}
.dialog-close:hover { background: var(--c-paper); border-color: color-mix(in srgb, var(--ink) 40%, transparent); }
.dialog-close .icon { width: 18px; height: 18px; }
.dialog-subtitle { margin-top: var(--space-3); max-width: 30em; font-size: var(--text-small); line-height: 1.55; color: var(--ink-soft); }

/* ---------- The contact form ---------- */
.contact-form { container-type: inline-size; display: grid; gap: var(--space-5); margin-top: clamp(24px, 3vw, 32px); }

/* Paired fields sit side by side once the form is wide enough */
.form-row { display: grid; gap: var(--space-5) var(--space-4); }
@container (min-width: 30rem) { .form-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.form-field { display: grid; gap: var(--space-2); align-content: start; min-width: 0; }
/* The label, and on its right a field that can be left empty says so, in mono */
.form-label {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3);
  font-size: var(--text-small); font-weight: 500; line-height: 1.3; color: var(--ink);
}
.form-optional {
  font-family: var(--font-mono); font-size: 11px; font-weight: 400; letter-spacing: var(--tracking-label);
  text-transform: uppercase; color: var(--ink-mute);
}

/* A hairline box, 48px tall, with 16px text so phones don't zoom in on it. Focus darkens the edge and lays the amber
   wash around it. */
.form-input {
  width: 100%; min-width: 0; min-height: 48px; padding: 11px 14px;
  border: 1px solid var(--field-line); border-radius: var(--radius-sm); background: var(--c-white);
  font-size: 16px; line-height: 1.4; color: var(--ink);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.form-input:hover { border-color: var(--ink-mute); }
.form-input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--amber-soft); }
.form-input[aria-invalid="true"] { border-color: var(--amber-ink); box-shadow: inset 0 0 0 1px var(--amber-ink); }
.form-input[aria-invalid="true"]:focus { box-shadow: inset 0 0 0 1px var(--amber-ink), 0 0 0 3px var(--amber-soft); }
textarea.form-input { min-height: 120px; resize: vertical; line-height: 1.5; }

/* A select draws its own chevron from the icon sprite, and reads as a hint until something is chosen */
.form-select { position: relative; display: block; }
.form-select .form-input { appearance: none; padding-right: 42px; cursor: pointer; text-overflow: ellipsis; }
.form-select .form-input:has(option[value=""]:checked) { color: var(--ink-mute); }
.form-select option { color: var(--ink); }
.form-select__icon { position: absolute; top: 50%; right: 14px; width: 16px; height: 16px; margin-top: -8px; color: var(--ink-mute); pointer-events: none; }

/* What to put right, in amber with the mark a product card gives something due */
.form-error { display: flex; align-items: baseline; gap: var(--space-2); font-size: var(--text-caption); font-weight: 600; line-height: 1.45; color: var(--amber-ink); }
.form-error::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--amber); transform: translateY(-1px); }

/* People never see the trap field; bots fill it in */
.form-trap { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* The foot: how we treat what's sent, and the send button, ruled off from the fields. A message and a waitlist share
   it: the note on the left, the amber button on the right, until the form is phone-narrow, when the button takes the
   width under the thumb and the note sits under it. */
.form-foot {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-4) var(--space-5);
  margin-top: var(--space-1); padding-top: var(--space-5); border-top: 1px solid var(--line);
}
.form-note { flex: 1 1 12rem; max-width: 21rem; font-size: var(--text-caption); line-height: 1.5; color: var(--ink-mute); }
.form-note .text-link { font-weight: 500; text-underline-offset: 3px; white-space: nowrap; }
.form-submit { flex: none; min-width: 10.5rem; }
@container (max-width: 23.99rem) {
  .form-foot { flex-direction: column-reverse; align-items: stretch; }
  .form-submit { width: 100%; }
  .form-note { flex: none; max-width: none; text-align: center; }
}

/* Why it couldn't be sent, as a highlighted row */
.form-status { padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); font-size: var(--text-small); line-height: 1.5; }
.form-status-error { background: var(--amber-soft); color: var(--c-ink); }
@starting-style {
  .form-status { opacity: 0; }
}
.form-status { transition: opacity var(--dur-ui) var(--ease-out); }

/* Once sent, the form gives way to the confirmation: a tick above the title the server sends ("Message sent"), what
   happens next in place of the line under it, and a button to close the dialog */
.dialog-sent-icon, .form-done { display: none; }
.dialog-panel:has(.contact-form.is-sent) .dialog-head { grid-template-areas: "icon close" "title title"; row-gap: var(--space-5); }
.dialog-panel:has(.contact-form.is-sent) :is(.dialog-kicker, .dialog-subtitle) { display: none; }
.dialog-panel:has(.contact-form.is-sent) .dialog-sent-icon {
  grid-area: icon; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%;
  background: var(--amber); color: var(--c-ink);
  transition: opacity var(--dur-ui) var(--ease-out), transform var(--dur-ui) var(--ease-out);
}
@starting-style {
  .dialog-panel:has(.contact-form.is-sent) .dialog-sent-icon { opacity: 0; transform: scale(0.8); }
}
.dialog-sent-icon .icon { width: 22px; height: 22px; }
.contact-form.is-sent { justify-items: start; gap: var(--space-6); margin-top: var(--space-3); }
.contact-form.is-sent > :not(.form-status, .form-done) { display: none; }
.contact-form.is-sent .form-status { max-width: 32em; padding: 0; background: none; font-size: var(--text-body); line-height: var(--leading-text); color: var(--ink-soft); overflow-wrap: anywhere; }
.contact-form.is-sent .form-done { display: inline-flex; min-width: 8rem; }

/* ---------- Phones: a sheet from the bottom of the screen ---------- */
@media (max-width: 35.99em) {
  .dialog, .dialog.is-waitlist { width: 100%; max-height: calc(100dvh - var(--space-5)); margin: auto 0 0; }
  .dialog-panel {
    max-height: calc(100dvh - var(--space-5)); padding: 24px 20px max(24px, env(safe-area-inset-bottom, 0px));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  @starting-style {
    .dialog[open] { opacity: 1; transform: translateY(100%); }
  }
  .dialog:not([open]) { opacity: 1; transform: translateY(100%); transition-duration: var(--dur-ui); }
}
