/* ═══════════════════════════════════════════
   Atlas OS — Mobile PWA Enhancements v2.0
   ═══════════════════════════════════════════ */

/* ── PWA Install Banner ── */
.pwa-install-banner {
  display: none;
  position: fixed;
  bottom: 80px;
  left: 16px;
  right: 16px;
  z-index: 9999;
  background: linear-gradient(135deg, #1a1a2e 0%, #16162a 100%);
  border: 1px solid rgba(139,92,246,.25);
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  animation: slideUp .4s cubic-bezier(.16,1,.3,1);
}
.pwa-install-banner.show { display: flex; align-items: center; gap: 14px; }
.pwa-install-banner .pwa-icon {
  width: 48px; height: 48px; border-radius: 12px;
  background: rgba(139,92,246,.15);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.pwa-install-banner .pwa-icon svg { width: 28px; height: 28px; color: #8B5CF6; }
.pwa-install-banner .pwa-text { flex: 1; }
.pwa-install-banner .pwa-text h4 { font-size: .9rem; font-weight: 600; color: #f0f0f5; margin-bottom: 2px; }
.pwa-install-banner .pwa-text p { font-size: .75rem; color: #9090a8; }
.pwa-install-banner .pwa-actions { display: flex; gap: 8px; flex-shrink: 0; }
.pwa-install-btn {
  background: #8B5CF6; color: #fff; border: none;
  padding: 8px 18px; border-radius: 8px;
  font-size: .8rem; font-weight: 600; cursor: pointer;
  transition: all .2s;
}
.pwa-install-btn:hover { background: #7c3aed; }
.pwa-dismiss-btn {
  background: transparent; color: #9090a8; border: none;
  padding: 8px; cursor: pointer; font-size: 1.1rem;
}

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

/* ── Bottom Navigation (mobile only) ── */
.atlas-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 9990;
  background: rgba(10,10,18,.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255,255,255,.06);
  padding: 0 0 env(safe-area-inset-bottom);
  height: calc(64px + env(safe-area-inset-bottom));
}
.atlas-bottom-nav-inner {
  display: flex; align-items: center; justify-content: space-around;
  height: 64px; max-width: 500px; margin: 0 auto;
}
.atlas-bottom-nav a {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 8px 12px;
  text-decoration: none; color: #9090a8;
  font-size: .65rem; font-weight: 500;
  transition: color .2s;
  -webkit-tap-highlight-color: transparent;
  min-width: 56px;
}
.atlas-bottom-nav a.active { color: #8B5CF6; }
.atlas-bottom-nav a:hover { color: #f0f0f5; }
.atlas-bottom-nav a svg { width: 22px; height: 22px; }
.atlas-bottom-nav a .nav-dot {
  width: 4px; height: 4px; border-radius: 50%;
  background: #8B5CF6; display: none;
}
.atlas-bottom-nav a.active .nav-dot { display: block; }

/* ── Mobile hamburger menu ── */
.mobile-hamburger {
  display: none;
  width: 44px; height: 44px;
  border: none; background: transparent;
  cursor: pointer; padding: 10px;
  -webkit-tap-highlight-color: transparent;
}
.mobile-hamburger span {
  display: block; width: 24px; height: 2px;
  background: #f0f0f5; border-radius: 2px;
  transition: all .3s;
}
.mobile-hamburger span + span { margin-top: 6px; }
.mobile-hamburger.open span:first-child { transform: rotate(45deg) translate(4px, 6px); }
.mobile-hamburger.open span:nth-child(2) { opacity: 0; }
.mobile-hamburger.open span:last-child { transform: rotate(-45deg) translate(4px, -6px); }

/* ── Mobile sidebar overlay ── */
.mobile-sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.6);
  z-index: 9980;
  opacity: 0;
  transition: opacity .3s;
}
.mobile-sidebar-overlay.show { display: block; opacity: 1; }

/* ── Pull to refresh indicator ── */
.pull-to-refresh {
  position: fixed;
  top: 0; left: 50%;
  transform: translateX(-50%) translateY(-60px);
  z-index: 9995;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(139,92,246,.15);
  border: 2px solid rgba(139,92,246,.3);
  display: flex; align-items: center; justify-content: center;
  transition: transform .3s;
}
.pull-to-refresh.pulling { transform: translateX(-50%) translateY(20px); }
.pull-to-refresh svg {
  width: 20px; height: 20px; color: #8B5CF6;
  transition: transform .3s;
}
.pull-to-refresh.refreshing svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════
   RESPONSIVE — MOBILE
   ══════════════════════════ */
@media (max-width: 768px) {
  /* Show bottom nav */
  .atlas-bottom-nav { display: block; }

  /* Show hamburger */
  .mobile-hamburger { display: flex; flex-direction: column; justify-content: center; }

  /* Ensure body padding for bottom nav */
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

  /* Touch-friendly buttons: min 44px */
  button, a.btn, .btn, [role="button"],
  input[type="submit"], input[type="button"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Fix nav for mobile */
  nav { padding: 0 16px; }
  .nav-links { display: none; }
  .nav-right .nav-login, .nav-right .nav-cta { display: none; }

  /* Sidebar collapse on mobile */
  .sidebar, [class*="sidebar"] {
    position: fixed !important;
    left: -280px !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 280px !important;
    z-index: 9985 !important;
    transition: left .3s cubic-bezier(.16,1,.3,1) !important;
    overflow-y: auto !important;
  }
  .sidebar.open, [class*="sidebar"].open {
    left: 0 !important;
  }

  /* Tables scroll horizontally */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Cards full width */
  .grid { grid-template-columns: 1fr !important; }

  /* Headings smaller */
  h1 { font-size: 1.5rem !important; }
  h2 { font-size: 1.25rem !important; }

  /* Modal/dialog full screen on mobile */
  .modal, [role="dialog"] {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    border-radius: 16px 16px 0 0 !important;
    bottom: 0 !important;
    top: auto !important;
  }
}

/* ══════════════════════════
   RESPONSIVE — TABLET
   ══════════════════════════ */
@media (min-width: 769px) and (max-width: 1024px) {
  .atlas-bottom-nav { display: none; }
  nav { padding: 0 24px; }
}

/* ── Safe areas for iOS ── */
@supports (padding: env(safe-area-inset-top)) {
  nav { padding-top: env(safe-area-inset-top); }
  .atlas-bottom-nav { padding-bottom: env(safe-area-inset-bottom); }
}

/* ── Standalone mode adjustments ── */
@media (display-mode: standalone) {
  nav {
    padding-top: env(safe-area-inset-top, 0px);
  }
  body {
    -webkit-user-select: none;
    user-select: none;
  }
  /* Disable pull-down browser chrome */
  html { overscroll-behavior-y: contain; }
}
