/**
 * Form Components
 * Modern form styling with :has() selector for conditional styling
 */

/* ============================================
   FORM GROUP
   ============================================ */

.form-group {
  margin-bottom: var(--space-5);
}

/* Form group with error gets error styling */
.form-group:has(.error) .form-label,
.form-group:has(.invalid) .form-label,
.form-group:has([aria-invalid="true"]) .form-label {
  color: var(--color-error);
}

.form-group:has(.error) .form-input,
.form-group:has(.error) .form-textarea,
.form-group:has(.error) .form-select,
.form-group:has(.invalid) .form-input,
.form-group:has(.invalid) .form-textarea,
.form-group:has(.invalid) .form-select,
.form-group:has([aria-invalid="true"]) .form-input,
.form-group:has([aria-invalid="true"]) .form-textarea,
.form-group:has([aria-invalid="true"]) .form-select {
  border-color: var(--color-error);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* Form group with success state */
.form-group:has(.success) .form-label {
  color: var(--color-success);
}

.form-group:has(.success) .form-input,
.form-group:has(.success) .form-textarea,
.form-group:has(.success) .form-select {
  border-color: var(--color-success);
}

/* ============================================
   FORM LABEL
   ============================================ */

.form-label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-primary);
}

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

/* ============================================
   FORM INPUTS
   ============================================ */

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: var(--text-body);
  font-family: inherit;
  color: var(--color-text-primary);
  background-color: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  /* Neumorphic inset - carved into surface */
  box-shadow:
    inset 1px 1px 2px rgba(0, 0, 0, 0.04),
    inset -0.5px -0.5px 1px rgba(255, 255, 255, 0.4);
  transition: all var(--transition-fast);
}

.form-input.gradient-border,
.form-textarea.gradient-border,
.form-select.gradient-border {
  border: none;
}

.form-input:hover,
.form-textarea:hover,
.form-select:hover {
  border-color: var(--color-border-dark);
  box-shadow:
    inset 1px 1px 2px rgba(0, 0, 0, 0.06),
    inset -0.5px -0.5px 1px rgba(255, 255, 255, 0.3);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--color-primary);
  /* Neumorphic focus with casting light glow */
  box-shadow:
    inset 1.5px 1.5px 3px rgba(0, 0, 0, 0.06),
    inset -0.5px -0.5px 1px rgba(255, 255, 255, 0.25),
    0 0 0 3px color-mix(in srgb, var(--color-primary) 12%, transparent),
    0 0 15px 0 color-mix(in srgb, var(--color-primary) 8%, transparent);
}

/* Dark mode adjustments */
[data-theme="dark"] .form-input,
[data-theme="dark"] .form-textarea,
[data-theme="dark"] .form-select {
  box-shadow:
    inset 1.5px 1.5px 3px rgba(0, 0, 0, 0.25),
    inset -0.5px -0.5px 1px rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .form-input:focus,
[data-theme="dark"] .form-textarea:focus,
[data-theme="dark"] .form-select:focus {
  box-shadow:
    inset 2px 2px 4px rgba(0, 0, 0, 0.3),
    inset -0.5px -0.5px 1px rgba(255, 255, 255, 0.02),
    0 0 0 3px color-mix(in srgb, var(--color-primary) 18%, transparent),
    0 0 20px 0 color-mix(in srgb, var(--color-primary) 12%, transparent);
}

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

.form-input::placeholder,
.form-textarea::placeholder,
.form-select::placeholder {
  color: var(--color-text-tertiary);
}

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

/* ============================================
   FORM HELP TEXT & ERRORS
   ============================================ */

.form-help {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

.form-error {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-error);
  font-weight: var(--weight-medium);
}

.form-success {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-success);
}

/* ============================================
   CHECKBOXES & RADIOS
   ============================================ */

.form-checkbox,
.form-radio {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.form-checkbox input[type="checkbox"],
.form-checkbox input[type="radio"],
.form-radio input[type="checkbox"],
.form-radio input[type="radio"] {
  margin-top: 0.25rem;
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  cursor: pointer;
}

.form-checkbox label,
.form-radio label {
  cursor: pointer;
  user-select: none;
}

/* ============================================
   FORM ACTIONS
   ============================================ */

.form-actions {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-6);
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .form-actions {
    flex-direction: column;
  }

  .form-actions .button {
    width: 100%;
  }
}

/* ============================================
   FORM WITH ICONS
   ============================================ */

/* Form group with icon */
.form-group:has(.form-icon) {
  position: relative;
}

.form-group:has(.form-icon) .form-icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  color: var(--color-text-tertiary);
  pointer-events: none;
}

.form-group:has(.form-icon) .form-input {
  padding-left: 2.75rem;
}

/* ============================================
   VALIDATION STATES
   ============================================ */

/* Input with error icon */
.form-group:has(.error-icon) {
  position: relative;
}

.form-group:has(.error-icon) .error-icon {
  position: absolute;
  right: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  color: var(--color-error);
}

.form-group:has(.error-icon) .form-input {
  padding-right: 2.75rem;
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

.form-group:has([aria-describedby]) .form-input:focus {
  /* Enhanced focus for inputs with descriptions */
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.15);
}
