/* ═══════════════════════════════════════════════════════════════════════════════
   SAFO — MOBILE PREMIUM EXPERIENCE
   Shein-level mobile shopping experience
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── Safe Area & Viewport ──────────────────────────────────────────────────── */

html {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body {
  -webkit-user-select: text;
  user-select: text;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-x: none;
  overscroll-behavior-y: auto;
}

input, textarea, button, select {
  -webkit-user-select: text;
  user-select: text;
}

/* ── Bottom Navigation Bar ─────────────────────────────────────────────────── */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 500;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  cursor: pointer;
  flex: 1;
  position: relative;
  border-radius: var(--radius-md);
}

.bottom-nav-item:active {
  background: var(--bg-secondary);
}

.bottom-nav-item.active {
  color: var(--accent);
  font-weight: 600;
}

.bottom-nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
}

.bottom-nav-item svg {
  width: 24px;
  height: 24px;
}

/* ── Scroll Padding for Fixed Elements ─────────────────────────────────────── */

html {
  scroll-padding-top: 60px;
  scroll-padding-bottom: 60px;
}

/* ── Touch-Friendly Buttons ────────────────────────────────────────────────── */

button, a[role="button"], input[type="button"], input[type="submit"] {
  min-height: 44px;
  min-width: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  font-weight: 600;
  transition: all var(--transition-fast);
  -webkit-user-select: none;
  user-select: none;
}

button:active, a[role="button"]:active {
  opacity: 0.8;
  transform: scale(0.98);
}

/* ── Form Elements ─────────────────────────────────────────────────────────── */

input, textarea, select {
  min-height: 44px;
  padding: 12px 14px;
  font-size: 16px; /* Prevents zoom on iOS */
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  font-family: inherit;
  transition: all var(--transition-fast);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

/* ── Swipe Gestures Support ────────────────────────────────────────────────── */

.swipe-container {
  touch-action: pan-y;
  overflow-x: hidden;
}

.swipe-item {
  transition: transform var(--transition-normal);
}

/* ── Pull-to-Refresh Indicator ─────────────────────────────────────────────── */

.pull-to-refresh {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  transition: all var(--transition-normal);
}

.pull-to-refresh.active {
  top: 10px;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: translateX(-50%) rotate(360deg);
  }
}

/* ── Haptic Feedback Simulation ────────────────────────────────────────────── */

.haptic-btn {
  position: relative;
}

.haptic-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.2);
  opacity: 0;
  pointer-events: none;
}

.haptic-btn:active::after {
  animation: haptic-pulse 0.3s ease-out;
}

@keyframes haptic-pulse {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.2);
  }
}

/* ── Floating Action Button ────────────────────────────────────────────────── */

.fab {
  position: fixed;
  bottom: 80px;
  right: 16px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  transition: all var(--transition-normal);
  z-index: 400;
}

.fab:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-xl);
}

.fab:active {
  transform: scale(0.95);
}

/* ── Scroll-to-Top Button ──────────────────────────────────────────────────── */

#scrollToTop {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) scale(0);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  transition: all var(--transition-normal);
  opacity: 0;
}

#scrollToTop.visible {
  transform: translateX(-50%) scale(1);
  opacity: 1;
}

#scrollToTop:active {
  transform: translateX(-50%) scale(0.95);
}

/* ── Modal Backdrop for Mobile ─────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.56);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

/* ── Modal Dialog ──────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1001;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  width: 100%;
  max-width: 100%;
  background: var(--bg-primary);
  border-radius: 22px 22px 16px 16px;
  max-height: min(88vh, calc(100dvh - 12px));
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.22);
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-primary);
}

.modal-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.modal-footer {
  position: sticky;
  bottom: 0;
  z-index: 1;
  background: var(--bg-primary);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.modal-footer .btn {
  flex: 1 1 140px;
}

/* ── Toast Notifications ───────────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100% - 32px);
}

.toast {
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  animation: slideDown 0.3s ease-out;
  pointer-events: auto;
  border-left: 4px solid var(--info);
}

.toast.toast-success {
  border-left-color: var(--success);
}

.toast.toast-error {
  border-left-color: var(--danger);
}

.toast.toast-warning {
  border-left-color: var(--warning);
}

@keyframes slideDown {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.toast.fade-out {
  animation: slideUp 0.3s ease-out forwards;
}

/* ── Loading Spinner ───────────────────────────────────────────────────────── */

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ── Safe Area Padding ─────────────────────────────────────────────────────── */

.safe-area-top {
  padding-top: env(safe-area-inset-top);
}

.safe-area-bottom {
  padding-bottom: env(safe-area-inset-bottom);
}

.safe-area-left {
  padding-left: env(safe-area-inset-left);
}

.safe-area-right {
  padding-right: env(safe-area-inset-right);
}

/* ── Responsive Typography ─────────────────────────────────────────────────── */

@media (max-width: 480px) {
  html {
    font-size: 14px;
  }

  body {
    font-size: 14px;
    line-height: 1.5;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 20px;
  }

  h3 {
    font-size: 16px;
  }

  h4 {
    font-size: 14px;
  }

  p {
    font-size: 14px;
  }

  button, input, select, textarea {
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* ── Landscape Mode Adjustments ────────────────────────────────────────────── */

@media (max-height: 500px) and (orientation: landscape) {
  .safo-mobile-header {
    padding: 8px 12px;
  }

  .sticky-search {
    top: 50px;
    padding: 8px 12px;
  }

  .bottom-nav {
    padding: 4px 0 max(4px, env(safe-area-inset-bottom));
  }

  .bottom-nav-item {
    padding: 4px 8px;
    gap: 2px;
  }
}

/* ── Dark Mode Support ─────────────────────────────────────────────────────── */

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #242424;
    --bg-tertiary: #2d2d2d;
    --text-primary: #f5f5f5;
    --text-secondary: #b0b0b0;
    --border-color: #3a3a3a;
    --border-light: #2d2d2d;
  }
}

/* ── Reduced Motion ────────────────────────────────────────────────────────── */

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

/* ── High Contrast Mode ────────────────────────────────────────────────────── */

@media (prefers-contrast: more) {
  :root {
    --border-color: #000;
    --text-primary: #000;
    --text-secondary: #333;
  }
}

/* ── Network Information API (Adaptive Loading) ────────────────────────────── */

@media (prefers-reduced-data: reduce) {
  img {
    background: var(--bg-secondary);
  }

  video {
    display: none;
  }
}
