/* ============================================================
   NexNestOS — Apple-Grade Polish System
   Shared animations, transitions, and premium feel
   ============================================================ */

/* ---- Design Tokens ---- */
:root {
  /* Animation timing */
  --ease-out: cubic-bezier(0.0, 0.0, 0.2, 1.0);
  --ease-in-out: cubic-bezier(0.4, 0.0, 0.2, 1.0);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.25, 0.1, 0.25, 1.0);

  --duration-fast: 0.15s;
  --duration-normal: 0.25s;
  --duration-slow: 0.4s;
  --duration-slower: 0.6s;

  /* Elevation shadows (layered for realism) */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.08), 0 4px 10px -4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 40px -5px rgba(0, 0, 0, 0.1), 0 8px 16px -8px rgba(0, 0, 0, 0.06);
  --shadow-glow: 0 0 20px rgba(22, 163, 74, 0.12);

  /* Glass effects */
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.2);
  --glass-blur: blur(20px);
  --glass-saturate: saturate(180%);
}


/* ============================================================
   1. PAGE ENTRANCE ANIMATION
   ============================================================ */

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

body {
  animation: pageEnter 0.5s var(--ease-out) both;
}

/* Staggered children entrance */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

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

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Subtle float for hero elements */
@keyframes subtleFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* Shimmer for skeleton loaders */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Gentle pulse for attention elements */
@keyframes gentlePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Rotate for loading */
@keyframes smoothSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}


/* ============================================================
   2. SCROLL-TRIGGERED ANIMATIONS
   ============================================================ */

.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--duration-slower) var(--ease-out),
              transform var(--duration-slower) var(--ease-out);
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

.reveal-left {
  opacity: 0;
  transform: translateX(-20px);
  transition: opacity var(--duration-slower) var(--ease-out),
              transform var(--duration-slower) var(--ease-out);
}

.reveal-left.visible {
  opacity: 1;
  transform: translateX(0);
}

.reveal-right {
  opacity: 0;
  transform: translateX(20px);
  transition: opacity var(--duration-slower) var(--ease-out),
              transform var(--duration-slower) var(--ease-out);
}

.reveal-right.visible {
  opacity: 1;
  transform: translateX(0);
}

.reveal-scale {
  opacity: 0;
  transform: scale(0.95);
  transition: opacity var(--duration-slower) var(--ease-out),
              transform var(--duration-slower) var(--ease-out);
}

.reveal-scale.visible {
  opacity: 1;
  transform: scale(1);
}

/* Stagger children animation delays */
.stagger-children > .reveal:nth-child(1) { transition-delay: 0s; }
.stagger-children > .reveal:nth-child(2) { transition-delay: 0.06s; }
.stagger-children > .reveal:nth-child(3) { transition-delay: 0.12s; }
.stagger-children > .reveal:nth-child(4) { transition-delay: 0.18s; }
.stagger-children > .reveal:nth-child(5) { transition-delay: 0.24s; }
.stagger-children > .reveal:nth-child(6) { transition-delay: 0.30s; }
.stagger-children > .reveal:nth-child(7) { transition-delay: 0.36s; }
.stagger-children > .reveal:nth-child(8) { transition-delay: 0.42s; }


/* ============================================================
   3. INTERACTIVE ELEMENT POLISH
   ============================================================ */

/* --- Buttons --- */

/* Primary button press effect */
button, .btn, [role="button"], input[type="submit"] {
  transition: all var(--duration-normal) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

button:active:not(:disabled),
.btn:active:not(:disabled),
[role="button"]:active:not(:disabled),
input[type="submit"]:active:not(:disabled) {
  transform: scale(0.97);
  transition-duration: 0.1s;
}

/* Keyboard focus ring */
button:focus-visible,
.btn:focus-visible,
[role="button"]:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent, #16a34a);
  outline-offset: 2px;
  border-radius: inherit;
}


/* --- Inputs --- */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
textarea,
select {
  transition: border-color var(--duration-normal) var(--ease-out),
              box-shadow var(--duration-normal) var(--ease-out),
              background-color var(--duration-normal) var(--ease-out);
}


/* --- Links --- */

a {
  transition: color var(--duration-fast) var(--ease-out),
              opacity var(--duration-fast) var(--ease-out);
}


/* ============================================================
   4. CARD HOVER EFFECTS
   ============================================================ */

.polish-card {
  transition: transform var(--duration-normal) var(--ease-out),
              box-shadow var(--duration-normal) var(--ease-out),
              border-color var(--duration-normal) var(--ease-out);
  will-change: transform, box-shadow;
}

.polish-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* Subtle card — no lift, just shadow change */
.polish-card-subtle {
  transition: box-shadow var(--duration-normal) var(--ease-out),
              border-color var(--duration-normal) var(--ease-out);
}

.polish-card-subtle:hover {
  box-shadow: var(--shadow-md);
}


/* ============================================================
   5. SKELETON LOADERS
   ============================================================ */

.skeleton {
  background: linear-gradient(
    90deg,
    #f0f0ef 25%,
    #e8e8e6 37%,
    #f0f0ef 63%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s var(--ease-in-out) infinite;
  border-radius: 8px;
  color: transparent !important;
  pointer-events: none;
  user-select: none;
}

.skeleton * {
  visibility: hidden;
}

.skeleton-text {
  height: 14px;
  margin-bottom: 10px;
  border-radius: 6px;
}

.skeleton-text.short { width: 40%; }
.skeleton-text.medium { width: 65%; }
.skeleton-text.long { width: 90%; }

.skeleton-circle {
  border-radius: 50%;
}

.skeleton-card {
  min-height: 120px;
  border-radius: 14px;
}

.skeleton-heading {
  height: 24px;
  width: 50%;
  margin-bottom: 16px;
  border-radius: 8px;
}

.skeleton-paragraph {
  display: flex;
  flex-direction: column;
  gap: 8px;
}


/* ============================================================
   6. MODAL & OVERLAY POLISH
   ============================================================ */

.polish-overlay {
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-slow) var(--ease-out),
              visibility var(--duration-slow) var(--ease-out);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.polish-overlay.active {
  opacity: 1;
  visibility: visible;
}

.polish-modal {
  opacity: 0;
  transform: scale(0.95) translateY(10px);
  transition: opacity var(--duration-slow) var(--ease-spring),
              transform var(--duration-slow) var(--ease-spring);
}

.polish-overlay.active .polish-modal,
.polish-modal.active {
  opacity: 1;
  transform: scale(1) translateY(0);
}


/* ============================================================
   7. NAV BAR GLASS EFFECT (Enhanced)
   ============================================================ */

.polish-nav {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur) var(--glass-saturate);
  backdrop-filter: var(--glass-blur) var(--glass-saturate);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  transition: background var(--duration-normal) var(--ease-out),
              box-shadow var(--duration-normal) var(--ease-out);
}

.polish-nav.scrolled {
  box-shadow: var(--shadow-sm);
}


/* ============================================================
   8. TAB CROSS-FADE
   ============================================================ */

.polish-tab-content {
  animation: fadeIn var(--duration-normal) var(--ease-out);
}

.polish-tab {
  position: relative;
  transition: color var(--duration-fast) var(--ease-out);
}

/* Active tab indicator that slides */
.polish-tab-indicator {
  position: absolute;
  bottom: -1px;
  height: 2px;
  background: var(--accent, #16a34a);
  border-radius: 2px;
  transition: left var(--duration-normal) var(--ease-spring),
              width var(--duration-normal) var(--ease-spring);
}


/* ============================================================
   9. LOADING SPINNER (Premium)
   ============================================================ */

.polish-spinner {
  width: 32px;
  height: 32px;
  border: 2.5px solid rgba(0, 0, 0, 0.08);
  border-top-color: var(--accent, #16a34a);
  border-radius: 50%;
  animation: smoothSpin 0.7s linear infinite;
}

.polish-spinner.sm {
  width: 18px;
  height: 18px;
  border-width: 2px;
}

.polish-spinner.lg {
  width: 44px;
  height: 44px;
  border-width: 3px;
}


/* ============================================================
   10. SMOOTH ACCORDION
   ============================================================ */

.polish-accordion-body {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows var(--duration-slow) var(--ease-out),
              opacity var(--duration-normal) var(--ease-out);
}

.polish-accordion-body.open {
  grid-template-rows: 1fr;
  opacity: 1;
}

.polish-accordion-body > div {
  overflow: hidden;
}


/* ============================================================
   11. TYPOGRAPHY REFINEMENTS
   ============================================================ */

/* Smoother text rendering */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Selection color */
::selection {
  background: rgba(22, 163, 74, 0.15);
  color: inherit;
}

::-moz-selection {
  background: rgba(22, 163, 74, 0.15);
  color: inherit;
}


/* ============================================================
   12. SCROLLBAR STYLING (Webkit)
   ============================================================ */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 100px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
  background-clip: padding-box;
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}


/* ============================================================
   13. REDUCED MOTION RESPECT
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  body {
    animation: none;
  }

  .reveal, .reveal-left, .reveal-right, .reveal-scale {
    opacity: 1;
    transform: none;
    transition: none;
  }
}


/* ============================================================
   14. UTILITY ANIMATIONS
   ============================================================ */

.animate-fade-in { animation: fadeIn var(--duration-normal) var(--ease-out) both; }
.animate-fade-in-up { animation: fadeInUp var(--duration-slow) var(--ease-out) both; }
.animate-scale-in { animation: scaleIn var(--duration-slow) var(--ease-spring) both; }
.animate-slide-right { animation: slideInRight var(--duration-slow) var(--ease-out) both; }
.animate-slide-left { animation: slideInLeft var(--duration-slow) var(--ease-out) both; }

.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.3s; }
.delay-4 { animation-delay: 0.4s; }
.delay-5 { animation-delay: 0.5s; }

/* Smooth page transition overlay */
.page-transition {
  position: fixed;
  inset: 0;
  background: var(--paper, #fafaf9);
  z-index: 99999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease-out);
}

.page-transition.active {
  opacity: 1;
  pointer-events: all;
}
