/**
 * Pilbe — Agency Contact Modal
 *
 * In-page "Contact Agent" dialog that replaces the mailto: on the agency
 * profile's "Send Message" button + "Contact <agency>" card. Built in vanilla
 * JS (pilbe-agency-contact.js); this sheet styles the modal it injects.
 *
 * Token-only (depends on pilbe-tokens.css). No new hex literals.
 *
 * @package Pilbe
 * @since   2.2.0
 */

/* ──────────────────────────────────────────────────────────────────
   Overlay + dialog shell
   ────────────────────────────────────────────────────────────────── */

.pilbe-cm {
  position: fixed;
  inset: 0;
  z-index: var(--pilbe-z-modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--pilbe-space-4);
  background: var(--pilbe-overlay);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--pilbe-duration-base) var(--pilbe-ease-standard),
              visibility var(--pilbe-duration-base) var(--pilbe-ease-standard);
  -webkit-tap-highlight-color: transparent;
}

.pilbe-cm.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.pilbe-cm__dialog {
  position: relative;
  z-index: var(--pilbe-z-modal);
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - var(--pilbe-space-8));
  display: flex;
  flex-direction: column;
  background: var(--pilbe-bg-surface);
  border: 1px solid var(--pilbe-border-default);
  border-radius: var(--pilbe-radius-lg);
  box-shadow: var(--pilbe-shadow-xl);
  overflow: hidden;
  transform: translateY(12px) scale(0.98);
  transition: transform var(--pilbe-duration-base) var(--pilbe-ease-entrance);
}

.pilbe-cm.is-open .pilbe-cm__dialog {
  transform: translateY(0) scale(1);
}

/* ──────────────────────────────────────────────────────────────────
   Header
   ────────────────────────────────────────────────────────────────── */

.pilbe-cm__header {
  display: flex;
  align-items: center;
  gap: var(--pilbe-space-3);
  padding: var(--pilbe-space-5) var(--pilbe-space-6);
  border-bottom: 1px solid var(--pilbe-border-default);
}

.pilbe-cm__icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: var(--pilbe-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--pilbe-neutral-900);
  color: var(--pilbe-text-inverse);
}

.pilbe-cm__icon svg {
  width: 20px;
  height: 20px;
}

.pilbe-cm__heading {
  flex: 1 1 auto;
  min-width: 0;
}

.pilbe-cm__title {
  margin: 0;
  font-family: var(--pilbe-font);
  font-size: var(--pilbe-text-h4);
  line-height: var(--pilbe-lh-h4);
  font-weight: 700;
  color: var(--pilbe-text-primary);
}

.pilbe-cm__subtitle {
  margin: 2px 0 0;
  font-family: var(--pilbe-font);
  font-size: var(--pilbe-text-sm);
  line-height: var(--pilbe-lh-sm);
  color: var(--pilbe-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pilbe-cm__close {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--pilbe-radius-md);
  background: transparent;
  color: var(--pilbe-text-secondary);
  cursor: pointer;
  transition: background var(--pilbe-duration-fast) var(--pilbe-ease-standard),
              color var(--pilbe-duration-fast) var(--pilbe-ease-standard);
}

.pilbe-cm__close:hover {
  background: var(--pilbe-bg-subtle);
  color: var(--pilbe-text-primary);
}

.pilbe-cm__close:focus-visible {
  outline: none;
  box-shadow: var(--pilbe-shadow-focus);
}

.pilbe-cm__close svg {
  width: 18px;
  height: 18px;
}

/* ──────────────────────────────────────────────────────────────────
   Body (scrolls if taller than the dialog)
   ────────────────────────────────────────────────────────────────── */

.pilbe-cm__body {
  padding: var(--pilbe-space-6);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.pilbe-cm__form {
  display: flex;
  flex-direction: column;
  gap: var(--pilbe-space-5);
}

.pilbe-cm__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--pilbe-space-4);
}

@media (max-width: 479px) {
  .pilbe-cm__row {
    grid-template-columns: 1fr;
  }
}

.pilbe-cm__field {
  display: flex;
  flex-direction: column;
  gap: var(--pilbe-space-2);
  min-width: 0;
}

.pilbe-cm__label {
  font-family: var(--pilbe-font);
  font-size: var(--pilbe-text-sm);
  line-height: var(--pilbe-lh-sm);
  font-weight: 700;
  color: var(--pilbe-text-primary);
}

.pilbe-cm__req {
  color: var(--pilbe-danger-500);
  margin-left: 2px;
}

.pilbe-cm__optional {
  font-weight: 400;
  color: var(--pilbe-text-secondary);
  margin-left: var(--pilbe-space-1);
}

/* ── Inputs / select / textarea ─────────────────────────────────── */

.pilbe-cm__input,
.pilbe-cm__select,
.pilbe-cm__textarea {
  width: 100%;
  font-family: var(--pilbe-font);
  font-size: var(--pilbe-text-base);
  line-height: var(--pilbe-lh-base);
  color: var(--pilbe-text-primary);
  background: var(--pilbe-bg-surface);
  border: 1px solid var(--pilbe-border-default);
  border-radius: var(--pilbe-radius-lg);
  transition: border-color var(--pilbe-duration-fast) var(--pilbe-ease-standard),
              box-shadow var(--pilbe-duration-fast) var(--pilbe-ease-standard);
  -webkit-appearance: none;
  appearance: none;
}

.pilbe-cm__input,
.pilbe-cm__select {
  height: 48px;
  padding: 0 var(--pilbe-space-4);
}

.pilbe-cm__textarea {
  min-height: 120px;
  padding: var(--pilbe-space-3) var(--pilbe-space-4);
  resize: vertical;
}

.pilbe-cm__input::placeholder,
.pilbe-cm__textarea::placeholder {
  color: var(--pilbe-text-secondary);
  opacity: 1;
}

.pilbe-cm__input:focus,
.pilbe-cm__select:focus,
.pilbe-cm__textarea:focus {
  outline: none;
  border-color: var(--pilbe-border-focus);
  box-shadow: var(--pilbe-shadow-focus);
}

/* Custom chevron for the native select (appearance reset above). */
.pilbe-cm__select {
  padding-right: var(--pilbe-space-10);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--pilbe-space-4) center;
  background-size: 18px 18px;
  cursor: pointer;
}

/* Unselected placeholder option reads as muted-but-legible. */
.pilbe-cm__select:invalid,
.pilbe-cm__select.is-placeholder {
  color: var(--pilbe-text-secondary);
}

/* ── Error state ────────────────────────────────────────────────── */

.pilbe-cm__input[aria-invalid="true"],
.pilbe-cm__select[aria-invalid="true"],
.pilbe-cm__textarea[aria-invalid="true"] {
  border-color: var(--pilbe-danger-500);
}

.pilbe-cm__input[aria-invalid="true"]:focus,
.pilbe-cm__select[aria-invalid="true"]:focus,
.pilbe-cm__textarea[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px var(--pilbe-danger-50);
}

.pilbe-cm__error {
  font-family: var(--pilbe-font);
  font-size: var(--pilbe-text-sm);
  line-height: var(--pilbe-lh-sm);
  color: var(--pilbe-danger-700);
}

.pilbe-cm__error:empty {
  display: none;
}

/* ── Consent row ────────────────────────────────────────────────── */

.pilbe-cm__consent {
  display: flex;
  align-items: flex-start;
  gap: var(--pilbe-space-3);
}

.pilbe-cm__checkbox {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--pilbe-brand-500);
  cursor: pointer;
}

.pilbe-cm__checkbox:focus-visible {
  outline: none;
  box-shadow: var(--pilbe-shadow-focus);
  border-radius: var(--pilbe-radius-xs);
}

.pilbe-cm__consent-label {
  font-family: var(--pilbe-font);
  font-size: var(--pilbe-text-sm);
  line-height: var(--pilbe-lh-sm);
  color: var(--pilbe-text-primary);
  cursor: pointer;
}

/* ── Honeypot — present in the DOM, invisible to real users ─────── */

.pilbe-cm__hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

/* ──────────────────────────────────────────────────────────────────
   Footer + submit (the modal's single primary CTA → brand gradient)
   ────────────────────────────────────────────────────────────────── */

.pilbe-cm__footer {
  padding: var(--pilbe-space-5) var(--pilbe-space-6);
  border-top: 1px solid var(--pilbe-border-default);
}

.pilbe-cm__submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--pilbe-space-2);
  width: 100%;
  min-height: 48px;
  padding: 12px 20px;
  font-family: var(--pilbe-font);
  font-size: var(--pilbe-text-base);
  line-height: 1;
  font-weight: 700;
  color: var(--pilbe-text-inverse);
  background: var(--pilbe-gradient);
  border: 1px solid transparent;
  border-radius: var(--pilbe-radius-md);
  cursor: pointer;
  transition: transform var(--pilbe-duration-base) var(--pilbe-ease-standard),
              box-shadow var(--pilbe-duration-base) var(--pilbe-ease-standard),
              background var(--pilbe-duration-base) var(--pilbe-ease-standard);
}

.pilbe-cm__submit:hover:not(:disabled) {
  background: var(--pilbe-gradient-hover);
  transform: translateY(-1px);
  box-shadow: var(--pilbe-shadow-md);
}

.pilbe-cm__submit:focus-visible {
  outline: none;
  box-shadow: var(--pilbe-shadow-focus);
}

.pilbe-cm__submit:disabled {
  opacity: 0.65;
  cursor: progress;
}

/* Spinner shown while submitting. */
.pilbe-cm__spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: var(--pilbe-text-inverse);
  border-radius: var(--pilbe-radius-circle);
  animation: pilbe-cm-spin 0.6s linear infinite;
}

@keyframes pilbe-cm-spin {
  to { transform: rotate(360deg); }
}

/* Form-level error banner (server/network failures). */
.pilbe-cm__form-error {
  margin-bottom: var(--pilbe-space-4);
  padding: var(--pilbe-space-3) var(--pilbe-space-4);
  font-family: var(--pilbe-font);
  font-size: var(--pilbe-text-sm);
  line-height: var(--pilbe-lh-sm);
  color: var(--pilbe-danger-700);
  background: var(--pilbe-danger-50);
  border: 1px solid var(--pilbe-danger-500);
  border-radius: var(--pilbe-radius-md);
}

/* ──────────────────────────────────────────────────────────────────
   Success state (replaces the form once the message is sent)
   ────────────────────────────────────────────────────────────────── */

.pilbe-cm__success {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--pilbe-space-3);
  padding: var(--pilbe-space-8) var(--pilbe-space-6);
}

.pilbe-cm__success-icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--pilbe-radius-circle);
  background: var(--pilbe-success-50);
  color: var(--pilbe-success-700);
}

.pilbe-cm__success-icon svg {
  width: 28px;
  height: 28px;
}

.pilbe-cm__success-title {
  margin: 0;
  font-family: var(--pilbe-font);
  font-size: var(--pilbe-text-h4);
  line-height: var(--pilbe-lh-h4);
  font-weight: 700;
  color: var(--pilbe-text-primary);
}

.pilbe-cm__success-body {
  margin: 0;
  max-width: 38ch;
  font-family: var(--pilbe-font);
  font-size: var(--pilbe-text-base);
  line-height: var(--pilbe-lh-base);
  color: var(--pilbe-text-secondary);
}

.pilbe-cm__success-btn {
  margin-top: var(--pilbe-space-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 24px;
  font-family: var(--pilbe-font);
  font-size: var(--pilbe-text-base);
  line-height: 1;
  font-weight: 700;
  color: var(--pilbe-text-primary);
  background: transparent;
  border: 1px solid var(--pilbe-border-strong);
  border-radius: var(--pilbe-radius-md);
  cursor: pointer;
  transition: background var(--pilbe-duration-fast) var(--pilbe-ease-standard),
              border-color var(--pilbe-duration-fast) var(--pilbe-ease-standard);
}

.pilbe-cm__success-btn:hover {
  background: var(--pilbe-bg-subtle);
  border-color: var(--pilbe-text-secondary);
}

.pilbe-cm__success-btn:focus-visible {
  outline: none;
  box-shadow: var(--pilbe-shadow-focus);
}

/* ──────────────────────────────────────────────────────────────────
   Mobile — full-height sheet anchored to the bottom of the viewport
   ────────────────────────────────────────────────────────────────── */

@media (max-width: 599px) {
  .pilbe-cm {
    padding: 0;
    align-items: stretch;
  }

  .pilbe-cm__dialog {
    max-width: none;
    max-height: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    transform: translateY(100%);
  }

  .pilbe-cm.is-open .pilbe-cm__dialog {
    transform: translateY(0);
  }

  .pilbe-cm__body {
    flex: 1 1 auto;
  }
}

/* ──────────────────────────────────────────────────────────────────
   Reduced motion — no slide/scale, no spin
   ────────────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .pilbe-cm,
  .pilbe-cm__dialog,
  .pilbe-cm__submit {
    transition: none;
  }

  .pilbe-cm__dialog,
  .pilbe-cm.is-open .pilbe-cm__dialog {
    transform: none;
  }

  .pilbe-cm__spinner {
    animation-duration: 1.6s;
  }
}
