/* ============================================================
   SPANINSIGHT FORM RENDERER — Premium Minimalist Design System
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&display=swap');

/* ── CSS Variables ── */
:root {
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-light: #14b8a6;
  --primary-glow: rgba(13, 148, 136, 0.08);
  --accent: #f97316;
  --accent-glow: rgba(249, 115, 22, 0.08);
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;

  --bg: #fafafa;
  --bg-alt: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: rgba(15, 23, 42, 0.08);
  --border-focus: #0d9488;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --input-bg: #f8fafc;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05);

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  --font: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Dark Mode ── */
[data-theme="dark"] {
  --bg: #0b0f19;
  --bg-alt: #111827;
  --surface: #1f2937;
  --surface-alt: #111827;
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: #14b8a6;
  --text: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --input-bg: #111827;
}

/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}

/* ── Navigation Fixed Icon ── */
.fixed-icon-link {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.fixed-icon-link:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.fixed-icon {
  height: 24px;
  width: auto;
  opacity: 0.85;
  transition: opacity var(--transition);
}

.fixed-icon-link:hover .fixed-icon {
  opacity: 1;
}

.theme-fab {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.theme-fab:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

.theme-fab .icon-sun,
.theme-fab .icon-moon {
  width: 18px;
  height: 18px;
  position: absolute;
  transition: var(--transition);
}

[data-theme="light"] .theme-fab .icon-moon {
  opacity: 0;
  transform: scale(0.5) rotate(-90deg);
}

[data-theme="light"] .theme-fab .icon-sun {
  opacity: 1;
  transform: scale(1) rotate(0);
}

[data-theme="dark"] .theme-fab .icon-sun {
  opacity: 0;
  transform: scale(0.5) rotate(90deg);
}

[data-theme="dark"] .theme-fab .icon-moon {
  opacity: 1;
  transform: scale(1) rotate(0);
}

/* ── Main Container ── */
.form-container {
  flex: 1;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  padding: 80px 16px 40px;
}

/* ── States ── */
.state {
  animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Loading ── */
#loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 20px;
}

.loader {
  position: relative;
  width: 44px;
  height: 44px;
}

.loader-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}

.loader-ring-delay {
  border-top-color: var(--accent);
  animation-delay: 0.2s;
  inset: 6px;
}

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

.loader-text {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
}

/* ── Error State ── */
#error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  gap: 16px;
}

.error-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

#error h2 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

#error p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  max-width: 320px;
}

/* ── Success State ── */
#success {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  gap: 16px;
}

.success-check {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--primary-glow);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.success-check svg {
  width: 28px;
  height: 28px;
}

@keyframes popIn {
  from {
    transform: scale(0);
  }
  to {
    transform: scale(1);
  }
}

#success h2 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

#success p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* ── Form Header ── */
.form-header {
  text-align: center;
  margin-bottom: 24px;
  padding: 32px 24px;
  background: var(--surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.form-logo-link {
  display: inline-block;
  margin-bottom: 16px;
}

.form-logo {
  height: 28px;
  width: auto;
  opacity: 0.8;
  transition: opacity var(--transition);
}

.form-logo:hover {
  opacity: 1;
}

#form-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 8px;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

#form-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
}

/* ── Field Cards ── */
.field-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.field-card:focus-within {
  border-color: var(--border-focus);
}

.field-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.field-label .required {
  color: var(--error);
  margin-left: 2px;
}

.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ── Input Styles ── */
.field-input {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: var(--transition);
}

.field-input::placeholder {
  color: var(--text-muted);
}

.field-input:focus {
  border-color: var(--primary);
  background: var(--surface);
}

.field-input.error {
  border-color: var(--error);
}

textarea.field-input {
  min-height: 80px;
  resize: vertical;
}

select.field-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
  cursor: pointer;
}

/* ── Radio & Checkbox Groups ── */
.option-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}

.option-item:hover {
  border-color: var(--primary-light);
  background: var(--surface);
}

.option-item:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-glow);
}

.option-item input[type="radio"],
.option-item input[type="checkbox"] {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
  position: relative;
}

.option-item input[type="checkbox"] {
  border-radius: 5px;
}

.option-item input:checked {
  border-color: var(--primary);
  background: var(--primary);
}

.option-item input:checked::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 6px;
  height: 6px;
  background: white;
  border-radius: 50%;
}

.option-item input[type="checkbox"]:checked::after {
  width: 4px;
  height: 8px;
  background: transparent;
  border: 2px solid white;
  border-top: none;
  border-left: none;
  transform: translate(-50%, -60%) rotate(45deg);
  border-radius: 0;
}

.option-text {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
}

/* ── Rating ── */
.rating-group {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.rating-star {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  color: var(--border);
  font-size: 24px;
}

.rating-star:hover,
.rating-star.active {
  color: #ffb703;
  transform: scale(1.1);
}

/* ── Validation Error ── */
.field-error {
  font-size: 0.75rem;
  color: var(--error);
  margin-top: 6px;
  display: none;
}

.field-error.visible {
  display: block;
}

/* ── Turnstile ── */
.turnstile-wrapper {
  margin: 20px 0;
  display: flex;
  justify-content: center;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-submit {
  width: 100%;
  padding: 12px;
  font-size: 0.95rem;
  border-radius: var(--radius-lg);
}

.btn-loader svg {
  width: 18px;
  height: 18px;
  animation: spin 0.8s linear infinite;
}

/* ── Powered By ── */
.powered-by-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  transition: var(--transition);
}

.powered-by-link:hover {
  transform: translateY(-1px);
}

.powered-by-text {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.powered-by-logo {
  height: 32px;
  width: auto;
  opacity: 0.85;
  transition: opacity var(--transition);
}

.powered-by-link:hover .powered-by-logo {
  opacity: 1;
}

/* ── Success Adverts ── */
.success-adverts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 440px;
  margin: 20px 0;
}

.advert-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.advert-card:hover {
  border-color: var(--primary-light);
  transform: translateY(-2px);
}

.advert-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--primary-glow);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.advert-icon svg {
  width: 20px;
  height: 20px;
}

.advert-card h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.advert-card p {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.btn-advert {
  padding: 6px 14px;
  font-size: 11px;
  border-radius: 100px;
  background: var(--primary-glow);
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  transition: var(--transition);
}

.btn-advert:hover {
  background: var(--primary);
  color: #fff;
}

.success-subtitle {
  color: var(--text-secondary);
  font-size: 13px;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .form-container {
    padding: 70px 12px 24px;
  }

  .form-header {
    padding: 24px 16px;
  }

  #form-title {
    font-size: 1.3rem;
  }

  .field-card {
    padding: 16px;
  }

  .rating-star {
    width: 32px;
    height: 32px;
    font-size: 20px;
  }

  .success-adverts {
    grid-template-columns: 1fr;
  }
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
