/* ============================================================
   SPANINSIGHT FORM RENDERER — Premium Design System
   ============================================================ */

/* ── CSS Variables (Light Mode) ───────────────────────────── */
:root {
  --primary: #6C63FF;
  --primary-dark: #5A52D5;
  --primary-light: #8B83FF;
  --accent: #00D9FF;
  --success: #00E676;
  --warning: #FFB74D;
  --error: #FF5252;

  --bg: #F5F6FA;
  --bg-alt: #ECEDF5;
  --surface: #FFFFFF;
  --surface-alt: #F0F1F8;
  --border: #E0E1EC;
  --border-focus: #6C63FF;
  --text: #1A1B2E;
  --text-secondary: #6B6D82;
  --text-muted: #9EA0B4;
  --input-bg: #F8F9FD;

  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.3);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.1);
  --shadow-glow: 0 0 24px rgba(108, 99, 255, 0.15);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 100px;

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

/* ── Dark Mode ────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg: #0A0B14;
  --bg-alt: #0D0F1A;
  --surface: #141627;
  --surface-alt: #1C1E33;
  --border: #2A2D4A;
  --border-focus: #8B83FF;
  --text: #EEEEF5;
  --text-secondary: #8E90A6;
  --text-muted: #5A5C72;
  --input-bg: #1A1C30;

  --glass-bg: rgba(20, 22, 39, 0.8);
  --glass-border: rgba(42, 45, 74, 0.5);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 32px rgba(108, 99, 255, 0.2);
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

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;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Theme Toggle FAB ─────────────────────────────────────── */
.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: all var(--transition);
  box-shadow: var(--shadow-sm);
}

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

.fixed-icon {
  height: 28px;
  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: 44px;
  height: 44px;
  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: all var(--transition);
  box-shadow: var(--shadow-sm);
}

.theme-fab:hover {
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: var(--shadow-glow);
}

.theme-fab .icon-sun,
.theme-fab .icon-moon {
  width: 20px;
  height: 20px;
  position: absolute;
  transition: all 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: 560px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

/* ── States (Loading, Error, Form, Success) ───────────────── */
.state {
  animation: fadeIn 0.4s ease-out;
}

.hidden {
  display: none !important;
}

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

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

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

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

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

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

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

/* ── 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: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255, 82, 82, 0.1);
  color: var(--error);
  font-size: 28px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

#error h2 {
  font-size: 22px;
  font-weight: 700;
}

#error p {
  color: var(--text-secondary);
  font-size: 14px;
  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: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(0, 230, 118, 0.1);
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

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

#success h2 {
  font-size: 24px;
  font-weight: 700;
}

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

/* ── Form Header ──────────────────────────────────────────── */
.form-header {
  text-align: center;
  margin-bottom: 32px;
  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: 20px;
}

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

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

#form-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.3;
}

#form-desc {
  color: var(--text-secondary);
  font-size: 14px;
  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: border-color var(--transition), box-shadow var(--transition);
}

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

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

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

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

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

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

.field-input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.1);
}

.field-input.error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(255, 82, 82, 0.1);
}

textarea.field-input {
  min-height: 100px;
  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='%236B6D82' 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: 12px;
  padding: 12px 16px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 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: rgba(108, 99, 255, 0.06);
}

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

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

.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: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
}

.option-item input[type="checkbox"]:checked::after {
  width: 5px;
  height: 10px;
  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: 14px;
  color: var(--text);
  font-weight: 500;
}

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

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

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

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

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

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

/* ── Submit Button ────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #FFFFFF;
  box-shadow: 0 4px 16px rgba(108, 99, 255, 0.3);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  box-shadow: 0 6px 24px rgba(108, 99, 255, 0.4);
  transform: translateY(-1px);
}

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

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

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

/* ── Footer ───────────────────────────────────────────────── */
.form-footer {
  text-align: center;
  padding: 24px 16px 8px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  transition: color var(--transition);
}

.footer-brand:hover {
  color: var(--primary-light);
}

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

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

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

.powered-by-logo {
  height: 40px;
  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: 16px;
  width: 100%;
  max-width: 480px;
  margin: 24px 0;
}

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

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

.advert-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

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

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

.btn-advert {
  padding: 8px 18px;
  font-size: 13px;
  border-radius: var(--radius-pill);
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  transition: all var(--transition);
}

.btn-advert:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(108, 99, 255, 0.3);
}

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

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

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

  #form-title {
    font-size: 20px;
  }

  .field-card {
    padding: 16px;
  }

  .rating-star {
    width: 38px;
    height: 38px;
    font-size: 24px;
  }

  .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;
  }
}
