/* ============================================================================
   DREAMDRAGON - FORM COMPONENTS
   ============================================================================ */

/* === FORM CONTAINER === */
.form {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  width: 100%;
}

.form-row {
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
}

.form-row.vertical {
  flex-direction: column;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  flex: 1;
}

/* === FORM LABELS === */
.form-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-main);
  margin-bottom: var(--space-xs);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.form-label.required::after {
  content: '*';
  color: var(--accent-red);
}

.form-label-description {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  font-weight: var(--font-weight-regular);
  margin-top: var(--space-xs);
}

/* === BASE INPUT STYLES === */
.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: var(--space-md) var(--space-lg);
  font-family: var(--font-family-primary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-regular);
  line-height: var(--line-height-normal);
  color: var(--text-main);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  transition: all var(--transition-fast);
  outline: none;
  min-height: 48px;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

/* === FOCUS STATES === */
.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px var(--accent-purple-soft);
  background: var(--bg-alt);
}

/* === INPUT VARIANTS === */
.form-input.error,
.form-textarea.error,
.form-select.error {
  border-color: var(--accent-red);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-input.success,
.form-textarea.success,
.form-select.success {
  border-color: var(--accent-neon);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}

.form-input:disabled,
.form-textarea:disabled,
.form-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--bg-alt);
}

/* === TEXTAREA === */
.form-textarea {
  min-height: 120px;
  max-height: 300px;
  resize: vertical;
  padding-top: var(--space-md);
  line-height: var(--line-height-relaxed);
}

/* === SELECT === */
.form-select {
  cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%23374151' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-position: right var(--space-md) center;
  background-repeat: no-repeat;
  background-size: 16px;
  padding-right: var(--space-3xl);
  appearance: none;
}

.form-select:focus {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%237c3aed' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
}

/* === INPUT GROUPS === */
.input-group {
  display: flex;
  align-items: stretch;
  position: relative;
}

.input-group .form-input {
  border-radius: 0;
  border-right: none;
}

.input-group .form-input:first-child {
  border-top-left-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius-lg);
}

.input-group .form-input:last-child {
  border-top-right-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
  border-right: 1px solid var(--border-subtle);
}

.input-group-prepend,
.input-group-append {
  display: flex;
  align-items: center;
  padding: 0 var(--space-lg);
  background: var(--bg-alt);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  white-space: nowrap;
}

.input-group-prepend {
  border-right: none;
  border-top-left-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius-lg);
}

.input-group-append {
  border-left: none;
  border-top-right-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

/* === CHECKBOX & RADIO === */
.form-checkbox,
.form-radio {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  cursor: pointer;
  user-select: none;
}

.form-checkbox input,
.form-radio input {
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
  position: relative;
  appearance: none;
  background: var(--bg-card);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.form-radio input {
  border-radius: var(--radius-pill);
}

.form-checkbox input:checked,
.form-radio input:checked {
  background: var(--accent-purple);
  border-color: var(--accent-purple);
}

.form-checkbox input:checked::before {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-main);
  font-size: 12px;
  font-weight: var(--font-weight-bold);
}

.form-radio input:checked::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--text-main);
}

.form-checkbox input:focus,
.form-radio input:focus {
  outline: 2px solid var(--accent-purple-soft);
  outline-offset: 2px;
}

/* === SWITCH === */
.form-switch {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  cursor: pointer;
  user-select: none;
}

.form-switch input {
  width: 44px;
  height: 24px;
  margin: 0;
  cursor: pointer;
  position: relative;
  appearance: none;
  background: var(--border-subtle);
  border-radius: var(--radius-pill);
  transition: all var(--transition-fast);
  outline: none;
}

.form-switch input::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-pill);
  background: var(--text-main);
  transition: all var(--transition-fast);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.form-switch input:checked {
  background: var(--accent-purple);
}

.form-switch input:checked::before {
  transform: translateX(20px);
}

.form-switch input:focus {
  box-shadow: 0 0 0 3px var(--accent-purple-soft);
}

/* === FILE INPUT === */
.form-file {
  position: relative;
  display: inline-block;
  cursor: pointer;
}

.form-file input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.form-file-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-xl);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  color: var(--text-main);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.form-file-label:hover {
  background: var(--bg-alt);
  border-color: var(--accent-purple);
}

.form-file-label:focus-within {
  box-shadow: 0 0 0 3px var(--accent-purple-soft);
}

/* === VALIDATION MESSAGES === */
.form-error,
.form-success,
.form-warning {
  font-size: var(--font-size-xs);
  margin-top: var(--space-xs);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.form-error {
  color: var(--accent-red);
}

.form-success {
  color: var(--accent-neon);
}

.form-warning {
  color: var(--accent-orange);
}

.form-error-icon,
.form-success-icon,
.form-warning-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* === LOADING STATE === */
.form-input.loading,
.form-textarea.loading {
  position: relative;
  color: transparent;
}

.form-input.loading::after,
.form-textarea.loading::after {
  content: '';
  position: absolute;
  right: var(--space-lg);
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-subtle);
  border-top: 2px solid var(--accent-purple);
  border-radius: var(--radius-pill);
  animation: spin 1s linear infinite;
}

/* === FORM SECTIONS === */
.form-section {
  padding: var(--space-xl);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-soft);
}

.form-section-header {
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border-subtle);
}

.form-section-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  color: var(--text-main);
  margin-bottom: var(--space-sm);
}

.form-section-description {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  line-height: var(--line-height-relaxed);
}

/* === RESPONSIVE === */
@media screen and (max-width: 768px) {
  .form-row {
    flex-direction: column;
  }

  .form-input,
  .form-textarea,
  .form-select {
    min-height: 52px; /* Larger touch targets on mobile */
  }

  .input-group {
    flex-direction: column;
  }

  .input-group .form-input {
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
  }

  .input-group-prepend,
  .input-group-append {
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    justify-content: center;
  }
}

@media screen and (max-width: 475px) {
  .form-section {
    padding: var(--space-lg);
  }

  .form-input,
  .form-textarea,
  .form-select {
    padding: var(--space-lg);
  }

  .form-switch input {
    width: 40px;
    height: 22px;
  }

  .form-switch input::before {
    width: 18px;
    height: 18px;
  }

  .form-switch input:checked::before {
    transform: translateX(18px);
  }
}

/* === DARK MODE ADJUSTMENTS === */
@media (prefers-color-scheme: dark) {
  .form-input,
  .form-textarea,
  .form-select {
    color-scheme: dark;
  }
}
