/* ─── Harvst motion ───────────────────────────────────────────────────────────
   Loaded after theme.css. Everything here is animation and the bolder layout
   moves that depend on it.

   Rule followed throughout: motion explains change, it never decorates. Content
   enters from where it came from, numbers count because they are counting,
   pressed things move down. Nothing loops forever except genuine progress.
   ──────────────────────────────────────────────────────────────────────────── */

:root {
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);       /* quint */
  --ease-io:  cubic-bezier(0.65, 0, 0.35, 1);
  --dur-1: 160ms;
  --dur-2: 280ms;
  --dur-3: 460ms;
}

/* ── Page entrance ────────────────────────────────────────────────────────────
   The shell is already there, so only content animates in. Staggered by
   position, which reads as the page assembling rather than one block fading. */

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@keyframes riseSm {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: none; }
}

.body > *, .panel, .stat, .tab-panel.active > * {
  animation: rise var(--dur-3) var(--ease-out) both;
}
.body > *:nth-child(1) { animation-delay: 0ms; }
.body > *:nth-child(2) { animation-delay: 45ms; }
.body > *:nth-child(3) { animation-delay: 90ms; }
.body > *:nth-child(4) { animation-delay: 135ms; }
.body > *:nth-child(5) { animation-delay: 180ms; }
.body > *:nth-child(6) { animation-delay: 225ms; }

/* Stat tiles cascade left to right, so the eye lands on the lead metric first. */
.stat-grid > .stat { animation: rise var(--dur-3) var(--ease-out) both; }
.stat-grid > .stat:nth-child(1) { animation-delay: 60ms; }
.stat-grid > .stat:nth-child(2) { animation-delay: 110ms; }
.stat-grid > .stat:nth-child(3) { animation-delay: 160ms; }
.stat-grid > .stat:nth-child(4) { animation-delay: 210ms; }

/* Sidebar items settle in sequence on first paint. */
.s-item { animation: riseSm 320ms var(--ease-out) both; }
.s-item:nth-child(2)  { animation-delay: 20ms; }
.s-item:nth-child(3)  { animation-delay: 40ms; }
.s-item:nth-child(4)  { animation-delay: 60ms; }
.s-item:nth-child(5)  { animation-delay: 80ms; }
.s-item:nth-child(6)  { animation-delay: 100ms; }
.s-item:nth-child(7)  { animation-delay: 120ms; }
.s-item:nth-child(8)  { animation-delay: 140ms; }

/* Rows stream in as data arrives. Capped so a 500-row table is not a light show. */
tbody tr { animation: riseSm 300ms var(--ease-out) both; }
tbody tr:nth-child(1) { animation-delay: 0ms; }
tbody tr:nth-child(2) { animation-delay: 30ms; }
tbody tr:nth-child(3) { animation-delay: 60ms; }
tbody tr:nth-child(4) { animation-delay: 90ms; }
tbody tr:nth-child(5) { animation-delay: 120ms; }
tbody tr:nth-child(6) { animation-delay: 150ms; }
tbody tr:nth-child(7) { animation-delay: 180ms; }
tbody tr:nth-child(n+8) { animation-delay: 200ms; }

/* ── Bolder dashboard: a bento, not a row of equal tiles ──────────────────── */

@media (min-width: 980px) {
  .stat-grid {
    display: grid;
    grid-template-columns: 1.75fr 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 12px;
  }
  /* Lead metric owns a tall cell on the left. */
  .stat-grid > .stat:nth-child(1) {
    grid-row: span 2;
    display: flex; flex-direction: column; justify-content: space-between;
    padding: 26px 26px 24px;
    background:
      radial-gradient(130% 120% at 0% 0%, var(--sand-dim), transparent 58%),
      var(--card);
  }
  .stat-grid > .stat:nth-child(1) .stat-val {
    font-size: 56px; letter-spacing: -0.035em; line-height: 0.95;
  }
  .stat-grid > .stat:nth-child(1) .stat-lbl { font-size: 11.5px; }
  .stat-grid > .stat:nth-child(1) .stat-ico { width: 40px; height: 40px; font-size: 19px; border-radius: 12px; }
  /* The third supporting tile stretches to close the grid. */
  .stat-grid > .stat:nth-child(4) { grid-column: 2 / span 2; }
  .stat-grid > .stat:nth-child(4) .stat-top { margin-bottom: 6px; }
}

/* ── Interaction ──────────────────────────────────────────────────────────── */

.stat[onclick] {
  cursor: pointer; position: relative; overflow: hidden;
  transition: transform var(--dur-2) var(--ease-out),
              box-shadow var(--dur-2) var(--ease-out),
              border-color var(--dur-2) var(--ease-out);
}
/* A hairline that draws itself along the top edge on hover. */
.stat[onclick]::after {
  content: ''; position: absolute; inset: 0 auto auto 0;
  height: 2px; width: 100%; transform: scaleX(0); transform-origin: left;
  background: linear-gradient(90deg, var(--navy), var(--sand));
  transition: transform var(--dur-2) var(--ease-out);
}
.stat[onclick]:hover::after { transform: scaleX(1); }
.stat[onclick]:hover { transform: translateY(-3px); box-shadow: var(--lift-2); border-color: var(--navy-14); }
.stat[onclick]:active { transform: translateY(-1px); transition-duration: 70ms; }

.stat-ico { transition: transform var(--dur-2) var(--ease-out); }
.stat[onclick]:hover .stat-ico { transform: scale(1.08) rotate(-4deg); }

/* Sidebar active marker slides rather than snapping. */
.s-item::before { transition: transform var(--dur-2) var(--ease-out), opacity var(--dur-1); }
.s-item:not(.active)::before { transform: scaleY(0); opacity: 0; }
.s-item.active::before { transform: scaleY(1); opacity: 1; }
.s-item i { transition: transform var(--dur-1) var(--ease-out); }
.s-item:hover i { transform: translateX(2px); }

/* Buttons press. */
.btn, button.btn-primary, .btn-navy {
  transition: transform var(--dur-1) var(--ease-out),
              box-shadow var(--dur-1) var(--ease-out),
              opacity var(--dur-1);
}
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.995); transition-duration: 60ms; }

/* Panels lift a little on hover so the surface feels alive without moving. */
.panel { transition: box-shadow var(--dur-2) var(--ease-out); }
.panel:hover { box-shadow: var(--lift-2); }

/* ── Value transitions ────────────────────────────────────────────────────── */

/* When a number finishes counting it settles, so the change is legible. */
@keyframes settle {
  0%   { transform: translateY(3px); opacity: .55; }
  100% { transform: none; opacity: 1; }
}
.stat-val.counted { animation: settle var(--dur-2) var(--ease-out) both; }

/* Skeleton hands off to content instead of snapping. */
@keyframes contentIn { from { opacity: 0; } to { opacity: 1; } }
.content-in { animation: contentIn var(--dur-2) var(--ease-out) both; }

/* Progress bars and meters grow from zero. */
.bar-fill, .meter-fill, .progress-fill {
  transition: width var(--dur-3) var(--ease-out);
}

/* ── Modals and drawers ───────────────────────────────────────────────────── */
.drawer-overlay, .modal-overlay { transition: opacity var(--dur-2) var(--ease-out); }
@keyframes drawerIn { from { transform: translateX(18px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes modalIn  { from { transform: translateY(12px) scale(.985); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer.open, #drawer.open { animation: drawerIn var(--dur-2) var(--ease-out) both; }
.modal.open, .modal-box { animation: modalIn var(--dur-2) var(--ease-out) both; }

/* ── Live pulse for genuinely live things only ────────────────────────────── */
@keyframes livePulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .35; }
}
.live-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--sage); margin-right: 6px;
  animation: livePulse 2s var(--ease-io) infinite;
}

/* ── Respect the setting ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
  .stat[onclick]:hover, .btn:active { transform: none; }
}
