/* ═══════════════════════════════════════════════════════
   AutoMixSJ88 — Mobile-First UX Layer
   10 ฟีเจอร์ที่ทำให้มือถือใช้ง่ายขึ้น
   ═══════════════════════════════════════════════════════ */

/* ────────────────────────────────────────────────────────
   #1  BOTTOM NAVIGATION BAR
   ──────────────────────────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 500;
  background: rgba(8, 8, 26, 0.92);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border-top: 1px solid rgba(255,255,255,0.06);
  padding: 6px 0;
  padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
}
.bottom-nav-items {
  display: flex;
  justify-content: space-around;
  align-items: center;
  max-width: 500px;
  margin: 0 auto;
}
.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  min-width: 56px;
}
.bottom-nav-icon {
  font-size: 1.3rem;
  line-height: 1;
  transition: transform 0.2s ease;
}
.bottom-nav-label {
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  transition: color 0.2s ease;
}
.bottom-nav-item.active .bottom-nav-icon {
  transform: scale(1.15);
  filter: drop-shadow(0 0 6px rgba(139, 92, 246, 0.5));
}
.bottom-nav-item.active .bottom-nav-label {
  color: var(--accent-1);
}
.bottom-nav-item:active {
  transform: scale(0.9);
  background: rgba(139, 92, 246, 0.08);
}
/* Active dot indicator */
.bottom-nav-item.active::after {
  content: '';
  display: block;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--accent-1);
  margin-top: 2px;
  box-shadow: 0 0 8px var(--accent-1);
}

/* ────────────────────────────────────────────────────────
   #2  STICKY AUDIO PLAYER
   ──────────────────────────────────────────────────────── */
.mini-player {
  display: none;
  position: fixed;
  bottom: 68px;
  left: 8px; right: 8px;
  z-index: 490;
  background: rgba(14, 14, 36, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.4);
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.mini-player.visible {
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slideUp 0.3s ease;
}
.mini-player-info {
  flex: 1;
  min-width: 0;
}
.mini-player-name {
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mini-player-status {
  font-size: 0.64rem;
  color: var(--text-muted);
}
.mini-player-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}
.mini-player-btn {
  width: 36px; height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: white;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}
.mini-player-btn:active { transform: scale(0.88); }
.mini-player-btn.secondary {
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
  width: 30px; height: 30px;
  font-size: 0.8rem;
}
.mini-player-progress {
  position: absolute;
  bottom: 0; left: 14px; right: 14px;
  height: 2px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
}
.mini-player-progress-fill {
  height: 100%;
  background: var(--accent-gradient);
  width: 0%;
  transition: width 0.3s linear;
}

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

/* ────────────────────────────────────────────────────────
   #3  PULL-TO-REFRESH
   ──────────────────────────────────────────────────────── */
.pull-indicator {
  display: none;
  position: fixed;
  top: 0; left: 50%;
  transform: translateX(-50%) translateY(-60px);
  z-index: 400;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  box-shadow: var(--shadow-md);
  transition: transform 0.3s ease;
  opacity: 0;
  pointer-events: none;
}
.pull-indicator.pulling {
  opacity: 1;
}
.pull-indicator.refreshing {
  opacity: 1;
  transform: translateX(-50%) translateY(16px);
  animation: spin 0.8s linear infinite;
}

/* ────────────────────────────────────────────────────────
   #4  SWIPE PAGE INDICATOR (Dots)
   ──────────────────────────────────────────────────────── */
.page-dots {
  display: none;
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 350;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(8, 8, 26, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.page-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  transition: all 0.3s ease;
}
.page-dot.active {
  width: 18px;
  border-radius: 3px;
  background: var(--accent-1);
}

/* ────────────────────────────────────────────────────────
   #5  TOUCH-OPTIMIZED TARGETS
   ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Min 44px touch targets */
  .btn-sm {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 16px;
    font-size: 0.8rem;
  }
  .file-actions {
    gap: 8px;
  }
  .file-actions .btn-sm {
    padding: 10px 14px;
  }
  .file-item {
    padding: 14px 16px;
    gap: 14px;
  }
  .file-icon {
    width: 44px; height: 44px;
    font-size: 1.3rem;
  }
  .form-input,
  .form-select,
  .form-textarea {
    padding: 14px 16px;
    font-size: 16px; /* Prevent iOS zoom */
  }
  .form-label {
    font-size: 0.82rem;
    margin-bottom: 8px;
  }
  .tab {
    min-height: 44px;
    padding: 10px 16px;
  }
  .nav-item {
    padding: 14px 14px;
    min-height: 48px;
  }
  /* Checkbox bigger */
  .file-checkbox,
  input[type="checkbox"],
  input[type="radio"] {
    width: 22px; height: 22px;
    min-width: 22px;
  }
}

/* ────────────────────────────────────────────────────────
   #6  COLLAPSIBLE SECTIONS (Accordion)
   ──────────────────────────────────────────────────────── */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  padding: 4px 0;
}
.collapsible-header::after {
  content: '▼';
  font-size: 0.6rem;
  color: var(--text-muted);
  transition: transform 0.3s ease;
  margin-left: 8px;
  flex-shrink: 0;
}
.collapsible-header.collapsed::after {
  transform: rotate(-90deg);
}
.collapsible-body {
  max-height: 2000px;
  overflow: hidden;
  transition: max-height 0.4s ease, opacity 0.3s ease;
  opacity: 1;
}
.collapsible-body.collapsed {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}

/* ────────────────────────────────────────────────────────
   #7  FAB (Floating Action Button)
   ──────────────────────────────────────────────────────── */
.fab {
  display: none;
  position: fixed;
  bottom: 80px;
  right: 16px;
  z-index: 480;
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--accent-gradient);
  color: white;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow:
    0 6px 24px rgba(99, 102, 241, 0.4),
    0 0 40px rgba(139, 92, 246, 0.15);
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  animation: fabPulse 3s ease-in-out infinite;
}
.fab:active {
  transform: scale(0.88) rotate(-5deg);
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.3);
}
.fab-tooltip {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-primary);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  box-shadow: var(--shadow-sm);
}
.fab:hover .fab-tooltip,
.fab:focus .fab-tooltip {
  opacity: 1;
}
@keyframes fabPulse {
  0%, 100% { box-shadow: 0 6px 24px rgba(99,102,241,0.4), 0 0 40px rgba(139,92,246,0.15); }
  50%      { box-shadow: 0 8px 32px rgba(99,102,241,0.5), 0 0 60px rgba(139,92,246,0.2); }
}

/* ────────────────────────────────────────────────────────
   #8  SAFE AREA + NOTCH SUPPORT
   ──────────────────────────────────────────────────────── */
@supports (padding: env(safe-area-inset-top)) {
  .main-content {
    padding-top: calc(60px + env(safe-area-inset-top, 0px));
  }
  .mobile-toggle {
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: calc(12px + env(safe-area-inset-left, 0px));
  }
  .sidebar {
    padding-top: calc(20px + env(safe-area-inset-top, 0px));
  }
  .auth-container {
    padding-top: calc(24px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }
  .bottom-nav {
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .fab {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
  .mini-player {
    bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }
}

/* ────────────────────────────────────────────────────────
   #9  BOTTOM SHEET MODAL
   ──────────────────────────────────────────────────────── */
.bottom-sheet-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 600;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.bottom-sheet-overlay.open { display: block; opacity: 1; }

.bottom-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 610;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 0 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
}
.bottom-sheet.open {
  transform: translateY(0);
}
.bottom-sheet-handle {
  width: 40px; height: 5px;
  border-radius: 100px;
  background: rgba(255,255,255,0.15);
  margin: 12px auto 16px;
}
.bottom-sheet-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.bottom-sheet-close {
  width: 32px; height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ────────────────────────────────────────────────────────
   #10  TOAST MOBILE — SNACKBAR STYLE + HAPTIC
   ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .toast-container {
    top: auto;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    right: 8px;
    left: 8px;
    align-items: stretch;
  }
  .toast {
    max-width: 100%;
    border-radius: 14px;
    padding: 14px 18px;
    font-size: 0.84rem;
    animation: snackbarIn 0.3s ease;
  }
  .toast-exit {
    animation: snackbarOut 0.25s ease forwards;
  }
  @keyframes snackbarIn {
    from { transform: translateY(30px) scale(0.95); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
  }
  @keyframes snackbarOut {
    from { transform: translateY(0) scale(1); opacity: 1; }
    to   { transform: translateY(30px) scale(0.95); opacity: 0; }
  }
}

/* ────────────────────────────────────────────────────────
   MOBILE-ONLY: Show bottom nav, FAB, dots
   ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .bottom-nav { display: block; }
  .fab { display: flex; align-items: center; justify-content: center; }
  .page-dots { display: flex; }

  /* Add bottom padding for bottom nav */
  .main-content {
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  /* Hide sidebar hamburger — replaced by bottom nav */
  .mobile-toggle { display: none !important; }

  /* Reduce aurora opacity on mobile for performance */
  .aurora-orb {
    opacity: 0.06;
    filter: blur(60px);
  }

  /* Keep sidebar accessible via swipe from left */
  .sidebar {
    width: 82vw;
    max-width: 320px;
  }
}

/* Very small phones */
@media (max-width: 380px) {
  .bottom-nav-label { font-size: 0.52rem; }
  .bottom-nav-item { min-width: 48px; padding: 6px 8px; }
  .fab { width: 50px; height: 50px; font-size: 1.2rem; }
}
