/* ==========================================================================
   CYBERVIS — Mobile App Shell
   Shared polish that makes the site + dashboards feel native on phones.
   Safe to include on every page; most rules only fire on mobile viewports
   or when display-mode is standalone (installed PWA).
   ========================================================================== */

/* --- Safe-area + viewport-fit + smooth scroll ---------------------------- */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --bottom-nav-height: 64px;
  --app-accent: #6C3CE1;
}

html { -webkit-text-size-adjust: 100%; }

body {
  /* Prevent iOS bounce blank area above/below on installed PWA */
  overscroll-behavior-y: contain;
}

/* --- Kill tap highlight + 300ms delay on mobile -------------------------- */
a, button, [role="button"], .cv-nav-item, .mobile-bottom-nav__item {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* --- Prevent iOS zoom-on-focus for form inputs --------------------------- */
@media (max-width: 768px) {
  input, select, textarea {
    font-size: 16px !important;
  }
  /* Minimum 44px tap targets on touch nav elements */
  .btn, .cv-btn, .cv-nav-item, button.cv-sidebar-collapse, a.nav-link {
    min-height: 44px;
  }
}

/* --- Standalone/installed PWA styling ------------------------------------ */
@media (display-mode: standalone) {
  /* Push content below iOS status bar when in standalone */
  body {
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
  }
  /* Hide “external browser” chrome the user would never see anyway */
  .pwa-hide-when-installed { display: none !important; }
}

/* --- Smooth native-feeling scroll on mobile ------------------------------ */
@media (max-width: 1024px) {
  html, body {
    -webkit-overflow-scrolling: touch;
  }
}

/* --- View Transitions (Chrome/Edge/Safari 18+) --------------------------- */
@view-transition {
  navigation: auto;
}
::view-transition-old(root) {
  animation: 180ms ease-out both fade-out, 220ms cubic-bezier(.2,.8,.2,1) both slide-out;
}
::view-transition-new(root) {
  animation: 220ms ease-in both fade-in, 260ms cubic-bezier(.2,.8,.2,1) both slide-in;
}
@keyframes fade-out { to { opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes slide-out { to { transform: translateX(-2%); } }
@keyframes slide-in { from { transform: translateX(2%); } }

/* ==========================================================================
   Install banner (shows once, on mobile, when install prompt is available)
   ========================================================================== */
.pwa-install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-bottom));
  z-index: 9999;
  background: #1A1A2E;
  color: #fff;
  border-radius: 16px;
  padding: 14px 16px;
  display: none;
  align-items: center;
  gap: 12px;
  box-shadow: 0 20px 60px -20px rgba(0,0,0,0.5);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', system-ui, sans-serif;
}
.pwa-install-banner.is-visible { display: flex; }
.pwa-install-banner__icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, #6C3CE1, #8b5cf6);
  display: grid; place-items: center; flex-shrink: 0;
  color: #fff; font-weight: 700;
}
.pwa-install-banner__text {
  flex: 1; font-size: 13px; line-height: 1.35;
}
.pwa-install-banner__text strong { display: block; font-size: 14px; margin-bottom: 2px; }
.pwa-install-banner__text small { opacity: 0.7; }
.pwa-install-banner__btn {
  background: #FF6B2B; color: #fff; border: 0;
  padding: 10px 14px; border-radius: 10px;
  font-weight: 600; font-size: 13px;
  min-height: 40px; cursor: pointer;
}
.pwa-install-banner__close {
  background: transparent; border: 0; color: #fff; opacity: 0.6;
  font-size: 18px; cursor: pointer; padding: 4px 6px;
}

/* ==========================================================================
   Mobile bottom tab bar (dashboards)
   Shown only on mobile; desktop keeps its existing sidebar.
   ========================================================================== */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  .mobile-bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 1000;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    background: rgba(255,255,255,0.96);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    backdrop-filter: saturate(180%) blur(18px);
    border-top: 1px solid rgba(0,0,0,0.08);
    padding-bottom: var(--safe-bottom);
    height: calc(var(--bottom-nav-height) + var(--safe-bottom));
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', system-ui, sans-serif;
  }
  .mobile-bottom-nav--dark {
    background: rgba(26,26,46,0.92);
    border-top-color: rgba(255,255,255,0.08);
  }
  .mobile-bottom-nav__item {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 3px;
    background: transparent; border: 0;
    color: #6B6B6B;
    font-size: 10px; font-weight: 600;
    padding: 6px 4px;
    cursor: pointer;
    min-height: 44px;
    text-decoration: none;
    transition: color 120ms ease, transform 120ms ease;
  }
  .mobile-bottom-nav--dark .mobile-bottom-nav__item { color: rgba(255,255,255,0.6); }
  .mobile-bottom-nav__item i { font-size: 18px; }
  .mobile-bottom-nav__item.is-active {
    color: var(--app-accent);
  }
  .mobile-bottom-nav--dark .mobile-bottom-nav__item.is-active { color: #a78bfa; }
  .mobile-bottom-nav__item:active { transform: scale(0.94); }

  /* Give content room above the bar so nothing is hidden behind it. */
  body.has-mobile-bottom-nav {
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 8px);
  }
}

/* ==========================================================================
   Dashboard-specific mobile polish (applies to admin + portal shells)
   ========================================================================== */
@media (max-width: 768px) {
  /* Hide the desktop sidebar on mobile; bottom nav replaces it */
  .cv-sidebar { display: none !important; }
  .cv-app { grid-template-columns: 1fr !important; }
  .cv-main { margin-left: 0 !important; }

  /* Topbar stays sticky with safe-area respect */
  .cv-topbar {
    padding-top: max(12px, var(--safe-top));
  }
}

/* ==========================================================================
   Pull-to-refresh style hint (visual only; behaviour left to browsers)
   ========================================================================== */
@media (max-width: 768px) {
  body { overscroll-behavior-y: contain; }
}

/* ==========================================================================
   Reduced motion respect
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none !important; }
  * { scroll-behavior: auto !important; }
}
