/* Mobile / PWA — iOS safe areas, touch targets, install banner */
@supports (padding: env(safe-area-inset-top)) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  #nav { padding-top: env(safe-area-inset-top); }
}

@media (max-width: 768px) {
  .nav-links { display: none; }
  .nav-center { display: none !important; }
  .nav-menu-btn { display: flex; }
  /* The full action row (notifications / import / quick-capture / +Memory /
     avatar, or the guest CTA row) doesn't fit next to the logo + hamburger
     on a phone-width bar — with no wrap/overflow handling it silently
     overflowed off-screen, which is what showed up as "only a few menu
     icons". Every one of these actions now lives in the mobile drawer
     instead (see #nav-mobile-menu below), so the top bar is just
     logo + hamburger on mobile — zero overflow risk at any width. */
  .nav-actions { display: none !important; }
  .container.section { padding-left: 16px; padding-right: 16px; }
  .btn, .nav-link, button { min-height: 44px; }
  .price-card, .vault-card { padding: 16px; }
  .modal-box { max-height: 90vh; overflow-y: auto; margin: 12px; }

  /* Grids with 2+ fixed columns had no phone-width override at all, so
     cards were forced down to ~100px-wide columns and their contents
     (icons/text/buttons) overlapped or overflowed. */
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3, .grid-4 { gap: 12px; }

  /* A fixed-position dropdown sized/positioned for desktop can run past
     the right edge on narrow phones. */
  #nav-notif-panel { left: 12px !important; right: 12px !important; width: auto !important; top: 60px !important; }

  select, #archive-filter { max-width: 100%; }

  /* iOS Safari auto-zooms the whole page on focus for any text input under
     16px — a jarring, distinctly non-premium moment on every single form
     interaction. Base inputs were 14px everywhere. */
  input, textarea, select { font-size: 16px; }
}

@media (max-width: 560px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* Global safety net — any image/video without a component-specific rule
   (e.g. dynamically-mounted reel player content) still shrinks to fit
   instead of forcing horizontal overflow. Low specificity so existing
   scoped rules (.memory-thumb img, etc.) still win. */
img, video { max-width: 100%; height: auto; }

#pwa-install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 500;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(10, 10, 12, 0.96);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

#pwa-install-banner.hidden { display: none; }

.pwa-install-text { font-size: 13px; color: var(--muted); flex: 1; min-width: 180px; }
.pwa-install-text strong { color: var(--gold); display: block; font-size: 14px; }

/* Mobile nav drawer */
.nav-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  margin-left: 8px;
  border: 1px solid var(--border, #1a1a2a);
  border-radius: var(--radius, 8px);
  background: var(--card, rgba(255, 255, 255, 0.04));
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

/* Logged-in only bottom nav (guest must not see member tabs) */
body:not(.lr-logged-in) #bottom-nav {
  display: none !important;
}

@media (max-width: 768px) {
  body.lr-logged-in #bottom-nav.bottom-nav {
    display: flex !important;
  }
}

#bottom-nav-more {
  color: var(--gold, #c9a84c);
  font-weight: 700;
  flex: 1.15;
  min-width: 56px;
}
.bottom-nav-item {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
}
.bottom-nav-item span:last-child {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-mobile-menu {
  position: fixed;
  inset: 0;
  z-index: 300;
  pointer-events: none;
  visibility: hidden;
}

.nav-mobile-menu.open {
  pointer-events: auto;
  visibility: visible;
}

.nav-mobile-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.nav-mobile-menu.open .nav-mobile-backdrop {
  opacity: 1;
}

.nav-mobile-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(320px, 92vw);
  height: 100%;
  background: #0f0f16;
  border-left: 1px solid var(--border, #1a1a2a);
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
}

.nav-mobile-menu.open .nav-mobile-panel {
  transform: translateX(0);
}

.nav-mobile-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border, #1a1a2a);
}

.nav-mobile-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-mobile-link {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: none;
  border-radius: var(--radius, 8px);
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
}

.nav-mobile-link:hover,
.nav-mobile-link:active {
  background: var(--card, rgba(255, 255, 255, 0.06));
}

.nav-mobile-link-highlight {
  color: var(--gold, #c9a84c);
  background: rgba(201, 168, 76, 0.08);
  border: 1px solid rgba(201, 168, 76, 0.25);
}

/* Quick-action row (Quick capture / Notifications) — the two highest-
   frequency actions get a prominent pair of tiles up top instead of being
   buried in the alphabetical link list below. */
.nav-mobile-quickrow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}

.nav-mobile-quick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  border: 1px solid rgba(201, 168, 76, 0.2);
  border-radius: var(--radius, 8px);
  background: rgba(201, 168, 76, 0.06);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.nav-mobile-quick:active {
  background: rgba(201, 168, 76, 0.14);
}

.nav-mobile-quick-icon {
  position: relative;
  font-size: 20px;
  line-height: 1;
}

.nav-mobile-quick-icon .notif-dot {
  position: absolute;
  top: -4px;
  right: -8px;
}

.nav-mobile-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ivory, #f7f4ec);
  opacity: 0.78;
  margin: 18px 4px 6px;
}

.nav-mobile-section-label:first-of-type {
  margin-top: 4px;
}

.nav-mobile-link-danger {
  color: #e8b4b4 !important;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin-top: 8px;
  padding-top: 14px;
}

/* Stagger-in for the drawer's own content once it opens — the
   backdrop/panel slide is handled above; this is the list settling in
   item-by-item rather than fading as one flat block. */
.nav-mobile-menu.open .nav-mobile-link,
.nav-mobile-menu.open .nav-mobile-quick {
  animation: navMobileItemIn 0.28s ease backwards;
}

.nav-mobile-quick:nth-of-type(1) { animation-delay: 0.02s; }
.nav-mobile-quick:nth-of-type(2) { animation-delay: 0.05s; }
.nav-mobile-link:nth-of-type(1)  { animation-delay: 0.08s; }
.nav-mobile-link:nth-of-type(2)  { animation-delay: 0.10s; }
.nav-mobile-link:nth-of-type(3)  { animation-delay: 0.12s; }
.nav-mobile-link:nth-of-type(4)  { animation-delay: 0.14s; }
.nav-mobile-link:nth-of-type(5)  { animation-delay: 0.16s; }
.nav-mobile-link:nth-of-type(6)  { animation-delay: 0.18s; }
.nav-mobile-link:nth-of-type(7)  { animation-delay: 0.20s; }
.nav-mobile-link:nth-of-type(8)  { animation-delay: 0.22s; }
.nav-mobile-link:nth-of-type(9)  { animation-delay: 0.24s; }
.nav-mobile-link:nth-of-type(10) { animation-delay: 0.26s; }
.nav-mobile-link:nth-of-type(n+11) { animation-delay: 0.28s; }

@keyframes navMobileItemIn {
  from { opacity: 0; transform: translateX(8px); }
  to { opacity: 1; transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .nav-mobile-menu.open .nav-mobile-link,
  .nav-mobile-menu.open .nav-mobile-quick {
    animation: none;
  }
}

body.nav-menu-open {
  overflow: hidden;
}
