/* =========================================================
   FORMS MOBILE OPTIMIZATIONS
   Mejoras específicas de formularios para dispositivos móviles
   ========================================================= */

/* === LAYOUT DE FORMULARIOS MÓVIL === */
@media (max-width: 1024px) {
  .form {
    gap: var(--space-lg);
  }

  .form-row {
    grid-template-columns: 1fr !important;
    gap: var(--space-md);
  }

  .form-section {
    padding: var(--mobile-padding);
    border-radius: var(--radius-md);
  }

  .form-section-header {
    padding: var(--mobile-padding-sm);
    margin: calc(-1 * var(--mobile-padding)) calc(-1 * var(--mobile-padding)) var(--mobile-padding);
  }

  .form-section-title {
    font-size: 1rem;
  }

  .form-section-description {
    font-size: 0.8125rem;
  }
}

/* === CAMPOS DE FORMULARIO MÓVIL === */
@media (max-width: 1024px) {
  .form-group {
    margin-bottom: var(--space-lg);
  }

  .form-label {
    font-size: 0.9375rem;
    margin-bottom: var(--space-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .form-label-required {
    color: var(--color-error);
    margin-left: var(--space-xs);
  }

  /* Inputs optimizados para móvil */
  .form-control {
    min-height: var(--touch-target-min);
    padding: var(--space-md) var(--mobile-padding);
    font-size: 1rem; /* Evita zoom automático en iOS */
    border-radius: var(--radius-md);
    -webkit-appearance: none;
    appearance: none;
  }

  .form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  }

  /* Textarea móvil */
  textarea.form-control {
    min-height: 120px;
    resize: vertical;
    line-height: 1.5;
  }

  /* Select móvil mejorado */
  select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%2394a3b8' d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--mobile-padding) center;
    background-size: 16px;
    padding-right: calc(var(--mobile-padding) * 2 + 16px);
    cursor: pointer;
  }

  /* Input con icono */
  .form-input-group {
    position: relative;
  }

  .form-input-icon {
    position: absolute;
    left: var(--mobile-padding);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1.125rem;
    pointer-events: none;
  }

  .form-input-group .form-control {
    padding-left: calc(var(--mobile-padding) * 2 + 20px);
  }

  /* Checkbox y Radio mejorados */
  .form-check {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    transition: background-color 0.2s ease;
    cursor: pointer;
    min-height: var(--touch-target-min);
  }

  .form-check:hover {
    background-color: var(--bg-hover);
  }

  .form-check-input {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    margin: 0;
    cursor: pointer;
    border: 2px solid var(--border-default);
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    background-color: var(--bg-input);
    position: relative;
  }

  .form-check-input:checked {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
  }

  .form-check-input:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 14px;
    font-weight: bold;
  }

  .form-check-input[type="radio"] {
    border-radius: 50%;
  }

  .form-check-input[type="radio"]:checked::after {
    content: '';
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: white;
  }

  .form-check-label {
    font-size: 0.9375rem;
    cursor: pointer;
    user-select: none;
    flex: 1;
  }

  /* Switch toggle */
  .form-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    background-color: var(--bg-secondary);
    min-height: var(--touch-target-min);
  }

  .form-switch-input {
    width: 52px;
    height: 28px;
    min-width: 52px;
    position: relative;
    cursor: pointer;
    background-color: var(--bg-tertiary);
    border-radius: 14px;
    transition: background-color 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
    border: none;
  }

  .form-switch-input::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 24px;
    height: 24px;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }

  .form-switch-input:checked {
    background-color: var(--color-primary);
  }

  .form-switch-input:checked::after {
    transform: translateX(24px);
  }

  .form-switch-label {
    font-size: 0.9375rem;
    flex: 1;
  }

  /* File input mejorado */
  .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-sm);
    padding: var(--space-md) var(--mobile-padding);
    min-height: var(--touch-target-min);
    background-color: var(--bg-secondary);
    border: 2px dashed var(--border-default);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
  }

  .form-file-label:hover {
    background-color: var(--bg-hover);
    border-color: var(--color-primary);
  }

  .form-file-label:active {
    transform: scale(0.98);
  }

  .form-file-icon {
    font-size: 1.5rem;
  }

  .form-file-text {
    font-size: 0.9375rem;
    color: var(--text-primary);
  }

  /* Mensajes de ayuda */
  .form-help {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: var(--space-xs);
    line-height: 1.4;
  }

  /* Mensajes de error */
  .form-error {
    font-size: 0.8125rem;
    color: var(--color-error);
    margin-top: var(--space-xs);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
  }

  .form-error::before {
    content: '⚠️';
    font-size: 0.875rem;
  }

  .form-control.is-invalid {
    border-color: var(--color-error);
  }

  .form-control.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
  }

  /* Mensajes de éxito */
  .form-success {
    font-size: 0.8125rem;
    color: var(--color-success);
    margin-top: var(--space-xs);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
  }

  .form-success::before {
    content: '✓';
    font-size: 0.875rem;
  }

  .form-control.is-valid {
    border-color: var(--color-success);
  }

  .form-control.is-valid:focus {
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
  }
}

/* === BOTONES DE FORMULARIO MÓVIL === */
@media (max-width: 1024px) {
  .form-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border-light);
  }

  .form-actions .btn {
    width: 100%;
    min-height: var(--touch-target-min);
    justify-content: center;
  }

  /* Botones primarios más prominentes */
  .form-actions .btn-primary {
    order: -1;
    font-size: 1rem;
    font-weight: 600;
    padding: var(--space-md) var(--space-xl);
  }

  /* Botones secundarios */
  .form-actions .btn-secondary,
  .form-actions .btn-outline {
    font-size: 0.9375rem;
  }

  /* Grupo de botones horizontal en móvil */
  .form-actions.horizontal {
    flex-direction: row;
  }

  .form-actions.horizontal .btn {
    flex: 1;
  }
}

/* === MÓVIL PEQUEÑO === */
@media (max-width: 768px) {
  .form {
    gap: var(--space-md);
  }

  .form-section {
    padding: var(--mobile-padding-sm);
  }

  .form-group {
    margin-bottom: var(--space-md);
  }

  .form-label {
    font-size: 0.875rem;
  }

  .form-control {
    padding: var(--space-sm) var(--mobile-padding-sm);
    font-size: 1rem;
  }

  textarea.form-control {
    min-height: 100px;
  }

  .form-check {
    padding: var(--space-sm) var(--space-md);
  }

  .form-switch {
    padding: var(--space-sm) var(--space-md);
  }

  .form-file-label {
    padding: var(--space-sm) var(--mobile-padding-sm);
  }

  .form-actions {
    gap: var(--space-sm);
  }
}

/* === ANIMACIONES === */
@media (max-width: 1024px) {
  @keyframes formFadeIn {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .form-group {
    animation: formFadeIn 0.3s ease;
    animation-fill-mode: backwards;
  }

  .form-group:nth-child(1) {
    animation-delay: 0.05s;
  }

  .form-group:nth-child(2) {
    animation-delay: 0.1s;
  }

  .form-group:nth-child(3) {
    animation-delay: 0.15s;
  }

  .form-group:nth-child(4) {
    animation-delay: 0.2s;
  }

  .form-group:nth-child(5) {
    animation-delay: 0.25s;
  }

  /* Animación de error */
  @keyframes shake {
    0%, 100% {
      transform: translateX(0);
    }
    25% {
      transform: translateX(-8px);
    }
    75% {
      transform: translateX(8px);
    }
  }

  .form-control.is-invalid {
    animation: shake 0.4s ease;
  }

  /* Animación de éxito */
  @keyframes successPulse {
    0% {
      box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
    }
    100% {
      box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
    }
  }

  .form-control.is-valid {
    animation: successPulse 0.6s ease;
  }

  /* Animación de botón */
  @keyframes buttonPress {
    0% {
      transform: scale(1);
    }
    50% {
      transform: scale(0.97);
    }
    100% {
      transform: scale(1);
    }
  }

  .btn:active {
    animation: buttonPress 0.2s ease;
  }
}

/* === MEJORAS DE ACCESIBILIDAD === */
@media (max-width: 1024px) {
  /* Focus visible mejorado */
  .form-control:focus-visible,
  .form-check-input:focus-visible,
  .form-switch-input:focus-visible,
  .form-file-label:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
  }

  /* Mejorar contraste de labels */
  .form-label {
    color: var(--text-primary);
    font-weight: 500;
  }

  /* Mejorar legibilidad de placeholders */
  .form-control::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
  }

  /* Mejorar visibilidad de campos deshabilitados */
  .form-control:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: var(--bg-tertiary);
  }
}

/* === VALIDACIÓN EN TIEMPO REAL === */
@media (max-width: 1024px) {
  .form-control.validating {
    border-color: var(--color-info);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='10' r='8' fill='none' stroke='%230ea5e9' stroke-width='2' stroke-dasharray='50' stroke-dashoffset='0'%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 10 10' to='360 10 10' dur='1s' repeatCount='indefinite'/%3E%3C/circle%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--mobile-padding) center;
    background-size: 20px;
    padding-right: calc(var(--mobile-padding) * 2 + 20px);
  }
}

/* === GRUPOS DE CAMPOS === */
@media (max-width: 1024px) {
  .form-group-inline {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
  }

  .form-group-inline .form-control {
    flex: 1;
  }

  /* Input con botón adjunto */
  .input-group {
    display: flex;
    gap: var(--space-sm);
  }

  .input-group .form-control {
    flex: 1;
  }

  .input-group .btn {
    min-width: var(--touch-target-min);
  }
}

/* === LANDSCAPE MODE === */
@media (max-width: 1024px) and (orientation: landscape) {
  .form-row {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .form-actions {
    flex-direction: row;
  }

  .form-actions .btn {
    flex: 1;
  }
}

/* === DARK MODE OPTIMIZATIONS === */
@media (max-width: 1024px) {
  [data-theme="dark"] .form-control {
    background-color: rgba(15, 23, 42, 0.6);
    border-color: rgba(148, 163, 184, 0.2);
    color: var(--text-primary);
  }

  [data-theme="dark"] .form-control:focus {
    background-color: rgba(15, 23, 42, 0.8);
  }

  [data-theme="dark"] .form-check-input {
    background-color: rgba(15, 23, 42, 0.6);
    border-color: rgba(148, 163, 184, 0.3);
  }

  [data-theme="dark"] .form-switch-input {
    background-color: rgba(51, 65, 85, 0.6);
  }

  [data-theme="light"] .form-control {
    background-color: rgba(255, 255, 255, 0.9);
    border-color: rgba(0, 0, 0, 0.15);
  }

  [data-theme="light"] .form-check-input {
    background-color: rgba(255, 255, 255, 0.9);
    border-color: rgba(0, 0, 0, 0.2);
  }

  [data-theme="light"] .form-switch-input {
    background-color: rgba(226, 232, 240, 0.8);
  }
}

/* === REDUCIR MOVIMIENTO === */
@media (prefers-reduced-motion: reduce) {
  .form-group,
  .form-control,
  .btn {
    animation: none !important;
  }

  .form-switch-input::after {
    transition-duration: 0.01ms !important;
  }
}

/* === MEJORAS DE RENDIMIENTO === */
@media (max-width: 1024px) {
  /* Hardware acceleration */
  .form-control,
  .btn,
  .form-switch-input::after {
    will-change: transform;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }
}
