/**
 * ThinkTree PWA Mobile-First CSS
 * Beautiful splash screen and mobile-optimized UI
 */

/* ============================================
   PWA SPLASH SCREEN
   ============================================ */
.pwa-splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  /* Dynamic viewport height for mobile */
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999999;
  transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
  overflow: hidden;
}

.pwa-splash-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Animated background patterns */
.pwa-splash-screen::before {
  content: '';
  position: absolute;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(224, 159, 62, 0.2) 0%, transparent 70%);
  top: -100px;
  right: -100px;
  animation: pulse 3s ease-in-out infinite;
}

.pwa-splash-screen::after {
  content: '';
  position: absolute;
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
  bottom: -50px;
  left: -50px;
  animation: pulse 3s ease-in-out infinite 1.5s;
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(1);
    opacity: 0.5;
  }

  50% {
    transform: scale(1.2);
    opacity: 0.8;
  }
}

/* Logo container */
.pwa-splash-logo {
  position: relative;
  z-index: 2;
  animation: logoEntry 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
  transform: scale(0.5);
}

@keyframes logoEntry {
  0% {
    opacity: 0;
    transform: scale(0.5) translateY(30px);
  }

  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.pwa-splash-logo img {
  width: 140px;
  height: 140px;
  border-radius: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: logoPulse 2s ease-in-out infinite 0.8s;
}

.pwa-splash-logo img.splash-logo-full {
  width: 280px;
  height: auto;
  border-radius: 0;
  box-shadow: none;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.2));
}

@keyframes logoPulse {

  0%,
  100% {
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  }

  50% {
    box-shadow: 0 25px 80px rgba(224, 159, 62, 0.4);
  }
}

.splash-logo-full {
  animation: logoPulseFull 2s ease-in-out infinite 0.8s !important;
}

@keyframes logoPulseFull {

  0%,
  100% {
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.2));
  }

  50% {
    filter: drop-shadow(0 15px 30px rgba(224, 159, 62, 0.4));
  }
}

/* App name */
.pwa-splash-title {
  position: relative;
  z-index: 2;
  margin-top: 2rem;
  text-align: center;
  animation: titleEntry 0.6s ease-out forwards 0.3s;
  opacity: 0;
}

@keyframes titleEntry {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.pwa-splash-title h1 {
  font-family: 'Cairo', sans-serif;
  font-size: 2.5rem;
  font-weight: 800;
  color: #1A3A2A;
  margin: 0;
  letter-spacing: -0.02em;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.pwa-splash-title p {
  font-family: 'Cairo', sans-serif;
  font-size: 1rem;
  color: #417D5A;
  margin-top: 0.5rem;
  font-weight: 500;
}

/* Loading spinner */
.pwa-splash-loader {
  position: relative;
  z-index: 2;
  margin-top: 3rem;
  animation: loaderEntry 0.4s ease-out forwards 0.6s;
  opacity: 0;
}

@keyframes loaderEntry {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

.pwa-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #E09F3E;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Loading dots alternative */
.pwa-loading-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.pwa-loading-dots span {
  width: 12px;
  height: 12px;
  background: #E09F3E;
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite both;
}

.pwa-loading-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.pwa-loading-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

.pwa-loading-dots span:nth-child(3) {
  animation-delay: 0s;
}

@keyframes bounce {

  0%,
  80%,
  100% {
    transform: scale(0.6);
    opacity: 0.5;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Chess pieces decoration */
.pwa-splash-chess-pieces {
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
}

.chess-piece {
  position: absolute;
  font-size: 2rem;
  color: #417D5A;
  animation: float 6s ease-in-out infinite;
}

.chess-piece:nth-child(1) {
  top: 10%;
  left: 10%;
  animation-delay: 0s;
}

.chess-piece:nth-child(2) {
  top: 20%;
  right: 15%;
  animation-delay: 1s;
}

.chess-piece:nth-child(3) {
  bottom: 30%;
  left: 5%;
  animation-delay: 2s;
}

.chess-piece:nth-child(4) {
  bottom: 15%;
  right: 10%;
  animation-delay: 0.5s;
}

.chess-piece:nth-child(5) {
  top: 50%;
  left: 80%;
  animation-delay: 1.5s;
}

.chess-piece:nth-child(6) {
  top: 70%;
  left: 15%;
  animation-delay: 2.5s;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }

  50% {
    transform: translateY(-20px) rotate(10deg);
  }
}

/* ============================================
   MOBILE-FIRST ENHANCEMENTS
   ============================================ */

/* Safe area insets for notch devices */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

/* Ensure proper viewport on standalone mode */
@media all and (display-mode: standalone) {
  body {
    padding-top: var(--sat);
    padding-bottom: var(--sab);
    padding-left: var(--sal);
    padding-right: var(--sar);
  }

  .tt-navbar {
    padding-top: calc(0.75rem + var(--sat));
  }

  .tt-footer {
    padding-bottom: calc(2rem + var(--sab));
  }
}

/* iOS standalone fixes */
@media all and (display-mode: standalone) {

  /* Prevent rubber banding on iOS */
  html,
  body {
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
  }

  /* Hide browser UI elements */
  .browser-only {
    display: none !important;
  }
}

/* Touch optimization */
@media (hover: none) and (pointer: coarse) {

  /* Increase touch targets */
  .btn-tt-primary,
  .btn-tt-secondary,
  .btn-tt-outline,
  .btn-tt-accent {
    min-height: 48px;
    min-width: 48px;
  }

  .tt-nav-links a {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* Disable hover effects on touch */
  .tt-feature-card:hover {
    transform: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
  }

  /* Add active states instead */
  .tt-feature-card:active {
    transform: scale(0.98);
  }

  .btn-tt-primary:active,
  .btn-tt-accent:active {
    transform: scale(0.95);
  }
}

/* ============================================
   PULL-TO-REFRESH INDICATOR
   ============================================ */
.pull-to-refresh {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tt-primary);
  color: white;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
  z-index: 9999;
}

.pull-to-refresh.visible {
  transform: translateY(0);
}

.pull-to-refresh i {
  font-size: 1.5rem;
  animation: spin 1s linear infinite;
}

/* ============================================
   OFFLINE INDICATOR
   ============================================ */
.offline-indicator {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #dc3545;
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 50px;
  font-family: 'Cairo', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 99999;
  animation: slideUp 0.3s ease-out;
}

.offline-indicator.online {
  background: var(--tt-primary);
}

@keyframes slideUp {
  from {
    transform: translate(-50%, 100%);
    opacity: 0;
  }

  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

/* ============================================
   INSTALL PROMPT BANNER
   ============================================ */
.pwa-install-prompt {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, #1A3A2A 0%, #2d5640 100%);
  color: white;
  padding: 1.25rem;
  padding-bottom: calc(1.25rem + var(--sab));
  display: flex;
  flex-direction: column;
  gap: 1rem;
  z-index: 99999;
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-family: 'Cairo', sans-serif;
}

.pwa-install-prompt.hidden {
  display: none;
}

.pwa-install-content {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.pwa-install-icon {
  width: 60px;
  height: 60px;
  border-radius: 14px;
  flex-shrink: 0;
}

.pwa-install-text h4 {
  margin: 0 0 0.25rem 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.pwa-install-text p {
  margin: 0;
  font-size: 0.85rem;
  opacity: 0.85;
}

.pwa-install-actions {
  display: flex;
  gap: 0.75rem;
}

.pwa-install-actions button {
  flex: 1;
  padding: 0.875rem 1rem;
  border-radius: 12px;
  font-family: 'Cairo', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.pwa-install-btn {
  background: #E09F3E;
  color: white;
}

.pwa-install-btn:hover,
.pwa-install-btn:active {
  background: #c78a32;
  transform: scale(0.98);
}

.pwa-later-btn {
  background: rgba(255, 255, 255, 0.15);
  color: white;
}

.pwa-later-btn:hover,
.pwa-later-btn:active {
  background: rgba(255, 255, 255, 0.25);
}

/* ============================================
   MOBILE NAVIGATION ENHANCEMENTS
   ============================================ */
@media (max-width: 991px) {

  /* Mobile bottom navigation */
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    display: flex;
    justify-content: space-around;
    padding: 0.5rem 0;
    padding-bottom: calc(0.5rem + var(--sab));
    box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    border-top: 1px solid var(--tt-gray-200);
  }

  .mobile-bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 1rem;
    color: var(--tt-gray-500);
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    transition: color 0.2s;
    min-width: 60px;
  }

  .mobile-bottom-nav a i {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
  }

  .mobile-bottom-nav a.active,
  .mobile-bottom-nav a:hover {
    color: var(--tt-primary);
  }

  .mobile-bottom-nav a.active i {
    color: var(--tt-primary);
  }

  /* Add padding to body to account for bottom nav */
  body.has-bottom-nav {
    padding-bottom: calc(70px + var(--sab));
  }

  /* Mobile menu hamburger */
  .mobile-menu-toggle {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
  }

  .mobile-menu-toggle span {
    width: 24px;
    height: 3px;
    background: var(--tt-gray-600);
    border-radius: 2px;
    transition: all 0.3s;
  }
}

/* ============================================
   SWIPE GESTURES SUPPORT
   ============================================ */
.swipeable {
  touch-action: pan-y;
}

.swipe-left-hint,
.swipe-right-hint {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  padding: 1rem;
  background: var(--tt-primary);
  color: white;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.2s;
}

.swipe-left-hint {
  left: -60px;
}

.swipe-right-hint {
  right: -60px;
}

/* ============================================
   SKELETON LOADING
   ============================================ */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 1rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.skeleton-title {
  height: 1.5rem;
  width: 60%;
  border-radius: 4px;
  margin-bottom: 1rem;
}

.skeleton-image {
  width: 100%;
  padding-top: 56.25%;
  /* 16:9 aspect ratio */
  border-radius: 12px;
}

/* ============================================
   SMOOTH SCROLL
   ============================================ */
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .pwa-splash-logo,
  .pwa-splash-title,
  .pwa-splash-loader,
  .chess-piece {
    animation: none !important;
  }
}

/* ============================================
   DARK MODE SUPPORT
   ============================================ */
@media (prefers-color-scheme: dark) {
  :root {
    --tt-gray-50: #1a1a1a;
    --tt-gray-100: #242424;
    --tt-gray-200: #333333;
    --tt-gray-900: #f5f5f5;
  }

  body {
    background-color: #121212;
    color: #f5f5f5;
  }

  .tt-navbar,
  .tt-card,
  .tt-feature-card,
  .tt-stat-card {
    background: #1e1e1e;
  }

  .skeleton {
    background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
    background-size: 200% 100%;
  }
}

/* ============================================
   PREMIUM VISUAL POLISH
   ============================================ */

/* Page transition animation */
.page-wrapper {
  animation: pageFadeIn 0.4s ease-out;
}

@keyframes pageFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Touch feedback for all interactive elements */
@media (hover: none) {

  a:active,
  button:active,
  .clickable:active {
    transform: scale(0.97);
    transition: transform 0.1s ease;
  }
}

/* Enhanced mobile headers (Glassmorphism) */
@media (max-width: 991px) {

  .main-header,
  .hub-control-bar {
    background: rgba(255, 255, 255, 0.85) !important;
    backdrop-filter: blur(15px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(15px) saturate(180%) !important;
  }
}

/* Improved list item spacing for touch */
.list-group-item {
  padding: 0.875rem 1rem !important;
  margin-bottom: 2px;
}

/* Haptic-like feedback for switches */
.form-switch .form-check-input:active {
  filter: brightness(0.9);
  transform: scale(0.9);
}