/* ── Main Column ─────────────────────────────────────── */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; position: relative; z-index: 1; }

/* ── Chat Area ───────────────────────────────────────── */
#chat-area {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 24px 16px 8px; position: relative;
  background: transparent; contain: layout style;
}
#chat-honeycomb {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none; z-index: 0; image-rendering: pixelated;
  transition: opacity .4s; opacity: 0;
}
#chat-area::-webkit-scrollbar       { width: 5px; }
#chat-area::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 5px; }

.messages-inner {
  position: relative; z-index: 1;
  max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 4px;
}

/* ── Empty State ─────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 60vh; gap: 10px; text-align: center;
  animation: fadeUp .4s var(--ease);
}
.empty-icon {
  width: 52px; height: 52px; background: var(--bg3); border-radius: 16px;
  display: flex; align-items: center; justify-content: center; color: var(--text3);
  margin-bottom: 4px;
}
.empty-icon img { width: 100%; height: 100%; object-fit: contain; }
.empty-state h2 { font-size: 19px; font-weight: 600; color: var(--text2); }
.empty-state p  { font-size: 13.5px; color: var(--text3); max-width: 280px; }
.suggestions    { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; max-width: 480px; }
.sug-chip {
  padding: 7px 15px; background: var(--bg2);
  border: 1px solid var(--border2); border-radius: 20px;
  font-size: 13px; color: var(--text2); cursor: pointer;
  font-family: var(--font); transition: all .2s;
}
.sug-chip:hover { background: var(--accent-glow); color: var(--accent2); border-color: rgba(59,130,246,.3); }

/* ── Message Rows ────────────────────────────────────── */
.msg-row { display: flex; align-items: flex-end; gap: 0; margin: 3px 0; animation: msgIn .25s var(--ease); }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: translateY(0) } }
.msg-row.user { justify-content: flex-end; }
.msg-row.ai   { justify-content: flex-start; }
.msg-avatar   { display: none; }

/* ── Message Bubbles ─────────────────────────────────── */
.msg-bubble {
  max-width: 86%; padding: 11px 16px; border-radius: 18px;
  font-size: 14.5px; line-height: 1.75;
  word-break: break-word; overflow-wrap: break-word;
  position: relative; min-width: 0;
}
.msg-row.user .msg-bubble {
  background: var(--user-bubble); color: var(--user-text);
  border-bottom-right-radius: 5px; box-shadow: 0 2px 14px rgba(37,99,235,.35);
}

/* ── AI Message Content (No Bubble) ──────────────────── */
.ai-msg-content {
  max-width: 100%; width: 100%;
  font-size: 14.5px; line-height: 1.75;
  word-break: break-word; overflow-wrap: break-word;
  color: var(--text); padding: 0;
}
.msg-row.ai { align-items: flex-start; }
.msg-row.ai .ai-msg-content.streaming { position: relative; }

/* Collapse button on user messages */
.msg-collapse-btn {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 6px; padding: 3px 10px;
  background: rgba(255,255,255,.12); border: none; border-radius: 20px;
  color: rgba(255,255,255,.8); font-size: 11.5px; font-family: var(--font);
  cursor: pointer; transition: background .15s;
}
.msg-collapse-btn:hover { background: rgba(255,255,255,.2); }
.msg-collapse-btn svg   { flex-shrink: 0; }

/* ── Bubble Content ──────────────────────────────────── */
.msg-bubble p              { margin: 0 0 8px; }
.msg-bubble p:last-child   { margin-bottom: 0; }
.msg-bubble strong         { font-weight: 600; color: inherit; }
.msg-bubble em             { font-style: italic; }
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 { font-weight: 600; margin: 12px 0 5px; line-height: 1.3; color: var(--text); }
.msg-bubble h1 { font-size: 17px; } .msg-bubble h2 { font-size: 15.5px; } .msg-bubble h3 { font-size: 14.5px; }
.msg-bubble code {
  background: rgba(59,130,246,.15); border-radius: 5px;
  padding: 2px 6px; font-size: 12.5px; font-family: 'SF Mono','Fira Code',monospace;
  color: #93c5fd; border: 1px solid rgba(59,130,246,.2);
}
.msg-row.user .msg-bubble code { background: rgba(255,255,255,.18); color: #fff; border-color: rgba(255,255,255,.2); }
.msg-bubble ul,.msg-bubble ol  { padding-left: 20px; margin: 6px 0; }
.msg-bubble li                 { margin: 3px 0; }
.msg-bubble blockquote {
  border-left: 3px solid var(--accent); padding-left: 12px;
  color: var(--text2); margin: 8px 0; font-style: italic;
  background: rgba(59,130,246,.05); border-radius: 0 6px 6px 0; padding: 8px 8px 8px 14px;
}
.msg-bubble a   { color: var(--accent2); text-decoration: underline; }
.msg-bubble table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.msg-bubble th,.msg-bubble td { padding: 7px 12px; border: 1px solid var(--border2); text-align: left; }
.msg-bubble th  { background: var(--bg3); font-weight: 600; color: var(--text); }
.msg-bubble hr  { border: none; border-top: 1px solid var(--border2); margin: 12px 0; }

/* ── AI Message Content Elements ─────────────────────── */
.ai-msg-content p              { margin: 0 0 8px; }
.ai-msg-content p:last-child   { margin-bottom: 0; }
.ai-msg-content strong         { font-weight: 600; color: inherit; }
.ai-msg-content em             { font-style: italic; }
.ai-msg-content h1,.ai-msg-content h2,.ai-msg-content h3 { font-weight: 600; margin: 12px 0 5px; line-height: 1.3; color: var(--text); }
.ai-msg-content h1 { font-size: 17px; } .ai-msg-content h2 { font-size: 15.5px; } .ai-msg-content h3 { font-size: 14.5px; }
.ai-msg-content code {
  background: rgba(59,130,246,.15); border-radius: 5px;
  padding: 2px 6px; font-size: 12.5px; font-family: 'SF Mono','Fira Code',monospace;
  color: #93c5fd; border: 1px solid rgba(59,130,246,.2);
}
.ai-msg-content ul,.ai-msg-content ol  { padding-left: 20px; margin: 6px 0; }
.ai-msg-content li                 { margin: 3px 0; }
.ai-msg-content blockquote {
  border-left: 3px solid var(--accent); padding-left: 12px;
  color: var(--text2); margin: 8px 0; font-style: italic;
  background: rgba(59,130,246,.05); border-radius: 0 6px 6px 0; padding: 8px 8px 8px 14px;
}
.ai-msg-content a   { color: var(--accent2); text-decoration: underline; }
.ai-msg-content table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.ai-msg-content th,.ai-msg-content td { padding: 7px 12px; border: 1px solid var(--border2); text-align: left; }
.ai-msg-content th  { background: var(--bg3); font-weight: 600; color: var(--text); }
.ai-msg-content hr  { border: none; border-top: 1px solid var(--border2); margin: 12px 0; }

/* ── Code Blocks ─────────────────────────────────────── */
.code-block-wrap {
  background: #13131a; border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px; margin: 8px 0; overflow: hidden; width: 100%;
  word-break: normal; word-wrap: normal; white-space: normal; cursor: pointer;
}
.code-block-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 7px 12px; background: rgba(255,255,255,.04);
  border-bottom: 1px solid rgba(255,255,255,.07); gap: 8px;
}
.code-block-lang {
  font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: rgba(255,255,255,.35); font-family: 'SF Mono','Fira Code',monospace; flex: 1;
}
.code-block-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.code-block-toggle,.code-preview-btn,.code-copy-btn {
  display: inline-flex; align-items: center; gap: 3px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1);
  border-radius: 5px; padding: 3px 8px;
  font-size: 10.5px; font-family: var(--font);
  color: rgba(255,255,255,.45); cursor: pointer; transition: all .15s; white-space: nowrap;
}
.code-block-toggle:hover,.code-preview-btn:hover,.code-copy-btn:hover { background: rgba(255,255,255,.12); color: rgba(255,255,255,.75); }
.code-block-body { overflow: hidden; transition: max-height .35s cubic-bezier(0.4,0,0.2,1); }
.code-block-body.collapsed {
  max-height: 120px;
  -webkit-mask: linear-gradient(to bottom, black 50%, transparent 100%);
  mask: linear-gradient(to bottom, black 50%, transparent 100%);
}
.code-block-body:hover { opacity: .85; }
.code-block-body pre {
  margin: 0; background: transparent; border: none; border-radius: 0;
  padding: 13px 16px; overflow-x: auto; font-size: 13px;
  font-family: 'SF Mono','Fira Code',monospace; line-height: 1.6;
  white-space: pre; word-break: normal; word-wrap: normal;
}
.code-block-body pre code {
  background: none; padding: 0; color: #c9d1d9; border: none; font-size: inherit;
  white-space: pre; word-break: normal;
}

/* ── Typing Cursor & Indicator ───────────────────────── */
.cursor {
  display: inline-block; width: 2px; height: 1em;
  background: var(--accent2); margin-left: 2px; vertical-align: text-bottom;
  animation: blink .8s step-end infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

.typing-indicator { display: flex; align-items: center; gap: 4px; padding: 11px 14px; }
.td {
  width: 7px; height: 7px; background: var(--text3); border-radius: 50%;
  animation: tdBounce 1.4s ease-in-out infinite;
}
.td:nth-child(2) { animation-delay: .18s; } .td:nth-child(3) { animation-delay: .36s; }
@keyframes tdBounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-7px); } }

/* ── Message Actions ─────────────────────────────────── */
.msg-actions { display: flex; align-items: center; gap: 4px; margin-top: 4px; padding-left: 4px; opacity: 0; transition: opacity .2s; }
.msg-actions.visible { opacity: 1; }
.msg-action-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 10px; background: none; border: 1px solid var(--border2);
  border-radius: 20px; cursor: pointer; font-family: var(--font);
  font-size: 11.5px; color: var(--text3); transition: all .15s;
}
.msg-action-btn:hover { background: var(--bg3); color: var(--text); border-color: var(--border2); }

/* Light theme */
[data-theme="light"] .msg-action-btn          { border-color: rgba(0,0,0,.18); color: var(--text2); }
[data-theme="light"] .msg-action-btn:hover    { background: var(--bg4); color: var(--text); }
[data-theme="light"] .code-block-wrap         { border-color: rgba(0,0,0,.14); background: #e8e8f2; }
[data-theme="light"] .code-block-header       { background: rgba(0,0,0,.05); border-bottom-color: rgba(0,0,0,.10); }
[data-theme="light"] .code-block-lang         { color: rgba(0,0,0,.45); }
[data-theme="light"] .code-block-toggle,
[data-theme="light"] .code-preview-btn,
[data-theme="light"] .code-copy-btn           { background: rgba(0,0,0,.06); border-color: rgba(0,0,0,.12); color: rgba(0,0,0,.55); }
[data-theme="light"] .code-block-toggle:hover,
[data-theme="light"] .code-preview-btn:hover,
[data-theme="light"] .code-copy-btn:hover     { background: rgba(0,0,0,.12); color: rgba(0,0,0,.8); }
[data-theme="light"] .code-block-body pre code { color: #1e1e2e; }
[data-theme="light"] .code-block-body pre     { background: #e8e8f2; }
[data-theme="light"] .hljs                    { background: #e8e8f2 !important; }
[data-theme="light"] .msg-collapse-btn        { background: rgba(37,99,235,.12); color: var(--accent); }

/* ── Formula Styles ───────────────────────────────────── */
.formula-inline {
  display: inline;
  vertical-align: middle;
}
.formula-display {
  display: block;
  text-align: center;
  margin: 8px 0;
  overflow-x: auto;
  padding: 4px 0;
}
.ai-msg-content .formula-display,
.msg-bubble .formula-display {
  background: transparent;
  border-radius: 8px;
  padding: 4px 8px;
}
.ai-msg-content mjx-container,
.msg-bubble mjx-container {
  overflow-x: auto;
  max-width: 100%;
}

/* ── Stream Rendering Zones ───────────────────────────── */
.sb-stable { contain: content; }
.sb-live { contain: content; }

/* ── Task List Styles ─────────────────────────────────── */
.task-item {
  list-style: none;
  margin-left: -20px;
}
.task-item input[type="checkbox"] {
  margin-right: 8px;
  vertical-align: middle;
}

/* ── Thinking Block Styles ─────────────────────────────── */
.thinking-block {
  margin: 12px 0;
  padding: 12px 16px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 12px;
  position: relative;
}

.thinking-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  color: var(--text2);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: color .2s;
}

.thinking-summary:hover {
  color: var(--text);
}

.thinking-status {
  flex: 1;
}

.thinking-caret {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-right: 1.6px solid var(--text3);
  border-bottom: 1.6px solid var(--text3);
  transform: rotate(45deg) translateY(-1px);
  transition: transform .2s;
}

.thinking-block.collapsed .thinking-caret {
  transform: rotate(-45deg) translateY(-1px);
}

.thinking-thread {
  margin-top: 12px;
  max-height: 1000px;
  overflow: hidden;
  transition: max-height .3s ease, opacity .3s ease;
}

.thinking-block.collapsed .thinking-thread {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

.thinking-step {
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}

.thinking-step:last-child {
  margin-bottom: 0;
}

.thinking-step code {
  background: rgba(59,130,246,.15);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: 'SF Mono','Fira Code',monospace;
  color: #93c5fd;
  border: 1px solid rgba(59,130,246,.2);
}

.thinking-step strong {
  font-weight: 600;
  color: var(--text);
}

.thinking-step em {
  font-style: italic;
}

.thinking-step a {
  color: var(--accent2);
  text-decoration: underline;
}

.thinking-block.streaming {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow);
}

.thinking-block.streaming .thinking-status {
  color: var(--accent);
}

[data-theme="light"] .thinking-block {
  background: var(--bg3);
  border-color: rgba(0,0,0,.1);
}

[data-theme="light"] .thinking-step code {
  background: rgba(59,130,246,.12);
  color: #2563eb;
  border-color: rgba(59,130,246,.15);
}
