/* ═══════════════════════════════════════════════════════════════════════════
   PREMIUM MOTION DESIGN SYSTEM — CeyreGueyrum PRO SaaS
   Unified motion engine: spring physics, staggered orchestration,
   animated floating tab indicators, card hover micro-elevation,
   tactile button feedback, skeleton crossfades, mobile optimization.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* Motion Spring & Easing Curves */
  --motion-ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --motion-ease-out:    cubic-bezier(0.2, 0.8, 0.2, 1);
  --motion-ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --motion-ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Motion Durations (Snappy, non-blocking) */
  --motion-duration-fast:   110ms;
  --motion-duration-base:   170ms;
  --motion-duration-smooth: 220ms;
  --motion-duration-stagger: 30ms;
}

/* ── 1. GLOBAL PAGE TRANSITIONS ───────────────────────────────────────── */
#view {
  position: relative;
  min-height: 100%;
}

.page-enter {
  animation: motion-page-enter var(--motion-duration-base) var(--motion-ease-out) both;
  will-change: transform, opacity;
}

@keyframes motion-page-enter {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.996);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Native View Transitions API support (Chromium/Safari) */
::view-transition-old(root) {
  animation: motion-view-old 130ms var(--motion-ease-out) both;
}
::view-transition-new(root) {
  animation: motion-view-new 170ms var(--motion-ease-out) both;
}

@keyframes motion-view-old {
  to { opacity: 0; transform: translateY(-4px); }
}
@keyframes motion-view-new {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── 2. STAGGERED CONTENT CHOREOGRAPHY ────────────────────────────────── */
/* Tier 1: Page Header & Title */
.section-head,
[data-motion="header"] {
  animation: motion-stagger-in var(--motion-duration-base) var(--motion-ease-out) both;
  animation-delay: 0ms;
  will-change: transform, opacity;
}

/* Tier 2: Top KPI / Metrics / Stat Cards */
.stat-overview,
.kpi-grid,
.stat-cards,
.skeleton-cards,
[data-motion="stats"] {
  animation: motion-stagger-in var(--motion-duration-base) var(--motion-ease-out) both;
  animation-delay: var(--motion-duration-stagger);
  will-change: transform, opacity;
}

/* Tier 3: Charts & Data Visualizations */
.chart-panel,
.chart-row,
.analytics-section,
.heatmap-wrap,
.funnel-wrap,
[data-motion="charts"] {
  animation: motion-stagger-in var(--motion-duration-base) var(--motion-ease-out) both;
  animation-delay: calc(var(--motion-duration-stagger) * 2);
  will-change: transform, opacity;
}

/* Tier 4: Tables, Records & Primary Content Panels */
.table-wrap,
.data-table,
.panel,
.quick-nav-grid,
[data-motion="tables"] {
  animation: motion-stagger-in var(--motion-duration-base) var(--motion-ease-out) both;
  animation-delay: calc(var(--motion-duration-stagger) * 3);
  will-change: transform, opacity;
}

/* Tier 5: Action Bars, Dividers & Footer Elements */
.action-panel,
.action-bar,
.section-divider,
[data-motion="footer"] {
  animation: motion-stagger-in var(--motion-duration-base) var(--motion-ease-out) both;
  animation-delay: calc(var(--motion-duration-stagger) * 4);
  will-change: transform, opacity;
}

@keyframes motion-stagger-in {
  0% {
    opacity: 0;
    transform: translateY(6px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── 3. ANIMATED TAB SYSTEM (Floating Spring Pill & Crossfade) ────────── */
.tabs {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.035);
  padding: 4px;
  border-radius: var(--r-sm, 10px);
  border: 1px solid var(--line-2);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  isolation: isolate;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

/* The animated floating pill indicator */
.tab-floating-indicator {
  position: absolute;
  top: 4px;
  height: calc(100% - 8px);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.24) 0%, rgba(37, 99, 235, 0.18) 100%);
  border: 1px solid rgba(59, 130, 246, 0.45);
  border-radius: calc(var(--r-sm, 10px) - 2px);
  box-shadow: 0 0 14px rgba(59, 130, 246, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  pointer-events: none;
  z-index: 1;
  transition: left var(--motion-duration-base) var(--motion-ease-spring),
              width var(--motion-duration-base) var(--motion-ease-spring),
              opacity var(--motion-duration-fast) ease-out;
  will-change: left, width;
}

.tabs .tab {
  position: relative;
  z-index: 2;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  padding: 7px 16px;
  border-radius: calc(var(--r-sm, 10px) - 2px);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: color var(--motion-duration-fast) ease-out;
  user-select: none;
  white-space: nowrap;
}

.tabs .tab:hover {
  color: var(--ink);
}

.tabs .tab.active {
  color: var(--ink);
  font-weight: 600;
}

/* Tab body crossfade */
.tab-pane-enter {
  animation: motion-tab-enter var(--motion-duration-base) var(--motion-ease-out) both;
  will-change: opacity, transform;
}

@keyframes motion-tab-enter {
  0% {
    opacity: 0;
    transform: translateY(5px) scale(0.998);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ── 4. CARD & COMPONENT MICRO-INTERACTIONS ───────────────────────────── */
/* Subtle card hover elevation */
.panel,
.kpi-card,
.stat-card,
.quick-link,
.card-hover-active {
  transition: transform var(--motion-duration-base) var(--motion-ease-spring),
              box-shadow var(--motion-duration-base) var(--motion-ease-spring),
              border-color var(--motion-duration-base) ease-out,
              background var(--motion-duration-base) ease-out;
}

.panel:hover,
.kpi-card:hover,
.stat-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow: 0 8px 24px -6px rgba(0, 0, 0, 0.4), inset 0 0 1px var(--glass-rim);
}

/* Button tactile press physics */
.button,
.auth-btn-primary,
.auth-btn-ghost,
.btn-primary,
button:not(.tab):not(.auth-eye-btn) {
  transition: transform 90ms var(--motion-ease-spring),
              box-shadow var(--motion-duration-fast) ease-out,
              background var(--motion-duration-fast) ease-out,
              border-color var(--motion-duration-fast) ease-out,
              filter var(--motion-duration-fast) ease-out;
}

.button:hover,
.auth-btn-primary:hover,
.btn-primary:hover {
  filter: brightness(1.05);
}

.button:active,
.auth-btn-primary:active,
.btn-primary:active,
button:active:not(.tab):not(.auth-eye-btn) {
  transform: scale(0.975);
}

/* Modal Spring Scale & Backdrop */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center; padding: 24px;
  background: rgba(5, 14, 26, 0.78);
  backdrop-filter: blur(12px) saturate(120%);
  -webkit-backdrop-filter: blur(12px) saturate(120%);
  animation: motion-backdrop-fade var(--motion-duration-base) var(--motion-ease-out) both;
}

.modal {
  animation: motion-modal-spring var(--motion-duration-smooth) var(--motion-ease-spring) both;
  will-change: transform, opacity;
}

@keyframes motion-backdrop-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes motion-modal-spring {
  0% {
    opacity: 0;
    transform: scale(0.95) translateY(12px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Dropdown popover animations */
.dropdown-menu,
.menu-popover {
  transform-origin: top;
  animation: motion-dropdown-spring var(--motion-duration-fast) var(--motion-ease-spring) both;
}

@keyframes motion-dropdown-spring {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── 5. SKELETON TO CONTENT CROSSFADE ─────────────────────────────────── */
.skeleton-crossfade-enter {
  animation: motion-crossfade-in var(--motion-duration-base) var(--motion-ease-out) both;
}

@keyframes motion-crossfade-in {
  from { opacity: 0; filter: blur(2px); }
  to   { opacity: 1; filter: blur(0); }
}

/* ── 6. ACCESSIBILITY & PREFERS-REDUCED-MOTION ────────────────────────── */
@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;
  }
  .page-enter,
  .section-head,
  .stat-overview,
  .chart-panel,
  .table-wrap,
  .modal,
  .tab-pane-enter {
    animation: none !important;
    transform: none !important;
    transition: none !important;
    opacity: 1 !important;
  }
  .tab-floating-indicator {
    transition: none !important;
    animation: none !important;
  }
}

/* ── 7. MOBILE PERFORMANCE OPTIMIZATION ───────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --motion-duration-base: 130ms;
    --motion-duration-stagger: 0ms; /* Collapse delays for instant touch response */
  }
  .page-enter {
    transform: none; /* Keep simple opacity fade on mobile for 120Hz scroll perfection */
  }
  .panel:hover,
  .kpi-card:hover {
    transform: none;
  }
}


/* ── 8. SMOOTH TABLE ENTRANCE & ROW STAGGER ───────────────────────────── */
.table-wrap {
  animation: motion-table-enter 240ms var(--motion-ease-spring) both;
  will-change: opacity, transform;
}

@keyframes motion-table-enter {
  0% {
    opacity: 0;
    transform: translateY(6px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Staggered Row Glide */
.table-wrap tbody tr {
  animation: motion-row-glide 220ms var(--motion-ease-out) both;
  will-change: opacity, transform;
}

.table-wrap tbody tr:nth-child(1)  { animation-delay: 15ms; }
.table-wrap tbody tr:nth-child(2)  { animation-delay: 30ms; }
.table-wrap tbody tr:nth-child(3)  { animation-delay: 45ms; }
.table-wrap tbody tr:nth-child(4)  { animation-delay: 60ms; }
.table-wrap tbody tr:nth-child(5)  { animation-delay: 75ms; }
.table-wrap tbody tr:nth-child(6)  { animation-delay: 90ms; }
.table-wrap tbody tr:nth-child(7)  { animation-delay: 105ms; }
.table-wrap tbody tr:nth-child(8)  { animation-delay: 120ms; }
.table-wrap tbody tr:nth-child(9)  { animation-delay: 135ms; }
.table-wrap tbody tr:nth-child(10) { animation-delay: 150ms; }
.table-wrap tbody tr:nth-child(n+11) { animation-delay: 165ms; }

@keyframes motion-row-glide {
  0% {
    opacity: 0;
    transform: translateY(4px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Hover feedback on table rows */
.table-wrap tbody tr {
  transition: background 120ms ease;
}
.table-wrap tbody tr:hover {
  background: rgba(255, 255, 255, 0.035) !important;
}

/* Skeleton Table Styles */
.skeleton-table-wrap {
  background: var(--card, rgba(15, 23, 42, 0.6));
  border: 1px solid var(--line-2, rgba(255, 255, 255, 0.08));
  border-radius: var(--r-md, 14px);
  overflow: hidden;
  padding: 12px 16px;
}

.table-skeleton {
  width: 100%;
  border-collapse: collapse;
}

.table-skeleton th {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-2, rgba(255, 255, 255, 0.08));
}

.table-skeleton td {
  padding: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.skeleton-view-wrap {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: motion-stagger-in var(--motion-duration-base) var(--motion-ease-out) both;
}
