/* CROC Chat — 16-Motion High-Tech Apple UI Animation System
   1. Spotlight · 2. Scroll Reveal · 3. Border Glow · 4. Magnetic · 5. Sticky Narrative
   6. 3D Tilt · 7. Text Decode · 8. Shimmer Sweep · 9. Parallax · 10. Count-Up
   11. Hover Lift · 12. Typewriter · 13. Stagger · 14. Marquee · 15. Spring · 16. Easing */

:root {
  --ease-apple: cubic-bezier(0.25, 0.1, 0.25, 1);
  --ease-spring: cubic-bezier(0.22, 1.16, 0.36, 1);
  --ease-decel: cubic-bezier(0.16, 1, 0.3, 1);
}

/* 15 & 16: Spring & Natural Easing Entrances */
@keyframes crocViewIn {
  from { opacity: 0; transform: translateY(8px) scale(0.994); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes crocStaggerIn {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* 3: Edge Border Flow Glow (边缘流光) */
@keyframes crocBorderFlow {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* 8: Shimmer Sweep (流光扫过) */
@keyframes crocSheen {
  0%   { transform: translateX(-140%) skewX(-22deg); }
  100% { transform: translateX(260%) skewX(-22deg); }
}

@keyframes crocProgressFlow {
  0%   { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

/* 14: Marquee Horizontal Ticker (跑马灯) */
@keyframes crocMarquee {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* SVG Complete Line Draw using pathLength="100" (NEVER cuts off!) */
@keyframes crocDraw100 {
  from { stroke-dashoffset: 100; }
  to   { stroke-dashoffset: 0; }
}

@keyframes crocPinFlash {
  0%   { background: var(--accent-soft); }
  100% { background: transparent; }
}

@keyframes grokShimmer {
  0%   { background-position: -180% 0; }
  100% { background-position: 180% 0; }
}

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-2.5px); opacity: 1; }
}

/* 13: Staggered Entrance — ONLY on actual route navigation (ZERO jitter on button clicks!) */
.workspace-main.route-entering > * {
  animation: crocViewIn 220ms var(--ease-decel) both;
}

.workspace-main.route-entering .page-scroll > .grid-4 > *,
.workspace-main.route-entering .page-scroll > .grid-3 > *,
.workspace-main.route-entering .page-scroll > .grid-2 > *,
.workspace-main.route-entering .stagger-grid > * {
  animation: crocStaggerIn 300ms var(--ease-spring) both;
}
.workspace-main.route-entering .page-scroll > .grid-4 > *:nth-child(2),
.workspace-main.route-entering .page-scroll > .grid-3 > *:nth-child(2),
.workspace-main.route-entering .page-scroll > .grid-2 > *:nth-child(2),
.workspace-main.route-entering .stagger-grid > *:nth-child(2) { animation-delay: 40ms; }
.workspace-main.route-entering .page-scroll > .grid-4 > *:nth-child(3),
.workspace-main.route-entering .page-scroll > .grid-3 > *:nth-child(3),
.workspace-main.route-entering .stagger-grid > *:nth-child(3) { animation-delay: 80ms; }
.workspace-main.route-entering .page-scroll > .grid-4 > *:nth-child(4),
.workspace-main.route-entering .stagger-grid > *:nth-child(4) { animation-delay: 120ms; }

/* 2: Scroll Reveal (滚动显现) */
.reveal-on-scroll {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 420ms var(--ease-decel), transform 460ms var(--ease-spring);
}
.reveal-on-scroll.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* 1 & 6 & 11: Colour/opacity feedback only (zero hover lift or press scale jitter) */
.card-interactive,
.kpi-card,
.org-bento-card {
  position: relative;
  overflow: visible;
  transition: background-color 160ms var(--ease-fluid), opacity 160ms var(--ease-fluid);
}
.card-interactive:active,
.nav-item:active {
  opacity: 0.85;
  transition-duration: 0ms;
}

/* 3: Edge Border Flow Glow Card (边缘流光) */
.border-glow-card {
  position: relative;
  border: 1px solid transparent !important;
  background-clip: padding-box;
}
.border-glow-card::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1.5px;
  background: linear-gradient(120deg, rgba(59, 102, 148, 0.12), rgba(59, 102, 148, 0.48), rgba(110, 159, 212, 0.36), rgba(59, 102, 148, 0.12));
  background-size: 260% 260%;
  animation: crocBorderFlow 4.2s ease 1;
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* 4 & 8: Primary Button (colour & opacity only) */
.btn-primary {
  position: relative;
  overflow: visible;
  transition: background-color 160ms ease, opacity 160ms ease;
}

/* 14: Marquee Ticker Strip (跑马灯，支持悬停暂停) */
.croc-marquee {
  position: relative;
  overflow: hidden;
  border-radius: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 10px 0;
  mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
}
.croc-marquee-track {
  display: flex;
  align-items: center;
  gap: 14px;
  width: max-content;
  animation: crocMarquee 26s linear 1;
}
.croc-marquee:hover .croc-marquee-track {
  animation-play-state: paused;
}

/* 5: Sticky Narrative Header (滚动叙事吸顶头) */
.sticky-narrative {
  position: sticky;
  top: 0;
  z-index: 12;
  background: var(--bg-surface-solid);
  margin: -26px -30px 0;
  padding: 16px 30px;
  border-bottom: none;
  box-shadow: var(--shadow-1);
}

/* Big-Tech Airy Tinted Unread Counter (Apple / Linear / Claude style — zero heavy black blobs!) */
.badge-unread {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-sans);
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 680;
  letter-spacing: 0;
  color: var(--accent-text);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
  text-shadow: none;
}
[data-theme="dark"] .badge-unread {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-text);
  box-shadow: none;
}

/* Progress Bar */
.progress-fill {
  position: relative;
  overflow: hidden;
  background: var(--accent);
}

/* Grok Thinking & Typing Dots */
.grok-thinking-shimmer {
  color: var(--accent-text);
  font-weight: 600;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.typing-dots span {
  width: 4.5px;
  height: 4.5px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typingBounce 1.15s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 150ms; }
.typing-dots span:nth-child(3) { animation-delay: 300ms; }

.msg-pin-highlight {
  border-radius: 16px;
  animation: crocPinFlash 1.4s ease-out;
}

/* Downloadable File Card */
.media-file-card {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-raised-sm);
  max-width: 380px;
  color: var(--text-primary);
}
.media-file-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Complete Drawn Org Tree Paths (uses pathLength="100" so NEVER truncated!) */
.org-tree-branch {
  stroke-dasharray: 100;
  stroke-dashoffset: 0;
  animation: crocDraw100 820ms var(--ease-decel) both;
}

/* Living Avatar Status Flow Rings (replaces dead tiny circle!) */
@keyframes avatarRingSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes avatarRingBreathe {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50%      { opacity: 1; transform: scale(1.05); }
}
@keyframes streamChunkIn {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Minimalist Linear/Apple Presence Indicator on Squircle Avatar */
@keyframes presencePulse {
  0%, 100% { opacity: 0.75; transform: scale(1); }
  50%      { opacity: 1; transform: scale(1.12); }
}
@keyframes presenceThink {
  0%, 100% { opacity: 0.65; transform: scale(1); }
  50%      { opacity: 1; transform: scale(1.10); }
}
.avatar-flow-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.avatar-presence-pip {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 9.5px;
  height: 9.5px;
  border-radius: 50%;
  border: 2px solid var(--bg-surface-solid);
  pointer-events: none;
}
/* L7：状态点改静态实色——删掉动 box-shadow 的点脉冲（presencePulse /
   presenceThink），呼吸感由细环承担。@keyframes 定义保留（他处若引用
   不报错），不再被任何 pip 引用。 */
.avatar-presence-pip.pip-working  { background: #3b6694; }
/* L5 简约风：thinking 点改低调灰，不要紫。 */
.avatar-presence-pip.pip-thinking { background: #9aa0a6; }
.avatar-presence-pip.pip-idle     { background: #6e7582; }
.avatar-presence-pip.pip-waiting,
.avatar-presence-pip.pip-delayed  { background: #9a5b13; }
.avatar-presence-pip.pip-blocked,
.avatar-presence-pip.pip-error    { background: #b8293d; }
.avatar-presence-pip.pip-offline  { background: #94a3b8; }
/* L7：乐观等待态——空心灰点（已发消息、无真实信号，不冒充思考中）。 */
.avatar-presence-pip.pip-waiting-optimistic {
  background: transparent;
  border-color: var(--text-muted);
}
/* L7：信号过期态——同色点半透明，不许当在线用。 */
.avatar-presence-pip.emp-status-stale { opacity: 0.55; }

/* L7：侧边栏/目录行状态行——仅活动态显示的一行 11px 小字，文案只取真实信号。 */
.comm-emp-status-line {
  margin-top: 2px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.comm-emp-status-line .typing-dots {
  margin-right: 2px;
  vertical-align: middle;
}
.avatar-flow-ring {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}
.avatar-flow-ring.ring-working {
  border: 2px solid #3b6694;
}
/* L5 简约风：thinking 光环改低调灰，不要紫/蓝。 */
.avatar-flow-ring.ring-thinking {
  border: 2px solid #9aa0a6;
}
.avatar-flow-ring.ring-idle {
  border: 1.5px solid rgba(59, 102, 148, 0.52);
}
.avatar-flow-ring.ring-waiting,
.avatar-flow-ring.ring-delayed {
  border: 1.5px solid rgba(154, 91, 19, 0.68);
}
.avatar-flow-ring.ring-blocked,
.avatar-flow-ring.ring-error {
  border: 1.5px solid rgba(184, 41, 61, 0.75);
}
.avatar-flow-ring.ring-offline {
  border: 1.5px dashed rgba(148, 163, 184, 0.55);
}

.stream-chunk {
  display: inline;
  animation: streamChunkIn 280ms var(--ease-decel) both;
}

/* Frosted Blurred Thinking / Tool-Call Trace (Claude / Grok / Antigravity style) */
.thinking-trace-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 9px 13px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.03);
  border: 1px solid var(--border-subtle);
  max-width: 520px;
}
[data-theme="dark"] .thinking-trace-card {
  background: rgba(255, 255, 255, 0.035);
}
.thinking-trace-line {
  font-size: 12.5px;
  color: var(--text-muted);
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 7px;
  animation: streamChunkIn 320ms var(--ease-decel) both;
}
.thinking-trace-line.active {
  color: var(--text-secondary);
  filter: none;
  opacity: 1;
}

/* Creative Editorial AI Activity Indicators (Neural Wave Bars + Orbital Spark + Ghost Draft) */
/* L5: 高度动画会触发布局，改 transform（scaleY），只动合成层。 */
@keyframes aiWaveBar {
  0%, 100% { transform: scaleY(0.3); opacity: 0.4; }
  50%      { transform: scaleY(1); opacity: 0.95; }
}
@keyframes aiOrbitSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes aiGhostBreathe {
  0%, 100% { opacity: 0.34; filter: blur(2.2px); }
  50%      { opacity: 0.56; filter: blur(1.4px); }
}

.ai-wave-bars {
  display: inline-flex;
  align-items: center;
  gap: 2.5px;
  height: 14px;
}
.ai-wave-bars span {
  width: 2px;
  height: 13px;
  border-radius: 2px;
  background: var(--text-secondary);
  transform-origin: center;
  animation: aiWaveBar 1.05s infinite ease-in-out;
}
.ai-wave-bars span:nth-child(2) { animation-delay: 140ms; }
.ai-wave-bars span:nth-child(3) { animation-delay: 280ms; }
.ai-wave-bars span:nth-child(4) { animation-delay: 420ms; }

.ai-orbit-svg {
  width: 15px;
  height: 15px;
  animation: aiOrbitSpin 2.6s linear infinite;
  color: var(--accent);
  flex-shrink: 0;
}

.ai-ghost-draft {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
  max-width: 440px;
  user-select: none;
  animation: aiGhostBreathe 2.6s ease-in-out infinite;
  transition: filter 220ms ease, opacity 220ms ease;
}
.ai-ghost-draft:hover {
  animation: none;
  filter: blur(0.6px);
  opacity: 0.72;
}

.croc-dd-menu.scrollable {
  max-height: 260px;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

/* ---- L5 真流式增量渲染（简约风：低调灰，不要绿、不要紫）---- */

/* 流式光标：生成中在气泡末尾闪烁，生成结束（转正）即移除。 */
@keyframes streamCursorBlink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0; }
}
.stream-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--text-secondary);
  animation: streamCursorBlink 0.9s steps(1) infinite;
}

/* 非贴底时底部“有新消息”提示：sticky 贴在 feed 底部，不动滚动条。 */
.comm-new-msg-banner {
  position: sticky;
  bottom: 12px;
  align-self: center;
  z-index: 5;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-raised-sm);
  cursor: pointer;
}
.comm-new-msg-banner:hover {
  color: var(--text-primary);
  border-color: var(--border-strong, var(--border-default));
}

/* L7 & C2：减弱动效偏好（系统偏好 + 设置开关） */
@media (prefers-reduced-motion: reduce) {
  .workspace-main.route-entering > *,
  .workspace-main.route-entering .page-scroll > .grid-4 > *,
  .workspace-main.route-entering .page-scroll > .grid-3 > *,
  .workspace-main.route-entering .page-scroll > .grid-2 > *,
  .workspace-main.route-entering .stagger-grid > *,
  .stream-chunk,
  .thinking-trace-line,
  .grok-thinking-shimmer,
  .ai-wave-bars span,
  .ai-orbit-svg,
  .ai-ghost-draft,
  .border-glow-card::after,
  .btn-primary::before,
  .croc-marquee-track,
  .progress-fill,
  .avatar-flow-ring,
  .typing-dots span {
    animation: none !important;
    transition: none !important;
  }
  .reveal-on-scroll {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  .card-interactive:hover,
  .kpi-card:hover,
  .org-bento-card:hover,
  .card-interactive:active,
  .nav-item:active {
    transform: none !important;
  }
}

[data-reduce-motion="true"] .workspace-main.route-entering > *,
[data-reduce-motion="true"] .workspace-main.route-entering .page-scroll > .grid-4 > *,
[data-reduce-motion="true"] .workspace-main.route-entering .page-scroll > .grid-3 > *,
[data-reduce-motion="true"] .workspace-main.route-entering .page-scroll > .grid-2 > *,
[data-reduce-motion="true"] .workspace-main.route-entering .stagger-grid > *,
[data-reduce-motion="true"] .stream-chunk,
[data-reduce-motion="true"] .thinking-trace-line,
[data-reduce-motion="true"] .grok-thinking-shimmer,
[data-reduce-motion="true"] .ai-wave-bars span,
[data-reduce-motion="true"] .ai-orbit-svg,
[data-reduce-motion="true"] .ai-ghost-draft,
[data-reduce-motion="true"] .border-glow-card::after,
[data-reduce-motion="true"] .btn-primary::before,
[data-reduce-motion="true"] .croc-marquee-track,
[data-reduce-motion="true"] .progress-fill,
[data-reduce-motion="true"] .avatar-flow-ring,
[data-reduce-motion="true"] .typing-dots span {
  animation: none !important;
  transition: none !important;
}
[data-reduce-motion="true"] .reveal-on-scroll {
  opacity: 1 !important;
  transform: none !important;
  transition: none !important;
}
[data-reduce-motion="true"] .card-interactive:hover,
[data-reduce-motion="true"] .kpi-card:hover,
[data-reduce-motion="true"] .org-bento-card:hover,
[data-reduce-motion="true"] .card-interactive:active,
[data-reduce-motion="true"] .nav-item:active {
  transform: none !important;
}
