/* CHAT PANEL — right-side slide-out */
.chat-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 33.333vw;
  z-index: 200;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.chat-panel.open {
  transform: translateX(0);
}

/* Header */
.chat-header {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface2);
}
.chat-header-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.03em;
}
.chat-header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.chat-header-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: border-color 0.15s, color 0.15s;
  font-family: 'IBM Plex Mono', monospace;
}
.chat-header-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Messages area */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--surface);
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: var(--surface); }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Message bubbles */
.chat-msg {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 90%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.chat-msg--user {
  align-self: flex-end;
  background: rgba(var(--accent-rgb), 0.12);
  border: 1px solid rgba(var(--accent-rgb), 0.25);
  border-bottom-right-radius: 2px;
}
.chat-msg--assistant {
  align-self: flex-start;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
  max-width: 96%;
}

/* Markdown content in assistant messages */
.chat-msg--assistant p { margin: 0 0 8px; }
.chat-msg--assistant p:last-child { margin-bottom: 0; }
.chat-msg--assistant strong { font-weight: 600; }
.chat-msg--assistant ul, .chat-msg--assistant ol {
  margin: 4px 0 8px;
  padding-left: 20px;
}
.chat-msg--assistant li { margin-bottom: 2px; }
.chat-msg--assistant code {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  background: rgba(var(--accent-rgb), 0.08);
  padding: 1px 4px;
  border-radius: 3px;
}
.chat-msg--assistant pre {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 12px;
  margin: 6px 0;
  overflow-x: auto;
  font-size: 11px;
}
.chat-msg--assistant pre code {
  background: none;
  padding: 0;
  font-size: 11px;
  white-space: pre;
}
.chat-msg--assistant h1,
.chat-msg--assistant h2,
.chat-msg--assistant h3 {
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 600;
  color: var(--text);
  margin: 8px 0 4px;
}
.chat-msg--assistant h1 { font-size: 15px; }
.chat-msg--assistant h2 { font-size: 13px; }
.chat-msg--assistant h3 { font-size: 12px; color: var(--muted); }
.chat-msg--assistant .table-wrap {
  overflow-x: auto;
  margin: 6px 0;
}
.chat-msg--assistant table {
  border-collapse: collapse;
  font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
  white-space: nowrap;
}
.chat-msg--assistant th, .chat-msg--assistant td {
  border: 1px solid var(--border);
  padding: 3px 8px;
  text-align: right;
}
.chat-msg--assistant th {
  background: var(--surface);
  font-weight: 600;
  text-align: left;
}

/* Typing indicator */
.chat-typing::after {
  content: '';
  display: inline-block;
  width: 4px;
  height: 14px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: chat-blink 0.6s step-end infinite;
}
@keyframes chat-blink {
  50% { opacity: 0; }
}

/* Empty state */
.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  color: var(--dim);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  line-height: 1.6;
}

/* Error */
.chat-error {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--red);
  padding: 6px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Input bar */
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 12px;
  outline: none;
  resize: none;
  min-height: 38px;
  max-height: 100px;
  transition: border-color 0.15s;
}
.chat-input:focus {
  border-color: var(--accent);
}
.chat-input::placeholder {
  color: var(--dim);
}
.chat-send-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  padding: 0 14px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: var(--surface);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  align-self: flex-end;
  height: 38px;
}
.chat-send-btn:hover {
  background: var(--accent-hover);
}
.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Responsive */
@media (max-width: 480px) {
  .chat-panel { width: 100%; }
}
