.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--sidebar-bg);
  border-left: 1px solid var(--border);
}

/* ── Tab bar (replaces the old .chat-header) ─────────── */
.chat-tabs {
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 40px;
  gap: 0;
}

.chat-tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 10px 10px;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: color 0.15s;
}

.chat-tab:hover {
  color: var(--text-primary);
}

.chat-tab-active {
  color: var(--text-primary);
}

.chat-tab-active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 1px 1px 0 0;
}

.chat-tab-badge {
  background: var(--accent);
  color: #1a1208;
  font-size: 9px;
  font-weight: 700;
  border-radius: 8px;
  padding: 1px 5px;
  line-height: 1.4;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Whole story context bar ─────────────────────────────────────── */
.chat-context-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-project-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.chat-project-toggle:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.chat-project-toggle--active {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* ── Chat sub-header (History link + New Chat button) ────────────── */
.chat-subheader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-history-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 0;
  cursor: pointer;
  transition: color 0.15s;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: transparent;
}

.chat-history-link:hover,
.chat-history-link-active {
  color: var(--text-primary);
  text-decoration-color: currentColor;
}

.chat-new-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.chat-new-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

/* ── History list ────────────────────────────────────────────────── */
.chat-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-history-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 9px 11px;
  border-radius: 6px;
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.12s, border-color 0.12s;
}

.chat-history-item:hover {
  background: var(--message-bg);
}

.chat-history-item-active {
  border-color: var(--border);
  background: var(--message-bg);
}

.chat-history-time {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.chat-history-summary {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.chat-history-item-active .chat-history-summary {
  color: var(--text-secondary);
}

/* ── Pending attachment indicator (between tab bar and messages) ─── */
.chat-attachment-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
  flex-shrink: 0;
}

.chat-attachment-indicator-icon {
  font-size: 15px;
  line-height: 1;
  opacity: 0.85;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-placeholder {
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font-serif);
  font-style: italic;
  text-align: center;
  margin: 24px 0;
  line-height: 1.6;
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-message-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.chat-message-user .chat-message-label {
  color: var(--accent);
}

.chat-message-content {
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-primary);
  font-family: var(--font-sans);
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--message-bg);
  border-radius: 6px;
  padding: 10px 12px;
}

/* Assistant messages use rendered Markdown — no pre-wrap needed */
.chat-message-assistant .chat-message-content {
  white-space: normal;
}

.chat-message-markdown {
  word-break: break-word;
}

.chat-message-markdown p {
  margin: 0 0 14px;
}
.chat-message-markdown p:last-child {
  margin-bottom: 0;
}

.chat-message-markdown h1,
.chat-message-markdown h2,
.chat-message-markdown h3 {
  color: var(--heading-color);
  font-family: var(--font-serif);
  font-weight: 600;
  margin: 12px 0 4px;
  line-height: 1.3;
}
.chat-message-markdown h1 { font-size: 15px; }
.chat-message-markdown h2 { font-size: 14px; }
.chat-message-markdown h3 { font-size: 13px; }

.chat-message-markdown ul,
.chat-message-markdown ol {
  margin: 4px 0 8px;
  padding-left: 18px;
}
.chat-message-markdown li {
  margin-bottom: 3px;
}

.chat-message-markdown code {
  font-family: monospace;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 3px;
  padding: 1px 4px;
}

.chat-message-markdown pre {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 5px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 6px 0;
}
.chat-message-markdown pre code {
  background: none;
  padding: 0;
  font-size: 12px;
}

.chat-message-markdown blockquote {
  border-left: 3px solid var(--accent);
  margin: 6px 0;
  padding: 2px 10px;
  color: var(--text-secondary);
  font-style: italic;
}

.chat-message-markdown strong {
  color: var(--text-primary);
  font-weight: 600;
}

.chat-message-markdown em {
  color: var(--text-secondary);
}

.chat-message-markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

.chat-message-user .chat-message-content {
  background: var(--user-message-bg);
}

.chat-streaming-cursor {
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.chat-typing {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  background: var(--message-bg);
  border-radius: 6px;
  width: fit-content;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s ease-in-out infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

.chat-error {
  background: rgba(200, 60, 60, 0.15);
  border: 1px solid rgba(200, 60, 60, 0.4);
  border-radius: 6px;
  color: #e07070;
  font-size: 12px;
  padding: 10px 12px;
}

.chat-info-notice {
  background: rgba(180, 140, 60, 0.12);
  border: 1px solid rgba(180, 140, 60, 0.35);
  border-radius: 6px;
  color: #c9a94a;
  font-size: 12px;
  padding: 10px 12px;
}

.chat-input-area {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Attachment chips bar (above the input row) ─── */
.chat-attachments-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-attachment-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 8px 3px 4px;
  font-size: 11px;
  color: var(--text-secondary);
  max-width: 180px;
}

.chat-attachment-thumb {
  width: 22px;
  height: 22px;
  object-fit: cover;
  border-radius: 12px;
  flex-shrink: 0;
}

.chat-attachment-icon {
  font-size: 14px;
  flex-shrink: 0;
  line-height: 1;
}

.chat-attachment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.chat-attachment-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 1px;
  flex-shrink: 0;
  transition: color 0.12s;
}

.chat-attachment-remove:hover {
  color: var(--text-primary);
}

/* ── Input row: paperclip + textarea + send ─── */
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-paperclip-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 18px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
  padding: 0;
}

.chat-paperclip-btn:hover:not(:disabled) {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.chat-paperclip-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ── Attachment chips shown inside past chat messages ─── */
.chat-message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 2px;
}

.chat-message-attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-textarea {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  padding: 8px 10px;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  min-height: 36px;
}

.chat-textarea:focus {
  border-color: var(--accent);
}

.chat-textarea::placeholder {
  color: var(--text-muted);
}

.chat-textarea:disabled {
  opacity: 0.5;
}

.chat-send-btn {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: #1a1208;
  font-size: 16px;
  font-weight: 700;
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.chat-send-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.chat-send-btn:not(:disabled):hover {
  opacity: 0.85;
}

/* ── Suggestion summary block inside assistant messages ─── */
.chat-message-suggestions {
  margin-top: 6px;
  border-top: 1px solid var(--border);
  padding-top: 7px;
}

.chat-suggestions-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.chat-suggestion-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-suggestion-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.chat-suggestion-badge {
  display: inline-block;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  flex-shrink: 0;
}

.chat-suggestion-excerpt {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.chat-suggestion-applied {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #1a1208;
  background: rgba(30, 200, 120, 0.85);
  border-radius: 3px;
  padding: 1px 5px;
  flex-shrink: 0;
}

/* ── Apply-to-bible action ───────────────────────────────────────── */
.chat-message-apply {
  margin-top: 10px;
}

.chat-apply-btn {
  background: none;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-apply-btn:hover {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
}
