/* agent-thinking-polish.css — Phase 9.1
 * Polish "Mei Agent thinking" timeline UI giống Claude artifacts:
 * gradient marker, smooth animations, placeholder thinking khi chưa có tool call.
 * Override các class .status-* trong quikAI.css mà không sửa file gốc.
 */

/* ── Inline emoji prefix support (Phase 9.2 narrative) ───────────────────
 * Detail có thể bắt đầu bằng emoji (📋 ✓ 🔍 📚 ✨...) — render to hơn để dễ scan.
 */
.status-step-detail {
  font-feature-settings: "liga" 1;
}

/* ── Container ──────────────────────────────────────────────────────────── */
.status-activity {
  position: relative;
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.96) 0%, rgba(241, 245, 249, 0.92) 100%);
  border: 1px solid rgba(226, 232, 240, 0.85);
  border-radius: 12px;
  padding: 12px 14px 10px;
  margin: 4px 0 8px;
  backdrop-filter: blur(8px);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 0 0 1px rgba(15, 23, 42, 0.02);
  transition: padding 0.22s ease, background 0.22s ease, border-color 0.22s ease, opacity 0.25s ease;
}

/* ── Toggle button (collapse / expand) ──────────────────────────────────── */
.status-activity-toggle {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.04);
  color: #475569;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.status-activity-toggle:hover {
  background: rgba(15, 23, 42, 0.08);
  color: #0f172a;
}
.status-activity-toggle:active { transform: scale(0.94); }
.status-activity-toggle svg { width: 12px; height: 12px; }

/* ── Collapsed mode ─────────────────────────────────────────────────────── */
.status-activity.is-collapsed {
  padding: 8px 14px;
  background: linear-gradient(180deg, rgba(241, 245, 249, 0.6) 0%, rgba(226, 232, 240, 0.45) 100%);
  border-color: rgba(203, 213, 225, 0.6);
}
.status-activity.is-collapsed .status-activity-head {
  margin-bottom: 0;
}
.status-activity.is-collapsed .status-step-list,
.status-activity.is-collapsed .status-activity-count,
.status-activity.is-collapsed .status-activity-kicker {
  display: none !important;
}
.status-activity.is-collapsed .status-activity-current {
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  letter-spacing: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.status-activity.is-collapsed .status-activity-current::after {
  display: none;
}
.status-activity.is-collapsed .status-activity-current::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(16, 185, 129, 0.35);
  /* SVG check inline qua mask */
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><circle cx='8' cy='8' r='8' fill='black'/><path d='M3.5 8.5l3 3 6-6.5' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/></svg>") center/14px no-repeat;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><circle cx='8' cy='8' r='8' fill='black'/><path d='M3.5 8.5l3 3 6-6.5' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/></svg>") center/14px no-repeat;
}

.status-activity.is-thinking-only {
  background: linear-gradient(180deg, rgba(254, 252, 232, 0.85) 0%, rgba(254, 249, 195, 0.6) 100%);
  border-color: rgba(250, 204, 21, 0.35);
}

.status-activity.is-thinking-only::before {
  content: "✨";
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 14px;
  animation: cap-thinking-sparkle 1.6s ease-in-out infinite;
}

@keyframes cap-thinking-sparkle {
  0%, 100% { opacity: 0.5; transform: scale(0.9) rotate(0deg); }
  50%      { opacity: 1;   transform: scale(1.15) rotate(20deg); }
}

/* ── Header (kicker + current tool) ─────────────────────────────────────── */
.status-activity-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}

.status-activity-kicker {
  display: inline-flex !important;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #2563eb;
  margin-bottom: 1px;
}

.is-thinking-only .status-activity-kicker {
  color: #ca8a04;
}

.status-activity-current {
  font-size: 13px;
  font-weight: 600;
  color: #0f172a;
  letter-spacing: -0.01em;
}

.status-activity-current::after {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #2563eb;
  margin-left: 6px;
  vertical-align: middle;
  animation: cap-pulse-dot 1.2s ease-in-out infinite;
}

.is-thinking-only .status-activity-current::after {
  background: #ca8a04;
}

@keyframes cap-pulse-dot {
  0%, 100% { opacity: 0.3; transform: scale(0.85); }
  50%      { opacity: 1;   transform: scale(1.2); }
}

.status-activity-count {
  font-size: 10.5px;
  color: #64748b;
  font-weight: 500;
  margin-top: 2px;
}

/* ── Step list (timeline) ───────────────────────────────────────────────── */
.status-step-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0 4px 0 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
  /* Phase 9.2: scroll khi nhiều steps (>10 entries → ~400px height) */
  max-height: 420px;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.4) transparent;
}

.status-step-list::-webkit-scrollbar {
  width: 6px;
}
.status-step-list::-webkit-scrollbar-track {
  background: transparent;
}
.status-step-list::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.35);
  border-radius: 3px;
}
.status-step-list::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.55);
}

.status-step-item {
  display: grid;
  grid-template-columns: 22px 1fr;
  column-gap: 10px;
  padding: 5px 0;
  align-items: flex-start;
  position: relative;
  animation: cap-step-slide-in 0.32s cubic-bezier(0.4, 0, 0.2, 1) both;
}

@keyframes cap-step-slide-in {
  from { opacity: 0; transform: translateX(-6px); }
  to   { opacity: 1; transform: translateX(0); }
}

.status-step-item:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 10.5px;
  top: 22px;
  bottom: -3px;
  width: 1.5px;
  background: linear-gradient(180deg, rgba(148, 163, 184, 0.45) 0%, rgba(148, 163, 184, 0.15) 100%);
  border-radius: 1px;
}

/* ── Marker (circle with state icon) ────────────────────────────────────── */
.status-step-marker {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border: 2px solid #cbd5e1;
  color: #64748b;
  flex-shrink: 0;
  transition: all 0.25s ease;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.status-step-item.is-running .status-step-marker {
  border-color: transparent;
  background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  color: #ffffff;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12), 0 2px 4px rgba(59, 130, 246, 0.25);
  animation: cap-marker-pulse 2s ease-in-out infinite;
}

@keyframes cap-marker-pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12), 0 2px 4px rgba(59, 130, 246, 0.25); }
  50%      { box-shadow: 0 0 0 7px rgba(59, 130, 246, 0.18), 0 2px 6px rgba(59, 130, 246, 0.35); }
}

.status-step-item.is-done .status-step-marker {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(16, 185, 129, 0.3);
}

.status-step-item.is-error .status-step-marker {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(239, 68, 68, 0.3);
}

.status-step-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: cap-spin 0.7s linear infinite;
}

@keyframes cap-spin {
  to { transform: rotate(360deg); }
}

.status-step-marker svg {
  width: 12px;
  height: 12px;
  stroke-width: 2.4;
}

/* Thinking placeholder — vàng/amber gradient instead of blue */
.is-thinking-placeholder .status-step-marker {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%) !important;
  box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.18), 0 2px 4px rgba(251, 191, 36, 0.3) !important;
  animation: cap-marker-pulse-amber 2s ease-in-out infinite !important;
}

@keyframes cap-marker-pulse-amber {
  0%, 100% { box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.18), 0 2px 4px rgba(251, 191, 36, 0.3); }
  50%      { box-shadow: 0 0 0 7px rgba(251, 191, 36, 0.28), 0 2px 6px rgba(251, 191, 36, 0.4); }
}

/* ── Step copy (title-row [title + duration] + detail) ─────────────────── */
.status-step-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  padding-top: 1px;
}

.status-step-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.status-step-title {
  font-size: 12.5px;
  font-weight: 600;
  color: #0f172a;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
}

/* Duration badge — số mờ bên phải title (Claude-style "1.2s") */
.status-step-duration {
  flex: 0 0 auto;
  font-size: 10.5px;
  font-weight: 500;
  color: #94a3b8;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  white-space: nowrap;
  opacity: 0.85;
  transition: opacity 0.2s ease;
}
.status-step-duration.is-live {
  color: #6366f1;
  opacity: 1;
  /* nhấp nháy nhẹ để cho thấy đang đếm */
  animation: cap-duration-live-pulse 1.6s ease-in-out infinite;
}
@keyframes cap-duration-live-pulse {
  0%, 100% { opacity: 0.65; }
  50%      { opacity: 1; }
}
.status-step-item.is-done .status-step-duration {
  color: #94a3b8;
  opacity: 0.7;
}
.status-step-item.is-error .status-step-duration {
  color: #ef4444;
  opacity: 0.85;
}

.status-step-item.is-done .status-step-title {
  color: #475569;
  font-weight: 500;
}

.status-step-item.is-running .status-step-title {
  background-image: linear-gradient(90deg, #1e40af, #3730a3);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  font-weight: 600;
}

.is-thinking-placeholder .status-step-title {
  background-image: linear-gradient(90deg, #b45309, #d97706) !important;
  -webkit-background-clip: text !important;
  background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  color: transparent;
}

.status-step-detail {
  font-size: 11.5px;
  color: #64748b;
  line-height: 1.5;
  word-break: break-word;
  /* Phase 9.2: KHÔNG clamp, hiển thị FULL narrative để user theo dõi từng action */
  white-space: normal;
}

.status-step-item.is-done .status-step-detail {
  opacity: 0.7;
}

/* Shimmer effect cho running step detail */
.status-step-item.is-running .status-step-detail {
  position: relative;
  background: linear-gradient(90deg, #64748b 0%, #94a3b8 50%, #64748b 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: cap-shimmer 2.4s linear infinite;
}

@keyframes cap-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Dark mode auto support (nếu app có toggle dark) ────────────────────── */
@media (prefers-color-scheme: dark) {
  .status-activity {
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.85) 0%, rgba(15, 23, 42, 0.7) 100%);
    border-color: rgba(71, 85, 105, 0.5);
  }
  .status-activity.is-thinking-only {
    background: linear-gradient(180deg, rgba(120, 53, 15, 0.4) 0%, rgba(69, 26, 3, 0.3) 100%);
    border-color: rgba(217, 119, 6, 0.4);
  }
  .status-activity.is-collapsed {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.55) 0%, rgba(2, 6, 23, 0.4) 100%);
    border-color: rgba(71, 85, 105, 0.45);
  }
  .status-activity.is-collapsed .status-activity-current { color: #cbd5e1; }
  .status-activity-current { color: #f1f5f9; }
  .status-step-item:not(.is-running):not(.is-done):not(.is-error) .status-step-marker {
    background: #1e293b; border-color: #475569; color: #94a3b8;
  }
  .status-step-title { color: #f1f5f9; }
  .status-step-item.is-done .status-step-title { color: #94a3b8; }
  .status-step-detail { color: #94a3b8; }
  .status-step-duration { color: #64748b; }
  .status-step-duration.is-live { color: #a5b4fc; }
  .status-step-item:not(:last-child)::before {
    background: linear-gradient(180deg, rgba(100, 116, 139, 0.5) 0%, rgba(71, 85, 105, 0.2) 100%);
  }
  .status-activity-toggle {
    background: rgba(255, 255, 255, 0.06);
    color: #cbd5e1;
  }
  .status-activity-toggle:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #f1f5f9;
  }
}

/* Theme-dark class (app's manual toggle) — same overrides */
:root.theme-dark .status-activity,
:root.dark .status-activity {
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.85) 0%, rgba(15, 23, 42, 0.7) 100%);
  border-color: rgba(71, 85, 105, 0.5);
}
:root.theme-dark .status-activity.is-thinking-only,
:root.dark .status-activity.is-thinking-only {
  background: linear-gradient(180deg, rgba(120, 53, 15, 0.4) 0%, rgba(69, 26, 3, 0.3) 100%);
  border-color: rgba(217, 119, 6, 0.4);
}
:root.theme-dark .status-activity.is-collapsed,
:root.dark .status-activity.is-collapsed {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.55) 0%, rgba(2, 6, 23, 0.4) 100%);
  border-color: rgba(71, 85, 105, 0.45);
}
:root.theme-dark .status-activity-current,
:root.dark .status-activity-current { color: #f1f5f9; }
/* Marker mặc định (idle): chỉ override khi KHÔNG phải running/done/error,
   tránh đè lên gradient màu của các state quan trọng. */
:root.theme-dark .status-step-item:not(.is-running):not(.is-done):not(.is-error) .status-step-marker,
:root.dark .status-step-item:not(.is-running):not(.is-done):not(.is-error) .status-step-marker {
  background: #1e293b;
  border-color: #475569;
  color: #94a3b8;
}
:root.theme-dark .status-step-title,
:root.dark .status-step-title { color: #f1f5f9; }
:root.theme-dark .status-step-item.is-done .status-step-title,
:root.dark .status-step-item.is-done .status-step-title { color: #94a3b8; }
:root.theme-dark .status-step-detail,
:root.dark .status-step-detail { color: #94a3b8; }
:root.theme-dark .status-step-duration,
:root.dark .status-step-duration { color: #64748b; }
:root.theme-dark .status-step-duration.is-live,
:root.dark .status-step-duration.is-live { color: #a5b4fc; }
:root.theme-dark .status-activity-toggle,
:root.dark .status-activity-toggle {
  background: rgba(255, 255, 255, 0.06);
  color: #cbd5e1;
}
:root.theme-dark .status-activity-toggle:hover,
:root.dark .status-activity-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #f1f5f9;
}

/* Reduce motion: tắt shimmer/pulse */
@media (prefers-reduced-motion: reduce) {
  .status-activity-current::after,
  .status-step-item.is-running .status-step-marker,
  .is-thinking-placeholder .status-step-marker,
  .status-step-item.is-running .status-step-detail,
  .status-step-duration.is-live,
  .status-activity.is-thinking-only::before {
    animation: none !important;
  }
}
