/* Chat look: a night-sky science palette for the conversation (original OWEN styling).
 * Deep indigo space, glowing cyan / magenta / yellow accents, bold rounded type and flat round
 * badges. Loaded after the illustrated theme so these rules win ties; scoped to the chat log and
 * composer, so the rest of the workspace keeps its existing look. Light and dark themes both apply. */

:root, body {
  --cosmic-cyan: #42c9e8;
  --cosmic-magenta: #ff5fa2;
  --cosmic-yellow: #ffd166;
  --cosmic-orange: #ff9f43;
  --cosmic-violet: #7864e8;
  --cosmic-teal: #35c6ae;
  --cosmic-space: #0f1538;
  --cosmic-indigo: #1d2259;
  --cosmic-indigo-2: #2e2a7a;
  --chat-highlight: #ffd16680;
  --chat-code-bg: #eeeafb;
  --chat-code-text: #4a36b0;
  --chat-row-alt: #f6f5fd;
  --chat-row-hover: #eef6fb;
}
:root[data-theme='dark'], body.theme-dark, :root[data-theme='dark'] body {
  --chat-highlight: #42c9e84d;
  --chat-code-bg: #2a2f63;
  --chat-code-text: #d0c7ff;
  --chat-row-alt: #1f2a50;
  --chat-row-hover: #26335e;
}

/* ---- Conversation backdrop: a faint nebula in light mode, a starfield in dark mode ---- */
body .chat-log:not([data-empty='true']) {
  background:
    radial-gradient(900px 420px at 92% -8%, #42c9e812, transparent 62%),
    radial-gradient(760px 380px at -6% 4%, #7864e811, transparent 60%),
    radial-gradient(640px 360px at 60% 108%, #ff5fa20b, transparent 60%),
    var(--owen-surface);
}
:root[data-theme='dark'] body .chat-log:not([data-empty='true']) {
  background:
    radial-gradient(circle at 12% 18%, #ffffffb3 0 0.8px, transparent 1.4px) 0 0 / 230px 210px,
    radial-gradient(circle at 64% 42%, #bfe9f799 0 0.7px, transparent 1.3px) 0 0 / 310px 260px,
    radial-gradient(circle at 38% 76%, #ffffff80 0 0.6px, transparent 1.2px) 0 0 / 190px 230px,
    radial-gradient(circle at 86% 88%, #ffd16673 0 0.8px, transparent 1.4px) 0 0 / 370px 330px,
    radial-gradient(900px 460px at 92% -10%, #42c9e817, transparent 62%),
    radial-gradient(760px 420px at -8% 6%, #7864e81f, transparent 60%),
    radial-gradient(700px 400px at 55% 110%, #ff5fa212, transparent 60%),
    var(--owen-bg);
}

/* ---- Bubbles ---- */
body .chat-log .bubble.user {
  color: #ffffff;
  background: var(--owen-indigo);
  border: 0;
  border-radius: 22px 22px 6px 22px;
  box-shadow: var(--shadow-sm);
}
:root[data-theme='dark'] body .chat-log .bubble.user {
  background: var(--owen-indigo);
  box-shadow: var(--shadow-sm);
}
body .chat-log .bubble.user :is(a, .bubble-attachment-label) { color: #ffffff; }
/* The answer card carries the surface; the assistant bubble itself stays clear so the
 * Thinking capsule and the card float on the backdrop. */
body .chat-log .bubble.assistant {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

body .chat-log .bubble.assistant .response-card {
  position: relative;
  border: 1px solid color-mix(in srgb, var(--cosmic-violet) 16%, var(--owen-border));
  border-radius: 22px;
  background:
    var(--owen-surface);
  box-shadow: var(--shadow-sm);
}
/* A thin aurora stripe across the top of every answer card. */
body .chat-log .bubble.assistant .response-card::before {
  content: "";
  position: absolute;
  inset: -1px -1px auto;
  height: 4px;
  border-radius: 22px 22px 0 0;
  background: linear-gradient(90deg, var(--cosmic-cyan), var(--cosmic-violet) 45%, var(--cosmic-magenta) 75%, var(--cosmic-yellow));
  pointer-events: none;
}
:root[data-theme='dark'] body .chat-log .bubble.assistant .response-card {
  border-color: #3b4778;
  background:
    var(--owen-surface);
  box-shadow: var(--shadow-sm);
}

/* ---- Section headings: bold titles with a colored planet dot and a glowing underline ---- */
body .chat-log .bubble.assistant .response-section { --section-color: var(--cosmic-cyan); }
body .chat-log .bubble.assistant .response-section:nth-of-type(5n + 2) { --section-color: var(--cosmic-magenta); }
body .chat-log .bubble.assistant .response-section:nth-of-type(5n + 3) { --section-color: var(--cosmic-yellow); }
body .chat-log .bubble.assistant .response-section:nth-of-type(5n + 4) { --section-color: var(--cosmic-violet); }
body .chat-log .bubble.assistant .response-section:nth-of-type(5n + 5) { --section-color: var(--cosmic-teal); }
body .chat-log .bubble.assistant :is(.streaming-plain, .typewriter-plain) > :is(h2, h3) { --section-color: var(--cosmic-cyan); }
body .chat-log .bubble.assistant :is(.streaming-plain, .typewriter-plain) > :is(h2, h3):nth-of-type(5n + 2) { --section-color: var(--cosmic-magenta); }
body .chat-log .bubble.assistant :is(.streaming-plain, .typewriter-plain) > :is(h2, h3):nth-of-type(5n + 3) { --section-color: var(--cosmic-yellow); }
body .chat-log .bubble.assistant :is(.streaming-plain, .typewriter-plain) > :is(h2, h3):nth-of-type(5n + 4) { --section-color: var(--cosmic-violet); }
body .chat-log .bubble.assistant :is(.streaming-plain, .typewriter-plain) > :is(h2, h3):nth-of-type(5n + 5) { --section-color: var(--cosmic-teal); }
body .chat-log .bubble.assistant :is(.response-section .section-heading, :is(.streaming-plain, .typewriter-plain) > :is(h2, h3)) {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 4px 0 12px;
  padding: 0 0 9px;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  backdrop-filter: none;
  color: var(--owen-text);
  font-family: var(--font-display);
  font-size: 1.16rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  position: relative;
}
body .chat-log .bubble.assistant :is(.response-section h3.section-heading, :is(.streaming-plain, .typewriter-plain) > h3) { font-size: 1.04rem; }
body .chat-log .bubble.assistant :is(.response-section .section-heading, :is(.streaming-plain, .typewriter-plain) > :is(h2, h3))::before {
  content: "";
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-inline-end: 10px;
  border-radius: 50%;
  vertical-align: 0.06em;
  background: var(--section-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--section-color) 22%, transparent), 0 0 10px color-mix(in srgb, var(--section-color) 55%, transparent);
}
body .chat-log .bubble.assistant :is(.response-section .section-heading, :is(.streaming-plain, .typewriter-plain) > :is(h2, h3))::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 46px;
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--section-color), color-mix(in srgb, var(--section-color) 0%, transparent));
  transition: width 0.25s ease;
}
body .chat-log .bubble.assistant .response-section .section-heading:hover {
  background: none;
  transform: none;
}
body .chat-log .bubble.assistant .response-section .section-heading:is(:hover, .is-active, :focus-visible)::after { width: 88px; }
body .chat-log .bubble.assistant .response-section .section-heading.is-active { background: none; }

/* Section shortcuts at the top of a long answer. */
body .chat-log .bubble.assistant .response-toc .toc-item {
  border: 1px solid color-mix(in srgb, var(--cosmic-violet) 26%, var(--owen-border));
  border-radius: 999px;
  background: color-mix(in srgb, var(--cosmic-violet) 5%, var(--owen-surface));
  color: var(--owen-text);
  font-weight: 600;
}
body .chat-log .bubble.assistant .response-toc .toc-item:hover {
  border-color: var(--cosmic-cyan);
  box-shadow: var(--shadow-sm);
  background: color-mix(in srgb, var(--cosmic-cyan) 8%, var(--owen-surface));
}

/* ---- Body text ---- */
/* Markdown output separates blocks with newline text nodes; under the bubble's pre-wrap they render as
 * blank lines between lists, callouts and tables. Paragraphs already wrap normally, so collapse only
 * the whitespace between blocks (sections of plain text keep pre-wrap). */
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain):has(> :is(p, ul, ol, blockquote, table, pre, h3, h4, hr)) {
  white-space: normal;
}
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) > p > strong,
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) > :is(ul, ol) > li > strong {
  color: inherit;
  font-weight: 700;
  padding: 0 0.12em;
  border-radius: 3px;
  background: linear-gradient(transparent 58%, var(--chat-highlight) 58%, var(--chat-highlight) 94%, transparent 94%);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
body .chat-log .bubble.assistant :not(pre) > code {
  padding: 0.1em 0.42em;
  border-radius: 6px;
  border: 0;
  background: var(--chat-code-bg);
  color: var(--chat-code-text);
  font-size: 0.88em;
}
body .chat-log .bubble.assistant hr {
  height: 2px;
  border: 0;
  margin: 18px 0;
  background: linear-gradient(90deg, transparent, var(--cosmic-violet) 30%, var(--cosmic-cyan) 70%, transparent);
  opacity: 0.45;
}

/* Bulleted lists: small glowing planets in rotating colors. */
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) ul {
  list-style: none;
  padding-inline-start: 4px;
}
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) ul > li {
  position: relative;
  padding-inline-start: 22px;
  --dot: var(--cosmic-cyan);
}
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) ul > li:nth-child(4n + 2) { --dot: var(--cosmic-magenta); }
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) ul > li:nth-child(4n + 3) { --dot: var(--cosmic-yellow); }
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) ul > li:nth-child(4n + 4) { --dot: var(--cosmic-teal); }
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) ul > li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 0.62em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--dot) 20%, transparent);
}
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) li ul > li::before { width: 6px; height: 6px; top: 0.7em; box-shadow: none; opacity: 0.85; }

/* Numbered lists: numbers in solid round badges. */
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) ol {
  list-style: none;
  counter-reset: cosmic-step;
  padding-inline-start: 2px;
}
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) ol > li {
  position: relative;
  counter-increment: cosmic-step;
  padding-inline-start: 36px;
  margin-bottom: 8px;
}
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) ol > li::before {
  content: counter(cosmic-step);
  position: absolute;
  left: 0;
  top: 0.08em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: #ffffff;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  background: #5542b8;
  box-shadow: var(--shadow-sm);
}
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) ol > li:nth-child(3n + 2)::before { background: #225e9d; box-shadow: var(--shadow-sm); }
body .chat-log .bubble.assistant :is(.section-body, .streaming-plain, .typewriter-plain) ol > li:nth-child(3n + 3)::before { background: #a92968; box-shadow: var(--shadow-sm); }

/* ---- Tables: deep-space header row, rounded frame, soft zebra rows ---- */
body .chat-log .bubble.assistant table {
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid color-mix(in srgb, var(--cosmic-violet) 22%, var(--owen-border));
  border-radius: 16px;
  overflow: hidden;
  background: var(--owen-surface);
}
body .chat-log .bubble.assistant table th {
  color: #ffffff;
  background: var(--owen-indigo);
  border: 0;
  border-bottom: 3px solid transparent;
  border-image: linear-gradient(90deg, var(--cosmic-cyan), var(--cosmic-violet), var(--cosmic-magenta)) 1;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.01em;
}
body .chat-log .bubble.assistant table td {
  border: 0;
  border-top: 1px solid color-mix(in srgb, var(--owen-border) 80%, transparent);
}
body .chat-log .bubble.assistant table tbody tr:first-child td { border-top: 0; }
body .chat-log .bubble.assistant table tbody tr:nth-child(even) td { background: var(--chat-row-alt); }
body .chat-log .bubble.assistant table tbody tr:hover td { background: var(--chat-row-hover); }
body .chat-log .bubble.assistant table td:first-child { font-weight: 600; color: var(--owen-text); }
:root[data-theme='dark'] body .chat-log .bubble.assistant table { background: #18214a; border-color: #3b4778; }
:root[data-theme='dark'] body .chat-log .bubble.assistant table th { background: var(--owen-indigo); }

/* ---- Response mode tag ("Thinking", "Research", ...) ---- */
body .chat-log .bubble.assistant .response-mode-badge {
  --mode-color: var(--cosmic-teal);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #ffffff1a;
  border-radius: 999px;
  color: #dfe4f5;
  background: var(--owen-indigo);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
  letter-spacing: 0.08em;
}
body .chat-log .bubble.assistant .response-mode-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mode-color);
  box-shadow: 0 0 6px var(--mode-color);
}
body .chat-log .bubble.assistant .response-mode-badge[data-response-mode='fast'] { --mode-color: var(--cosmic-yellow); }
body .chat-log .bubble.assistant .response-mode-badge[data-response-mode='thinking'] { --mode-color: var(--cosmic-magenta); }
body .chat-log .bubble.assistant .response-mode-badge[data-response-mode='research'] { --mode-color: var(--cosmic-cyan); }

/* ---- Live status line while an answer is being prepared ---- */
body .chat-log .bubble.thinking .bubble-status {
  border: 1px solid color-mix(in srgb, var(--cosmic-violet) 28%, var(--owen-border));
  background: color-mix(in srgb, var(--cosmic-violet) 7%, var(--owen-surface));
  box-shadow: var(--shadow-sm);
}
body .chat-log .bubble.thinking .bubble-status .bubble-status-text { color: var(--owen-text); }
body .chat-log .thinking-dot {
  background: var(--cosmic-cyan);
  box-shadow: 0 0 6px var(--cosmic-cyan);
  animation: cosmic-status-dot 1.4s ease-in-out infinite;
}
@keyframes cosmic-status-dot {
  0%, 100% { transform: scale(0.85); box-shadow: var(--shadow-sm); }
  50% { transform: scale(1.1); box-shadow: var(--shadow-sm); }
}

/* ---- Composer ---- */
body .chat-composer.composer-card:focus-within {
  border-color: color-mix(in srgb, var(--cosmic-cyan) 55%, var(--owen-border));
  box-shadow: var(--shadow-sm);
}
body .chat-composer .composer-send {
  background: var(--owen-accent);
  box-shadow: var(--shadow-sm);
}
body .chat-composer .composer-send:hover:not(:disabled) {
  background: var(--owen-accent-hover);
  box-shadow: var(--shadow-sm);
}

@media (prefers-reduced-motion: reduce) {
  body .chat-log .thinking-dot { animation: none !important; }
}
