/**
 * BAJ Design System - Form Components
 * Standardized form validation patterns with accessibility
 * 
 * @package baj-theme
 * @version 2.0.0
 */

/* =============================================================================
   BAJ Form System - Design System Standardization
   ========================================================================== */

/* Form Group - Container for label + input + message */
.baj-form-group {
  margin-bottom: 24px; /* Brand: 24px spacing */
  position: relative;
  width: 100%;
}

/* Form Labels - Brand Typography */
.baj-form-label {
  display: block;
  font-family: 'Poppins', sans-serif;
  font-weight: 500; /* Brand: Medium weight */
  font-size: 16px;
  color: #2E2E2E; /* Brand: Text color */
  margin-bottom: 8px; /* Brand: 8px spacing */
  line-height: 1.4;
  
  /* Required Field Indicator */
  &[data-required="true"]::after,
  &.baj-form-label--required::after {
    content: ' *';
    color: #E07A5F; /* Brand: Coral for required */
    font-weight: 600;
  }
  
  /* Optional Field Indicator */
  &[data-optional="true"]::after,
  &.baj-form-label--optional::after {
    content: ' (optional)';
    color: #A3BFA8; /* Brand: Secondary sage */
    font-weight: 400;
    font-size: 14px;
  }
}

/* Form Inputs - Base Styling */
.baj-form-input,
.baj-form-textarea,
.baj-form-select {
  /* Layout */
  width: 100%;
  min-height: 48px; /* Accessibility: minimum touch target */
  padding: 12px 16px; /* Brand: 12px and 16px spacing */
  
  /* Typography */
  font-family: 'Poppins', sans-serif;
  font-size: 16px;
  font-weight: 400; /* Brand: Regular for inputs */
  line-height: 1.5;
  color: #2E2E2E; /* Brand: Text color */
  
  /* Appearance */
  background-color: #FFFFFF;
  border: 2px solid #e0ddd7; /* Brand: Border color */
  border-radius: 6px;
  box-shadow: none;
  -webkit-appearance: none;
  
  /* Interaction */
  transition: all 0.2s ease-in-out;
  
  /* Placeholder */
  &::placeholder {
    color: #888888;
    opacity: 1;
    font-weight: 400;
  }
  
  /* Focus State - WCAG Compliant */
  &:focus,
  &:focus-visible {
    outline: none;
    border-color: #3AA6A1; /* Brand: Primary teal */
    box-shadow: 0 0 0 3px rgba(58, 166, 161, 0.2);
    background-color: #FFFFFF;
  }
  
  /* Hover State */
  &:hover:not(:disabled):not(:focus) {
    border-color: #2B7D79; /* Darker teal on hover */
  }
}

/* Textarea Specific */
.baj-form-textarea {
  min-height: 120px; /* Minimum 3 lines */
  resize: vertical;
  line-height: 1.6;
  padding-top: 14px;
  padding-bottom: 14px;
}

/* Select Specific */
.baj-form-select {
  background-image: url("data:image/svg+xml;charset=UTF-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232E2E2E'><path d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px;
  padding-right: 48px;
  cursor: pointer;
  
  &:focus {
    background-image: url("data:image/svg+xml;charset=UTF-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%233AA6A1'><path d='M7 10l5 5 5-5z'/></svg>");
  }
}

/* Form Validation States */

/* Error State */
.baj-form-input--error,
.baj-form-textarea--error,
.baj-form-select--error {
  border-color: #E07A5F; /* Brand: Coral for errors */
  background-color: rgba(224, 122, 95, 0.05);
  
  &:focus,
  &:focus-visible {
    border-color: #C5654A; /* Darker coral on focus */
    box-shadow: 0 0 0 3px rgba(224, 122, 95, 0.2);
  }
}

/* Success State */
.baj-form-input--success,
.baj-form-textarea--success,
.baj-form-select--success {
  border-color: #A3BFA8; /* Brand: Secondary sage */
  background-color: rgba(163, 191, 168, 0.05);
  
  &:focus,
  &:focus-visible {
    border-color: #8DA894;
    box-shadow: 0 0 0 3px rgba(163, 191, 168, 0.2);
  }
}

/* Warning State */
.baj-form-input--warning,
.baj-form-textarea--warning,
.baj-form-select--warning {
  border-color: #F59E0B; /* Warn amber */
  background-color: rgba(245, 158, 11, 0.05);
  
  &:focus,
  &:focus-visible {
    border-color: #D97706;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
  }
}

/* Disabled State */
.baj-form-input:disabled,
.baj-form-textarea:disabled,
.baj-form-select:disabled,
.baj-form-input--disabled,
.baj-form-textarea--disabled,
.baj-form-select--disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: #f5f5f5;
  border-color: #d1d5db;
  color: #6b7280;
}

/* Form Messages - Validation Feedback */
.baj-form-message {
  display: flex;
  align-items: flex-start;
  gap: 6px; /* Brand: Close to 8px spacing */
  margin-top: 8px; /* Brand: 8px spacing */
  font-size: 14px;
  line-height: 1.4;
  font-family: 'Poppins', sans-serif;
  
  /* Icon placeholder */
  &::before {
    content: '';
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    margin-top: 1px;
    background-size: contain;
    background-repeat: no-repeat;
  }
}

/* Error Messages */
.baj-form-message--error {
  color: #C5654A; /* Darker coral for readability */
  
  &::before {
    background-image: url("data:image/svg+xml;charset=UTF-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23E07A5F'><circle cx='10' cy='10' r='10'/><path d='M13 7L7 13M7 7l6 6' stroke='white' stroke-width='2' stroke-linecap='round'/></svg>");
  }
}

/* Success Messages */
.baj-form-message--success {
  color: #7A9B7E; /* Darker sage for readability */
  
  &::before {
    background-image: url("data:image/svg+xml;charset=UTF-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23A3BFA8'><circle cx='10' cy='10' r='10'/><path d='M6 10l2 2 6-6' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  }
}

/* Info Messages */
.baj-form-message--info {
  color: #2B7D79; /* Darker teal for readability */
  
  &::before {
    background-image: url("data:image/svg+xml;charset=UTF-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%233AA6A1'><circle cx='10' cy='10' r='10'/><path d='M10 6v4M10 14h.01' stroke='white' stroke-width='2' stroke-linecap='round'/></svg>");
  }
}

/* Warning Messages */
.baj-form-message--warning {
  color: #D97706; /* Darker amber for readability */
  
  &::before {
    background-image: url("data:image/svg+xml;charset=UTF-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23F59E0B'><circle cx='10' cy='10' r='10'/><path d='M10 6v4M10 14h.01' stroke='white' stroke-width='2' stroke-linecap='round'/></svg>");
  }
}

/* Checkbox & Radio Base */
.baj-form-checkbox,
.baj-form-radio {
  display: flex;
  align-items: flex-start;
  gap: 12px; /* Brand: 12px spacing */
  margin-bottom: 16px; /* Brand: 16px spacing */
  cursor: pointer;
  
  input[type="checkbox"],
  input[type="radio"] {
    width: 20px;
    height: 20px;
    margin: 0;
    flex-shrink: 0;
    cursor: pointer;
    
    /* Custom styling */
    -webkit-appearance: none;
    appearance: none;
    background-color: #FFFFFF;
    border: 2px solid #e0ddd7; /* Brand: Border color */
    border-radius: 3px; /* For checkbox */
    
    &:focus {
      outline: 2px solid #3AA6A1; /* Brand: Primary */
      outline-offset: 2px;
      box-shadow: 0 0 0 3px rgba(58, 166, 161, 0.2);
    }
    
    &:checked {
      background-color: #3AA6A1; /* Brand: Primary */
      border-color: #3AA6A1;
      background-image: url("data:image/svg+xml;charset=UTF-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='white'><path d='M13 4L6 11 3 8l1-1 2 2 6-6z'/></svg>");
      background-repeat: no-repeat;
      background-position: center;
      background-size: 12px;
    }
  }
  
  /* Radio specific */
  input[type="radio"] {
    border-radius: 50%;
    
    &:checked {
      background-image: url("data:image/svg+xml;charset=UTF-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='white'><circle cx='8' cy='8' r='3'/></svg>");
      background-size: 8px;
    }
  }
  
  .baj-form-checkbox__label,
  .baj-form-radio__label {
    font-family: 'Poppins', sans-serif;
    font-size: 16px;
    color: #2E2E2E; /* Brand: Text color */
    line-height: 1.4;
    cursor: pointer;
    margin-top: -1px; /* Align with checkbox/radio */
  }
}

/* Form Fieldset & Legend */
.baj-form-fieldset {
  border: 1px solid #e0ddd7; /* Brand: Border color */
  border-radius: 6px;
  padding: 24px; /* Brand: 24px spacing */
  margin-bottom: 24px; /* Brand: 24px spacing */
  
  .baj-form-legend {
    font-family: 'Poppins', sans-serif;
    font-weight: 600; /* SemiBold for legends */
    font-size: 18px;
    color: #2E2E2E; /* Brand: Text color */
    padding: 0 12px; /* Brand: 12px spacing */
    margin-bottom: 16px; /* Brand: 16px spacing */
  }
}

/* Form Grid - For multi-column layouts */
.baj-form-grid {
  display: grid;
  gap: 24px; /* Brand: 24px spacing */
  
  &.baj-form-grid--2col {
    grid-template-columns: repeat(2, 1fr);
  }
  
  &.baj-form-grid--3col {
    grid-template-columns: repeat(3, 1fr);
  }
  
  &.baj-form-grid--auto {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }
}

/* Responsive Form Layout */
@media (max-width: 768px) {
  .baj-form-input,
  .baj-form-textarea,
  .baj-form-select {
    font-size: 16px; /* Prevent zoom on iOS */
    min-height: 44px;
  }
  
  .baj-form-grid {
    grid-template-columns: 1fr !important;
    gap: 16px; /* Brand: 16px on mobile */
  }
  
  .baj-form-group {
    margin-bottom: 20px;
  }
  
  .baj-form-fieldset {
    padding: 16px; /* Brand: 16px on mobile */
    margin-bottom: 20px;
  }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  .baj-form-input,
  .baj-form-textarea,
  .baj-form-select {
    border-width: 3px;
  }
  
  .baj-form-input:focus,
  .baj-form-textarea:focus,
  .baj-form-select:focus {
    outline-width: 3px;
  }
  
  .baj-form-checkbox input[type="checkbox"]:focus,
  .baj-form-radio input[type="radio"]:focus {
    outline-width: 3px;
  }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .baj-form-input,
  .baj-form-textarea,
  .baj-form-select,
  .baj-form-checkbox input,
  .baj-form-radio input {
    transition: none;
  }
}

/* Legacy Form Compatibility - Override existing inputs */
input[type="text"].baj-form-input,
input[type="email"].baj-form-input,
input[type="password"].baj-form-input,
input[type="tel"].baj-form-input,
input[type="url"].baj-form-input,
input[type="search"].baj-form-input,
input[type="number"].baj-form-input,
textarea.baj-form-textarea,
select.baj-form-select {
  /* Override existing form styles */
  border-radius: 6px !important;
  font-family: 'Poppins', sans-serif !important;
  min-height: 48px !important;
}