/* ============================================================
   Cosmic Robotics — Native Forms
   RFQ modal + inline newsletter, matching site design
   ============================================================ */

/* ---------------- Modal overlay and container ---------------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.3s var(--ease);
}

.modal-overlay.is-open {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
}

.modal {
  position: relative;
  width: 90%;
  max-width: 640px;
  max-height: 85vh;
  background: #0a0a0a;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  padding: clamp(1.5rem, 4vw, 2.5rem);
  overflow-y: auto;
  transform: translateY(20px);
  transition: transform 0.3s var(--ease);
}

.modal-overlay.is-open .modal {
  transform: translateY(0);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}

.modal-close:hover {
  color: var(--white);
  background: rgba(255, 255, 255, 0.08);
}

.modal-close svg {
  width: 20px;
  height: 20px;
}

.modal-title {
  font-size: clamp(1.4rem, 3vw, 1.8rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0 0 0.5rem 0;
  color: var(--white);
}

.modal-subtitle {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 0 0 2rem 0;
  line-height: 1.4;
}

/* ---------------- Form elements ---------------- */
.form-group {
  margin-bottom: 1.5rem;
  scroll-margin-top: 5rem;
}

.form-group.form-group-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-field {
  /* Individual field wrapper within inline groups */
  position: relative;
  scroll-margin-top: 5rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--white);
  margin-bottom: 0.5rem;
}

.form-label-required::after {
  content: ' *';
  color: #ff6b6b;
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 0.75rem 1rem;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--white);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 2px;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--white);
  background: rgba(255, 255, 255, 0.06);
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23ffffff' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.5rem;
}

.form-radio-group {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.75rem;
}

.form-radio-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s var(--ease);
}

.form-radio-label:hover {
  color: var(--white);
}

.form-radio {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  cursor: pointer;
  transition: border-color 0.2s var(--ease);
  position: relative;
}

.form-radio:checked {
  border-color: var(--white);
}

.form-radio:checked::after {
  content: '';
  position: absolute;
  inset: 3px;
  background: var(--white);
  border-radius: 50%;
}

.form-conditional {
  display: none;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.form-conditional.is-visible {
  display: block;
}

.form-error {
  color: #ff6b6b;
  font-size: 0.8rem;
  margin-top: 0.4rem;
  display: none;
}

.form-group.has-error .form-error {
  display: block;
}

.form-group.has-error .form-input,
.form-group.has-error .form-textarea,
.form-group.has-error .form-select {
  border-color: #ff6b6b;
}

/* Error styles for paired fields (.form-field wrapper) */
.form-field.has-error .form-error {
  display: block;
}

.form-field.has-error .form-input,
.form-field.has-error .form-select,
.form-field.has-error .form-textarea {
  border-color: #ff6b6b !important;
  background: rgba(239, 68, 68, 0.04) !important;
}

/* Honeypot (hidden from humans, visible to bots) */
.form-hp {
  position: absolute;
  left: -9999px;
  opacity: 0;
  pointer-events: none;
}

/* ---------------- Form actions ---------------- */
.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 2rem;
  flex-wrap: wrap;
}

.form-submit {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 2rem;
  background: var(--white);
  color: var(--black);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  border: 1px solid var(--white);
  border-radius: 2px;
  cursor: pointer;
  transition: background-color 0.25s var(--ease), color 0.25s var(--ease), opacity 0.25s var(--ease);
}

.form-submit:hover:not(:disabled) {
  background: transparent;
  color: var(--white);
}

.form-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.form-submit-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.form-submit.is-loading .form-submit-spinner {
  display: block;
}

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

.form-status {
  font-size: 0.9rem;
  padding: 1rem;
  border-radius: 2px;
  margin-top: 0;
  margin-bottom: 1rem;
  display: none;
}

.form-status.is-visible {
  display: block;
  position: sticky;
  top: 0;
  z-index: 2;
}

.form-status.is-success {
  background: rgb(27, 50, 28);
  border: 1px solid rgba(76, 175, 80, 0.3);
  color: #a5d6a7;
}

.form-status.is-error {
  background: rgb(42, 20, 20);
  border: 1px solid rgba(244, 67, 54, 0.3);
  color: #ef9a9a;
}

/* ---------------- Newsletter inline form ---------------- */
.newsletter-form {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.newsletter-input-wrapper {
  position: relative;
  flex: 1 1 200px;
  min-width: 200px;
  max-width: 100%;
}

.newsletter-input {
  width: 100%;
  padding: 0.4rem 0.85rem;
  font-family: inherit;
  font-size: 0.72rem;
  color: var(--white);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--hairline);
  border-radius: 2px;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}

.newsletter-input:focus {
  outline: none;
  border-color: var(--white);
  background: rgba(255, 255, 255, 0.06);
}

.newsletter-input.has-error {
  border-color: #ff6b6b;
}

.newsletter-error {
  position: absolute;
  top: 100%;
  left: 0;
  color: #ff6b6b;
  font-size: 0.65rem;
  margin-top: 0.3rem;
  display: none;
}

.newsletter-input.has-error ~ .newsletter-error {
  display: block;
}

.newsletter-submit {
  flex-shrink: 0;
}

/* Mobile newsletter redesign (below and including 768px) */
@media (max-width: 768px) {
  .newsletter-form {
    width: 100%;
    max-width: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    padding: 0;
    margin-bottom: 0;
  }

  .newsletter-input-wrapper {
    position: relative;
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
  }

  .newsletter-input {
    width: 100%;
    height: 48px;
    padding: 0.75rem 1rem;
    font-size: 16px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 2px;
  }

  .newsletter-input:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.3);
  }

  .newsletter-input.has-error {
    border-color: #ff6b6b;
    background: rgba(239, 68, 68, 0.08);
  }

  .newsletter-error {
    position: static;
    color: #ff6b6b;
    font-size: 0.875rem;
    margin-top: 0.5rem;
    line-height: 1.4;
  }

  .newsletter-submit {
    width: 100%;
    min-height: 44px;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    margin-top: 0.75rem;
  }
}

/* ---------------- Turnstile widget ---------------- */
.cf-turnstile {
  margin: 1.5rem 0;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 600px) {
  .modal {
    width: 95%;
    max-height: 90vh;
    padding: 1.5rem;
  }

  .form-group.form-group-inline {
    grid-template-columns: 1fr;
  }

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .form-submit {
    justify-content: center;
  }

  .newsletter-form {
    flex-direction: column;
    align-items: stretch;
  }

  .newsletter-input-wrapper {
    min-width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal-overlay,
  .modal {
    transition: none;
  }
}
