/* ═══════════════════════════════════════════════
   LOOPSUITE — Conversation View + History Cards
   A 1-to-1 conversation feel, not a chat log.

   LAYOUT MODEL
   ────────────
   .convo-view              ← scroll container (absolute, fills parent)
   ├─ .convo-avatar-area    ← sticky at top, always visible
   └─ .convo-response       ← flex column, fills remaining height
      ├─ ::before           ← flex spacer (collapses when content is tall)
      ├─ .convo-response-inner ← the actual content group
      │   ├─ .convo-thinking
      │   ├─ .convo-user-echo
      │   ├─ .convo-response-card
      │   └─ .convo-welcome
      └─ ::after            ← flex spacer (collapses when content is tall)

   SHORT content → spacers share extra space → card centred vertically
   LONG content  → spacers collapse to 0     → card starts below avatar, scrolls
   ═══════════════════════════════════════════════ */

/* ═══ VIEW MODE TOGGLE ═══ */
.view-toggle-btn {
  background: var(--white); border: var(--bw) solid var(--black);
  border-radius: var(--r-sm); padding: 5px 8px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s ease;
  box-shadow: 2px 2px 0 var(--black);
}
.view-toggle-btn:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--black);
}
.view-toggle-btn:active { transform: translate(0, 0); box-shadow: none; }
.view-toggle-btn svg {
  width: 16px; height: 16px;
  stroke: currentColor; stroke-width: 2.5;
  fill: none; stroke-linecap: round; stroke-linejoin: round;
}
.view-toggle-btn.active {
  background: var(--brand); box-shadow: 2px 2px 0 var(--black);
}

/* ═══════════════════════════════════════════
   CONVERSATION VIEW
   ═══════════════════════════════════════════ */

/* ── Scroll container — fills the chat area ── */
.convo-view {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center;
  overflow-y: auto;
  background: transparent;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 2;
}
.convo-view.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}
/* Hide scrollbar but keep scroll functionality */
.convo-view::-webkit-scrollbar { width: 0; height: 0; }
.convo-view { scrollbar-width: none; -ms-overflow-style: none; }

/* ── Avatar Area — sticky at the very top ── */
.convo-avatar-area {
  position: sticky; top: 0; z-index: 3;
  display: flex; flex-direction: column;
  align-items: center; gap: 5px;
  padding: 24px 24px 18px;
  flex-shrink: 0;
  width: 100%;
  background: transparent; /* Fully transparent — floats over background */
}

.convo-avatar {
  width: 64px; height: 64px;
  border-radius: 18px;
  overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.3s ease;
  border: var(--bw) solid var(--black);
  box-shadow: 3px 3px 0 var(--brand);
}
.convo-avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 16px;
}

/* Idle — gentle breathing */
.convo-avatar.idle {
  animation: convoBreath 3s ease-in-out infinite;
}
@keyframes convoBreath {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.03); }
}

/* Thinking — pulse + glow ring */
.convo-avatar.thinking {
  animation: convoThink 1.2s ease-in-out infinite;
  box-shadow: 3px 3px 0 var(--brand),
              0 0 0 4px rgba(255, 245, 173, 0.2);
}
@keyframes convoThink {
  0%, 100% { transform: scale(1); }
  30%      { transform: scale(1.06); }
  60%      { transform: scale(0.97); }
}

.convo-avatar-name {
  font-family: var(--font-h); font-weight: 700;
  font-size: 0.8rem; color: var(--g900);
  letter-spacing: -0.02em;
}

.convo-status {
  font-size: 0.62rem; color: var(--g500);
  display: flex; align-items: center; gap: 5px;
}
.convo-status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--g400);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}
.convo-status-dot.online {
  background: var(--brand-green);
  box-shadow: 0 0 6px rgba(52, 211, 153, 0.5);
}
.convo-status-dot.thinking {
  background: var(--brand);
  animation: convoPulse 1s ease infinite;
}
@keyframes convoPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

/* ── Response Wrapper ──
   Uses ::before/::after flex spacers for safe vertical centring.
   "Safe" means: centred when content is short, scrollable when tall
   (no upward clipping like justify-content: center causes). */
.convo-response {
  width: 100%; max-width: 640px;
  padding: 0 24px 120px; /* bottom padding clears the input area */
  flex: 1 0 0;           /* grow to fill remaining height; basis 0 */
  display: flex;
  flex-direction: column;
  align-items: stretch;
  /* NO justify-content: center — that clips on overflow */
}

/* Top spacer: shares extra space to push content down → centres it */
.convo-response::before {
  content: '';
  flex: 1 1 0px; /* grow=1, shrink=1, basis=0 → collapses when tight */
}
/* Bottom spacer: shares extra space equally with top → centres content */
.convo-response::after {
  content: '';
  flex: 1 1 0px;
}

/* ── Inner content group — holds the actual visible elements ── */
.convo-response-inner {
  flex-shrink: 0; /* never shrink — allow parent to grow & scroll instead */
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* ── Thinking Indicator ── */
.convo-thinking {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 22px;
  background: var(--white);
  border: var(--bw) solid var(--black);
  border-radius: var(--r);
  box-shadow: var(--shadow-y);
  margin-bottom: 14px;
  align-self: center; /* Centre horizontally */
  max-width: 220px; /* Compact width */
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.convo-thinking.visible {
  opacity: 1; transform: translateY(0);
}
.convo-thinking-dots {
  display: flex; gap: 4px;
}
.convo-thinking-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--g400);
  animation: convoDots 1.4s ease-in-out infinite;
}
.convo-thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.convo-thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes convoDots {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40%           { opacity: 1;   transform: scale(1.2); }
}
.convo-thinking-text {
  font-size: 0.8rem; color: var(--g400);
  font-style: italic;
}

/* ── User Echo (shows what the user just asked) ── */
.convo-user-echo {
  font-size: 0.74rem; color: var(--g400);
  margin-bottom: 12px;
  padding: 7px 14px;
  background: rgba(0, 0, 0, 0.025);
  border-radius: var(--r-xs);
  border-left: 3px solid var(--g200);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.3s ease 0.1s, transform 0.3s ease 0.1s;
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.convo-user-echo.visible { opacity: 1; transform: translateY(0); }
.convo-user-echo strong { font-weight: 600; color: var(--g500); }

/* ── Response Card ── */
.convo-response-card {
  background: var(--white);
  border: var(--bw) solid var(--black);
  border-radius: var(--r);
  padding: 28px 32px;
  box-shadow: var(--shadow-y);
  font-size: 0.92rem; line-height: 1.7;
  color: var(--g900);
  word-break: break-word;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  transition: opacity 0.5s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.5s cubic-bezier(0.22, 1, 0.36, 1),
              box-shadow 0.3s ease;
}
.convo-response-card.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.convo-response-card:hover {
  box-shadow: 5px 5px 0 var(--brand);
}

/* Markdown inside response card */
.convo-response-card p { margin: 0 0 12px; }
.convo-response-card p:last-child { margin-bottom: 0; }
.convo-response-card strong { font-weight: 700; }
.convo-response-card em { font-style: italic; }
.convo-response-card code {
  background: var(--bg); padding: 2px 6px;
  border-radius: 4px; font-family: var(--font-h);
  font-size: 0.82rem;
}
.convo-response-card pre {
  background: #1a1a1a; color: #e5e5e5;
  padding: 16px; border-radius: var(--r-sm);
  overflow-x: auto; font-family: var(--font-h);
  font-size: 0.8rem; margin: 12px 0;
  border: var(--bw) solid var(--black);
}
.convo-response-card ul, .convo-response-card ol {
  margin: 8px 0; padding-left: 20px;
}
.convo-response-card li { margin-bottom: 4px; }
.convo-response-card a {
  color: var(--brand-blue, #738aa8);
  text-decoration: underline;
}
.convo-response-card blockquote {
  border-left: 3px solid var(--brand);
  padding-left: 14px; margin: 12px 0;
  color: var(--g600); font-style: italic;
}
/* Action links inside card */
.convo-response-card a[href^="loopsuite-action:"] {
  display: inline-block;
  background: var(--brand); color: var(--black);
  font-family: var(--font-h); font-weight: 700; font-size: 0.75rem;
  padding: 7px 18px; border-radius: var(--r-full);
  border: var(--bw) solid var(--black); text-decoration: none;
  box-shadow: var(--shadow-b-sm); cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  margin: 4px 4px 2px 0;
}
.convo-response-card a[href^="loopsuite-action:"]:hover {
  transform: translate(-2px, -2px); box-shadow: var(--shadow-b);
}
.convo-response-card a[href^="loopsuite-action:"]:active {
  transform: translate(0, 0); box-shadow: none;
}

/* ═══ WELCOME STATE ═══ */
.convo-welcome {
  text-align: center;
  color: var(--g500);
  font-size: 0.9rem;
  padding: 8px 0;
  opacity: 0;
  animation: convoWelcomeIn 0.7s cubic-bezier(0.22, 1, 0.36, 1) 0.3s forwards;
}
@keyframes convoWelcomeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.convo-welcome-title {
  font-family: var(--font-h); font-weight: 700;
  font-size: 1.2rem; color: var(--g900);
  margin-bottom: 8px; letter-spacing: -0.03em;
}
.convo-welcome-sub {
  font-size: 0.88rem; color: var(--g500);
  max-width: 300px; margin: 0 auto;
  line-height: 1.65;
}


/* ═══════════════════════════════════════════
   HISTORY VIEW — STACKED CARDS
   ═══════════════════════════════════════════ */
.history-view {
  position: absolute; inset: 0;
  overflow-y: auto;
  padding: 16px 16px 120px;
  display: flex; flex-direction: column;
  gap: 12px;
  background: transparent;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 2;
}
.history-view.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}
/* Hide scrollbar */
.history-view::-webkit-scrollbar { width: 0; height: 0; }
.history-view { scrollbar-width: none; -ms-overflow-style: none; }

.history-card {
  max-height: 70vh;
  background: var(--white);
  border: var(--bw) solid var(--black);
  border-radius: var(--r);
  padding: 24px;
  box-shadow: var(--shadow-y);
  display: flex; flex-direction: column;
  gap: 16px;
  flex-shrink: 0;
  overflow-y: auto;
  opacity: 0;
  animation: historyCardIn 0.35s ease forwards;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.history-card:hover {
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--brand);
}
@keyframes historyCardIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
/* Stagger */
.history-card:nth-child(1) { animation-delay: 0s; }
.history-card:nth-child(2) { animation-delay: 0.05s; }
.history-card:nth-child(3) { animation-delay: 0.1s; }
.history-card:nth-child(4) { animation-delay: 0.15s; }

.history-card-question {
  font-size: 0.78rem; color: var(--g500);
  padding: 10px 14px;
  background: var(--bg);
  border-radius: var(--r-sm);
  border: 1px solid var(--g200, #e5e5e0);
  border-left: 3px solid var(--g300);
  line-height: 1.5;
}
.history-card-question strong {
  color: var(--g700, #525252); font-weight: 600;
}
.history-card-answer {
  flex: 1;
  font-size: 0.88rem; line-height: 1.65;
  color: var(--g900);
  word-break: break-word;
}
.history-card-answer p { margin: 0 0 10px; }
.history-card-answer p:last-child { margin-bottom: 0; }
.history-card-answer code {
  background: var(--bg); padding: 2px 6px;
  border-radius: 4px; font-family: var(--font-h);
  font-size: 0.8rem;
}
.history-card-answer pre {
  background: #1a1a1a; color: #e5e5e5;
  padding: 14px; border-radius: var(--r-sm);
  overflow-x: auto; font-family: var(--font-h);
  font-size: 0.78rem; margin: 10px 0;
  border: var(--bw) solid var(--black);
}
.history-card-answer ul, .history-card-answer ol { margin: 6px 0; padding-left: 18px; }
.history-card-answer li { margin-bottom: 3px; }

.history-card-time {
  font-size: 0.65rem; color: var(--g400);
  font-family: var(--font-h); font-weight: 500;
  text-align: right; margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--g200, #e5e5e0);
}

.history-empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  flex: 1; text-align: center;
  color: var(--g400); font-size: 0.85rem;
  padding: 40px; gap: 8px;
}


/* ═══ VIEW TRANSITIONS ═══ */
.chat-messages.cv-hidden {
  display: none !important;
}


/* ═══ RESPONSIVE ═══ */
@media (max-width: 600px) {
  .convo-avatar-area { padding: 18px 16px 14px; }
  .convo-avatar { width: 48px; height: 48px; border-radius: 14px; }
  .convo-avatar img { border-radius: 12px; }
  .convo-response { padding: 0 16px 110px; }
  .convo-response-card { padding: 20px 22px; font-size: 0.88rem; }
  .convo-user-echo { max-width: 260px; }

  .history-view { padding: 12px 12px 110px; gap: 10px; }
  .history-card { padding: 18px; max-height: 65vh; }
}
