/* 1. App Shell Base */
html, body {
  overscroll-behavior: none; /* prevent bounce */
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}

body.has-bottom-nav {
  padding-bottom: calc(60px + env(safe-area-inset-bottom));
}

/* 2. Bottom Navigation Bar */
.app-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(60px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--ui-border);
  z-index: 1000;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  transition: transform 0.3s ease;
  padding-bottom: env(safe-area-inset-bottom);
}

@media (min-width: 769px) {
  .app-bottom-nav {
    display: none;
  }
  body.has-bottom-nav {
    padding-bottom: 0;
  }
}

.app-bottom-nav.nav-hidden {
  transform: translateY(100%);
}

.app-nav-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--ui-muted);
  font-size: 0.75rem;
  font-weight: 500;
  transition: color 0.2s;
  padding-top: 8px;
}

.app-nav-tab.active {
  color: var(--ui-primary);
}

.app-nav-icon {
  font-size: 1.25rem;
  margin-bottom: 4px;
}

/* 3. Page Transition Animations */
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideInLeft { from { transform: translateX(-100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.page-enter {
  animation: fadeIn 0.3s ease forwards;
}

/* 4. Toast Notifications */
.app-toast-container {
  position: fixed;
  top: env(safe-area-inset-top, 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  gap: 8px;
  width: 90vw;
  max-width: 400px;
}

.app-toast {
  background: white;
  border-radius: 12px;
  padding: 12px 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideDown 0.3s ease;
  pointer-events: auto;
  transition: transform 0.2s, opacity 0.2s;
  width: 100%;
}

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

.app-toast.toast-success { border-left: 4px solid var(--ui-success); }
.app-toast.toast-error { border-left: 4px solid var(--ui-danger); }
.app-toast.toast-info { border-left: 4px solid var(--ui-primary); }

/* 5. Bottom Sheet */
.app-bottom-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1400;
  opacity: 0;
  transition: opacity 0.3s;
}

.app-bottom-sheet-backdrop.show {
  opacity: 1;
}

.app-bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--ui-card-bg);
  z-index: 1500;
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  padding: 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  max-height: 90vh;
  overflow-y: auto;
}

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

.sheet-drag-handle {
  width: 40px;
  height: 4px;
  background: #cbd5e1;
  border-radius: 4px;
  margin: 0 auto 16px;
}

@media (min-width: 769px) {
  .app-bottom-sheet {
    bottom: auto;
    top: 50%;
    left: 50%;
    right: auto;
    width: 500px;
    border-radius: 16px;
    padding-bottom: 24px;
    transform: translate(-50%, -40%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
  }
  .app-bottom-sheet.show {
    transform: translate(-50%, -50%);
    opacity: 1;
  }
  .sheet-drag-handle {
    display: none;
  }
}

/* 6. Floating Action Button (FAB) */
.app-fab {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--ui-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(37,99,235,0.4);
  z-index: 900;
  border: none;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.app-fab:active {
  transform: scale(0.9);
}

/* 7. Skeleton Loading */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite linear;
}

.skeleton-text { height: 16px; border-radius: 4px; margin-bottom: 8px; width: 100%; }
.skeleton-circle { border-radius: 50%; }
.skeleton-card { height: 120px; border-radius: 12px; }

/* 8. Process Screen */
.process-overlay {
  position: fixed;
  inset: 0;
  background: white;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

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

.process-icon {
  font-size: 64px;
  margin-bottom: 24px;
  animation: pulseIcon 2s infinite;
}

@keyframes pulseIcon {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.process-progress-container {
  width: 100%;
  max-width: 400px;
  height: 6px;
  background: var(--ui-border);
  border-radius: 3px;
  margin: 24px 0;
  overflow: hidden;
}

.process-progress-bar {
  height: 100%;
  background: var(--ui-primary);
  width: 0%;
  transition: width 0.3s ease;
}

.process-steps {
  width: 100%;
  max-width: 400px;
  text-align: left;
  margin-top: 16px;
}

.process-step {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--ui-muted);
  font-size: 0.9rem;
  transition: all 0.3s;
}

.process-step.done {
  color: var(--ui-success);
}
.process-step.done::before {
  content: '✅';
}

.process-step.active {
  color: var(--ui-text);
  font-weight: 600;
  animation: slideInRight 0.3s ease forwards;
}

.process-step.pending {
  opacity: 0.5;
}

.process-fun-facts {
  position: absolute;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 24px;
  right: 24px;
  font-size: 0.85rem;
  color: var(--ui-muted);
  font-style: italic;
  min-height: 40px;
}

/* 9. Button Feedback */
.app-btn {
  transition: all 0.2s var(--ui-ease);
}
.app-btn:active {
  transform: scale(0.96);
}

/* 10. App Install Banner */
.install-banner {
  background: var(--ui-primary);
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  position: sticky;
  top: 0;
  z-index: 1000;
}
.install-banner button {
  background: white;
  color: var(--ui-primary);
  border: none;
  padding: 6px 12px;
  border-radius: 20px;
  font-weight: 600;
  cursor: pointer;
}
.install-banner .close-btn {
  background: transparent;
  color: rgba(255,255,255,0.8);
  font-size: 20px;
  padding: 0 8px;
}
