/**
 * Form Components CSS
 * Comprehensive form styling for both light and dark themes
 * Includes inputs, selects, textareas, and form validation
 */

/* ===== Base Form Styles ===== */
.form-group {
  margin-bottom: 1.5rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--theme-text-secondary);
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

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

/* ===== Input Elements ===== */
.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--theme-text-primary);
  background-color: var(--theme-input-bg);
  border: 1px solid var(--theme-input-border);
  border-radius: 8px;
  transition: all var(--theme-transition-normal);
  font-family: inherit;
  box-sizing: border-box;
}

/* Input Focus States */
.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--theme-input-focus-border);
  box-shadow: 0 0 0 3px var(--theme-focus-ring);
  background-color: var(--theme-input-bg);
}

/* Placeholder Styling */
.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--theme-input-placeholder);
  opacity: 1;
}

/* Disabled State */
.form-input:disabled,
.form-textarea:disabled,
.form-select:disabled {
  background-color: var(--theme-bg-tertiary);
  border-color: var(--theme-border-muted);
  color: var(--theme-text-muted);
  cursor: not-allowed;
  opacity: 0.6;
}

/* ===== Specific Input Types ===== */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"] {
  @extend .form-input;
}

/* Number Input Styling */
input[type="number"] {
  text-align: center;
}

/* Remove number input spinners in webkit browsers */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Remove number input spinners in Firefox */
input[type="number"] {
  -moz-appearance: textfield;
}

/* ===== Textarea Styling ===== */
.form-textarea {
  resize: vertical;
  min-height: 100px;
  font-family: inherit;
}

/* ===== Select Styling ===== */
.form-select {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.75rem center;
  background-repeat: no-repeat;
  background-size: 1.25rem;
  padding-right: 2.5rem;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  cursor: pointer;
}

/* Dark theme select arrow */
[data-theme="dark"] .form-select {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%94a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
}

/* ===== Checkbox and Radio Styling ===== */
.form-checkbox,
.form-radio {
  width: 1.125rem;
  height: 1.125rem;
  color: var(--theme-brand-primary);
  background-color: var(--theme-input-bg);
  border: 1px solid var(--theme-input-border);
  border-radius: 0.25rem;
  transition: all var(--theme-transition-normal);
  cursor: pointer;
}

.form-radio {
  border-radius: 50%;
}

.form-checkbox:checked,
.form-radio:checked {
  background-color: var(--theme-brand-primary);
  border-color: var(--theme-brand-primary);
}

.form-checkbox:focus,
.form-radio:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--theme-focus-ring);
}

/* ===== Form Validation States ===== */
.form-input.is-valid,
.form-textarea.is-valid,
.form-select.is-valid {
  border-color: var(--theme-brand-success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.form-input.is-invalid,
.form-textarea.is-invalid,
.form-select.is-invalid {
  border-color: var(--theme-brand-error);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
  animation: shake 0.3s ease-in-out;
}

/* Validation Messages */
.form-feedback {
  font-size: 0.875rem;
  margin-top: 0.25rem;
  line-height: 1.4;
}

.form-feedback.valid {
  color: var(--theme-brand-success);
}

.form-feedback.invalid {
  color: var(--theme-brand-error);
}

/* ===== Form Groups and Layouts ===== */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.form-row > .form-group {
  flex: 1;
  margin-bottom: 0;
  min-width: 200px;
}

.form-grid {
  display: grid;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.form-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.form-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.form-grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

/* ===== Input Groups ===== */
.input-group {
  display: flex;
  align-items: stretch;
  width: 100%;
}

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

.input-group .form-input:first-child {
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
}

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

.input-group-text {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--theme-text-secondary);
  text-align: center;
  white-space: nowrap;
  background-color: var(--theme-bg-secondary);
  border: 1px solid var(--theme-input-border);
  border-radius: 8px;
}

.input-group .input-group-text:first-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}

.input-group .input-group-text:last-child {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left: none;
}

/* ===== File Upload Styling ===== */
.file-upload {
  position: relative;
  display: inline-block;
  cursor: pointer;
  width: 100%;
}

.file-upload input[type="file"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.file-upload-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border: 2px dashed var(--theme-input-border);
  border-radius: 8px;
  background-color: var(--theme-input-bg);
  color: var(--theme-text-secondary);
  transition: all var(--theme-transition-normal);
  cursor: pointer;
  min-height: 100px;
  text-align: center;
}

.file-upload:hover .file-upload-label,
.file-upload.dragover .file-upload-label {
  border-color: var(--theme-brand-primary);
  background-color: var(--theme-hover-bg);
  color: var(--theme-brand-primary);
}

.file-upload.has-file .file-upload-label {
  border-color: var(--theme-brand-success);
  background-color: rgba(16, 185, 129, 0.05);
  color: var(--theme-brand-success);
}

/* ===== Search Input Styling ===== */
.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input {
  padding-left: 2.5rem;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  width: 1rem;
  height: 1rem;
  color: var(--theme-text-muted);
  pointer-events: none;
  z-index: 1;
}

/* ===== Form Buttons ===== */
.form-actions {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--theme-border-primary);
}

.form-actions.centered {
  justify-content: center;
}

.form-actions.start {
  justify-content: flex-start;
}

/* ===== Animations ===== */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.form-loading {
  position: relative;
  pointer-events: none;
}

.form-loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--theme-overlay-bg);
  border-radius: 8px;
  animation: pulse 1.5s ease-in-out infinite;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  
  .form-row > .form-group {
    margin-bottom: 1.5rem;
    min-width: auto;
  }
  
  .form-grid-2,
  .form-grid-3,
  .form-grid-4 {
    grid-template-columns: 1fr;
  }
  
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }
  
  .input-group {
    flex-direction: column;
  }
  
  .input-group .form-input,
  .input-group .input-group-text {
    border-radius: 8px;
    border: 1px solid var(--theme-input-border);
  }
  
  .input-group .form-input:not(:last-child),
  .input-group .input-group-text:not(:last-child) {
    margin-bottom: 0.5rem;
  }
}

/* ===== Accessibility Enhancements ===== */
.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  /* Enhanced focus for better accessibility */
  box-shadow: 0 0 0 3px var(--theme-focus-ring);
}

/* Screen reader only text */
.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;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .form-input,
  .form-textarea,
  .form-select {
    border-width: 2px;
  }
  
  .form-input:focus,
  .form-textarea:focus,
  .form-select:focus {
    border-width: 3px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .form-input,
  .form-textarea,
  .form-select,
  .form-checkbox,
  .form-radio,
  .file-upload-label {
    transition: none;
  }
  
  .form-input.is-invalid,
  .form-textarea.is-invalid,
  .form-select.is-invalid {
    animation: none;
  }
}