/* ============================================
   FORMS COMPONENT - CASCADE OF HOPE HMS
   ============================================ */

/* ============================================
   FORM CONTAINER
   ============================================ */

.form {
  width: 100%;
}

.form-section {
  margin-bottom: var(--space-8);
}

.form-section-title {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--border-light);
}

/* ============================================
   FORM GROUP (Label + Input + Error)
   ============================================ */

.form-group {
  margin-bottom: var(--space-5);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.form-inline {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* ============================================
   LABELS
   ============================================ */

.form-label {
  display: inline-block;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
}

.form-label.required::after {
  content: ' *';
  color: var(--danger);
}

/* ============================================
   INPUT FIELDS (Text, Email, Tel, Number, etc.)
   ============================================ */

.form-input,
.form-select,
.form-textarea {
  display: block;
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-primary);
  font-size: var(--text-base);
  font-weight: var(--font-normal);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
  background-color: var(--bg-secondary);
  color: var(--text-disabled);
  cursor: not-allowed;
  opacity: 0.6;
}

.form-input::placeholder {
  color: var(--text-tertiary);
}

/* ============================================
   INPUT SIZES
   ============================================ */

.form-input-sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  height: var(--input-height-sm);
}

.form-input-md {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  height: var(--input-height-base);
}

.form-input-lg {
  padding: var(--space-4) var(--space-5);
  font-size: var(--text-lg);
  height: var(--input-height-lg);
}

/* ============================================
   TEXTAREA
   ============================================ */

.form-textarea {
  min-height: 6rem;
  resize: vertical;
  line-height: var(--leading-relaxed);
}

.form-textarea-sm {
  min-height: 4rem;
}

.form-textarea-lg {
  min-height: 10rem;
}

/* ============================================
   SELECT DROPDOWN
   ============================================ */

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 12px;
  padding-right: var(--space-10);
}

.form-select::-ms-expand {
  display: none;
}

/* ============================================
   INPUT WITH ICON
   ============================================ */

.form-input-group {
  position: relative;
}

.form-input-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
  width: 1.25rem;
  height: 1.25rem;
}

.form-input-group .form-input {
  padding-left: var(--space-10);
}

.form-input-icon-right {
  left: auto;
  right: var(--space-3);
}

.form-input-group .form-input.has-icon-right {
  padding-right: var(--space-10);
  padding-left: var(--space-4);
}

/* ============================================
   INPUT ADDON (Prepend/Append)
   ============================================ */

.input-group {
  display: flex;
  width: 100%;
}

.input-group-prepend,
.input-group-append {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  white-space: nowrap;
}

.input-group-prepend {
  border-right: 0;
  border-top-left-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
}

.input-group-append {
  border-left: 0;
  border-top-right-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

.input-group .form-input {
  flex: 1;
  border-radius: 0;
}

.input-group .form-input:first-child {
  border-top-left-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
}

.input-group .form-input:last-child {
  border-top-right-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

/* ============================================
   CHECKBOX & RADIO
   ============================================ */

.form-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.form-check-input {
  width: 1.125rem;
  height: 1.125rem;
  margin: 0;
  cursor: pointer;
  border: 2px solid var(--border-medium);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  accent-color: var(--primary-500);
}

.form-check-input[type="checkbox"] {
  border-radius: var(--radius-sm);
}

.form-check-input[type="radio"] {
  border-radius: var(--radius-full);
}

.form-check-input:checked {
  background-color: var(--primary-500);
  border-color: var(--primary-500);
}

.form-check-input:focus {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

.form-check-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.form-check-label {
  font-size: var(--text-sm);
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}

.form-check-input:disabled + .form-check-label {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================
   SWITCH TOGGLE
   ============================================ */

.form-switch {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.form-switch-input {
  position: relative;
  appearance: none;
  width: 2.75rem;
  height: 1.5rem;
  background-color: var(--neutral-400);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.form-switch-input::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.25rem;
  height: 1.25rem;
  background-color: white;
  border-radius: var(--radius-full);
  transition: transform var(--transition-fast);
}

.form-switch-input:checked {
  background-color: var(--primary-500);
}

.form-switch-input:checked::before {
  transform: translateX(1.25rem);
}

.form-switch-input:focus {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

/* ============================================
   FILE UPLOAD
   ============================================ */

.form-file {
  position: relative;
}

.form-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.form-file-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 2px dashed var(--border-medium);
  border-radius: var(--radius-md);
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.form-file-label:hover {
  border-color: var(--primary-500);
  background-color: var(--primary-50);
  color: var(--primary-500);
}

.form-file-input:focus + .form-file-label {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

.form-file-preview {
  margin-top: var(--space-3);
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.form-file-preview-item {
  position: relative;
  width: 5rem;
  height: 5rem;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.form-file-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.form-file-preview-remove {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  width: 1.5rem;
  height: 1.5rem;
  background-color: var(--danger);
  color: white;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
}

/* ============================================
   VALIDATION STATES
   ============================================ */

.form-input.is-valid,
.form-select.is-valid,
.form-textarea.is-valid {
  border-color: var(--success);
}

.form-input.is-valid:focus,
.form-select.is-valid:focus,
.form-textarea.is-valid:focus {
  box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.1);
}

.form-input.is-invalid,
.form-select.is-invalid,
.form-textarea.is-invalid {
  border-color: var(--danger);
}

.form-input.is-invalid:focus,
.form-select.is-invalid:focus,
.form-textarea.is-invalid:focus {
  box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

/* ============================================
   HELPER TEXT & ERROR MESSAGES
   ============================================ */

.form-help {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

.form-error {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--danger);
  font-weight: var(--font-medium);
}

.form-success {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--success);
  font-weight: var(--font-medium);
}

/* ============================================
   DATE & TIME INPUTS
   ============================================ */

.form-input[type="date"],
.form-input[type="time"],
.form-input[type="datetime-local"] {
  cursor: pointer;
}

/* ============================================
   NUMBER INPUT WITH SPINNERS
   ============================================ */

.form-input[type="number"]::-webkit-inner-spin-button,
.form-input[type="number"]::-webkit-outer-spin-button {
  height: auto;
}

/* ============================================
   SEARCH INPUT
   ============================================ */

.form-search {
  position: relative;
}

.form-search-input {
  padding-left: var(--space-10);
  padding-right: var(--space-10);
}

.form-search-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  width: 1.25rem;
  height: 1.25rem;
  pointer-events: none;
}

.form-search-clear {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: var(--space-1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.form-search-clear:hover {
  color: var(--text-primary);
}

/* ============================================
   RANGE SLIDER
   ============================================ */

.form-range {
  width: 100%;
  height: 0.5rem;
  background-color: var(--neutral-300);
  border-radius: var(--radius-full);
  outline: none;
  appearance: none;
}

.form-range::-webkit-slider-thumb {
  appearance: none;
  width: 1.25rem;
  height: 1.25rem;
  background-color: var(--primary-500);
  border-radius: var(--radius-full);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: var(--shadow-sm);
}

.form-range::-moz-range-thumb {
  width: 1.25rem;
  height: 1.25rem;
  background-color: var(--primary-500);
  border-radius: var(--radius-full);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: var(--shadow-sm);
}

/* ============================================
   FORM ACTIONS (Buttons Container)
   ============================================ */

.form-actions {
  display: flex;
  gap: var(--space-3);
  padding-top: var(--space-6);
  margin-top: var(--space-6);
  border-top: 1px solid var(--border-light);
}

.form-actions.centered {
  justify-content: center;
}

.form-actions.right {
  justify-content: flex-end;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 640px) {
  .form-row {
    grid-template-columns: 1fr;
  }
  
  .form-inline {
    flex-direction: column;
    align-items: stretch;
  }
  
  .form-actions {
    flex-direction: column;
  }
  
  .form-actions .btn {
    width: 100%;
  }
  
  .input-group {
    flex-wrap: wrap;
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  .form-input,
  .form-select,
  .form-textarea {
    border: 1px solid var(--border-dark);
    background-color: transparent;
  }
  
  .form-actions {
    display: none;
  }
  
  .form-file-label {
    display: none;
  }
}