/* Stan CLI cockpit — enhancements (additive, loaded after styles.css).
   Only adds polish; never overrides core layout. Theme-aware via /brand tokens. */

/* Gentle fade-in for newly added chat messages. */
@keyframes enh-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
#thread > .enh-in { animation: enh-in .28s cubic-bezier(.22,.61,.36,1) both; }
#home-feed > .enh-in { animation: enh-in .30s cubic-bezier(.22,.61,.36,1) both; }
@media (prefers-reduced-motion: reduce) { #thread > .enh-in, #home-feed > .enh-in { animation: none; } }

/* Lightweight toast (shared by copy / actions). */
#enh-toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(10px);
  background: var(--text-primary, #000); color: var(--bg-card, #fff);
  font-size: 13px; font-weight: 600; padding: 8px 14px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  z-index: 99999; box-shadow: 0 8px 24px rgba(0,0,0,.22); max-width: 80vw; text-align: center;
}
#enh-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (prefers-reduced-motion: reduce) { #enh-toast { transition: opacity .15s ease; } }

/* "Scroll to top" affordance — appears in the chat thread when scrolled down far.
   Scoped to the thread's container (same as #jump-btn) so it hides off the chat tab. */
.enh-totop {
  position: absolute; left: 16px; bottom: calc(var(--composer-h, 132px) + 12px); z-index: 6;
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg-card, #fff); color: var(--text-secondary, #3C3C43); border: 1px solid var(--border, #E5E5EA);
  box-shadow: 0 4px 14px rgba(0,0,0,.14); cursor: pointer;
  opacity: 0; transform: translateY(6px) scale(.92); pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.enh-totop.show { opacity: 1; transform: none; pointer-events: auto; }
.enh-totop svg { width: 20px; height: 20px; }
@media (prefers-reduced-motion: reduce) { .enh-totop { transition: opacity .15s ease; } }

/* Accessibility: visible keyboard focus. The app strips default outlines everywhere with no
   replacement, so keyboard users get no focus indicator. :focus-visible only triggers on keyboard
   navigation — mouse/touch users see no change. Outline follows border-radius on modern browsers. */
button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent, #FF3B5C);
  outline-offset: 2px;
}

/* Consistency: the dir/mode composer chips were the only tap targets that didn't scale on press
   (every other button does). Match the press-feedback language. */
.meta-chip:active { transform: scale(.96); }

/* Cute "Stan cat" mascot on the welcome (empty) screen — playful but contained; hidden once chatting. */
.enh-cat { display: flex; justify-content: center; margin-top: 16px; animation: enhCatFloat 4.5s ease-in-out infinite; }
.enh-cat-img { width: 152px; height: auto; display: block; filter: drop-shadow(0 12px 18px rgba(0,0,0,.20)); user-select: none; -webkit-user-drag: none; }
/* Stan on the auth/lock screen (swapped into the existing .auth-mascot slot). */
img.auth-mascot.enh-auth-stan { object-fit: contain; animation: enhCatFloat 4.5s ease-in-out infinite; }
/* Stan greeting in the (otherwise empty) home hero. */
.enh-hero-stan { display: flex; align-items: center; gap: 14px; padding: 4px 2px 10px; }
.enh-hero-stan img { width: 66px; height: auto; flex: none; filter: drop-shadow(0 6px 12px rgba(0,0,0,.18)); animation: enhCatFloat 4.5s ease-in-out infinite; user-select: none; -webkit-user-drag: none; }
.enh-hero-txt b { display: block; font-size: 17px; font-weight: 700; letter-spacing: -.01em; color: var(--text-primary, #000); }
.enh-hero-txt span { font-size: 13px; color: var(--text-dim, #8E8E93); }
@media (prefers-reduced-motion: reduce) { img.auth-mascot.enh-auth-stan, .enh-hero-stan img { animation: none; } }

/* Easter egg: raining Stans. Decorative, never blocks taps. */
.enh-rain { position: fixed; top: -72px; width: 42px; pointer-events: none; z-index: 9998; will-change: transform, opacity; animation: enhRainFall linear forwards; }
.enh-rain img { width: 100%; height: auto; filter: drop-shadow(0 4px 8px rgba(0,0,0,.2)); }
@keyframes enhRainFall { 0% { transform: translateY(0) rotate(0); opacity: 0; } 10% { opacity: 1; } 100% { transform: translateY(112vh) rotate(var(--enh-rot, 360deg)); opacity: .9; } }

/* Stan celebrates briefly when a turn completes (same spot as the thinking-cat). */
.enh-celebrate {
  position: fixed; right: 14px; bottom: calc(var(--composer-h, 132px) + 14px); z-index: 8; width: 58px;
  pointer-events: none; opacity: 0; transform: translateY(8px) scale(.7);
  transition: opacity .25s ease, transform .35s cubic-bezier(.2,1.3,.4,1);
}
.enh-celebrate.pop { opacity: 1; transform: none; }
.enh-celebrate img { width: 100%; height: auto; filter: drop-shadow(0 6px 12px rgba(0,0,0,.20)); }
@media (prefers-reduced-motion: reduce) { .enh-celebrate { transition: opacity .15s ease; transform: none; } }
.enh-cat-svg { width: 86px; height: auto; overflow: visible; }
.enh-cat-svg .cat-head, .enh-cat-svg .cat-ear { fill: var(--bg-secondary, #F2F2F7); stroke: var(--border-mid, #C6C6C8); stroke-width: 1.5; }
.enh-cat-svg .cat-ear-in { fill: var(--accent, #FF3B5C); }
.enh-cat-svg .cat-eye { fill: var(--text-primary, #000); transform-box: fill-box; transform-origin: center; animation: enhCatBlink 5.2s ease-in-out infinite; }
.enh-cat-svg .cat-nose { fill: var(--accent, #FF3B5C); }
.enh-cat-svg .cat-blush { fill: var(--accent, #FF3B5C); opacity: .22; }
.enh-cat-svg .cat-whisker, .enh-cat-svg .cat-mouth { stroke: var(--text-dim, #8E8E93); stroke-width: 1.4; fill: none; stroke-linecap: round; }
@keyframes enhCatFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes enhCatBlink { 0%, 90%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.12); } }
@media (prefers-reduced-motion: reduce) { .enh-cat { animation: none; } .enh-cat-svg .cat-eye { animation: none; } }

/* Stan reacts: thinking-cat peeks in while the agent is working (decorative, never blocks taps). */
.enh-statuscat {
  position: fixed; right: 14px; bottom: calc(var(--composer-h, 132px) + 14px); z-index: 7; width: 54px;
  pointer-events: none; opacity: 0; transform: translateY(10px) scale(.9);
  transition: opacity .25s ease, transform .25s ease;
}
.enh-statuscat.show { opacity: 1; transform: none; }
.enh-statuscat img { width: 100%; height: auto; display: block; filter: drop-shadow(0 6px 12px rgba(0,0,0,.20)); }
@media (prefers-reduced-motion: reduce) { .enh-statuscat { transition: opacity .15s ease; transform: none; } }

/* ════════════════════════════════════════════════════════════════════════
   Motion & life pass — additive. Page transitions · sliding tab indicator ·
   stat count-up pulse · list stagger · skeleton shimmer · typing dots.
   Single accent, no glows (per DESIGN.md). All respect reduced-motion.
   ════════════════════════════════════════════════════════════════════════ */

/* 1 · Page transition when a .tab-panel becomes visible */
@keyframes enh-page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.tab-panel.enh-page-in { animation: enh-page-in .22s cubic-bezier(.22,.61,.36,1) both; }

/* 2 · Sliding active-tab indicator — rides the tab bar's top hairline */
#enh-tabline {
  position: absolute; top: 0; left: 0; height: 2px; width: 0; opacity: 0;
  background: var(--accent); border-radius: 0 0 2px 2px; pointer-events: none; z-index: 11;
  transition: transform .34s var(--ease), width .34s var(--ease), opacity .2s ease;
}

/* 3 · Stat live-pulse on value change (scale only — quiet, on-brand) */
@keyframes enh-pulse { 0% { transform: scale(1); } 35% { transform: scale(1.07); } 100% { transform: scale(1); } }
.enh-pulse { animation: enh-pulse .42s var(--ease); transform-origin: left center; }
.pi-stat-val.enh-pulse, .pi-tile-val.enh-pulse { transform-origin: center; }

/* 4 · Staggered list-row entrance */
.enh-row-in { animation: enh-in .34s cubic-bezier(.22,.61,.36,1) both; animation-delay: calc(min(var(--enh-i, 0), 12) * 38ms); }

/* 5 · Skeleton shimmer (DESIGN.md: skeletons, never spinners). Theme-aware. */
.enh-skel { padding: 6px 0; }
.enh-skel-row {
  height: 52px; border-radius: var(--r-md, 12px); margin: 8px 16px;
  background: linear-gradient(100deg, var(--bg-secondary) 30%, var(--border-mid) 50%, var(--bg-secondary) 70%);
  background-size: 200% 100%; animation: enh-shimmer 1.25s ease-in-out infinite;
}
@keyframes enh-shimmer { 0% { background-position: 180% 0; } 100% { background-position: -80% 0; } }

/* 6 · Chat typing indicator — three bouncing dots */
.enh-typing {
  display: inline-flex; align-items: center; gap: 5px; width: fit-content;
  padding: 10px 14px; margin: 6px 0 6px 2px; background: var(--bg-secondary); border-radius: 14px;
}
.enh-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); display: inline-block; animation: enh-bounce 1.1s ease-in-out infinite; }
.enh-typing i:nth-child(2) { animation-delay: .15s; }
.enh-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes enh-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .tab-panel.enh-page-in { animation: none; }
  #enh-tabline { transition: opacity .15s ease; }
  .enh-pulse { animation: none; }
  .enh-row-in { animation: none; }
  .enh-skel-row { animation: none; }
  .enh-typing i { animation: none; opacity: .6; }
}

/* ════════════════════════════════════════════════════════════════════════
   Per-page micro-interactions (deck) — pure CSS, confirmed selectors.
   Press feedback · focus rings · hover lift · smooth bars · Power=destructive.
   Single accent, rings use accent-dim (no glows). Respects reduced-motion.
   ════════════════════════════════════════════════════════════════════════ */

/* Terminal key bar — tactile press */
#keybar .key-btn { transition: transform .08s ease, background-color .12s ease, color .12s ease; }
#keybar .key-btn:active { transform: scale(.9); background: var(--accent-dim); color: var(--accent); }

/* Projects pin chips — press + settle */
.pin-chip { transition: transform .1s var(--ease, ease), background-color .15s, border-color .15s; }
.pin-chip:active { transform: scale(.93); }

/* Agents launcher search — focus ring (accent-dim, not a glow) */
.launcher-search { transition: border-color .15s, box-shadow .2s; }
.launcher-search:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-dim); outline: none; }

/* Pi overview tiles — hover lift + smooth animated bar fill */
.pi-stat-tile { transition: transform .16s var(--ease, ease), box-shadow .16s; }
.pi-stat-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.pi-tile-bar-fill { transition: width .5s var(--ease, ease); }

/* Pi control segment nav — press + active; Power = destructive red */
.pi-seg-btn { transition: transform .1s ease, color .15s, background-color .15s; }
.pi-seg-btn:active { transform: scale(.95); }
.pi-seg-btn[data-section="power"]:hover,
.pi-seg-btn[data-section="power"].active { color: var(--red); }

/* Screen connect — press feedback + gentle attention pulse while it's the lone CTA */
#screen-topbar-connect-btn { transition: transform .12s ease, background-color .15s; }
#screen-topbar-connect-btn:active { transform: scale(.95); }
@keyframes enh-attn { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }
#screen-topbar-connect-btn:not([style*="display: none"]):not([style*="display:none"]) { animation: enh-attn 2.6s ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) {
  #keybar .key-btn:active, .pin-chip:active, .pi-seg-btn:active, #screen-topbar-connect-btn:active { transform: none; }
  .pi-stat-tile:hover { transform: none; }
  .pi-tile-bar-fill { transition: none; }
  #screen-topbar-connect-btn { animation: none; }
}

/* ════════════════════════════════════════════════════════════════════════
   Glow pass (deck) — accent halos on active/live elements. rgba fallbacks.
   ════════════════════════════════════════════════════════════════════════ */
#enh-tabline { box-shadow: 0 0 9px var(--glow-accent, rgba(255,59,92,.42)); }
.tab-btn.active svg { filter: drop-shadow(0 0 6px var(--glow-accent-soft, rgba(255,59,92,.3))); }
.launcher-search:focus { box-shadow: 0 0 0 4px var(--accent-dim), 0 0 15px var(--glow-accent-soft, rgba(255,59,92,.22)); }
.pi-tile-bar-fill { box-shadow: 0 0 8px var(--glow-accent-soft, rgba(255,59,92,.22)); }
.pi-seg-btn.active { box-shadow: 0 0 10px var(--glow-accent-soft, rgba(255,59,92,.22)); }

/* ════════════════════════════════════════════════════════════════════════
   Motion pass v2 (deck) — more life. Decorative; reduced-motion guarded.
   ════════════════════════════════════════════════════════════════════════ */
/* Active tab icon springs when selected */
@keyframes tab-pop { 0% { transform: scale(1); } 40% { transform: scale(1.22); } 100% { transform: scale(1); } }
.tab-btn.active svg { animation: tab-pop .4s var(--ease, cubic-bezier(.16,1,.3,1)); }
/* Pi load bars: a sheen sweeps across the fill */
.pi-tile-bar-fill { position: relative; overflow: hidden; }
.pi-tile-bar-fill::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,.3), transparent); transform: translateX(-100%); animation: bar-sheen 2.6s ease-in-out infinite; }
@keyframes bar-sheen { 0% { transform: translateX(-100%); } 60%,100% { transform: translateX(240%); } }
/* Stat tile hover gains a glow */
.pi-stat-tile:hover { box-shadow: var(--shadow-sm), 0 0 14px var(--glow-accent-soft, rgba(255,59,92,.2)); }
/* Press glows */
#keybar .key-btn:active { box-shadow: 0 0 12px var(--glow-accent, rgba(255,59,92,.45)); }
.pin-chip:active { box-shadow: 0 0 10px var(--glow-accent-soft, rgba(255,59,92,.25)); }

/* Tap ripple on the main interactive controls (JS injects .enh-ripple) */
.tab-btn, .pi-seg-btn, .key-btn, .pin-chip { overflow: hidden; }
.enh-ripple { position: absolute; border-radius: 50%; background: var(--glow-accent, rgba(255,59,92,.4)); opacity: .5; transform: scale(0); pointer-events: none; animation: enh-ripple .55s ease-out forwards; }
@keyframes enh-ripple { to { transform: scale(2.4); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .tab-btn.active svg, .pi-tile-bar-fill::after, .enh-ripple { animation: none; }
}
