/* ─────────────────────────────────────────────────────────────
   Capraseo — front-page chat thread (mockup)
   Empty state is untouched; everything here only takes effect once
   .chat-active is toggled on .center.center-hero (see js/chat-thread.js).
   The composer center→bottom glide is driven by a FLIP transform in JS;
   this file only owns the resting layouts and the message styling.
   ───────────────────────────────────────────────────────────── */

/* ── Empty state ──────────────────────────────────────────────
   Zero layout footprint so the page is pixel-identical to before. */
.chat-thread { display: none; }

/* ── Active state ─────────────────────────────────────────────
   Restructure the hero column into: (collapsed hero) + scrolling
   thread (flex:1) + docked composer footer. */
.center.center-hero.chat-active {
  justify-content: flex-start;
  gap: 0;
}

.chat-active .hero {
  max-height: 0;
  margin: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  transition:
    max-height 0.3s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.22s cubic-bezier(0.22, 1, 0.36, 1),
    margin 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.chat-active .chat-thread {
  display: flex;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.chat-active .chat-thread::-webkit-scrollbar { width: 4px; }
.chat-active .chat-thread::-webkit-scrollbar-track { background: transparent; }
.chat-active .chat-thread::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 4px;
}
.chat-active .chat-thread::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.28);
}

.chat-thread-inner {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Docked composer — reads as a footer bar across the stage while its
   inner card/chips stay at the original 640px so the FLIP is a clean
   vertical-only glide. overflow:visible keeps the upward model menu
   (css/chat.css:347) from being clipped. */
.chat-active .composer {
  align-self: stretch;
  align-items: center;
  width: 100%;
  padding: 14px 24px 18px;
  border-top: 1px solid var(--line);
  background: linear-gradient(
    180deg,
    rgba(10, 10, 11, 0) 0%,
    rgba(10, 10, 11, 0.92) 55%
  );
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  flex-shrink: 0;
  overflow: visible;
}
.chat-active .composer::before { display: none; }
.chat-active .composer > .chatcard,
.chat-active .composer > .chips {
  width: 100%;
  max-width: 1100px;
}

/* In the docked composer the chips sit on the very bottom edge of the
   viewport, so a menu anchored below its chip (css/chat.css:298) drops
   off-screen and can't be seen. The model menu already opens upward
   (css/chat.css:347); mirror that for the skill + MCP menus here.
   max-height keeps a long skill list from running off the top too. */
.chat-active .dropdown[data-dropdown="skill"] .menu,
.chat-active .dropdown[data-dropdown="mcp"] .menu {
  top: auto;
  bottom: calc(100% + 8px);
  transform: translateY(4px);
  max-height: min(60vh, 360px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.chat-active .dropdown[data-dropdown="skill"] .menu::-webkit-scrollbar,
.chat-active .dropdown[data-dropdown="mcp"] .menu::-webkit-scrollbar {
  width: 4px;
}
.chat-active .dropdown[data-dropdown="skill"] .menu::-webkit-scrollbar-thumb,
.chat-active .dropdown[data-dropdown="mcp"] .menu::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 4px;
}
.chat-active .dropdown[data-dropdown="skill"] .menu.open,
.chat-active .dropdown[data-dropdown="mcp"] .menu.open {
  transform: translateY(0);
}

/* ── Messages ─────────────────────────────────────────────────── */
.chat-msg {
  display: flex;
  gap: 12px;
  opacity: 0;
  animation: chatMsgIn 0.34s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.chat-msg.ai { animation-delay: 0.12s; }

@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to   { opacity: 1; transform: none; }
}

.chat-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: -0.005em;
}
/* ── Rendered Markdown (assistant replies) ───────────────────────
   The model answers in Markdown; js/chat-thread.js turns it into the
   elements below. Spacing is tuned for a chat bubble (tighter than a
   document) and the bubble's own padding owns the outer gap, so the
   first/last child shed their margins. */
.chat-bubble > :first-child { margin-top: 0; }
.chat-bubble > :last-child { margin-bottom: 0; }
.chat-bubble p { margin: 0.55em 0; }

.chat-bubble h1,
.chat-bubble h2,
.chat-bubble h3,
.chat-bubble h4 {
  margin: 1.15em 0 0.5em;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--text);
}
.chat-bubble h1 { font-size: 1.28em; }
.chat-bubble h2 { font-size: 1.14em; }
.chat-bubble h3 { font-size: 1.02em; }
.chat-bubble h4 { font-size: 0.95em; color: var(--muted); }

.chat-bubble strong { font-weight: 600; }
.chat-bubble em { font-style: italic; }
.chat-bubble del { opacity: 0.6; }
.chat-bubble a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chat-msg.user .chat-bubble a { color: #053218; }

.chat-bubble ul,
.chat-bubble ol {
  margin: 0.55em 0;
  padding-left: 1.4em;
}
.chat-bubble li { margin: 0.3em 0; }
.chat-bubble li::marker { color: var(--muted); }
.chat-msg.user .chat-bubble li::marker { color: rgba(4, 33, 15, 0.55); }

.chat-bubble hr {
  border: 0;
  border-top: 1px solid var(--line-strong);
  margin: 1.1em 0;
}

.chat-bubble blockquote {
  margin: 0.7em 0;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.chat-bubble blockquote > :first-child { margin-top: 0; }
.chat-bubble blockquote > :last-child { margin-bottom: 0; }

.chat-bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.1em 0.4em;
}
.chat-bubble pre {
  margin: 0.7em 0;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
}
.chat-bubble pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.84em;
  line-height: 1.5;
}

/* Tables — the divider/scroll wrapper keeps wide tables from
   overflowing the bubble on narrow viewports. */
.chat-bubble .md-table {
  margin: 0.7em 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.chat-bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92em;
}
.chat-bubble th,
.chat-bubble td {
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}
.chat-bubble thead th {
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
  white-space: nowrap;
}
.chat-bubble tbody tr:last-child td { border-bottom: 0; }
.chat-bubble tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* User — iMessage-style: a solid brand-green bubble so the person's
   turn is unmistakable against the AI's neutral reply. Dark green text
   (not white) because #22c55e is bright — this keeps it well above AA. */
.chat-msg.user { justify-content: flex-end; }
.chat-msg.user .chat-bubble {
  max-width: min(74%, 560px);
  background: linear-gradient(180deg, #2ecc6a 0%, #1faa52 100%);
  color: #04210f;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 14px 40px -16px rgba(34, 197, 94, 0.45);
}

/* Assistant — the particle goat returns small as the AI avatar */
.chat-msg.ai { justify-content: flex-start; }
.chat-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background-color: var(--accent);
  -webkit-mask: url('/goat_silhouette_mask.png') center / 20px 20px no-repeat;
  mask: url('/goat_silhouette_mask.png') center / 20px 20px no-repeat;
  filter: drop-shadow(0 0 6px rgba(34, 197, 94, 0.35));
}
.chat-msg.ai .chat-bubble {
  max-width: min(80%, 760px);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line-strong);
}

/* ── Embedded data card (AI bubble) ──────────────────────────────
   Reflects "every feature is also context for the AI" — a compact
   glass widget the model can speak to. */
.chat-card {
  margin-top: 12px;
  padding: 14px 16px;
  background: linear-gradient(
    180deg,
    rgba(28, 28, 32, 0.55) 0%,
    rgba(18, 18, 21, 0.62) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
.chat-card-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin: 0 0 12px 0;
}
.chat-card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
}
.chat-stat { display: flex; flex-direction: column; gap: 3px; }
.chat-stat-num {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.chat-stat-num.up { color: var(--accent); }
.chat-stat-label {
  font-size: 11.5px;
  color: var(--muted);
}
.chat-card-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 40px;
  margin-top: 14px;
}
.chat-card-bars i {
  flex: 1;
  display: block;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(
    180deg,
    rgba(34, 197, 94, 0.65),
    rgba(34, 197, 94, 0.12)
  );
}

/* ── Thinking indicator ──────────────────────────────────────────
   Shown in the AI bubble while the model reply is in flight (the
   call is non-streaming, so latency needs to be visible). */
.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 8px;
}
.chat-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: chatTyping 1s ease-in-out infinite;
}
.chat-typing i:nth-child(2) { animation-delay: 0.16s; }
.chat-typing i:nth-child(3) { animation-delay: 0.32s; }

@keyframes chatTyping {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30%           { opacity: 1;    transform: translateY(-3px); }
}

/* ── Error bubble ────────────────────────────────────────────────
   A failed turn (no domain in focus, no model, OpenRouter down).
   Reads like an AI reply so the thread stays legible. */
.chat-msg.ai .chat-bubble.is-error {
  background: rgba(225, 75, 74, 0.06);
  border-color: rgba(225, 75, 74, 0.35);
  color: var(--muted);
}

/* ── Reduced motion ──────────────────────────────────────────────
   FLIP transform is skipped in JS; here we drop the layout/message
   transitions so the end state appears instantly. */
@media (prefers-reduced-motion: reduce) {
  .chat-active .hero,
  .chat-active .composer { transition: none; }
  .chat-msg { animation: none; opacity: 1; }
  .chat-typing i { animation: none; opacity: 0.5; }
}
