/* FB Instant Form — mobile-first (IG in-app) */

:root {
  --bg: #000000;
  --field: #2c2c2e;
  --field-focus: #3a3a3c;
  --text: #fff;
  --muted: rgba(255, 255, 255, 0.65);
  --dim: rgba(255, 255, 255, 0.45);
  --blue: #1877f2;
  --blue-press: #1464d0;
  --green: #31a24c;
  --red: #ff453a;
  --radius: 10px;
  --field-radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
  height: -webkit-fill-available;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: -webkit-fill-available;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

/* ── Page ── */
.instant-form-page {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  background: var(--bg);
  overflow-x: hidden;
}

.instant-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ── Header ── */
.instant-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(16px + var(--safe-top)) 16px 8px;
  flex-shrink: 0;
}

.instant-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.instant-info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--dim);
  font-size: 16px;
  cursor: pointer;
}

.instant-sub {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
}

.instant-close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  margin: -4px -4px 0 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

/* ── Form ── */
.instant-form {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.instant-fields {
  padding: 8px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.instant-field {
  position: relative;
  display: block;
  background: var(--field);
  border-radius: var(--field-radius);
  border: 1.5px solid transparent;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.instant-field:focus-within {
  background: var(--field-focus);
  border-color: rgba(24, 119, 242, 0.55);
}

.instant-field.is-valid {
  border-color: rgba(49, 162, 76, 0.45);
}

.instant-field.is-invalid {
  border-color: rgba(255, 69, 58, 0.55);
}

.instant-label {
  display: block;
  padding: 10px 14px 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  pointer-events: none;
}

.instant-input {
  display: block;
  width: 100%;
  padding: 2px 40px 12px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.35;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  scroll-margin-bottom: 120px;
}

body.keyboard-open .instant-submit-wrap {
  padding-bottom: 12px;
}

.instant-input:-webkit-autofill,
.instant-input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--field) inset;
  -webkit-text-fill-color: var(--text);
  caret-color: var(--text);
}

/* Checkmark */
.instant-check {
  position: absolute;
  right: 12px;
  top: 50%;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--green);
  opacity: 0;
  transform: translateY(-50%) scale(0.5);
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.instant-check::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 4px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.instant-field.is-valid .instant-check {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

/* ── Submit ── */
.instant-submit-wrap {
  padding: 16px 16px calc(16px + var(--safe-bottom));
  flex-shrink: 0;
  background: var(--bg);
}

.instant-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--blue);
  color: #fff;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.instant-submit:active:not(:disabled) {
  background: var(--blue-press);
  transform: scale(0.98);
}

.instant-submit:disabled {
  opacity: 0.65;
}

.instant-submit.is-loading .instant-submit-text { opacity: 0; }
.instant-submit.is-loading .instant-submit-spinner { opacity: 1; }

.instant-submit-spinner {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  opacity: 0;
  animation: spin 0.7s linear infinite;
}

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

/* ── Thank you / privacy ── */
.instant-shell--center {
  justify-content: center;
  align-items: center;
  padding: 24px;
}

.instant-thank { text-align: center; padding: 32px 20px; }

.instant-thank-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: var(--green);
  position: relative;
}

.instant-thank-icon::after {
  content: "";
  position: absolute;
  left: 22px;
  top: 16px;
  width: 12px;
  height: 24px;
  border: solid #fff;
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}

.instant-thank-title {
  margin: 0 0 10px;
  font-size: 24px;
  font-weight: 700;
}

.instant-thank-copy {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  color: var(--muted);
}

/* ── Inline success (post-submit) ── */
.instant-success {
  padding: 24px 16px calc(24px + var(--safe-bottom));
  text-align: center;
}

.instant-success-text {
  margin: 0;
  font-size: 17px;
  line-height: 1.5;
  font-weight: 600;
  color: var(--green);
}

.instant-back {
  display: inline-block;
  margin-bottom: 16px;
  font-size: 15px;
  color: var(--blue);
  text-decoration: none;
}

.instant-legal-title { margin: 0 0 16px; font-size: 22px; font-weight: 700; }
.instant-legal-body { font-size: 14px; line-height: 1.6; color: var(--muted); }
.instant-legal-body p { margin: 0 0 14px; }
.instant-shell--legal { padding: 20px 16px 32px; }

a { color: var(--blue); text-decoration: none; }

/* ── Desktop preview only ── */
@media (min-width: 520px) {
  .instant-form-page:not(.instant-thank-page):not(.instant-privacy-page) {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    padding: 24px;
  }

  .instant-shell {
    max-width: 430px;
    min-height: auto;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: none;
  }

  .instant-header {
    padding-top: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
