/**
 * forms.css - Form Component Styles
 * Input fields, buttons, and form layouts
 */

/* ==========================================================================
   FORM CONTAINER
   ========================================================================== */

.form {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

.form-section {
  margin-bottom: var(--space-6);
}

.form-title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
  text-align: center;
}

.form-subtitle {
  font-size: var(--font-size-base);
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: var(--space-6);
}

/* ==========================================================================
   FORM GROUPS
   ========================================================================== */

.form-group {
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.form-label.required::after {
  content: ' *';
  color: var(--color-secondary);
}

.form-helper {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  margin-top: var(--space-1);
}

.form-error {
  font-size: var(--font-size-xs);
  color: var(--text-error);
  margin-top: var(--space-1);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.form-error-icon {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

/* ==========================================================================
   INPUT FIELDS
   ========================================================================== */

.form-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--font-size-base);
  transition: var(--transition-all);
}

.form-input:hover {
  border-color: var(--border-secondary);
}

.form-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.1);
  background: var(--bg-elevated);
}

.form-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-disabled);
}

.form-input.error {
  border-color: var(--border-error);
}

.form-input.error:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-input.success {
  border-color: var(--border-success);
}

.form-input.success:focus {
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

/* Input with Icon */
.input-group {
  position: relative;
}

.input-icon {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.input-group .form-input {
  padding-left: var(--space-11);
}

/* Password Input with Toggle */
.password-input-group {
  position: relative;
}

.password-toggle {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  transition: var(--transition-colors);
}

.password-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ==========================================================================
   TEXTAREA
   ========================================================================== */

.form-textarea {
  width: 100%;
  min-height: 100px;
  padding: var(--space-3) var(--space-4);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--font-size-base);
  font-family: inherit;
  resize: vertical;
  transition: var(--transition-all);
}

.form-textarea:hover {
  border-color: var(--border-secondary);
}

.form-textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.1);
  background: var(--bg-elevated);
}

/* ==========================================================================
   SELECT
   ========================================================================== */

.form-select {
  width: 100%;
  padding: var(--space-3) var(--space-10) var(--space-3) var(--space-4);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--font-size-base);
  cursor: pointer;
  transition: var(--transition-all);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%23737373' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-4) center;
}

.form-select:hover {
  border-color: var(--border-secondary);
}

.form-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.1);
  background-color: var(--bg-elevated);
}

/* ==========================================================================
   CHECKBOX & RADIO
   ========================================================================== */

.form-checkbox,
.form-radio {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  margin-bottom: var(--space-2);
}

.form-checkbox input[type='checkbox'],
.form-radio input[type='radio'] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin: 0;
  cursor: pointer;
  accent-color: var(--color-primary);
}

.form-checkbox label,
.form-radio label {
  font-size: var(--font-size-base);
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}

/* Custom Checkbox/Radio */
.custom-checkbox,
.custom-radio {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  margin-bottom: var(--space-2);
}

.custom-checkbox input,
.custom-radio input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.custom-checkbox-mark,
.custom-radio-mark {
  width: 20px;
  height: 20px;
  background: var(--input-bg);
  border: 2px solid var(--input-border);
  border-radius: var(--radius-sm);
  transition: var(--transition-all);
  position: relative;
  flex-shrink: 0;
}

.custom-radio-mark {
  border-radius: var(--radius-full);
}

.custom-checkbox input:checked ~ .custom-checkbox-mark,
.custom-radio input:checked ~ .custom-radio-mark {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.custom-checkbox-mark::after {
  content: '';
  position: absolute;
  display: none;
  left: 6px;
  top: 2px;
  width: 5px;
  height: 10px;
  border: solid var(--text-inverse);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.custom-radio-mark::after {
  content: '';
  position: absolute;
  display: none;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--text-inverse);
}

.custom-checkbox input:checked ~ .custom-checkbox-mark::after,
.custom-radio input:checked ~ .custom-radio-mark::after {
  display: block;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition-all);
  border: 1px solid transparent;
  white-space: nowrap;
  user-select: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Button Variants */
.btn-primary {
  background: var(--button-primary-bg);
  color: var(--text-inverse);
  border-color: transparent;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-primary);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-secondary);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--color-error);
  color: var(--text-inverse);
  border-color: transparent;
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-error-dark);
  box-shadow: var(--shadow-error);
}

/* Button Sizes */
.btn-sm {
  padding: var(--space-2) var(--space-4);
  font-size: var(--font-size-sm);
}

.btn-lg {
  padding: var(--space-4) var(--space-8);
  font-size: var(--font-size-lg);
}

.btn-block {
  width: 100%;
}

/* Button with Icon */
.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-full);
}

.btn-icon.btn-sm {
  width: 32px;
  height: 32px;
}

.btn-icon.btn-lg {
  width: 48px;
  height: 48px;
}

/* Loading Button */
.btn-loading {
  position: relative;
  color: transparent;
}

.btn-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid var(--text-inverse);
  border-top-color: transparent;
  border-radius: var(--radius-full);
  animation: var(--animation-spin);
}

/* ==========================================================================
   FILE UPLOAD
   ========================================================================== */

.file-upload {
  position: relative;
  display: inline-block;
  cursor: pointer;
  width: 100%;
}

.file-upload input[type='file'] {
  position: absolute;
  left: -9999px;
}

.file-upload-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-4);
  background: var(--bg-secondary);
  border: 2px dashed var(--border-secondary);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: var(--transition-all);
  text-align: center;
}

.file-upload-label:hover {
  background: var(--bg-hover);
  border-color: var(--color-primary);
}

.file-upload.dragover .file-upload-label {
  background: var(--bg-active);
  border-color: var(--color-primary);
  transform: scale(1.02);
}

.file-upload-icon {
  font-size: var(--font-size-4xl);
  color: var(--text-tertiary);
  margin-bottom: var(--space-3);
}

.file-upload-text {
 font-size: var(--font-size-base);
 color: var(--text-primary);
 margin-bottom: var(--space-1);
}

.file-upload-hint {
 font-size: var(--font-size-sm);
 color: var(--text-secondary);
}

/* ==========================================================================
  FORM ACTIONS
  ========================================================================== */

.form-actions {
 display: flex;
 gap: var(--space-3);
 margin-top: var(--space-6);
}

.form-actions.center {
 justify-content: center;
}

.form-actions.space-between {
 justify-content: space-between;
}

.form-actions.stack {
 flex-direction: column;
}

/* ==========================================================================
  FORM DIVIDER
  ========================================================================== */

.form-divider {
 position: relative;
 text-align: center;
 margin: var(--space-6) 0;
}

.form-divider::before {
 content: '';
 position: absolute;
 top: 50%;
 left: 0;
 right: 0;
 height: 1px;
 background: var(--border-primary);
}

.form-divider span {
 position: relative;
 padding: 0 var(--space-4);
 background: var(--bg-primary);
 color: var(--text-tertiary);
 font-size: var(--font-size-sm);
}

/* ==========================================================================
  TOGGLE SWITCH
  ========================================================================== */

.toggle-switch {
 position: relative;
 display: inline-flex;
 align-items: center;
 gap: var(--space-3);
 cursor: pointer;
}

.toggle-switch input {
 position: absolute;
 opacity: 0;
 cursor: pointer;
}

.toggle-slider {
 width: 48px;
 height: 24px;
 background: var(--bg-tertiary);
 border-radius: var(--radius-full);
 position: relative;
 transition: var(--transition-colors);
}

.toggle-slider::before {
 content: '';
 position: absolute;
 width: 18px;
 height: 18px;
 left: 3px;
 top: 3px;
 background: var(--text-inverse);
 border-radius: var(--radius-full);
 transition: var(--transition-transform);
}

.toggle-switch input:checked ~ .toggle-slider {
 background: var(--color-primary);
}

.toggle-switch input:checked ~ .toggle-slider::before {
 transform: translateX(24px);
}

.toggle-label {
 font-size: var(--font-size-base);
 color: var(--text-primary);
 user-select: none;
}

/* ==========================================================================
  RANGE SLIDER
  ========================================================================== */

.range-slider {
 width: 100%;
}

.range-slider-label {
 display: flex;
 justify-content: space-between;
 margin-bottom: var(--space-2);
}

.range-slider-value {
 font-weight: var(--font-weight-semibold);
 color: var(--color-primary);
}

.range-input {
 width: 100%;
 height: 6px;
 background: var(--bg-tertiary);
 border-radius: var(--radius-full);
 outline: none;
 -webkit-appearance: none;
 appearance: none;
}

.range-input::-webkit-slider-thumb {
 -webkit-appearance: none;
 width: 20px;
 height: 20px;
 background: var(--color-primary);
 border: 2px solid var(--bg-primary);
 border-radius: var(--radius-full);
 cursor: pointer;
 transition: var(--transition-transform);
}

.range-input::-webkit-slider-thumb:hover {
 transform: scale(1.2);
 box-shadow: var(--shadow-primary);
}

.range-input::-moz-range-thumb {
 width: 20px;
 height: 20px;
 background: var(--color-primary);
 border: 2px solid var(--bg-primary);
 border-radius: var(--radius-full);
 cursor: pointer;
 transition: var(--transition-transform);
}

.range-input::-moz-range-thumb:hover {
 transform: scale(1.2);
 box-shadow: var(--shadow-primary);
}

/* ==========================================================================
  SEARCH BOX
  ========================================================================== */

.search-box {
 position: relative;
 width: 100%;
 max-width: 400px;
}

.search-input {
 width: 100%;
 padding: var(--space-3) var(--space-12) var(--space-3) var(--space-11);
 background: var(--input-bg);
 border: 1px solid var(--input-border);
 border-radius: var(--radius-full);
 color: var(--text-primary);
 font-size: var(--font-size-base);
 transition: var(--transition-all);
}

.search-input:hover {
 border-color: var(--border-secondary);
}

.search-input:focus {
 outline: none;
 border-color: var(--border-focus);
 box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.1);
 background: var(--bg-elevated);
}

.search-icon {
 position: absolute;
 left: var(--space-4);
 top: 50%;
 transform: translateY(-50%);
 width: 20px;
 height: 20px;
 color: var(--text-tertiary);
 pointer-events: none;
}

.search-clear {
 position: absolute;
 right: var(--space-3);
 top: 50%;
 transform: translateY(-50%);
 width: 28px;
 height: 28px;
 background: transparent;
 border: none;
 color: var(--text-tertiary);
 cursor: pointer;
 display: flex;
 align-items: center;
 justify-content: center;
 border-radius: var(--radius-full);
 transition: var(--transition-colors);
 opacity: 0;
 pointer-events: none;
}

.search-input:not(:placeholder-shown) ~ .search-clear {
 opacity: 1;
 pointer-events: auto;
}

.search-clear:hover {
 background: var(--bg-hover);
 color: var(--text-primary);
}

/* ==========================================================================
  TAGS INPUT
  ========================================================================== */

.tags-input {
 display: flex;
 flex-wrap: wrap;
 gap: var(--space-2);
 padding: var(--space-2);
 background: var(--input-bg);
 border: 1px solid var(--input-border);
 border-radius: var(--radius-md);
 min-height: 48px;
 cursor: text;
 transition: var(--transition-all);
}

.tags-input:hover {
 border-color: var(--border-secondary);
}

.tags-input.focused {
 border-color: var(--border-focus);
 box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.1);
 background: var(--bg-elevated);
}

.tag {
 display: inline-flex;
 align-items: center;
 gap: var(--space-1);
 padding: var(--space-1) var(--space-2);
 background: var(--bg-tertiary);
 border-radius: var(--radius-full);
 font-size: var(--font-size-sm);
 color: var(--text-primary);
}

.tag-remove {
 width: 16px;
 height: 16px;
 background: transparent;
 border: none;
 color: var(--text-tertiary);
 cursor: pointer;
 display: flex;
 align-items: center;
 justify-content: center;
 border-radius: var(--radius-full);
 transition: var(--transition-colors);
}

.tag-remove:hover {
 background: var(--bg-hover);
 color: var(--color-secondary);
}

.tags-input-field {
 flex: 1;
 min-width: 100px;
 border: none;
 background: transparent;
 outline: none;
 color: var(--text-primary);
 font-size: var(--font-size-base);
}

/* ==========================================================================
  VALIDATION STATES
  ========================================================================== */

.field-success {
 position: relative;
}

.field-success .form-input,
.field-success .form-textarea,
.field-success .form-select {
 border-color: var(--border-success);
 padding-right: var(--space-11);
}

.field-success::after {
 content: '✓';
 position: absolute;
 right: var(--space-4);
 top: 50%;
 transform: translateY(-50%);
 color: var(--color-success);
 font-weight: var(--font-weight-bold);
}

.field-error {
 position: relative;
}

.field-error .form-input,
.field-error .form-textarea,
.field-error .form-select {
 border-color: var(--border-error);
 padding-right: var(--space-11);
}

.field-error::after {
 content: '!';
 position: absolute;
 right: var(--space-4);
 top: 50%;
 transform: translateY(-50%);
 width: 20px;
 height: 20px;
 background: var(--color-error);
 color: var(--text-inverse);
 border-radius: var(--radius-full);
 display: flex;
 align-items: center;
 justify-content: center;
 font-size: var(--font-size-xs);
 font-weight: var(--font-weight-bold);
}

/* ==========================================================================
  FORM FEEDBACK
  ========================================================================== */

.form-feedback {
 padding: var(--space-3) var(--space-4);
 border-radius: var(--radius-md);
 margin-bottom: var(--space-4);
 display: flex;
 align-items: center;
 gap: var(--space-2);
 animation: var(--animation-slide-down);
}

.form-feedback-icon {
 width: 20px;
 height: 20px;
 flex-shrink: 0;
}

.form-feedback-text {
 flex: 1;
 font-size: var(--font-size-sm);
}

.form-feedback.success {
 background: rgba(16, 185, 129, 0.1);
 border: 1px solid var(--color-success);
 color: var(--color-success);
}

.form-feedback.error {
 background: rgba(239, 68, 68, 0.1);
 border: 1px solid var(--color-error);
 color: var(--color-error);
}

.form-feedback.warning {
 background: rgba(245, 158, 11, 0.1);
 border: 1px solid var(--color-warning);
 color: var(--color-warning);
}

.form-feedback.info {
 background: rgba(59, 130, 246, 0.1);
 border: 1px solid var(--color-info);
 color: var(--color-info);
}

/* ==========================================================================
  RESPONSIVE DESIGN
  ========================================================================== */

@media (max-width: 640px) {
 .form {
   max-width: 100%;
 }
 
 .form-actions {
   flex-direction: column;
 }
 
 .btn {
   width: 100%;
 }
 
 .toggle-switch {
   justify-content: space-between;
   width: 100%;
 }
}

/* ==========================================================================
  ANIMATIONS
  ========================================================================== */

@keyframes slideDown {
 from {
   opacity: 0;
   transform: translateY(-10px);
 }
 to {
   opacity: 1;
   transform: translateY(0);
 }
}

@keyframes shake {
 0%, 100% { transform: translateX(0); }
 10%, 30%, 50%, 70%, 90% { transform: translateX(-2px); }
 20%, 40%, 60%, 80% { transform: translateX(2px); }
}

.form-input.error {
 animation: shake 0.5s;
}

/* ==========================================================================
  LOADING STATES
  ========================================================================== */

.form-loading {
 position: relative;
 pointer-events: none;
 opacity: 0.6;
}

.form-loading::after {
 content: '';
 position: absolute;
 top: 50%;
 left: 50%;
 transform: translate(-50%, -50%);
 width: 32px;
 height: 32px;
 border: 3px solid var(--border-primary);
 border-top-color: var(--color-primary);
 border-radius: var(--radius-full);
 animation: var(--animation-spin);
}

/* ==========================================================================
  DISABLED STATES
  ========================================================================== */

.form-disabled {
 pointer-events: none;
 opacity: 0.5;
}

.form-disabled .form-input,
.form-disabled .form-textarea,
.form-disabled .form-select,
.form-disabled .btn {
 cursor: not-allowed;
 background: var(--bg-disabled);
}