/* chat-v2.css — TREOSA 新版聊天 UI 设计系统 */

:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;

  /* 底色 */
  --bg-deep: #0f1117;
  --bg: #161821;
  --bg-card: #1c1f2a;
  --bg-hover: #222638;

  /* 边框 */
  --border: #2a2d3a;
  --border-strong: #3a3e4f;

  /* 文字 */
  --text: #e8e9ed;
  --text-secondary: #b0b3c0;
  --text-muted: #787b8a;

  /* 品牌色 — 琥珀金 */
  --amber: #d99828;
  --amber-light: #f0b840;
  --amber-glow: rgba(217, 152, 40, 0.15);

  /* 功能色 */
  --green: #4caf7d;
  --green-soft: rgba(76, 175, 125, 0.12);
  --red: #e06055;
  --red-soft: rgba(224, 96, 85, 0.1);
  --blue: #5b9bd5;
  --blue-soft: rgba(91, 155, 213, 0.1);

  /* 尺寸 */
  --max-width: 720px;
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  /* Fix #2: ensure body scroll is handled by .chat, not by body itself */
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}
/* Prevent text selection on long-press (anti-reverse #6) */
body {
  -webkit-user-select: none;
  user-select: none;
}
/* Allow selection in input/textarea */
input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

button, textarea, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
}

/* ===== Layout ===== */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;       /* fallback for old browsers */
  height: 100dvh;      /* override: dynamic viewport for mobile */
  min-height: 100vh;
  min-height: 100dvh;
}

/* ===== Top Bar ===== */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0px);
  height: 56px;
  height: calc(56px + env(safe-area-inset-top, 0px));
  background: rgba(15, 17, 23, 0.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.topbar-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  justify-self: center;
}

.topbar-brand strong {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--amber);
}

.topbar-brand span {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.memory-btn {
  display: flex !important;
  align-items: center;
  gap: 6px;
}

.memory-btn-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.btn-ghost {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.btn-ghost:hover {
  background: var(--bg-card);
  color: var(--text);
}

/* ===== Chat Area ===== */
.chat {
  flex: 1;
  min-height: 0;       /* Critical: allows flex child to shrink and scroll */
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;  /* momentum scrolling on iOS */
  padding: 24px 20px 16px;
  scroll-behavior: smooth;
}

/* Class-based hiding (avoids CSS [hidden] override issues) */
.hidden { display: none !important; }

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  padding: 40px 20px;
}

.empty-icon {
  margin-bottom: 24px;
  opacity: 0.6;
}

.empty-state h1 {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
  color: var(--text);
}

.empty-state > p {
  color: var(--text-secondary);
  font-size: 15px;
  max-width: 400px;
  margin-bottom: 32px;
  line-height: 1.6;
}

.starters {
  display: grid;
  gap: 10px;
  width: 100%;
  max-width: 480px;
}

.starter-btn {
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1.5;
}

.starter-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--text);
}

/* ===== Messages ===== */
.messages {
  display: flex;
  flex-direction: column;
  gap: 28px;
  max-width: var(--max-width);
  margin: 0 auto;
  padding-bottom: 20px;
}

/* User Message */
.msg-user {
  display: flex;
  justify-content: flex-end;
}

.msg-user .bubble {
  max-width: 75%;
  padding: 12px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px 18px 6px 18px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
}

.msg-user .attachments {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.msg-user .attachments img {
  max-width: 180px;
  max-height: 140px;
  border-radius: 10px;
  object-fit: cover;
}

/* Assistant Message */
.msg-assistant {
  display: flex;
  flex-direction: column;
}

/* Answer Card */
.answer-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  animation: card-in 0.35s ease-out;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Verdict Section */
.answer-verdict {
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}

.answer-verdict h2 {
  font-size: 18px;
  font-weight: 650;
  line-height: 1.55;
  color: var(--text);
  margin-bottom: 10px;
}

.answer-verdict p {
  font-size: 15px;
  line-height: 1.72;
  color: var(--text-secondary);
}

.answer-risk {
  margin-top: 14px;
  padding: 12px 16px;
  background: var(--amber-glow);
  border-left: 3px solid var(--amber);
  border-radius: 0 8px 8px 0;
  font-size: 14px;
  color: var(--amber-light);
  line-height: 1.65;
}

/* Sections */
.answer-sections {
  padding: 18px 22px;
}

.answer-section {
  margin-bottom: 20px;
}

.answer-section:last-child {
  margin-bottom: 0;
}

.answer-section h3 {
  font-size: 15px;
  font-weight: 650;
  color: var(--amber-light);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.answer-section h3::before {
  content: "";
  width: 4px;
  height: 4px;
  background: var(--amber);
  border-radius: 50%;
  flex-shrink: 0;
}

.answer-section ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.answer-section li {
  padding: 10px 14px;
  background: rgba(255,255,255,0.025);
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-secondary);
  border-left: 2px solid transparent;
  transition: border-color 0.2s;
}

.answer-section li:hover {
  border-left-color: var(--border-strong);
  background: rgba(255,255,255,0.04);
}

/* Choices */
.answer-choices {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.15);
}

.answer-choices-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.choice-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice-btn {
  padding: 10px 16px;
  background: var(--bg-hover);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.choice-btn:hover {
  background: var(--amber-glow);
  border-color: var(--amber);
  color: var(--amber-light);
}

.choice-btn-custom {
  border-style: dashed;
  color: var(--text-muted);
}

/* Follow-up */
.answer-followup {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--green);
  line-height: 1.65;
  background: var(--green-soft);
}

/* Sources */
.answer-sources {
  padding: 12px 22px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}

.answer-sources summary {
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 0;
}

.answer-sources summary:hover { color: var(--text-secondary); }

.source-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.source-item {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.source-item a {
  color: var(--blue);
  text-decoration: none;
}

.source-item a:hover { text-decoration: underline; }

.source-item.source-case { color: var(--orange, #f59e0b); }
.source-item.source-qbank { color: var(--purple, #a855f7); }
.source-item.source-knowledge { color: var(--green, #22c55e); }
.source-item.source-external { color: var(--blue, #3b82f6); }

.source-quality {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  background: rgba(168,85,247,0.15);
  color: var(--purple, #a855f7);
  margin-left: 6px;
}

/* Action */
.answer-action {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: var(--blue-soft);
}

.action-label {
  font-size: 12px;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.action-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.action-why {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 10px;
}

.action-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-meta-item {
  padding: 10px 12px;
  background: rgba(91,155,213,0.08);
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.5;
}

.action-meta-item strong {
  display: block;
  color: var(--blue);
  font-size: 11px;
  margin-bottom: 4px;
}

.action-meta-item span {
  color: var(--text-secondary);
}

/* Profit Preview */
.answer-profit {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: var(--amber-glow);
}

.profit-label {
  font-size: 12px;
  color: var(--amber);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.profit-number {
  font-size: 22px;
  font-weight: 700;
  color: var(--amber-light);
  margin-bottom: 6px;
}

.profit-detail {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ===== Rich Text Highlights ===== */
.direct-body {
  margin-bottom: 10px;
}
.direct-body:last-child {
  margin-bottom: 0;
}

mark.hl-quote {
  background: var(--amber-glow);
  color: var(--amber-light);
  padding: 1px 3px;
  border-radius: 3px;
  font-weight: 500;
}

mark.hl-book {
  color: var(--blue);
  font-weight: 500;
  background: transparent;
}

strong.hl-enum {
  color: var(--amber-light);
  font-weight: 650;
}

/* Feedback */
.answer-feedback {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding: 0 4px;
}

.feedback-btn {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-muted);
  border: 1px solid transparent;
  transition: all 0.2s;
}

.feedback-btn:hover {
  border-color: var(--border);
  color: var(--text-secondary);
}

.feedback-btn.active {
  background: var(--green-soft);
  border-color: var(--green);
  color: var(--green);
}

/* ===== Progress Panel ===== */
.progress-panel {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.progress-steps {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-step {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 0;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
}

/* Cascade reveal: slow fade-in → stay visible (removed quick fade-out so
   steps accumulate as the pipeline advances, then the panel hides as a whole) */
.progress-step.revealed {
  animation: step-cascade-stay 0.7s ease-out forwards;
  animation-delay: var(--step-delay, 0s);
}

/* Active step dot glow during reveal */
.progress-step.revealed .step-dot {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber-glow);
  animation: pulse-dot 1.2s ease-in-out infinite;
}

/* Done step stays visible */
.progress-step.revealed.stay {
  animation: step-cascade-stay 1s ease-out forwards;
  color: var(--green);
  font-weight: 500;
}
.progress-step.revealed.stay .step-dot {
  background: var(--green);
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.4);
  animation: none;
}
.progress-step.revealed.stay .step-check {
  opacity: 1;
  transform: scale(1);
}

.step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-strong);
  transition: background 0.3s, box-shadow 0.3s;
  flex-shrink: 0;
}

.step-label {
  flex: 1;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.7; }
}

/* === Cascade Animations === */

/* step-cascade-stay: fade in and stay visible until the panel hides */
@keyframes step-cascade-stay {
  0%   { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; }
  45%  { opacity: 1; max-height: 32px; padding-top: 4px; padding-bottom: 4px; }
  100% { opacity: 1; max-height: 32px; padding-top: 4px; padding-bottom: 4px; }
}

.step-check {
  width: 14px;
  height: 14px;
  opacity: 0;
  transform: scale(0);
  transition: all 0.3s;
}

.progress-cancel {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  flex-shrink: 0;
  transition: all 0.2s;
}

.progress-cancel:hover {
  border-color: var(--red);
  color: var(--red);
}

/* Cancel button — prominent during long LLM wait */
.progress-cancel.thinking-phase {
  padding: 10px 16px;
  border-color: var(--amber);
  color: var(--amber-light);
  font-weight: 600;
  animation: cancel-pulse 2s ease-in-out infinite;
}

@keyframes cancel-pulse {
  0%, 100% { border-color: var(--amber); box-shadow: 0 0 0 0 rgba(217, 152, 40, 0.3); }
  50% { border-color: var(--amber-light); box-shadow: 0 0 0 6px rgba(217, 152, 40, 0); }
}

/* Thinking indicator — appears below progress steps during LLM wait */
.progress-thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(217, 152, 40, 0.06);
  border: 1px dashed var(--amber);
  border-radius: 8px;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: all 0.3s ease-out;
}

.progress-thinking.active {
  opacity: 1;
  max-height: 48px;
}

.progress-thinking .thinking-dot {
  width: 6px;
  height: 6px;
  background: var(--amber);
  border-radius: 50%;
  animation: thinking-bounce 1.4s ease-in-out infinite;
}

.progress-thinking .thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.progress-thinking .thinking-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-6px); opacity: 1; }
}

.progress-thinking .thinking-text {
  font-size: 12px;
  color: var(--amber-light);
  margin-left: 4px;
}

/* ===== Composer ===== */
.composer {
  flex-shrink: 0;
  padding: 12px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
  background: var(--bg-deep);
  border-top: 1px solid var(--border);
}

.composer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
}

.attach-tray {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.attach-tray img {
  width: 120px;
  height: 120px;
  border-radius: 10px;
  object-fit: cover;
  border: 2px solid var(--border);
  transition: border-color 0.2s;
}

.attach-tray img:hover {
  border-color: var(--amber);
}

.attach-tray .remove-attach {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  background: var(--red);
  color: white;
  border: 2px solid var(--bg);
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s;
  line-height: 1;
}

.attach-tray .remove-attach:hover {
  transform: scale(1.2);
}

.attach-item {
  position: relative;
}

/* Integrated attach button inside composer-form */
.attach-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 8px;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-muted);
  padding: 6px;
}

.attach-btn:hover {
  border-color: var(--amber);
  color: var(--amber);
  background: var(--amber-glow);
}

.attach-btn svg {
  width: 18px;
  height: 18px;
}

.attach-btn.has-images {
  border-style: solid;
  border-color: var(--amber);
  color: var(--amber);
  background: var(--amber-glow);
}

.composer-form {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  transition: border-color 0.2s;
  overflow: hidden;
}

.composer-form:focus-within {
  border-color: var(--amber);
}

.composer-form textarea {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  padding: 10px 12px;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  max-height: 160px;
  min-height: 44px;       /* two-line feel */
  -webkit-appearance: none;
  appearance: none;
}

.composer-form textarea::placeholder {
  color: var(--text-muted);
}

/* Button toolbar — unified bottom row */
.composer-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 4px 2px;
}

.composer-toolbar .spacer {
  flex: 1;
}

.send-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--amber);
  border-radius: 10px;
  flex-shrink: 0;
  transition: all 0.2s;
  color: var(--bg-deep);
}

.send-btn:hover {
  background: var(--amber-light);
  transform: scale(1.05);
}

.send-btn:disabled {
  background: var(--border-strong);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

.send-btn svg {
  width: 18px;
  height: 18px;
}

/* ===== Enhance & Voice buttons (#8, #9) ===== */
.enhance-btn, .voice-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-radius: 8px;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-muted);
  padding: 7px;
}
.enhance-btn:hover, .voice-btn:hover {
  color: var(--amber);
  background: var(--amber-glow);
}
.enhance-btn svg, .voice-btn svg {
  width: 18px;
  height: 18px;
}
.voice-btn.recording {
  color: var(--red);
  background: var(--red-soft);
  animation: pulse-dot 0.8s ease-in-out infinite;
}
.enhance-btn.enhancing {
  color: var(--amber);
  pointer-events: none;
  opacity: 0.6;
}

/* ===== Trust indicator (#3) ===== */
.answer-trust {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding: 6px 12px;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-muted);
}
.answer-trust .trust-icon {
  font-size: 14px;
  line-height: 1;
}
.answer-trust .trust-bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  max-width: 80px;
}
.answer-trust .trust-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.6s ease-out;
}
.trust-fill.high { background: var(--green); }
.trust-fill.medium { background: var(--amber); }
.trust-fill.low { background: var(--red); }

/* ===== Metrics Average (#5) ===== */
.metrics-avg {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 4px 10px;
  background: var(--blue-soft);
  border: 1px solid rgba(91, 155, 213, 0.2);
  border-radius: 6px;
  font-size: 12px;
  color: var(--blue);
  font-weight: 500;
}
.metrics-avg .avg-label {
  opacity: 0.7;
  font-weight: 400;
}

/* ===== Skill Badge ===== */
.skill-badge {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-secondary);
  z-index: 20;
  pointer-events: none;
  animation: badge-in 0.3s ease-out;
}

@keyframes badge-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.skill-dot {
  width: 6px;
  height: 6px;
  background: var(--amber);
  border-radius: 50%;
  animation: pulse-dot 1.2s ease-in-out infinite;
}

/* Scrollbar */
.chat::-webkit-scrollbar { width: 6px; }
.chat::-webkit-scrollbar-track { background: transparent; }
.chat::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

/* Typing indicator (simplified) */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ==================== Mobile (< 480px) ==================== */
@media (max-width: 479px) {
  :root {
    --max-width: 100%;
  }

  /* Topbar */
  .topbar {
    padding: 0 12px;
    padding-top: env(safe-area-inset-top, 0px);
  }
  .topbar-brand strong { font-size: 15px; }
  .topbar-brand span { font-size: 11px; }
  .btn-ghost { padding: 8px 10px; font-size: 12px; }

  /* Chat area */
  .chat {
    padding: 16px 12px 12px;
  }

  /* Empty state */
  .empty-state {
    min-height: 50vh;
    padding: 24px 16px;
  }
  .empty-icon { margin-bottom: 16px; }
  .empty-icon svg { width: 40px; height: 40px; }
  .empty-state h1 {
    font-size: 20px;
    line-height: 1.35;
    margin-bottom: 8px;
  }
  .empty-state > p {
    font-size: 13px;
    margin-bottom: 24px;
    line-height: 1.65;
  }

  /* Starter buttons */
  .starters {
    max-width: 100%;
    gap: 8px;
  }
  .starter-btn {
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.45;
    border-radius: 10px;
  }

  /* Messages */
  .messages {
    gap: 20px;
    padding-bottom: 12px;
  }

  /* User bubble */
  .msg-user .bubble {
    max-width: 85%;
    font-size: 14px;
    padding: 10px 14px;
    line-height: 1.6;
    border-radius: 16px 16px 4px 16px;
  }
  .msg-user .attachments img {
    max-width: 120px;
    max-height: 100px;
  }

  /* Answer card */
  .answer-verdict {
    padding: 16px 14px;
  }
  .answer-verdict h2 {
    font-size: 16px;
    line-height: 1.5;
    margin-bottom: 8px;
  }
  .answer-verdict p,
  .direct-body {
    font-size: 14px;
    line-height: 1.8;
  }
  .answer-risk {
    margin-top: 12px;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.65;
  }

  /* Sections */
  .answer-sections {
    padding: 14px;
  }
  .answer-section {
    margin-bottom: 16px;
  }
  .answer-section h3 {
    font-size: 14px;
    margin-bottom: 8px;
  }
  .answer-section ul {
    gap: 6px;
  }
  .answer-section li {
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.7;
    border-radius: 6px;
  }

  /* Choices */
  .answer-choices {
    padding: 14px;
  }
  .choice-btn {
    padding: 10px 14px;
    font-size: 13px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* Follow-up */
  .answer-followup {
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.65;
  }

  /* Sources */
  .answer-sources {
    padding: 10px 14px;
  }
  .source-item { font-size: 11px; }

  /* Action */
  .answer-action {
    padding: 14px;
  }
  .action-title { font-size: 14px; }
  .action-why { font-size: 12px; line-height: 1.65; }
  .action-meta {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .action-meta-item {
    padding: 8px 10px;
    font-size: 11px;
  }

  /* Profit */
  .answer-profit {
    padding: 14px;
  }
  .profit-number {
    font-size: 20px;
  }
  .profit-detail {
    font-size: 12px;
  }

  /* Feedback — touch targets >= 44px */
  .answer-feedback {
    gap: 6px;
    padding: 0 2px;
    margin-top: 8px;
  }
  .feedback-btn {
    padding: 10px 12px;
    font-size: 12px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
  }

  /* Progress panel */
  .progress-panel {
    padding: 12px 14px;
    gap: 12px;
  }
  .progress-step {
    font-size: 12px;
  }
  @keyframes step-cascade-stay {
    0%   { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; }
    40%  { opacity: 1; max-height: 30px; padding-top: 3px; padding-bottom: 3px; }
    100% { opacity: 1; max-height: 30px; padding-top: 3px; padding-bottom: 3px; }
  }
  .progress-cancel {
    padding: 10px 12px;
    font-size: 12px;
    min-height: 44px;
  }

  /* Composer */
  .composer {
    padding: 8px 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }
  .composer-form {
    padding: 4px;
    border-radius: 10px;
  }
  .composer-form textarea {
    font-size: 16px; /* prevent iOS auto-zoom */
    padding: 8px 10px;
    line-height: 1.5;
    min-height: 40px;
  }
  .composer-toolbar {
    gap: 2px;
    padding: 3px 3px 1px;
  }
  .attach-btn {
    width: 34px;
    height: 34px;
  }
  .send-btn {
    width: 36px;
    height: 36px;
  }
  .send-btn svg, .attach-btn svg {
    width: 16px;
    height: 16px;
  }
  .enhance-btn, .voice-btn {
    width: 34px;
    height: 34px;
    padding: 5px;
  }
  .enhance-btn svg, .voice-btn svg {
    width: 16px;
    height: 16px;
  }
  .attach-tray img {
    width: 80px;
    height: 80px;
  }

  /* Skill badge */
  .skill-badge {
    bottom: calc(90px + env(safe-area-inset-bottom, 0px));
    padding: 6px 12px;
    font-size: 11px;
  }
}

/* ==================== Tablet (480px - 767px) ==================== */
@media (min-width: 480px) and (max-width: 767px) {
  :root {
    --max-width: 100%;
  }

  .chat {
    padding: 20px 16px 12px;
  }

  .empty-state h1 {
    font-size: 22px;
  }
  .empty-state > p {
    font-size: 14px;
  }
  .starters {
    max-width: 100%;
  }

  .msg-user .bubble {
    max-width: 80%;
  }

  .answer-verdict {
    padding: 18px 18px;
  }
  .answer-verdict h2 {
    font-size: 17px;
  }
  .answer-verdict p,
  .direct-body {
    font-size: 14.5px;
    line-height: 1.75;
  }

  .answer-sections {
    padding: 16px 18px;
  }
  .answer-section li {
    font-size: 13.5px;
  }

  .composer {
    padding: 10px 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
  }
  .composer-form textarea {
    font-size: 16px;
    min-height: 44px;
  }

  .feedback-btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
  .choice-btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
}

/* ==================== Memory Toggle Button ==================== */
.memory-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

/* ==================== Memory Panel Overlay ==================== */
.memory-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  overflow: hidden;
}

.memory-overlay.hidden {
  display: none;
}

.memory-curtain {
  position: absolute;
  inset: 0;
  background: var(--bg-deep);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: curtain-rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes curtain-rise {
  0% {
    transform: translateY(100%);
    border-radius: 32px 32px 0 0;
  }
  60% {
    transform: translateY(0);
    border-radius: 32px 32px 0 0;
  }
  100% {
    transform: translateY(0);
    border-radius: 0;
  }
}

/* Stage 1: Logo reveal */
.memory-logo-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: logo-appear 0.6s 0.7s both, logo-fade-out 0.5s 2s both;
}

.memory-logo {
  width: 80px;
  height: 80px;
  animation: logo-pulse 1.5s 0.8s ease-in-out;
}

.memory-logo svg {
  width: 100%;
  height: 100%;
}

.memory-logo-text {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--amber);
  opacity: 0;
  animation: text-fade-in 0.5s 1.2s both;
}

@keyframes logo-appear {
  0% { opacity: 0; transform: scale(0.8); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes logo-pulse {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(86, 197, 154, 0)); }
  50% { filter: drop-shadow(0 0 20px rgba(86, 197, 154, 0.4)); }
}

@keyframes text-fade-in {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes logo-fade-out {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.95); pointer-events: none; }
}

/* Stage 2: History content */
.memory-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  animation: content-appear 0.5s 2.3s both;
}

@keyframes content-appear {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.memory-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  padding-top: max(20px, env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.memory-header h2 {
  font-size: 18px;
  color: var(--text);
  margin: 0;
}

.memory-close {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.memory-close:hover {
  color: var(--text);
  border-color: var(--amber);
  background: rgba(217, 152, 40, 0.1);
}

.memory-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
}

.memory-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
  font-size: 15px;
  width: 100%;
}

.memory-item {
  display: inline-block;
  padding: 8px 14px;
  background: rgba(217, 152, 40, 0.06);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.memory-item:hover {
  border-color: var(--amber);
  background: rgba(217, 152, 40, 0.15);
  color: var(--amber);
}

.memory-footer {
  padding: 12px 20px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  text-align: center;
  flex-shrink: 0;
}

.memory-hint {
  font-size: 13px;
  color: var(--text-muted);
}

.memory-hint strong {
  color: var(--amber);
}

/* ==================== Feedback Modal ==================== */
.feedback-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.feedback-modal.hidden {
  display: none;
}

.feedback-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.feedback-modal-card {
  position: relative;
  background: var(--bg-card, #1a1d28);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: modal-slide-up 0.3s ease-out;
}

@keyframes modal-slide-up {
  0% { opacity: 0; transform: translateY(20px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.feedback-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.feedback-modal-header h3 {
  font-size: 17px;
  color: var(--text);
  margin: 0;
}

.feedback-modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.feedback-modal-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.feedback-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.feedback-modal-footer {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  justify-content: flex-end;
}

/* Feedback checkboxes */
.feedback-check-group {
  margin-bottom: 16px;
}

.feedback-check-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 14px;
  color: var(--text);
}

.feedback-check-label:hover {
  border-color: var(--amber);
  background: rgba(217, 152, 40, 0.05);
}

.feedback-check-label input[type="checkbox"] {
  accent-color: var(--amber);
  width: 18px;
  height: 18px;
}

.feedback-textarea {
  width: 100%;
  min-height: 80px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  resize: vertical;
  font-family: inherit;
}

.feedback-textarea:focus {
  outline: none;
  border-color: var(--amber);
}

/* Useful: download / expand options */
.feedback-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.feedback-option-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: rgba(217, 152, 40, 0.08);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.feedback-option-btn:hover {
  border-color: var(--amber);
  background: rgba(217, 152, 40, 0.15);
}

.feedback-option-btn .option-icon {
  font-size: 22px;
  flex-shrink: 0;
}

.feedback-option-btn .option-text strong {
  display: block;
  color: var(--amber-light);
  margin-bottom: 2px;
}

.feedback-option-btn .option-text span {
  font-size: 12px;
  color: var(--text-muted);
}

/* ==================== Memory Panel Mobile ==================== */
@media (max-width: 479px) {
  .memory-btn {
    width: 36px;
    height: 36px;
  }

  .memory-logo {
    width: 64px;
    height: 64px;
  }

  .memory-logo-text {
    font-size: 20px;
  }

  .memory-header {
    padding: 16px 16px 12px;
  }

  .memory-header h2 {
    font-size: 16px;
  }

  .memory-list {
    padding: 10px 16px;
    gap: 6px;
  }

  .memory-item {
    padding: 6px 12px;
    font-size: 12px;
  }

  .feedback-modal-card {
    max-width: 100%;
    margin: 8px;
  }
}

@media (min-width: 480px) and (max-width: 767px) {
  .memory-logo {
    width: 72px;
    height: 72px;
  }
}
