/* ══════════════════════════════════════════════════════════════════════════
   Kashif motion system
   Durations stay short on purpose: operators repeat these interactions all
   day, so anything that reads as "animated" becomes friction by the
   four-hundredth repetition.
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  --dur-instant: 80ms;
  --dur-fast: 120ms;
  --dur-base: 160ms;
  --dur-slow: 240ms;
  --dur-count: 420ms;

  --ease-out: cubic-bezier(.22, .61, .36, 1);
  --ease-in-out: cubic-bezier(.4, 0, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.26, .64, 1);

  --stagger-step: 40ms;
}

/* ── Keyframes ──────────────────────────────────────────────────────────── */

@keyframes k-fade-in { from { opacity: 0 } to { opacity: 1 } }

@keyframes k-room-in {
  from { opacity: 0; transform: translateY(4px) }
  to   { opacity: 1; transform: none }
}

@keyframes k-block-in {
  from { opacity: 0; transform: translateY(3px) }
  to   { opacity: 1; transform: none }
}

@keyframes k-scale-in {
  from { opacity: 0; transform: scale(.97) }
  to   { opacity: 1; transform: none }
}

@keyframes k-pop-in {
  0%   { opacity: 0; transform: scale(.82) }
  100% { opacity: 1; transform: scale(1) }
}

@keyframes k-toast-in {
  from { opacity: 0; transform: translateY(8px) scale(.98) }
  to   { opacity: 1; transform: none }
}

@keyframes k-toast-out {
  from { opacity: 1; transform: none }
  to   { opacity: 0; transform: translateY(6px) scale(.98) }
}

@keyframes k-flash {
  0%   { background: hsl(var(--primary) / .14) }
  100% { background: transparent }
}

@keyframes k-shimmer {
  0%   { background-position: -360px 0 }
  100% { background-position: 360px 0 }
}

/* ── Room transitions (item 17) ─────────────────────────────────────────── */
/* Rooms toggle via display:none, which restarts CSS animations on reveal. */

.room { animation: k-room-in var(--dur-base) var(--ease-out) both; }

/* ── Streamed answer blocks (item 18) ───────────────────────────────────── */

.k-block-in { animation: k-block-in var(--dur-fast) var(--ease-out) both; }

/* ── Staggered list entry (item 31) ─────────────────────────────────────── */

.k-stagger > * { animation: k-block-in var(--dur-fast) var(--ease-out) both; }
.k-stagger > *:nth-child(1)  { animation-delay: 0ms }
.k-stagger > *:nth-child(2)  { animation-delay: 40ms }
.k-stagger > *:nth-child(3)  { animation-delay: 80ms }
.k-stagger > *:nth-child(4)  { animation-delay: 120ms }
.k-stagger > *:nth-child(5)  { animation-delay: 160ms }
.k-stagger > *:nth-child(6)  { animation-delay: 200ms }
.k-stagger > *:nth-child(7)  { animation-delay: 240ms }
.k-stagger > *:nth-child(8)  { animation-delay: 280ms }
.k-stagger > *:nth-child(9)  { animation-delay: 320ms }
.k-stagger > *:nth-child(n+10) { animation-delay: 360ms }

/* ── Row change feedback (items 23, 24) ─────────────────────────────────── */

.k-flash { animation: k-flash 900ms var(--ease-out) both; }

.k-removing {
  overflow: hidden;
  transition: opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              max-height var(--dur-base) var(--ease-out),
              margin var(--dur-base) var(--ease-out);
  opacity: 0;
  transform: translateX(-8px);
  max-height: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* ── Tool pills (item 21) ───────────────────────────────────────────────── */

.k-pop { animation: k-pop-in var(--dur-fast) var(--ease-spring) both; }

/* ── Button press feedback (item 28) ────────────────────────────────────── */

button:not(:disabled):active,
[role="button"]:not([aria-disabled="true"]):active {
  transform: translateY(.5px) scale(.985);
}
button { transition: transform var(--dur-instant) var(--ease-out); }

/* ── Card hover lift — borders only, no shadows (item 29) ───────────────── */

.k-liftable {
  transition: border-color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.k-liftable:hover {
  border-color: hsl(var(--ring) / .5);
  transform: translateY(-1px);
}

/* ── Sidebar active indicator (item 27) ─────────────────────────────────── */

.nav-item { position: relative; }
.nav-item::before {
  content: "";
  position: absolute;
  left: 0; top: 50%;
  width: 2px; height: 0;
  border-radius: 0 2px 2px 0;
  background: hsl(var(--primary));
  opacity: 0;
  transform: translateY(-50%);
  transition: height var(--dur-base) var(--ease-spring), opacity var(--dur-fast) var(--ease-out);
}
.nav-item.active::before { height: 16px; opacity: 1; }

/* ── Tab underline (item 30) ────────────────────────────────────────────── */

.k-tab { position: relative; transition: color var(--dur-fast) var(--ease-out); }
.k-tab::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: hsl(var(--primary));
  transform: scaleX(0);
  transform-origin: center;
  transition: transform var(--dur-base) var(--ease-spring);
}
.k-tab[aria-selected="true"]::after { transform: scaleX(1); }

/* ── Theme cross-fade (item 34) ─────────────────────────────────────────── */

body.k-theming,
body.k-theming * {
  transition: background-color var(--dur-slow) var(--ease-in-out),
              border-color var(--dur-slow) var(--ease-in-out),
              color var(--dur-slow) var(--ease-in-out) !important;
}

/* ── Chart + thumbnail entry (item 32) ──────────────────────────────────── */

.k-chart-in { animation: k-chart-in var(--dur-slow) var(--ease-out) both; }

@keyframes k-chart-in {
  from { opacity: 0; transform: translateY(6px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

/* ══════════════════════════════════════════════════════════════════════════
   Reduced motion (item 16)
   Loading spinners are deliberately exempt — a frozen spinner reads as a
   hung app rather than a respected preference.
   ══════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *:not(.animate-spin),
  *:not(.animate-spin)::before,
  *:not(.animate-spin)::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  .k-liftable:hover { transform: none; }
  button:active { transform: none; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Ambient motion
   Everything below is additive polish: it makes the app feel alive without
   moving layout. All of it is disabled by the reduced-motion block above.
   ═══════════════════════════════════════════════════════════════════════ */

@keyframes k-fade        { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes k-slide-right { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: none; } }
@keyframes k-grow-x      { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes k-grow-y      { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes k-pulse-ring  { 0% { box-shadow: 0 0 0 0 hsl(var(--primary) / .35); } 70% { box-shadow: 0 0 0 7px hsl(var(--primary) / 0); } 100% { box-shadow: 0 0 0 0 hsl(var(--primary) / 0); } }
@keyframes k-breathe     { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }
@keyframes k-drift       { from { background-position: 0% 50%; } to { background-position: 180% 50%; } }
@keyframes k-check       { from { stroke-dashoffset: 26; } to { stroke-dashoffset: 0; } }
@keyframes k-count-tick  { 0% { transform: translateY(2px); opacity: .55; } 100% { transform: none; opacity: 1; } }

.k-fade  { animation: k-fade var(--dur-base) var(--ease-out) both; }
.k-slide { animation: k-slide-right var(--dur-base) var(--ease-out) both; }

/* Live/active things breathe instead of sitting still. */
.k-live-dot { animation: k-breathe 1.9s ease-in-out infinite; }

/* Primary call to action gets one attention ring when it first appears. */
.k-attention { animation: k-pulse-ring 1.6s var(--ease-out) 2; }

/* Bars, meters, and progress fills grow from their own baseline. */
.c-bar-fill, .board-fill, .k-meter-fill {
  transform-origin: left center;
  animation: k-grow-x var(--dur-slow) var(--ease-spring) both;
}

/* Risk bars in the churn scorecard rise rather than appear. */
.c-bar-row { animation: k-fade var(--dur-base) var(--ease-out) both; }

/* Tick marks draw themselves. */
.k-check path, .k-check polyline {
  stroke-dasharray: 26;
  animation: k-check var(--dur-slow) var(--ease-out) both;
}

/* Sidebar counts nudge when they change. */
.k-tick { animation: k-count-tick var(--dur-base) var(--ease-out); }

/* Row hover: a quiet lift on anything tabular and clickable. */
.c-tr, .ops-item, .j-row {
  transition: background-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}

/* Inputs settle into focus rather than snapping. */
input, textarea, select {
  transition: border-color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}

/* Buttons depress slightly on press (item 28). */
button:not(:disabled):active,
.j-btn:not(:disabled):active,
.c-save:not(:disabled):active {
  transform: translateY(1px);
}

/* Skeleton shimmer drifts across rather than blinking. */
.k-skel {
  background-size: 180% 100%;
  animation: k-shimmer 1.4s linear infinite, k-drift 2.8s linear infinite;
}

/* Staggered entry for any list that opts in with .k-stagger-list. */
.k-stagger-list > * { animation: k-fade var(--dur-base) var(--ease-out) both; }
.k-stagger-list > *:nth-child(1)  { animation-delay: 0ms; }
.k-stagger-list > *:nth-child(2)  { animation-delay: 35ms; }
.k-stagger-list > *:nth-child(3)  { animation-delay: 70ms; }
.k-stagger-list > *:nth-child(4)  { animation-delay: 105ms; }
.k-stagger-list > *:nth-child(5)  { animation-delay: 140ms; }
.k-stagger-list > *:nth-child(6)  { animation-delay: 175ms; }
.k-stagger-list > *:nth-child(7)  { animation-delay: 210ms; }
.k-stagger-list > *:nth-child(n+8) { animation-delay: 240ms; }

/* ── Applied to the containers the app already renders ──────────────────── */

/* Dashboard grids and card decks come in staggered rather than all at once. */
.board-grid > *, .c-qgrid > *, .ops-stats > * {
  animation: k-fade var(--dur-base) var(--ease-out) both;
}
.board-grid > *:nth-child(2), .c-qgrid > *:nth-child(2), .ops-stats > *:nth-child(2) { animation-delay: 35ms; }
.board-grid > *:nth-child(3), .c-qgrid > *:nth-child(3), .ops-stats > *:nth-child(3) { animation-delay: 70ms; }
.board-grid > *:nth-child(4), .c-qgrid > *:nth-child(4), .ops-stats > *:nth-child(4) { animation-delay: 105ms; }
.board-grid > *:nth-child(5), .c-qgrid > *:nth-child(5), .ops-stats > *:nth-child(5) { animation-delay: 140ms; }
.board-grid > *:nth-child(n+6), .c-qgrid > *:nth-child(n+6), .ops-stats > *:nth-child(n+6) { animation-delay: 170ms; }

/* Status dots on anything live keep a slow pulse so the page has a heartbeat. */
.flow-dot, .insight-dot, .j-dot { animation: k-breathe 2.2s ease-in-out infinite; }

/* Toast and dialog entries already animate; give the backdrop a real fade. */
.k-backdrop { animation: k-fade-in var(--dur-base) var(--ease-out) both; }
