/* ============================================================
   Chat content-page theme — dialogue layout
   Scoped entirely under .chat-active so non-chat pages are
   completely untouched. Server still emits the full Markdown
   as static HTML; this only rearranges it into bubbles.
   ============================================================ */

.chat-active.content-item {
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
  padding: 0 !important;
  max-width: none;
  position: relative;
}

/* Soft glow behind the thread (subtle, theme-aware) */
.chat-active.content-item::before {
  content: "";
  position: absolute;
  inset: -40px -10% 0;
  background:
    radial-gradient(60% 50% at 18% 0%, color-mix(in oklab, var(--c, #6366f1) 22%, transparent), transparent 70%),
    radial-gradient(55% 45% at 85% 8%, rgba(139, 92, 246, 0.16), transparent 70%);
  filter: blur(8px);
  opacity: .55;
  pointer-events: none;
  z-index: 0;
}

.chat-active .chat-thread {
  position: relative;
  z-index: 1;
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 14px 0 48px;
}

/* ---- rows (stacked: name/avatar line ABOVE the bubble) ---- */
.chat-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: flex-start;
  animation: chatIn .35s ease both;
}
.chat-row-bot { align-items: flex-start; }
.chat-row-user { align-items: flex-end; }
.chat-row-intro { align-items: center; }

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

/* ---- avatar + name ---- */
.chat-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.chat-row-user .chat-meta { flex-direction: row-reverse; }

.chat-avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 50%;
  background: var(--c, #6366f1);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 14px color-mix(in oklab, var(--c, #6366f1) 45%, transparent);
  user-select: none;
}

.chat-name {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--c, #6366f1);
  letter-spacing: .2px;
}

/* ---- bubbles ---- */
.chat-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.72;
  font-size: 15px;
  box-shadow: 0 6px 22px rgba(15, 23, 42, .07);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
/* Light-theme "我" bubble: light surface + dark text (high contrast; fits white theme) */
.chat-row-user .chat-bubble {
  background: #ffffff;
  color: #1f2937;
  border: 1px solid color-mix(in oklab, var(--c, #6366f1) 22%, #ffffff);
  border-bottom-right-radius: 6px;
  box-shadow: 0 6px 22px rgba(99, 102, 241, .14);
}
.chat-row-bot .chat-bubble {
  background: var(--bub-bot-bg);
  color: var(--bub-bot-text);
  border: 1px solid var(--bub-bot-border);
  border-bottom-left-radius: 6px;
}
.chat-bubble-intro {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: var(--muted);
  font-style: italic;
  text-align: center;
  max-width: 90%;
}

/* ---- inline content inside bubbles ---- */
.chat-bubble > *:first-child { margin-top: 0; }
.chat-bubble > *:last-child { margin-bottom: 0; }
.chat-bubble p { margin: 0 0 10px; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3,
.chat-bubble h4, .chat-bubble h5, .chat-bubble h6 {
  margin: 14px 0 8px;
  line-height: 1.35;
}
.chat-bubble a {
  color: var(--c, #6366f1);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chat-row-user .chat-bubble a { color: #4f46e5; text-decoration: underline; }

.chat-bubble img {
  max-width: 100%;
  border-radius: 10px;
  margin: 6px 0;
}

.chat-bubble ul, .chat-bubble ol { margin: 0 0 10px; padding-left: 1.4em; }
.chat-bubble li { margin: 3px 0; }

.chat-bubble code {
  background: rgba(127, 127, 127, .18);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: .9em;
}
.chat-row-user .chat-bubble code {
  background: color-mix(in oklab, var(--c, #6366f1) 12%, #ffffff);
  color: #4338ca;
}

.chat-bubble pre {
  background: #0d1117;
  color: #e6edf3;
  padding: 13px 15px;
  border-radius: 11px;
  overflow: auto;
  margin: 8px 0 12px;
  font-size: 13.5px;
  line-height: 1.6;
}
.chat-bubble pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.chat-bubble blockquote {
  margin: 8px 0;
  padding: 4px 14px;
  border-left: 3px solid var(--c, #6366f1);
  color: var(--muted);
}

/* ---- tables inside bubbles (normalize + visible empty cells) ---- */
.chat-table-wrap {
  overflow-x: auto;
  margin: 10px 0 12px;
  -webkit-overflow-scrolling: touch;
}
.chat-bubble table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
  line-height: 1.5;
}
.chat-bubble th,
.chat-bubble td {
  border: 1px solid var(--bub-bot-border);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}
.chat-bubble th {
  background: color-mix(in oklab, var(--c, #6366f1) 12%, transparent);
  font-weight: 700;
  color: var(--bub-bot-text);
  white-space: nowrap;
}
.chat-row-user .chat-bubble th {
  background: color-mix(in oklab, var(--c, #6366f1) 10%, #ffffff);
  color: #1f2937;
  border-color: color-mix(in oklab, var(--c, #6366f1) 20%, #ffffff);
}
.chat-row-user .chat-bubble td {
  border-color: rgba(15, 23, 42, .10);
}

/* ---- theme variables ---- */
.chat-active {
  --bub-bot-bg: rgba(255, 255, 255, .74);
  --bub-bot-border: rgba(15, 23, 42, .08);
  --bub-bot-text: #1f2937;
  --muted: #64748b;
}
:root[data-theme='dark'] .chat-active {
  --bub-bot-bg: rgba(30, 41, 59, .55);
  --bub-bot-border: rgba(255, 255, 255, .10);
  --bub-bot-text: #e5e9f0;
  --muted: #94a3b8;
}

/* Dark-theme "我" bubble: keep a gradient accent + white text so it pops
   against the dark background (overrides the light-theme light surface). */
:root[data-theme='dark'] .chat-active .chat-row-user .chat-bubble {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
  border-bottom-right-radius: 6px;
  box-shadow: 0 6px 22px rgba(99, 102, 241, .35);
}
:root[data-theme='dark'] .chat-active .chat-row-user .chat-bubble a { color: #fff; }
:root[data-theme='dark'] .chat-active .chat-row-user .chat-bubble code {
  background: rgba(255, 255, 255, .25);
  color: #fff;
}
:root[data-theme='dark'] .chat-active .chat-row-user .chat-bubble th {
  background: rgba(255, 255, 255, .20);
  color: #fff;
  border-color: rgba(255, 255, 255, .30);
}
:root[data-theme='dark'] .chat-active .chat-row-user .chat-bubble td {
  border-color: rgba(255, 255, 255, .28);
}
:root[data-theme='dark'] .chat-active.content-item::before { opacity: .42; }

@media (max-width: 600px) {
  .chat-bubble { max-width: 90%; font-size: 14.5px; }
  .chat-avatar { width: 32px; height: 32px; flex-basis: 32px; font-size: 13px; }
}
