/**
 * 999DEX MOBILE UI COMPONENTS
 *
 * Mobile-specific UI patterns and components
 * - Bottom sheets (replaces center modals on mobile)
 * - Action sheets (iOS-style action menus)
 * - Floating Action Button (FAB)
 * - Tab bars (bottom navigation)
 * - Toast notifications (mobile-optimized)
 * - Safe area handling (iPhone X+ notch)
 *
 * @version 1.0.0
 * @author Agent 24 - Mobile Optimization
 * @date November 3, 2025
 */

/* ============================================
   BOTTOM SHEETS
   ============================================ */

.bottom-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 300ms cubic-bezier(0.4, 0, 0.2, 1),
              visibility 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.bottom-sheet-overlay.active {
  opacity: 1;
  visibility: visible;
}

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

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

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

.bottom-sheet-handle:active {
  cursor: grabbing;
  background: rgba(255, 255, 255, 0.5);
}

/* Bottom sheet header */
.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;
  flex-shrink: 0;
}

.bottom-sheet-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: #fff;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.bottom-sheet-close {
  width: 32px;
  height: 32px;
  min-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: all 200ms ease;
  flex-shrink: 0;
}

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

.bottom-sheet-close:active {
  transform: scale(0.95);
}

.bottom-sheet-close svg {
  width: 18px;
  height: 18px;
}

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

.bottom-sheet-content::-webkit-scrollbar {
  width: 4px;
}

.bottom-sheet-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

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

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

/* Sizes */
.bottom-sheet-small {
  max-height: 40vh;
}

.bottom-sheet-medium {
  max-height: 60vh;
}

.bottom-sheet-large {
  max-height: 85vh;
}

.bottom-sheet-full {
  max-height: 95vh;
  border-radius: 16px 16px 0 0;
}

/* Desktop: Center modal instead */
@media (min-width: 768px) {
  .bottom-sheet {
    bottom: auto;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%) scale(0.9);
    opacity: 0;
    max-width: 500px;
    width: 90%;
    border-radius: 24px;
    max-height: 80vh;
  }

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

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

  .bottom-sheet-footer {
    padding-bottom: 16px;
  }
}

/* ============================================
   ACTION SHEETS (iOS-Style)
   ============================================ */

.action-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1100;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 200ms ease;
}

.action-sheet-overlay.active {
  opacity: 1;
  visibility: visible;
}

.action-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1101;
  padding: var(--spacing-sm);
  transform: translateY(100%);
  transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

.action-sheet-menu {
  background: rgba(30, 30, 40, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 8px;
}

.action-sheet-item {
  padding: var(--spacing-md) 20px;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: #fff;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: background 200ms ease;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
}

.action-sheet-item:last-child {
  border-bottom: none;
}

.action-sheet-item:active {
  background: rgba(255, 255, 255, 0.1);
}

.action-sheet-item.destructive {
  color: var(--error);
  font-weight: var(--font-weight-semibold);
}

.action-sheet-item.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.action-sheet-cancel {
  background: rgba(30, 30, 40, 0.95);
  backdrop-filter: blur(20px);
  border-radius: var(--spacing-md);
  padding: var(--spacing-md) 20px;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: #fff;
  text-align: center;
  cursor: pointer;
  transition: background 200ms ease;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-sheet-cancel:active {
  background: rgba(255, 255, 255, 0.1);
}

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

/* Desktop: Action sheets become dropdown menus */
@media (min-width: 768px) {
  .action-sheet {
    position: absolute;
    bottom: auto;
    left: auto;
    right: auto;
    min-width: 200px;
    max-width: 300px;
    padding: var(--spacing-xs);
    transform: translateY(8px);
    opacity: 0;
    visibility: hidden;
  }

  .action-sheet.active {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
  }

  .action-sheet-menu {
    margin-bottom: 0;
  }

  .action-sheet-item {
    text-align: left;
    padding: var(--spacing-base) var(--spacing-md);
    min-height: 44px;
  }

  .action-sheet-cancel {
    display: none;
  }
}

/* ============================================
   FLOATING ACTION BUTTON (FAB)
   ============================================ */

.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--accent-purple) 0%, var(--accent-cyan) 100%);
  border-radius: var(--radius-full);
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow-purple);
  z-index: 900;
  transition: var(--transition-all-medium);
}

.fab:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 12px 32px rgba(168, 85, 247, 0.6);
}

.fab:active {
  transform: translateY(-2px) scale(0.98);
}

.fab svg {
  width: 28px;
  height: 28px;
}

/* FAB with label */
.fab-extended {
  width: auto;
  border-radius: 32px;
  padding: 0 var(--spacing-lg);
  gap: var(--spacing-sm);
}

.fab-label {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
}

/* Mini FAB */
.fab-mini {
  width: 48px;
  height: 48px;
}

.fab-mini svg {
  width: 20px;
  height: 20px;
}

/* FAB variants */
.fab-secondary {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
}

.fab-success {
  background: var(--success);
}

.fab-danger {
  background: var(--error);
}

/* Hide FAB on scroll down, show on scroll up */
.fab.hidden {
  transform: translateY(100px);
  opacity: 0;
}

/* Safe area support */
@supports (bottom: env(safe-area-inset-bottom)) {
  .fab {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .fab {
    width: 56px;
    height: 56px;
    bottom: 16px;
    right: 16px;
  }

  .fab svg {
    width: 24px;
    height: 24px;
  }

  .fab-mini {
    width: 44px;
    height: 44px;
  }

  .fab-extended {
    padding: 0 20px;
  }

  .fab-label {
    font-size: var(--font-size-sm);
  }
}

/* ============================================
   BOTTOM TAB BAR (Alternative Navigation)
   ============================================ */

.bottom-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: rgba(20, 20, 30, 0.95);
  backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding: 0 8px;
}

.bottom-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm);
  min-height: 48px;
  color: rgba(255, 255, 255, 0.5);
  text-decoration: none;
  transition: color 200ms ease;
  cursor: pointer;
  position: relative;
}

.bottom-tab:active {
  transform: scale(0.95);
}

.bottom-tab-icon {
  width: 24px;
  height: 24px;
  transition: transform 200ms ease;
}

.bottom-tab-label {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.bottom-tab.active {
  color: var(--accent-purple);
}

.bottom-tab.active .bottom-tab-icon {
  transform: translateY(-2px);
}

/* Tab badge */
.bottom-tab-badge {
  position: absolute;
  top: 6px;
  right: 50%;
  transform: translateX(12px);
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  background: var(--error);
  color: var(--text-primary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(20, 20, 30, 1);
}

/* Safe area support */
@supports (height: calc(64px + env(safe-area-inset-bottom))) {
  .bottom-tab-bar {
    height: calc(64px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Desktop: Hide bottom tab bar */
@media (min-width: 1024px) {
  .bottom-tab-bar {
    display: none;
  }
}

/* ============================================
   MOBILE TOAST NOTIFICATIONS
   ============================================ */

.mobile-toast-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  padding: var(--spacing-sm);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  pointer-events: none;
}

.mobile-toast {
  background: rgba(20, 20, 30, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 12px;
  padding: var(--spacing-md);
  display: flex;
  align-items: center;
  gap: var(--spacing-base);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transform: translateY(-100px);
  opacity: 0;
  transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: all;
  max-width: 500px;
  margin: 0 auto;
  width: calc(100% - 16px);
}

.mobile-toast.active {
  transform: translateY(0);
  opacity: 1;
}

.mobile-toast-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.mobile-toast-content {
  flex: 1;
  min-width: 0;
}

.mobile-toast-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: #fff;
  margin-bottom: 2px;
}

.mobile-toast-message {
  font-size: var(--font-size-sm);
  color: rgba(255, 255, 255, 0.7);
  line-height: var(--line-height-normal);
}

.mobile-toast-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 150ms ease;
}

.mobile-toast-close:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.mobile-toast-close svg {
  width: 14px;
  height: 14px;
}

/* Toast variants */
.mobile-toast.success {
  border-color: rgba(34, 197, 94, 0.3);
  background: var(--success-light);
}

.mobile-toast.success .mobile-toast-icon {
  color: var(--success);
}

.mobile-toast.error {
  border-color: rgba(239, 68, 68, 0.3);
  background: var(--error-light);
}

.mobile-toast.error .mobile-toast-icon {
  color: var(--error);
}

.mobile-toast.warning {
  border-color: rgba(251, 191, 36, 0.3);
  background: rgba(251, 191, 36, 0.15);
}

.mobile-toast.warning .mobile-toast-icon {
  color: var(--warning);
}

.mobile-toast.info {
  border-color: rgba(6, 182, 212, 0.3);
  background: rgba(6, 182, 212, 0.15);
}

.mobile-toast.info .mobile-toast-icon {
  color: var(--info);
}

/* Safe area support */
@supports (padding-top: env(safe-area-inset-top)) {
  .mobile-toast-container {
    padding-top: calc(8px + env(safe-area-inset-top));
  }
}

/* ============================================
   CONTEXT MENU (Mobile Long Press)
   ============================================ */

.mobile-context-menu {
  position: fixed;
  z-index: 1200;
  min-width: 200px;
  background: rgba(30, 30, 40, 0.98);
  backdrop-filter: blur(20px);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  padding: var(--spacing-xs);
  transform: scale(0.9);
  opacity: 0;
  visibility: hidden;
  transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-context-menu.active {
  transform: scale(1);
  opacity: 1;
  visibility: visible;
}

.mobile-context-menu-item {
  padding: var(--spacing-xs) var(--spacing-md);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: #fff;
  display: flex;
  align-items: center;
  gap: var(--spacing-base);
  cursor: pointer;
  border-radius: 8px;
  transition: background 150ms ease;
  min-height: 44px;
}

.mobile-context-menu-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.mobile-context-menu-item:active {
  background: rgba(255, 255, 255, 0.15);
}

.mobile-context-menu-item.destructive {
  color: var(--error);
}

.mobile-context-menu-item .icon {
  width: 18px;
  height: 18px;
  opacity: 0.7;
}

.mobile-context-menu-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 4px 0;
}

/* ============================================
   CHIP / TAG (Touch-Friendly)
   ============================================ */

.mobile-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: #fff;
  cursor: pointer;
  transition: all 150ms ease;
  min-height: 36px;
}

.mobile-chip:hover {
  background: rgba(255, 255, 255, 0.15);
}

.mobile-chip:active {
  transform: scale(0.95);
}

.mobile-chip-icon {
  width: 16px;
  height: 16px;
}

.mobile-chip-remove {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 150ms ease;
}

.mobile-chip-remove:hover {
  background: rgba(255, 255, 255, 0.3);
}

.mobile-chip-remove svg {
  width: 12px;
  height: 12px;
}

/* ============================================
   SAFE AREA HELPERS
   ============================================ */

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

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

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

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

.safe-area-inset {
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

/* ============================================
   REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .bottom-sheet,
  .action-sheet,
  .fab,
  .mobile-toast,
  .mobile-context-menu {
    transition-duration: 0.01ms !important;
  }
}
