/*
 * Publish flow (/give).
 *
 * Follows docs/web-companion-spec.md and the Editorial Organicism rules:
 * definition through tonal surface shifts (no 1px dividers), heavy rounding,
 * pill-shaped primary actions, asymmetric editorial spacing. Mobile-first;
 * the live preview column appears from 64rem upwards.
 */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.give-page {
  width: min(100% - 2rem, 72rem);
  margin-inline: auto;
  /* The site header is fixed; the top padding clears it (see .disc-page). */
  padding-block: clamp(7rem, 12vw, 8rem) 4rem;
}

/* ---------- sign-in gate (anonymous / unknown sessions) ---------- */

.give-gate {
  display: grid;
  gap: 1.7rem;
  align-items: center;
  padding: 2.4rem 1.7rem;
  border-radius: 2rem;
  background: var(--color-surface-container-low);
}

.give-gate__copy h2 {
  margin: 0.4rem 0 0.8rem;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  line-height: 1.15;
}

.give-gate__copy p:not(.home-eyebrow) {
  max-width: 46ch;
  color: var(--color-muted);
}

.give-gate__copy .button-row {
  margin-top: 1.4rem;
}

.give-gate__visual {
  display: none;
  justify-content: center;
}

/*
 * JavaScript resolves the session and toggles the hidden attributes of the
 * gate and the form shell. The guard keeps hidden authoritative even where
 * a class sets an explicit display value.
 */
[data-give] [hidden] {
  display: none !important;
}

/* ---------- shell layout ---------- */

.give-shell[data-give-app] {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2.4rem;
}

.give-preview {
  display: none;
}

@media (min-width: 64rem) {
  .give-shell[data-give-app] {
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: 3.4rem;
  }

  .give-preview {
    display: block;
    position: sticky;
    top: 6.5rem;
    height: fit-content;
  }

  .give-gate {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    padding: 3.4rem 2.4rem;
  }

  .give-gate__visual {
    display: flex;
  }
}

/* ---------- live preview card ---------- */

.give-preview h2 {
  margin: 0;
  font-size: 1.5rem;
}

.give-preview__lead {
  margin: 0.3rem 0 1.4rem;
  color: var(--color-muted);
}

.give-preview-card {
  overflow: hidden;
  border-radius: 2rem;
  background: var(--color-surface-container-lowest);
}

.give-preview-card__media {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--color-surface-container);
}

.give-preview-card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.give-preview-card__badge {
  position: absolute;
  top: 1rem;
  left: 1rem;
  padding: 0.3rem 0.8rem;
  border-radius: 0.5rem;
  background: var(--color-tertiary-container);
  color: var(--color-on-tertiary-container);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.give-preview-card__body {
  display: grid;
  gap: 0.6rem;
  padding: 1.7rem 1.4rem 1.4rem;
}

.give-preview-card__body h3 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.give-preview-card__location {
  display: flex;
  gap: 0.4rem;
  align-items: baseline;
  margin: 0;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.give-preview-card__description {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.9rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-line;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.give-preview-card__meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 0.6rem 0 0;
  padding-top: 0.9rem;
  /* Tonal separation instead of a divider line. */
  background: linear-gradient(var(--color-surface-container-lowest), var(--color-surface-container-lowest));
  font-size: 0.8rem;
  font-weight: 700;
}

.give-preview-card__time {
  color: var(--color-subtle);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.66rem;
}

.give-tip {
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
  margin-top: 1.7rem;
  padding: 1.4rem 1.2rem;
  border-radius: 2rem;
  background: color-mix(in srgb, var(--color-primary-container) 30%, var(--color-background));
  color: var(--color-on-primary-container);
}

.give-tip p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.55;
}

/* ---------- stepper ---------- */

.give-stepper {
  display: flex;
  gap: 0.75rem;
  margin: 0 0 2.4rem;
  padding: 0;
  list-style: none;
}

.give-stepper__step {
  width: 0.75rem;
  height: 0.4rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--color-on-surface) 22%, var(--color-background));
  transition: width 0.4s ease, background-color 0.4s ease;
}

.give-stepper__step[aria-current="step"] {
  width: 2.5rem;
  background: var(--color-primary);
}

.give-stepper__step[data-step-done="true"] {
  background: var(--color-primary-container);
}

/* ---------- steps ---------- */

.give-step {
  display: grid;
  gap: 1.7rem;
  margin: 0;
  padding: 0;
  border: 0;
}

.give-step__legend {
  padding: 0;
}

.give-step__heading {
  margin: 0;
  font-size: clamp(1.7rem, 5vw, 2.4rem);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.give-step__heading:focus {
  outline: none;
}

.give-step__lead {
  margin: 0.5rem 0 0;
  color: var(--color-muted);
  font-size: 1.05rem;
}

.field-hint {
  margin: 0.35rem 0 0 0.2rem;
  color: var(--color-muted);
  font-size: 0.85rem;
}

/* ---------- photo upload ---------- */

.give-photo {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 14rem;
  overflow: hidden;
  border-radius: 2rem;
  border: 2px dashed color-mix(in srgb, var(--color-on-surface) 25%, var(--color-background));
  background: var(--color-surface-container-highest);
}

.give-photo__preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.give-photo__prompt {
  display: grid;
  gap: 0.5rem;
  justify-items: center;
  color: var(--color-muted);
  font-weight: 700;
  pointer-events: none;
}

.give-photo__icon {
  width: 2.6rem;
  height: 2.6rem;
}

.give-photo input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.give-photo input[type="file"]:focus-visible {
  opacity: 1;
  /* Keep the focus ring visible for keyboard users. */
  clip-path: inset(0 round 2rem);
}

.give-photo:hover {
  background: var(--color-surface-container-high);
}

.give-photo[data-has-photo="true"] {
  border-style: solid;
  border-color: transparent;
}

.give-photo[data-has-photo="true"] .give-photo__prompt {
  display: none;
}

.give-photo__replace {
  margin-top: 0.6rem;
  justify-self: start;
}

.give-checklist {
  padding: 1.4rem 1.4rem 1.2rem;
  border-radius: 2rem;
  background: var(--color-surface-container-low);
}

.give-checklist h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.6rem;
  font-size: 1rem;
}

.give-checklist__icon {
  width: 1.15rem;
  height: 1.15rem;
  color: var(--color-primary);
}

.give-checklist ul {
  margin: 0;
  padding-left: 1.4rem;
  color: var(--color-muted);
  font-size: 0.92rem;
  line-height: 1.7;
}

/* ---------- category chips ---------- */

.give-categories {
  margin: 0;
  padding: 0;
  border: 0;
}

.give-categories legend,
.give-location legend {
  margin-bottom: 0.6rem;
  padding: 0;
  font-weight: 700;
  font-size: 0.95rem;
}

.give-categories__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.give-chip {
  position: relative;
  display: inline-flex;
}

.give-chip input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.give-chip span {
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  background: var(--color-surface-container-highest);
  color: var(--color-on-surface);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.give-chip input:checked + span {
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: 700;
}

.give-chip input:focus-visible + span {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.give-count input {
  max-width: 9rem;
}

/* ---------- location ---------- */

.give-location {
  display: grid;
  gap: 1rem;
  margin: 0;
  padding: 1.4rem;
  border: 0;
  border-radius: 2rem;
  background: var(--color-surface-container-low);
}

.give-location__value {
  margin: 0;
  font-weight: 600;
}

.give-location__value[data-state="chosen"] {
  color: var(--color-primary-dim);
}

.give-location__search {
  display: grid;
  gap: 0.4rem;
}

.give-location__search label {
  font-size: 0.9rem;
  font-weight: 700;
}

.give-location__search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.give-location__search-row input {
  flex: 1 1 12rem;
  min-width: 0;
}

.give-privacy {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  padding: 1.2rem 1.4rem;
  border-radius: 2rem;
  background: var(--color-surface-container);
}

.give-privacy__icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 2.9rem;
  height: 2.9rem;
  border-radius: 999px;
  background: var(--color-surface-container-lowest);
  color: var(--color-primary);
}

.give-privacy__title {
  margin: 0 0 0.2rem;
  font-weight: 700;
  font-size: 0.95rem;
}

.give-privacy__body {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.give-expiry {
  margin: 0;
  padding: 0.9rem 1.4rem;
  border-radius: 1rem;
  background: color-mix(in srgb, var(--color-tertiary-container) 26%, var(--color-background));
  color: var(--color-on-surface);
  font-size: 0.92rem;
}

/*
 * The rules confirmation reuses the shared .field-checkbox pattern (see
 * /register): it overrides the global input sizing (min-height 3rem, width
 * 100%) that would otherwise misalign the checkbox. The tonal card keeps it
 * visually grouped with the privacy and expiry notes above.
 */
.give-rules .field-checkbox {
  padding: 1.2rem 1.4rem;
  border-radius: 1rem;
  background: var(--color-surface-container-low);
  align-items: center;
}

.give-rules .field-checkbox input {
  margin-top: 0;
}

.give-rules .field-checkbox label {
  color: var(--color-on-surface);
}

.give-rules .field-checkbox a {
  color: var(--color-primary-dim);
  font-weight: 700;
}

/* ---------- actions ---------- */

.give-actions {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2.4rem;
}

.give-actions__forward {
  margin-left: auto;
}

.give-actions__cancel {
  margin-right: auto;
}

.give-actions .button[aria-busy="true"] {
  opacity: 0.7;
}

/* ---------- success ---------- */

.give-success {
  display: grid;
  gap: 1.2rem;
  justify-items: center;
  padding: 2.4rem 1.7rem;
  border-radius: 2rem;
  background: var(--color-surface-container-low);
  text-align: center;
}

.give-success__badge {
  display: grid;
  place-items: center;
  width: 4.6rem;
  height: 4.6rem;
  border-radius: 999px;
  background: var(--color-primary-container);
  color: var(--color-on-primary-container);
}

.give-success__badge svg {
  width: 2.2rem;
  height: 2.2rem;
}

.give-success h2 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.1rem);
}

.give-success > p {
  margin: 0;
  color: var(--color-muted);
}

.give-success__card {
  width: min(100%, 26rem);
  text-align: left;
}

.give-success__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  justify-content: center;
}

/* ---------- field error states (not color-only: icon prefix) ---------- */

.give-page .field-error:not([hidden])::before {
  content: "⚠ ";
}

.give-page [aria-invalid="true"] {
  outline: 2px solid var(--color-error);
  outline-offset: 1px;
}

@media (prefers-reduced-motion: reduce) {
  .give-stepper__step,
  .give-chip span {
    transition: none;
  }
}
