/* ============================================================
   ENFIITY — Native App Feel (Spotify-Inspired)
   Uses !important to override inline page styles
   ============================================================ */

:root {
  --sat: env(safe-area-inset-top);
  --sar: env(safe-area-inset-right);
  --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --page-bg: #f4f6f8;
}

/* ============================================================
   SOLID BOTTOM TAB BAR + GRADIENT FADE (Spotify-style)
   Content fades seamlessly into the bar via a gradient overlay
   ============================================================ */
.app-nav {
  background: var(--page-bg, #f4f6f8) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border-top: none !important;
  padding: 6px 0 max(6px, env(safe-area-inset-bottom)) !important;
  height: auto !important;
  box-shadow: none !important;
  overflow: visible !important;
}

/* Gradient fade above the bar — content dissolves into it */
.app-nav::before {
  content: '' !important;
  position: absolute !important;
  bottom: 100% !important;
  left: 0 !important;
  right: 0 !important;
  height: 100px !important;
  background: linear-gradient(
    to bottom,
    rgba(244, 246, 248, 0) 0%,
    rgba(244, 246, 248, 0.4) 30%,
    rgba(244, 246, 248, 0.75) 55%,
    var(--page-bg, #f4f6f8) 100%
  ) !important;
  pointer-events: none !important;
  z-index: -1 !important;
}

.app-nav-btn {
  color: #8E8E93 !important;
  font-size: 10px !important;
  font-weight: 500 !important;
  letter-spacing: 0.02em !important;
  gap: 2px !important;
  padding: 6px 0 !important;
  min-height: 44px !important;
  transition: transform 0.15s ease, color 0.2s ease, opacity 0.15s ease !important;
  text-decoration: none !important;
}

.app-nav-btn svg {
  width: 24px !important;
  height: 24px !important;
  stroke-width: 1.6 !important;
}

.app-nav-btn.active {
  color: var(--c, #1ac8db) !important;
  font-weight: 700 !important;
}

.app-nav-btn.active svg {
  stroke-width: 2.2 !important;
}

.app-nav-btn:active {
  transform: scale(0.85) !important;
  opacity: 0.6 !important;
  transition: transform 0.1s ease, opacity 0.1s ease !important;
}

/* ============================================================
   STICKY LOCKING HEADER (Spotify-style)
   Avatar left — Title center — Spacer right
   ============================================================ */
.native-sticky-header {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  height: calc(48px + env(safe-area-inset-top)) !important;
  padding: env(safe-area-inset-top) 16px 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  z-index: 9998 !important;
  background: rgba(244, 246, 248, 0) !important;
  transition: background 0.2s ease, backdrop-filter 0.2s ease !important;
  pointer-events: none !important;
  -webkit-transform: translateZ(0) !important;
  transform: translateZ(0) !important;
  will-change: transform !important;
}

.native-sticky-header.scrolled {
  background: rgba(244, 246, 248, 0.92) !important;
  backdrop-filter: saturate(180%) blur(20px) !important;
  -webkit-backdrop-filter: saturate(180%) blur(20px) !important;
  pointer-events: auto !important;
}

.native-sticky-header.scrolled::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 0.33px;
  background: rgba(0, 0, 0, 0.12);
}

/* --- Profile avatar button (left) --- */
.sticky-avatar {
  width: 32px !important;
  height: 32px !important;
  border-radius: 50% !important;
  border: none !important;
  background: rgba(0, 0, 0, 0.06) !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  overflow: hidden !important;
  flex-shrink: 0 !important;
  pointer-events: none !important;
  opacity: 0 !important;
  transition: transform 0.15s ease, opacity 0.2s ease !important;
  color: #8E8E93 !important;
}
.native-sticky-header.scrolled .sticky-avatar {
  opacity: 1 !important;
  pointer-events: auto !important;
}
.sticky-avatar:active {
  transform: scale(0.88) !important;
  opacity: 0.7 !important;
}
.sticky-avatar-img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  border-radius: 50% !important;
}
.sticky-avatar-initial {
  font-size: 14px !important;
  font-weight: 700 !important;
  color: #fff !important;
  background: var(--c, #1ac8db) !important;
  width: 100% !important;
  height: 100% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  border-radius: 50% !important;
}

/* --- Title (center) --- */
.sticky-title {
  font-size: 17px !important;
  font-weight: 700 !important;
  color: #1a1a2e !important;
  letter-spacing: -0.02em !important;
  opacity: 0 !important;
  transform: translateY(-6px) scale(0.98) !important;
  transition: opacity 0.2s ease, transform 0.2s ease !important;
  position: absolute !important;
  left: 50% !important;
  transform: translateX(-50%) translateY(-6px) scale(0.98) !important;
}
.native-sticky-header.scrolled .sticky-title {
  opacity: 1 !important;
  transform: translateX(-50%) translateY(0) scale(1) !important;
}

/* --- Spacer (right, same width as avatar for centering) --- */
.sticky-spacer {
  width: 32px !important;
  flex-shrink: 0 !important;
  opacity: 0 !important;
}
.native-sticky-header.scrolled .sticky-spacer {
  opacity: 1 !important;
}

/* ============================================================
   ACCOUNT PANEL (slides down from header)
   ============================================================ */
.native-panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 9996;
  pointer-events: none;
  transition: background 0.25s ease;
}
.native-panel-backdrop.open {
  background: rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}

.native-account-panel {
  position: fixed;
  top: calc(48px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  max-width: 340px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.12), 0 1px 3px rgba(0,0,0,0.08);
  z-index: 9997;
  overflow: hidden;
  transform: translateY(-10px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s ease;
}
.native-account-panel.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* Panel header */
.np-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 0.5px solid rgba(0,0,0,0.06);
}
.np-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: rgba(0,0,0,0.04);
}
.panel-av-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.panel-av-initial {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  background: var(--c, #1ac8db);
  border-radius: 50%;
}
.np-info { flex: 1; min-width: 0; }
.np-name {
  font-size: 16px;
  font-weight: 700;
  color: #1a1a2e;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.np-email {
  font-size: 13px;
  color: #8E8E93;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tier badge row */
.np-tier {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 0.5px solid rgba(0,0,0,0.06);
}
.np-tier-name {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a2e;
}
.np-tier-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(26, 200, 219, 0.1);
  color: var(--c, #1ac8db);
  letter-spacing: 0.5px;
}

/* Menu items */
.np-menu, .np-logout {
  padding: 4px 0;
}
.np-logout {
  border-top: 0.5px solid rgba(0,0,0,0.06);
}
.np-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 500;
  color: #1a1a2e;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease;
  font-family: inherit;
}
.np-item:active {
  background: rgba(0,0,0,0.04);
}
.np-danger {
  color: #e74c3c !important;
}

/* Login prompt (logged out state) */
.np-login-prompt {
  padding: 24px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.np-login-text {
  font-size: 14px;
  color: #8E8E93;
  line-height: 1.4;
}
.np-login-btn {
  background: var(--c, #1ac8db);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 32px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s ease, opacity 0.1s ease;
}
.np-login-btn:active {
  transform: scale(0.95);
  opacity: 0.8;
}

/* ============================================================
   PAGE BACKGROUND + FONT SMOOTHING
   No entry animation — it caused black flash in WKWebView
   ============================================================ */
html {
  background: var(--page-bg, #f4f6f8) !important;
}

body {
  -webkit-font-smoothing: antialiased !important;
  -moz-osx-font-smoothing: grayscale !important;
  background: var(--page-bg, #f4f6f8) !important;
}

/* ============================================================
   TOUCH & INTERACTION
   ============================================================ */
* {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

*:not(input):not(textarea):not(select):not([contenteditable="true"]) {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.selectable, .article-content, .chat-bubble p, .insight-body, p.description,
.message-content, .insight-text, .expert-bio {
  -webkit-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
}

/* Spotify-style press feedback: scale + opacity */
.nav-btn:active,
.card:active,
.stat-card:active,
.expert-card:active,
.insight-card:active,
.action-card:active,
.domain-card:active,
.plan-card:active,
.btn:active,
.cta-btn:active,
a[class*="card"]:active,
div[class*="card"]:active {
  transform: scale(0.97) !important;
  opacity: 0.7 !important;
  transition: transform 0.15s ease, opacity 0.15s ease !important;
}

button:active {
  transform: scale(0.92) !important;
  opacity: 0.8 !important;
  transition: transform 0.1s ease, opacity 0.1s ease !important;
}

/* ============================================================
   FROSTED GLASS CARDS (mobile)
   ============================================================ */
@media (max-width: 768px) {
  .stat-card,
  .domain-card {
    background: rgba(255, 255, 255, 0.75) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 0.5px solid rgba(255,255,255,0.6) !important;
    transition: transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 0.15s ease !important;
  }
}

/* ============================================================
   SIDEBAR HIDDEN ON MOBILE + WEBVIEW (force)
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    display: none !important;
  }
  .sidebar.open {
    display: flex !important;
  }
  .app-nav {
    display: flex !important;
  }
  .main {
    margin-left: 0 !important;
    padding-top: max(16px, env(safe-area-inset-top)) !important;
  }
}

html.is-webview .sidebar {
  display: none !important;
}
html.is-webview .sidebar.open {
  display: flex !important;
}
html.is-webview .app-nav {
  display: flex !important;
}
html.is-webview .main {
  margin-left: 0 !important;
  padding-top: max(16px, env(safe-area-inset-top)) !important;
}

/* ============================================================
   SCROLLBAR HIDDEN (native apps never show scrollbars)
   ============================================================ */
::-webkit-scrollbar {
  display: none !important;
}
html {
  -ms-overflow-style: none !important;
  scrollbar-width: none !important;
}

/* Paint over WKWebView's black background — covers status bar area
   AND the overscroll bounce zone above the viewport.
   position:fixed stays put during iOS bounce. */
html::before {
  content: '' !important;
  position: fixed !important;
  top: -100vh !important;
  left: 0 !important;
  right: 0 !important;
  height: calc(100vh + env(safe-area-inset-top, 59px)) !important;
  background: var(--page-bg, #f4f6f8) !important;
  z-index: 99999 !important;
  pointer-events: none !important;
}

/* ============================================================
   SKELETON SHIMMER ANIMATION
   ============================================================ */
.skeleton {
  background: linear-gradient(90deg,
    rgba(0,0,0,0.04) 0%, rgba(0,0,0,0.09) 50%, rgba(0,0,0,0.04) 100%
  ) !important;
  background-size: 200% 100% !important;
  animation: shimmer 1.5s ease-in-out infinite !important;
  border-radius: 8px !important;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text { height: 14px; margin-bottom: 8px; border-radius: 4px; }
.skeleton-text.short { width: 60%; }
.skeleton-text.medium { width: 80%; }
.skeleton-avatar { width: 48px; height: 48px; border-radius: 50%; }
.skeleton-card { height: 120px; border-radius: 16px; }

/* ============================================================
   HAIRLINE SEPARATORS (iOS native 0.33px)
   ============================================================ */
.hairline {
  border: none !important;
  height: 0.33px !important;
  background: rgba(0, 0, 0, 0.15) !important;
}

/* ============================================================
   SAFE AREA HANDLING (standalone PWA)
   ============================================================ */
html {
  min-height: calc(100% + env(safe-area-inset-top));
}

/* Ensure main wrapper covers full viewport height */
.app, .page-content, .content {
  min-height: 100vh !important;
  min-height: 100dvh !important;
  background: var(--page-bg, #f4f6f8) !important;
}

/* ============================================================
   iOS DYNAMIC TYPE HOOK
   ============================================================ */
@supports (font: -apple-system-body) {
  html {
    font: -apple-system-body;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
  }
}

/* ============================================================
   PREVENT iOS ZOOM ON INPUT FOCUS (must be >= 16px)
   ============================================================ */
input, textarea, select {
  font-size: 16px !important;
}

/* View Transitions removed — caused black flash in WKWebView */

/* ============================================================
   BACK BUTTON (detail pages — injected by native.js)
   ============================================================ */
.native-back-btn {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: 8px;
  width: 40px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  z-index: 9999;
  color: var(--c, #1ac8db);
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.native-back-btn svg {
  width: 22px;
  height: 22px;
}
.native-back-btn:active {
  opacity: 0.5;
  transform: scale(0.9);
}

/* ============================================================
   CONTENT-VISIBILITY (render only visible sections)
   Cuts off-screen rendering by 50-80%
   ============================================================ */
.domain-card,
.expert-card,
.insight-card,
.stat-section,
.recent-section,
.evolution-map,
section,
.card-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 200px;
}

/* ============================================================
   MICRO-INTERACTIONS
   ============================================================ */

/* Active tab dot indicator */
.app-nav-btn.active::after {
  content: '' !important;
  display: block !important;
  width: 4px !important;
  height: 4px !important;
  border-radius: 50% !important;
  background: var(--c, #1ac8db) !important;
  margin-top: 2px !important;
}

/* Smooth link/card hover lift (desktop) */
@media (hover: hover) {
  .expert-card,
  .insight-card,
  .domain-card,
  .stat-card,
  .plan-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.15s ease !important;
  }
  .expert-card:hover,
  .insight-card:hover,
  .domain-card:hover,
  .stat-card:hover,
  .plan-card:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08) !important;
  }
}

/* Success pulse animation (usable on any element) */
@keyframes successPulse {
  0%   { box-shadow: 0 0 0 0 rgba(26, 200, 219, 0.4); }
  70%  { box-shadow: 0 0 0 10px rgba(26, 200, 219, 0); }
  100% { box-shadow: 0 0 0 0 rgba(26, 200, 219, 0); }
}
.pulse-success {
  animation: successPulse 0.6s ease !important;
}

/* Loading spinner (reusable) */
@keyframes nativeSpin {
  to { transform: rotate(360deg); }
}
.native-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(0,0,0,0.1);
  border-top-color: var(--c, #1ac8db);
  border-radius: 50%;
  animation: nativeSpin 0.7s linear infinite;
}

/* Content loaded fade-in */
@keyframes contentFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.content-loaded {
  animation: contentFadeIn 0.3s ease both;
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
