/**
 * CR AI Form Builder - Frontend Base Styles
 * Common styles shared across all themes
 *
 * @package CR_AI_Form_Builder
 * @since 1.0.0
 */

/* Form Container */
.crf-form-container {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  max-width: 100%;
  margin: 0 auto;
  padding: 24px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Form Title and Description */
.crf-form-title {
  margin: 0 0 8px 0;
  font-size: 24px;
  font-weight: 600;
  color: #1f2937;
}

.crf-form-description {
  margin: 0 0 24px 0;
  font-size: 15px;
  color: #6b7280;
  line-height: 1.5;
}

/* Form Wrapper - Common to all themes */
.crf-form-wrapper {
  position: relative;
  width: 100%;
}

.crf-form {
  width: 100%;
}

/* Field Groups */
.crf-field-group {
  margin-bottom: 20px;
}

.crf-field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

/* Input Fields */
.crf-input,
.crf-textarea,
.crf-select {
  width: 100%;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.5;
  color: #1f2937;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.crf-input:hover,
.crf-textarea:hover,
.crf-select:hover {
  border-color: #9ca3af;
}

.crf-input:focus,
.crf-textarea:focus,
.crf-select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  outline: none;
}

.crf-textarea {
  min-height: 120px;
  resize: vertical;
}

/* Placeholder */
.crf-input::placeholder,
.crf-textarea::placeholder {
  color: #9ca3af;
}

/* Form Fields Grid Layout */
.crf-form,
.crf-traditional-form {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

/* Field Width Classes */
.crf-field-group,
.crf-field {
  box-sizing: border-box;
}

.crf-field-width-full {
  width: 100%;
  flex: 0 0 100%;
}

.crf-field-width-half {
  width: calc(50% - 8px);
  flex: 0 0 calc(50% - 8px);
}

.crf-field-width-third {
  width: calc(33.333% - 11px);
  flex: 0 0 calc(33.333% - 11px);
}

.crf-field-width-quarter {
  width: calc(25% - 12px);
  flex: 0 0 calc(25% - 12px);
}

/* Full width elements that should break the flex row */
.crf-form-title,
.crf-form-description,
.crf-submit-wrapper,
.crf-success-message,
.crf-error-message {
  width: 100%;
  flex: 0 0 100%;
}

/* Hidden inputs should not affect layout */
.crf-form input[type="hidden"] {
  display: none;
}

/* Responsive: Stack fields on mobile */
@media (max-width: 600px) {
  .crf-field-width-half,
  .crf-field-width-third,
  .crf-field-width-quarter {
    width: 100%;
    flex: 0 0 100%;
  }
}

/* Help Text */
.crf-help-text {
  margin-top: 4px;
  font-size: 13px;
  color: #6b7280;
}

/* Required Indicator */
.crf-required {
  color: #dc3545;
  margin-left: 2px;
}

/* Hidden Fields */
.crf-honeypot,
input[name="_honeypot"] {
  position: absolute !important;
  left: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Loading State */
.crf-form.loading {
  opacity: 0.6;
  pointer-events: none;
}

.crf-form.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #3498db;
  border-radius: 50%;
  animation: crf-spin 1s linear infinite;
}

@keyframes crf-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Message Containers */
.crf-success-message,
.crf-error-message {
  padding: 16px 20px;
  margin-bottom: 20px;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.5;
  animation: crf-slide-in 0.3s ease-out;
}

@keyframes crf-slide-in {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.crf-message-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.crf-success-icon,
.crf-error-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-weight: bold;
  flex-shrink: 0;
}

.crf-success-message {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.crf-success-icon {
  background: #155724;
  color: white;
}

.crf-error-message {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.crf-error-icon {
  background: #721c24;
  color: white;
}

/* Submit Button States */
.crf-submit-wrapper {
  margin-top: 24px;
}

.crf-submit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 32px;
  font-size: 16px;
  font-weight: 500;
  color: white;
  background: #2563eb;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 140px;
}

.crf-submit-btn:hover:not(:disabled) {
  background: #1d4ed8;
}

.crf-submit-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.crf-submit-btn.crf-loading {
  background: #64748b;
}

.crf-btn-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.crf-spinner {
  animation: crf-spin 1s linear infinite;
}

/* Field Validation States */
.crf-field {
  position: relative;
  margin-bottom: 20px;
}

.crf-field.has-error .crf-input,
.crf-field.has-error .crf-textarea,
.crf-field.has-error .crf-select {
  border-color: #dc3545;
}

.crf-field-error {
  display: block;
  color: #dc3545;
  font-size: 13px;
  margin-top: 5px;
}

/* File Upload Preview */
.crf-file-preview {
  margin-top: 10px;
  padding: 10px;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 4px;
}

.crf-file-preview-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px;
}

.crf-file-preview-name {
  flex: 1;
  font-size: 14px;
}

.crf-file-remove {
  color: #dc3545;
  cursor: pointer;
  font-size: 12px;
}

/* Signature Pad */
.crf-signature-wrapper {
  position: relative;
}

.crf-signature-canvas {
  display: block;
  touch-action: none;
}

/* Multi-Step Forms */
.crf-form-steps {
  display: flex;
  justify-content: space-between;
  margin-bottom: 30px;
  padding: 0;
  list-style: none;
}

.crf-form-step {
  flex: 1;
  text-align: center;
  padding: 10px;
  position: relative;
}

.crf-form-step::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: #dee2e6;
  z-index: -1;
}

.crf-form-step.active {
  font-weight: 600;
}

.crf-form-step.completed {
  color: #28a745;
}

/* Conditional Fields */
.crf-field[data-conditional="true"] {
  display: none;
}

.crf-field[data-conditional="true"].show {
  display: block;
}

/* CAPTCHA Container */
.crf-captcha-container {
  margin: 20px 0;
}

/* Address Autocomplete */
.crf-address-autocomplete {
  position: relative;
}

.crf-address-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ced4da;
  border-top: none;
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.crf-address-suggestion {
  padding: 10px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
}

.crf-address-suggestion:hover {
  background: #f8f9fa;
}

/* Date Range Picker */
.crf-date-range {
  display: flex;
  gap: 10px;
  align-items: center;
}

.crf-date-range input {
  flex: 1;
}

.crf-date-separator {
  color: #6c757d;
  font-weight: 600;
}

/* Star Rating */
.crf-star-rating {
  display: flex;
  gap: 5px;
  font-size: 0;
}

.crf-star {
  display: inline-block;
  font-size: 24px;
  cursor: pointer;
  transition: color 0.2s ease, transform 0.2s ease;
}

/* Slider/Range */
.crf-slider-wrapper {
  padding: 10px 0;
}

.crf-slider {
  width: 100%;
}

.crf-slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #6c757d;
  margin-top: 5px;
}

/* Checkbox/Radio Groups */
.crf-checkbox-group,
.crf-radio-group,
.crf-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.crf-checkbox-option,
.crf-radio-option,
.crf-choice-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.crf-checkbox-option label,
.crf-radio-option label {
  margin: 0;
  cursor: pointer;
}

/* Choice Layout Options */
.crf-choices.crf-layout-vertical {
  flex-direction: column;
  gap: 10px;
}

.crf-choices.crf-layout-horizontal {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 16px 24px;
}

.crf-choices.crf-layout-columns-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 20px;
}

.crf-choices.crf-layout-columns-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 20px;
}

/* Responsive: Stack columns on mobile */
@media (max-width: 600px) {
  .crf-choices.crf-layout-horizontal {
    flex-direction: column;
    gap: 10px;
  }

  .crf-choices.crf-layout-columns-2,
  .crf-choices.crf-layout-columns-3 {
    grid-template-columns: 1fr;
  }
}

/* Choice Input Styling */
.crf-choice-input {
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
  accent-color: #3b82f6;
}

/* Grid Layout Support */
.crf-field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin-bottom: 20px;
}

/* Note: Width classes defined above in "Field Width Classes" section */

/* Responsive */
@media (max-width: 768px) {

  .crf-date-range {
    flex-direction: column;
  }

  .crf-date-separator {
    display: none;
  }
}

/* Accessibility */
.crf-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus Styles for Accessibility */
.crf-input:focus,
.crf-textarea:focus,
.crf-select:focus,
.crf-checkbox:focus,
.crf-radio:focus {
  outline: 2px solid #4d90fe;
  outline-offset: 2px;
}

/* Auto-save Indicator */
.crf-autosave-indicator {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 8px 16px;
  background: #10b981;
  color: white;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 9999;
  pointer-events: none;
}

/* Resume Notification */
.crf-resume-notification {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #eff6ff;
  border: 1px solid #3b82f6;
  border-radius: 8px;
  margin-bottom: 16px;
  color: #1e40af;
  font-size: 14px;
  line-height: 1.5;
}

.crf-resume-notification svg {
  flex-shrink: 0;
  color: #3b82f6;
}

.crf-resume-notification span {
  flex: 1;
}

.crf-resume-dismiss {
  background: none;
  border: none;
  color: #1e40af;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s ease;
}

.crf-resume-dismiss:hover {
  background: rgba(59, 130, 246, 0.1);
}

.crf-resume-dismiss:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Print Styles */
@media print {
  .crf-submit-wrapper,
  .crf-captcha-container,
  .crf-autosave-indicator,
  .crf-resume-notification {
    display: none;
  }

  .crf-form {
    border: 1px solid #000;
    padding: 20px;
  }
}

/* ============================================
   Display Modes & Mode Switching
   ============================================ */

/* Hybrid Mode Toggle */
.crf-hybrid-toggle {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  background: #f9fafb;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  justify-content: center;
}

.crf-toggle-btn {
  flex: 1;
  max-width: 200px;
  padding: 0.75rem 1.5rem;
  border: 2px solid #e5e7eb;
  background: white;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.9375rem;
}

.crf-toggle-btn:hover {
  border-color: #6366f1;
  background: #f5f3ff;
}

.crf-toggle-btn.active {
  border-color: #6366f1;
  background: #6366f1;
  color: white;
}

/* User Select Mode */
.crf-mode-selection-screen {
  text-align: center;
  padding: 2rem;
}

.crf-mode-select-heading {
  font-size: 1.75rem;
  margin-bottom: 2rem;
  color: #1f2937;
  font-weight: 600;
}

.crf-mode-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  max-width: 800px;
  margin: 0 auto;
}

.crf-mode-option {
  padding: 2rem;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  background: white;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: left;
}

.crf-mode-option:hover {
  border-color: #6366f1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.crf-mode-option-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.crf-mode-option-label {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  color: #1f2937;
  font-weight: 600;
}

.crf-mode-option-description {
  color: #6b7280;
  margin-bottom: 1rem;
  line-height: 1.5;
  font-size: 0.9375rem;
}

.crf-mode-option-features {
  list-style: none;
  padding: 0;
  margin: 0;
}

.crf-mode-option-features li {
  padding: 0.25rem 0;
  color: #6b7280;
  font-size: 0.875rem;
}

/* Mode Switcher (in hybrid/traditional/conversational modes) */
.crf-mode-switcher {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1rem;
}

.crf-switch-to-conversational,
.crf-switch-to-traditional {
  padding: 0.5rem 1rem;
  border: 1px solid #e5e7eb;
  background: white;
  border-radius: 6px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.crf-switch-to-conversational:hover,
.crf-switch-to-traditional:hover {
  border-color: #6366f1;
  background: #f5f3ff;
}

/* View containers */
.crf-traditional-view,
.crf-conversational-view {
  transition: opacity 0.3s ease;
}

.crf-traditional-view.hidden,
.crf-conversational-view.hidden {
  display: none;
  opacity: 0;
}

.crf-traditional-view.active,
.crf-conversational-view.active {
  display: block;
  opacity: 1;
}

/* Loading states */
.crf-loading {
  text-align: center;
  padding: 3rem 2rem;
}

.crf-spinner {
  border: 3px solid #f3f4f6;
  border-top: 3px solid #6366f1;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: crf-spin 1s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes crf-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 640px) {
  .crf-mode-options {
    grid-template-columns: 1fr;
  }

  .crf-hybrid-toggle {
    flex-direction: column;
  }

  .crf-toggle-btn {
    max-width: 100%;
  }

  .crf-mode-select-heading {
    font-size: 1.5rem;
  }

  .crf-mode-option {
    padding: 1.5rem;
  }
}
