/* Split View Layout */
.chat-split-container {
  display: flex;
  gap: 0;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.chat-main {
  min-width: 400px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Smooth transition when sidebar opens/closes */
  transition: flex 250ms ease-out;
}

.chat-sidebar {
  flex: 1;
  min-width: 300px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slide-in 200ms ease-out;
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Sidebar Panel */
.sidebar-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--panel);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--panel);
}

/* Smaller close button for sidebar */
.sidebar-header .btn {
  padding: 4px 8px;
  font-size: 14px;
  min-width: auto;
  line-height: 1;
}

.sidebar-title {
  font-weight: 600;
  font-size: 14px;
}

.sidebar-content {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

.sidebar-markdown {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}

/* ── Headings ── */

.sidebar-markdown :where(h1) {
  font-size: 1.65em;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin: 1.6em 0 0.6em;
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--border);
  line-height: 1.25;
}

.sidebar-markdown :where(h2) {
  font-size: 1.35em;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin: 1.4em 0 0.5em;
  padding-bottom: 0.25em;
  border-bottom: 1px solid var(--border);
  line-height: 1.3;
}

.sidebar-markdown :where(h3) {
  font-size: 1.15em;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 1.2em 0 0.4em;
  line-height: 1.35;
}

.sidebar-markdown :where(h4, h5, h6) {
  font-size: 1em;
  font-weight: 600;
  margin: 1em 0 0.35em;
  line-height: 1.4;
  color: var(--text-strong);
}

.sidebar-markdown > :where(h1, h2, h3, h4, h5, h6):first-child {
  margin-top: 0;
}

/* ── Paragraphs & spacing ── */

.sidebar-markdown :where(p, ul, ol, pre, blockquote, table, details) {
  margin: 0;
}

.sidebar-markdown :where(p + p, p + ul, p + ol, p + pre, p + blockquote, p + table, p + details) {
  margin-top: 0.75em;
}

.sidebar-markdown :where(h1 + p, h2 + p, h3 + p, h4 + p) {
  margin-top: 0;
}

/* ── Lists ── */

.sidebar-markdown :where(ul, ol) {
  padding-left: 1.6em;
}

.sidebar-markdown :where(li + li) {
  margin-top: 0.3em;
}

.sidebar-markdown :where(li > p) {
  margin-top: 0.25em;
}

.sidebar-markdown :where(li > ul, li > ol) {
  margin-top: 0.25em;
}

/* ── Links ── */

.sidebar-markdown :where(a) {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  transition: text-decoration-color var(--duration-fast) ease;
}

.sidebar-markdown :where(a:hover) {
  text-decoration-color: var(--accent);
}

/* ── Inline code ── */

.sidebar-markdown code {
  font-family: var(--mono);
  font-size: 0.88em;
}

.sidebar-markdown :where(:not(pre) > code) {
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.12);
  border: 1px solid var(--border);
}

:root[data-theme-mode="light"] .sidebar-markdown :where(:not(pre) > code) {
  background: rgba(0, 0, 0, 0.06);
}

/* ── Code blocks ── */

.sidebar-markdown pre {
  background: rgba(0, 0, 0, 0.12);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  overflow-x: auto;
  margin-top: 0.75em;
}

:root[data-theme-mode="light"] .sidebar-markdown pre {
  background: rgba(0, 0, 0, 0.04);
}

.sidebar-markdown :where(pre code) {
  background: none;
  border: none;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.55;
}

/* ── Blockquotes ── */

.sidebar-markdown :where(blockquote) {
  border-left: 3px solid var(--border-strong);
  padding: 8px 14px;
  margin-left: 0;
  margin-top: 0.75em;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

:root[data-theme-mode="light"] .sidebar-markdown :where(blockquote) {
  background: rgba(0, 0, 0, 0.025);
}

.sidebar-markdown :where(blockquote blockquote) {
  margin-top: 8px;
}

/* ── Tables ── */

.sidebar-markdown :where(table) {
  margin-top: 0.75em;
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  display: block;
  overflow-x: auto;
}

.sidebar-markdown :where(th, td) {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}

.sidebar-markdown :where(th) {
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  background: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.sidebar-markdown :where(tbody tr:hover) {
  background: var(--bg-hover);
}

/* ── Horizontal rules ── */

.sidebar-markdown :where(hr) {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5em 0;
}

/* ── Bold / italic ── */

.sidebar-markdown :where(strong) {
  font-weight: 600;
  color: var(--text-strong);
}

/* ── Images ── */

.sidebar-markdown .markdown-inline-image {
  display: block;
  max-width: 100%;
  max-height: 420px;
  width: auto;
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--secondary) 70%, transparent);
  object-fit: contain;
  margin-top: 0.75em;
}

/* ── Details / summary ── */

.sidebar-markdown :where(details) {
  margin-top: 0.75em;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  overflow: hidden;
}

.sidebar-markdown :where(summary) {
  cursor: pointer;
  padding: 8px 12px;
  font-weight: 500;
  font-size: 13px;
  user-select: none;
  transition: background var(--duration-fast) ease;
}

.sidebar-markdown :where(summary:hover) {
  background: var(--bg-hover);
}

.sidebar-markdown :where(details[open] > :not(summary)) {
  padding: 0 12px 10px;
}

/* Mobile: Full-screen modal */
@media (max-width: 768px) {
  .chat-split-container--open {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
  }

  .chat-split-container--open .chat-main {
    display: none; /* Hide chat on mobile when sidebar open */
  }

  .chat-split-container--open .chat-sidebar {
    width: 100%;
    min-width: 0;
    border-left: none;
  }
}
