/* ============================================================
   features.win — PWA Mobile Stylesheet
   Scope: loaded on all pages, activates only on PWA / small screens
   ============================================================ */

/* ─── Design tokens (mirror customnew.css) ─────────────────── */
:root {
  --pwa-bg:           #0a0a0a;
  --pwa-surface:      #161616;
  --pwa-surface2:     #1e1e1e;
  --pwa-border:       rgba(255,255,255,0.07);
  --pwa-accent:       #a49dc6;
  --pwa-accent-glow:  rgba(164,157,198,0.18);
  --pwa-pink:         #e14eca;
  --pwa-pink-glow:    rgba(225,78,202,0.18);
  --pwa-text:         #e8e8e8;
  --pwa-text-dim:     rgba(255,255,255,0.45);
  --pwa-radius:       16px;
  --pwa-radius-sm:    10px;
  --pwa-nav-h:        60px;       /* top nav height             */
  --pwa-safe-b:       env(safe-area-inset-bottom, 0px);
  --pwa-safe-t:       env(safe-area-inset-top, 0px);
  --pwa-ease:         cubic-bezier(.4, 0, .2, 1);
  --pwa-spring:       cubic-bezier(.175, .885, .32, 1.275);
}

/* ─── PWA standalone detection ─────────────────────────────── */
/* These rules apply ONLY when running as installed PWA */
@media (display-mode: standalone) {
  /* hide the sidebar on iOS PWA — we use top nav instead */
  .sidebar,
  #sidebar,
  .sb-edge-toggle,
  #sidebarToggle,
  .sb-mobile-toggle,
  #mobileToggle,
  .sb-mobile-overlay,
  #mobileOverlay {
    display: none !important;
  }
  .main-content {
    margin-left: 0 !important;
    padding-top: calc(var(--pwa-nav-h) + var(--pwa-safe-t) + 16px) !important;
  }
}

/* ─── Top Nav ───────────────────────────────────────────────── */
.pwa-bottom-nav {
  display: none;             /* hidden on desktop */
}

@media (max-width: 768px) {
  /* push entire page body below the fixed nav — covers every wrapper type */
  body {
    padding-top: calc(var(--pwa-nav-h) + var(--pwa-safe-t)) !important;
  }

  .pwa-bottom-nav {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    height: calc(var(--pwa-nav-h) + var(--pwa-safe-t));
    padding-top: var(--pwa-safe-t);
    /* Solid opaque background — backdrop-filter removed on mobile (causes
       iOS Safari fixed-element disappear bug on URL-bar show/hide) */
    background: #0e0e0e;
    border-bottom: 1px solid var(--pwa-border);
    align-items: stretch;
    overflow: hidden;
    box-shadow: 0 2px 16px rgba(0,0,0,0.6);
    /* Persistent GPU layer */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: transform;
  }

  /* remove double padding — body offset already handles it */
  .container,
  .container-fluid {
    padding-top: 16px !important;
  }

  /* hide sidebar completely on mobile — top nav takes over */
  .sidebar,
  #sidebar,
  .sb-edge-toggle,
  #sidebarToggle,
  .sb-mobile-toggle,
  #mobileToggle,
  .sb-mobile-overlay,
  #mobileOverlay {
    display: none !important;
  }

  .main-content {
    margin-left: 0 !important;
    padding-top: 16px !important;
  }
}

/* ─── Bottom Nav Items ──────────────────────────────────────────── */
/* Each item = 1/4.3 of viewport so 4 items fill screen with ~7% peek of 5th */
.pwa-nav-item {
  flex-shrink: 0;
  width: calc(100vw / 4.3);
  min-width: 56px;
  max-width: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 2px 4px 10px;
  text-decoration: none;
  color: var(--pwa-text-dim);
  transition: color 0.2s var(--pwa-ease), transform 0.2s var(--pwa-spring);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
}

.pwa-nav-item:active {
  transform: scale(0.88);
}

.pwa-nav-item.active {
  color: var(--pwa-accent);
}

.pwa-nav-item .pwa-nav-icon {
  font-size: 1.25rem;
  transition: transform 0.25s var(--pwa-spring);
  position: relative;
}

.pwa-nav-item.active .pwa-nav-icon {
  transform: translateY(2px) scale(1.1);
}

/* Active indicator pill */
.pwa-nav-item.active::before {
  content: '';
  position: absolute;
  bottom: 0;
  top: auto;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  border-radius: 4px 4px 0 0;
  background: var(--pwa-accent);
  animation: pwa-pill-in 0.3s var(--pwa-spring) forwards;
}

@keyframes pwa-pill-in {
  from { width: 0; opacity: 0; }
  to   { width: 32px; opacity: 1; }
}

.pwa-nav-label {
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  transition: color 0.2s var(--pwa-ease);
}

/* Badge on nav icon */
.pwa-nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 20px);
  background: var(--pwa-pink);
  color: #fff;
  font-size: 0.55rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
  border: 2px solid var(--pwa-bg);
}

/* ─── Page transitions ──────────────────────────────────────── */
@media (max-width: 768px) {
  .pwa-page-enter {
    animation: pwa-fade-up 0.32s var(--pwa-ease) both;
  }

  @keyframes pwa-fade-up {
    from {
      opacity: 0;
      transform: translateY(18px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* View Transitions API (iOS 17.2+, Chrome 111+) */
@view-transition {
  navigation: auto;
}

::view-transition-old(root) {
  animation: 0.22s ease-in both pwa-vt-out;
}

::view-transition-new(root) {
  animation: 0.28s var(--pwa-ease) both pwa-vt-in;
}

@keyframes pwa-vt-out {
  to { opacity: 0; transform: scale(0.96); }
}

@keyframes pwa-vt-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
}

/* ─── Install prompt banner ─────────────────────────────────── */
.pwa-install-banner {
  display: none;
  position: fixed;
  bottom: 16px;
  left: 12px;
  right: 12px;
  z-index: 10000;
  background: var(--pwa-surface2);
  border: 1px solid var(--pwa-border);
  border-radius: var(--pwa-radius);
  padding: 14px 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6), 0 0 0 1px var(--pwa-accent-glow);
  animation: pwa-banner-in 0.4s var(--pwa-spring) forwards;
  align-items: center;
  gap: 12px;
}

.pwa-install-banner.visible {
  display: flex;
}

@keyframes pwa-banner-in {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)  scale(1); }
}

.pwa-install-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  flex-shrink: 0;
  object-fit: cover;
}

.pwa-install-text {
  flex: 1;
  min-width: 0;
}

.pwa-install-text strong {
  display: block;
  color: var(--pwa-text);
  font-size: 0.88rem;
  margin-bottom: 2px;
}

.pwa-install-text span {
  color: var(--pwa-text-dim);
  font-size: 0.75rem;
}

.pwa-install-btn {
  background: var(--pwa-accent);
  color: #0a0a0a;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s var(--pwa-ease), transform 0.15s var(--pwa-spring);
  -webkit-tap-highlight-color: transparent;
}

.pwa-install-btn:active {
  transform: scale(0.93);
}

.pwa-install-close {
  background: none;
  border: none;
  color: var(--pwa-text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

/* ─── iOS add-to-home hint ──────────────────────────────────── */
.pwa-ios-hint {
  display: none;
  position: fixed;
  bottom: 80px;
  left: 16px;
  right: 16px;
  z-index: 10000;
  background: var(--pwa-surface2);
  border: 1px solid var(--pwa-border);
  border-radius: var(--pwa-radius);
  padding: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  text-align: center;
  animation: pwa-banner-in 0.4s var(--pwa-spring) forwards;
}

.pwa-ios-hint.visible {
  display: block;
}

.pwa-ios-hint::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid var(--pwa-surface2);
}

.pwa-ios-hint p {
  color: var(--pwa-text);
  font-size: 0.85rem;
  margin: 0 0 8px;
  line-height: 1.5;
}

.pwa-ios-hint .hint-icon {
  color: var(--pwa-accent);
  font-size: 1.2rem;
}

.pwa-ios-hint-close {
  background: none;
  border: none;
  color: var(--pwa-text-dim);
  font-size: 0.75rem;
  cursor: pointer;
  text-decoration: underline;
  margin-top: 8px;
  display: block;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Pull-to-refresh indicator ─────────────────────────────── */
.pwa-ptr {
  position: fixed;
  top: calc(var(--pwa-nav-h) + var(--pwa-safe-t) + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(-80px);
  z-index: 9998;
  background: var(--pwa-surface2);
  border: 1px solid var(--pwa-border);
  border-radius: 24px;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--pwa-text-dim);
  transition: transform 0.25s var(--pwa-ease), opacity 0.25s var(--pwa-ease);
  pointer-events: none;
  opacity: 0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.pwa-ptr.pulling {
  opacity: 1;
}

.pwa-ptr.refreshing {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.pwa-ptr .ptr-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--pwa-border);
  border-top-color: var(--pwa-accent);
  border-radius: 50%;
  animation: pwa-spin 0.8s linear infinite;
}

@keyframes pwa-spin {
  to { transform: rotate(360deg); }
}

/* ─── Toast notifications ───────────────────────────────────── */
.pwa-toast-container {
  position: fixed;
  top: calc(var(--pwa-nav-h) + var(--pwa-safe-t) + 8px);
  left: 16px;
  right: 16px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

@media (min-width: 769px) {
  .pwa-toast-container {
    left: auto;
    right: 24px;
    max-width: 360px;
  }
}

.pwa-toast {
  background: var(--pwa-surface2);
  border: 1px solid var(--pwa-border);
  border-radius: var(--pwa-radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  animation: pwa-toast-in 0.3s var(--pwa-spring) forwards;
  pointer-events: all;
  cursor: pointer;
}

.pwa-toast.exiting {
  animation: pwa-toast-out 0.25s var(--pwa-ease) forwards;
}

@keyframes pwa-toast-in {
  from { opacity: 0; transform: translateY(-12px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0)     scale(1); }
}

@keyframes pwa-toast-out {
  to { opacity: 0; transform: translateY(-6px) scale(0.96); }
}

.pwa-toast-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.pwa-toast-text {
  flex: 1;
  font-size: 0.83rem;
  color: var(--pwa-text);
  line-height: 1.4;
}

.pwa-toast.success { border-left: 3px solid #4caf50; }
.pwa-toast.error   { border-left: 3px solid #e74c3c; }
.pwa-toast.info    { border-left: 3px solid var(--pwa-accent); }
.pwa-toast.warning { border-left: 3px solid #f39c12; }

.pwa-toast.success .pwa-toast-icon { color: #4caf50; }
.pwa-toast.error   .pwa-toast-icon { color: #e74c3c; }
.pwa-toast.info    .pwa-toast-icon { color: var(--pwa-accent); }
.pwa-toast.warning .pwa-toast-icon { color: #f39c12; }

/* ─── Smooth card interactions on mobile ─────────────────────── */
@media (max-width: 768px) {
  .card {
    transition: transform 0.2s var(--pwa-spring), box-shadow 0.2s var(--pwa-ease);
  }

  .card:active {
    transform: scale(0.98);
  }

  /* Larger touch targets */
  .btn {
    min-height: 44px;
    border-radius: 10px !important;
  }

  .form-control {
    min-height: 44px;
    border-radius: 10px !important;
    font-size: 16px !important; /* prevent iOS zoom on focus */
  }

  .nav-link,
  .btn,
  a[role="button"],
  button {
    -webkit-tap-highlight-color: transparent;
  }

  /* Scrollable tables */
  .table-responsive {
    border-radius: var(--pwa-radius-sm);
    -webkit-overflow-scrolling: touch;
  }
}

/* ─── Status bar area (iPhone with notch/dynamic island) ──────── */
@supports (padding-top: env(safe-area-inset-top)) {
  @media (display-mode: standalone) {
    .main-content {
      padding-top: calc(var(--pwa-nav-h) + env(safe-area-inset-top) + 16px) !important;
    }
  }
}

/* ─── Offline mode indicator ────────────────────────────────── */
.pwa-offline-bar {
  display: none;
  position: fixed;
  top: calc(var(--pwa-nav-h) + var(--pwa-safe-t));
  left: 0;
  right: 0;
  z-index: 99998;
  background: #e74c3c;
  color: #fff;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 12px;
  letter-spacing: 0.3px;
}

.pwa-offline-bar.visible {
  display: block;
}

/* ─── Ripple effect for tap feedback ─────────────────────────── */
.pwa-ripple {
  position: relative;
  overflow: hidden;
}

.pwa-ripple::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--pwa-rx, 50%) var(--pwa-ry, 50%), rgba(255,255,255,0.12) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.4s var(--pwa-ease);
  pointer-events: none;
}

.pwa-ripple:active::after {
  opacity: 1;
  transition: opacity 0s;
}

/* ─── Loading skeleton (for async content) ───────────────────── */
.pwa-skeleton {
  background: linear-gradient(90deg, var(--pwa-surface) 25%, var(--pwa-surface2) 50%, var(--pwa-surface) 75%);
  background-size: 200% 100%;
  animation: pwa-shimmer 1.5s infinite;
  border-radius: var(--pwa-radius-sm);
}

@keyframes pwa-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ─── Haptic feedback polyfill via CSS ───────────────────────── */
/* Ensures visual feedback on iOS even without Haptic API */
.pwa-tap-scale:active {
  transform: scale(0.94) !important;
  transition: transform 0.1s var(--pwa-ease) !important;
}

/* ─── Network status colors on bottom nav ────────────────────── */
.pwa-network-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4caf50;
  position: absolute;
  bottom: 14px;
  right: calc(50% - 18px);
  transition: background 0.3s;
}

.offline .pwa-network-dot {
  background: #e74c3c;
}

/* ─── App Launch Splash Screen ─────────────────────────────────── */
#pwa-splash {
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: var(--pwa-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s cubic-bezier(.4,0,.2,1), transform 0.5s cubic-bezier(.4,0,.2,1);
}

#pwa-splash.dismissing {
  opacity: 0;
  transform: scale(1.04);
  pointer-events: none;
}

.pwa-splash-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  animation: splash-enter 0.6s cubic-bezier(.175,.885,.32,1.275) forwards;
}

@keyframes splash-enter {
  from { opacity: 0; transform: translateY(20px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Logo container with rings */
.pwa-splash-logo-wrap {
  position: relative;
  width: 88px;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pwa-splash-rings {
  position: absolute;
  inset: 0;
}

.pwa-splash-rings div {
  position: absolute;
  border-radius: 50%;
  border: 1.5px solid var(--pwa-accent);
  animation: splash-ring-pulse 2s ease-in-out infinite;
}

.pwa-splash-rings div:nth-child(1) { inset: -0px;  animation-delay: 0s;    opacity: 0.55; }
.pwa-splash-rings div:nth-child(2) { inset: -18px; animation-delay: 0.4s;  opacity: 0.30; }
.pwa-splash-rings div:nth-child(3) { inset: -36px; animation-delay: 0.8s;  opacity: 0.14; }

@keyframes splash-ring-pulse {
  0%, 100% { transform: scale(0.92); }
  50%       { transform: scale(1.06); }
}

.pwa-splash-logo {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  object-fit: contain;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 0 16px rgba(164,157,198,0.35));
  animation: splash-logo-glow 2s ease-in-out infinite;
}

@keyframes splash-logo-glow {
  0%, 100% { filter: drop-shadow(0 0 10px rgba(164,157,198,0.25)); }
  50%       { filter: drop-shadow(0 0 26px rgba(164,157,198,0.55)); }
}

.pwa-splash-name {
  font-family: -apple-system, 'SF Pro Display', 'Segoe UI', sans-serif;
  font-size: 1.45rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
  animation: splash-text-in 0.5s ease 0.3s both;
}

.pwa-splash-name span {
  color: var(--pwa-accent);
}

@keyframes splash-text-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.pwa-splash-bar {
  position: relative;
  width: 120px;
  height: 3px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
  animation: splash-text-in 0.5s ease 0.5s both;
}

.pwa-splash-progress {
  position: absolute;
  top: 0;
  left: -40%;
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, transparent, var(--pwa-accent), transparent);
  border-radius: 2px;
  animation: splash-shimmer 1.5s ease-in-out infinite;
}

@keyframes splash-shimmer {
  0%   { left: -40%; }
  100% { left: 140%; }
}

/* ─── Scroll-reveal (mobile only) ──────────────────────────────── */
@media (max-width: 768px) {
  .pwa-anim-hidden {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.45s ease, transform 0.45s cubic-bezier(.175,.885,.32,1.275);
    will-change: opacity, transform;
  }

  .pwa-anim-in {
    opacity: 1 !important;
    transform: translateY(0) !important;
  }

  /* Stagger siblings */
  .pwa-anim-hidden:nth-child(1) { transition-delay: 0.00s; }
  .pwa-anim-hidden:nth-child(2) { transition-delay: 0.07s; }
  .pwa-anim-hidden:nth-child(3) { transition-delay: 0.14s; }
  .pwa-anim-hidden:nth-child(4) { transition-delay: 0.21s; }
  .pwa-anim-hidden:nth-child(5) { transition-delay: 0.28s; }
  .pwa-anim-hidden:nth-child(6) { transition-delay: 0.35s; }
  .pwa-anim-hidden:nth-child(7) { transition-delay: 0.42s; }
  .pwa-anim-hidden:nth-child(8) { transition-delay: 0.49s; }
}

/* ─── Touch ripple ──────────────────────────────────────────────── */
.pwa-touch-ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  transform: scale(0);
  animation: pwa-ripple-expand 0.55s ease-out forwards;
  pointer-events: none;
  z-index: 0;
}

@keyframes pwa-ripple-expand {
  to { transform: scale(4); opacity: 0; }
}
