/**
 * 999DEX MOBILE FORMS - Touch-Optimized Inputs
 *
 * Mobile-first form design with touch-friendly inputs and controls
 * - Prevents zoom on input focus (font-size >= 16px)
 * - Large touch targets (>= 44px WCAG AAA)
 * - Bottom sheet modals for mobile
 * - Sticky submit buttons
 * - Mobile keyboard optimization
 *
 * @version 1.0.0
 * @author Agent 24 - Mobile Optimization
 * @date November 3, 2025
 */

/* ============================================
   BASE INPUT STYLES (Mobile-Optimized)
   ============================================ */

input,
textarea,
select {
  /* Prevent zoom on iOS */
  font-size: 16px !important;

  /* Touch-friendly sizing */
  min-height: 48px;
  padding: var(--spacing-base) var(--spacing-md);

  /* Better mobile appearance */
  -webkit-appearance: none;
  appearance: none;
  border-radius: var(--radius-lg);
  border: 2px solid var(--border-primary);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  width: 100%;

  /* Smooth transitions */
  transition: var(--transition-all-normal);
}

/* Focus state - prominent for accessibility */
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent-purple);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.1);
}

/* Placeholder styling */
input::placeholder,
textarea::placeholder {
  color: rgba(255, 255, 255, 0.4);
  font-size: 16px;
}

/* Disabled state */
input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: rgba(255, 255, 255, 0.02);
}

/* ============================================
   MOBILE FORM LAYOUT
   ============================================ */

.mobile-form {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
  padding: var(--spacing-md);
}

.mobile-form-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.mobile-form-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.mobile-form-label .required {
  color: var(--error);
}

.mobile-form-hint {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  margin-top: calc(var(--spacing-xs) * -1);
}

.mobile-form-error {
  font-size: var(--font-size-xs);
  color: var(--error);
  font-weight: var(--font-weight-medium);
  display: none;
}

.mobile-form-group.error .mobile-form-error {
  display: block;
}

.mobile-form-group.error input,
.mobile-form-group.error textarea,
.mobile-form-group.error select {
  border-color: var(--error);
  background: var(--error-light);
}

/* ============================================
   MOBILE INPUT VARIANTS
   ============================================ */

/* Number input with mobile keyboard */
input[type="number"],
input[type="tel"],
input[inputmode="numeric"] {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-lg) !important;
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.5px;
}

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

input[type="number"] {
  -moz-appearance: textfield;
}

/* Email input */
input[type="email"] {
  text-transform: lowercase;
  font-family: -apple-system-monospaced, ui-monospace, monospace;
}

/* URL input */
input[type="url"] {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm) !important;
}

/* Search input */
input[type="search"] {
  border-radius: 24px;
  padding-left: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='rgba(255,255,255,0.5)'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 14px center;
  background-size: 20px;
}

/* Clear search button */
input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='rgba(255,255,255,0.5)'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M6 18L18 6M6 6l12 12'%3E%3C/path%3E%3C/svg%3E");
  background-size: 20px;
  cursor: pointer;
}

/* ============================================
   TEXTAREA
   ============================================ */

textarea {
  min-height: 120px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.5;
}

textarea.auto-resize {
  resize: none;
  overflow: hidden;
}

/* ============================================
   SELECT / DROPDOWN
   ============================================ */

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='rgba(255,255,255,0.7)'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px;
  padding-right: 44px;
  cursor: pointer;
}

select:focus {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='rgba(139,92,246,1)'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}

/* ============================================
   TOUCH-FRIENDLY BUTTONS
   ============================================ */

.mobile-btn {
  min-height: 48px;
  padding: 14px var(--spacing-lg);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  position: relative;
  overflow: hidden;
}

.mobile-btn:active {
  transform: scale(0.97);
}

.mobile-btn-primary {
  background: linear-gradient(135deg, var(--accent-purple) 0%, var(--accent-cyan) 100%);
  color: var(--text-primary);
  box-shadow: var(--shadow-glow-purple);
}

.mobile-btn-primary:hover {
  box-shadow: 0 6px 16px rgba(168, 85, 247, 0.4);
}

.mobile-btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border: 1px solid var(--border-primary);
}

.mobile-btn-success {
  background: var(--accent-green);
  color: #000;
  box-shadow: var(--shadow-glow-green);
}

.mobile-btn-danger {
  background: var(--error);
  color: var(--text-primary);
  box-shadow: var(--shadow-glow-red);
}

.mobile-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.mobile-btn-loading {
  pointer-events: none;
}

.mobile-btn-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================
   STICKY SUBMIT BUTTON (Always Visible)
   ============================================ */

.mobile-form-submit-sticky {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--spacing-md);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.95) 0%, rgba(0, 0, 0, 0.8) 100%);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 10;
  margin-top: auto;
}

/* Safe area support for iOS */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .mobile-form-submit-sticky {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* ============================================
   BOTTOM SHEET MODAL (Mobile-Optimized)
   ============================================ */

.mobile-bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 90vh;
  background: rgba(15, 15, 20, 0.98);
  backdrop-filter: blur(20px);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
  transform: translateY(100%);
  transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.mobile-bottom-sheet.active {
  transform: translateY(0);
}

/* Bottom sheet handle (swipe indicator) */
.mobile-bottom-sheet-handle {
  width: 40px;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  margin: 12px auto 8px;
  cursor: grab;
}

.mobile-bottom-sheet-handle:active {
  cursor: grabbing;
}

/* Bottom sheet header */
.mobile-bottom-sheet-header {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mobile-bottom-sheet-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: #fff;
}

.mobile-bottom-sheet-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 200ms ease;
}

.mobile-bottom-sheet-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Bottom sheet content */
.mobile-bottom-sheet-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}

/* Bottom sheet footer */
.mobile-bottom-sheet-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.3);
}

/* Safe area support */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .mobile-bottom-sheet-footer {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* ============================================
   FLOATING LABELS (Space-Saving)
   ============================================ */

.mobile-input-floating {
  position: relative;
  margin-top: 12px;
}

.mobile-input-floating input,
.mobile-input-floating textarea {
  padding-top: 20px;
  padding-bottom: 8px;
}

.mobile-input-floating label {
  position: absolute;
  top: var(--spacing-md);
  left: var(--spacing-md);
  font-size: var(--font-size-base);
  color: rgba(255, 255, 255, 0.5);
  pointer-events: none;
  transition: all 200ms ease;
}

.mobile-input-floating input:focus ~ label,
.mobile-input-floating input:not(:placeholder-shown) ~ label,
.mobile-input-floating textarea:focus ~ label,
.mobile-input-floating textarea:not(:placeholder-shown) ~ label {
  top: var(--spacing-sm);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: rgba(139, 92, 246, 0.9);
}

/* ============================================
   INPUT GROUPS (Compound Inputs)
   ============================================ */

.mobile-input-group {
  display: flex;
  gap: 0;
  width: 100%;
}

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

.mobile-input-group input:first-child {
  border-radius: 12px 0 0 12px;
}

.mobile-input-group input:last-child {
  border-radius: 0 12px 12px 0;
  border-right: 2px solid rgba(255, 255, 255, 0.1);
}

.mobile-input-group-addon {
  display: flex;
  align-items: center;
  padding: var(--spacing-base) var(--spacing-md);
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-left: none;
  border-radius: 0 12px 12px 0;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: rgba(255, 255, 255, 0.7);
}

/* ============================================
   TOGGLE SWITCH (Touch-Friendly)
   ============================================ */

.mobile-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-base);
  cursor: pointer;
  user-select: none;
  min-height: 44px;
}

.mobile-toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

.mobile-toggle-switch {
  position: relative;
  width: 52px;
  height: 32px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  transition: background 200ms ease;
}

.mobile-toggle-switch::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  background: #fff;
  border-radius: 50%;
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.mobile-toggle input:checked + .mobile-toggle-switch {
  background: #8b5cf6;
}

.mobile-toggle input:checked + .mobile-toggle-switch::after {
  transform: translateX(20px);
}

/* ============================================
   RADIO BUTTONS (Touch-Friendly)
   ============================================ */

.mobile-radio-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-base);
}

.mobile-radio {
  display: flex;
  align-items: center;
  gap: var(--spacing-base);
  padding: var(--spacing-base) var(--spacing-md);
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  cursor: pointer;
  transition: all 200ms ease;
  min-height: 52px;
}

.mobile-radio:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.mobile-radio input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

.mobile-radio-indicator {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  position: relative;
  flex-shrink: 0;
  transition: all 200ms ease;
}

.mobile-radio input:checked ~ .mobile-radio-indicator {
  border-color: #8b5cf6;
  background: #8b5cf6;
}

.mobile-radio input:checked ~ .mobile-radio-indicator::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}

.mobile-radio:has(input:checked) {
  background: rgba(139, 92, 246, 0.1);
  border-color: #8b5cf6;
}

/* ============================================
   CHECKBOX (Touch-Friendly)
   ============================================ */

.mobile-checkbox {
  display: flex;
  align-items: center;
  gap: var(--spacing-base);
  cursor: pointer;
  min-height: 44px;
  user-select: none;
}

.mobile-checkbox input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

.mobile-checkbox-indicator {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  position: relative;
  flex-shrink: 0;
  transition: all 200ms ease;
}

.mobile-checkbox input:checked ~ .mobile-checkbox-indicator {
  border-color: #8b5cf6;
  background: #8b5cf6;
}

.mobile-checkbox input:checked ~ .mobile-checkbox-indicator::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 7px;
  width: 6px;
  height: 12px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ============================================
   RANGE SLIDER (Touch-Friendly)
   ============================================ */

.mobile-range {
  width: 100%;
  margin: 12px 0;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
  padding: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  background: #8b5cf6;
  border-radius: 50%;
  cursor: grab;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.5);
}

input[type="range"]::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  background: #8b5cf6;
  border-radius: 50%;
  cursor: grab;
  border: none;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.5);
}

/* ============================================
   FILE UPLOAD (Touch-Friendly)
   ============================================ */

.mobile-file-upload {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  border: 2px dashed rgba(255, 255, 255, 0.3);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: all 200ms ease;
  padding: var(--spacing-lg);
  text-align: center;
}

.mobile-file-upload:hover {
  border-color: rgba(139, 92, 246, 0.6);
  background: rgba(139, 92, 246, 0.05);
}

.mobile-file-upload input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.mobile-file-upload-icon {
  width: 48px;
  height: 48px;
  color: rgba(255, 255, 255, 0.4);
  margin-bottom: 12px;
}

.mobile-file-upload-text {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: #fff;
  margin-bottom: 4px;
}

.mobile-file-upload-hint {
  font-size: var(--font-size-xs);
  color: rgba(255, 255, 255, 0.5);
}

/* ============================================
   FORM VALIDATION FEEDBACK
   ============================================ */

.mobile-form-success {
  padding: var(--spacing-base) var(--spacing-md);
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  border-radius: 12px;
  color: #22c55e;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.mobile-form-warning {
  padding: var(--spacing-base) var(--spacing-md);
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: 12px;
  color: #fbbf24;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (min-width: 768px) {
  /* Desktop: smaller buttons */
  .mobile-btn {
    min-height: 44px;
    padding: 12px 20px;
  }

  /* Desktop: bottom sheets become center modals */
  .mobile-bottom-sheet {
    bottom: auto;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%) scale(0.95);
    opacity: 0;
    max-width: 500px;
    width: 90%;
    border-radius: 24px;
  }

  .mobile-bottom-sheet.active {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }

  .mobile-bottom-sheet-handle {
    display: none;
  }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

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

  .mobile-btn {
    border: 2px solid currentColor;
  }
}
