/* ---- AI Chat panel (right sidebar) ---- */

.chat-panel {
  position: fixed;
  top: 0; right: 0;
  width: 360px;
  height: 100vh;
  z-index: 200;
  background: var(--card);
  border-left: 1px solid var(--rule);
  box-shadow: -6px 0 28px rgba(28,26,23,0.12);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}
.chat-panel.open {
  transform: translateX(0);
}

/* Topbar-height header */
.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 66px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--rule);
  background: var(--card);
}
.chat-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
}
.chat-panel-icon {
  width: 26px; height: 26px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 5px;
  display: grid; place-items: center;
  font-size: 13px;
  flex-shrink: 0;
}
.chat-panel-header-btns {
  display: flex; gap: 4px;
}
.chat-hdr-btn {
  background: transparent; border: 0;
  width: 30px; height: 30px;
  border-radius: 6px;
  display: grid; place-items: center;
  color: var(--ink-3);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.chat-hdr-btn:hover { background: rgba(28,26,23,0.07); color: var(--ink); }

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--rule-2); border-radius: 3px; }

.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--ink-3);
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  line-height: 1.6;
  padding: 20px 10px;
}
.chat-empty-hint {
  margin-top: 8px;
  font-size: 13px;
  font-style: normal;
  font-family: var(--sans);
  color: var(--ink-3);
}

.chat-setup {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  padding: 28px 20px;
}
.chat-setup-icon {
  width: 46px; height: 46px;
  background: var(--ink); color: var(--paper);
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 22px;
  margin-bottom: 4px;
}
.chat-setup-title {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
}
.chat-setup-body {
  font-size: 13.5px;
  color: var(--ink-2);
  line-height: 1.6;
  max-width: 260px;
}
.chat-setup-hint {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--ink-3);
  letter-spacing: 0.03em;
}

.chat-msg { display: flex; flex-direction: column; }
.chat-msg-user { align-items: flex-end; }
.chat-msg-assistant { align-items: flex-start; }

.chat-bubble {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.55;
}
.chat-msg-user .chat-bubble {
  background: var(--ink);
  color: var(--paper);
  border-bottom-right-radius: 3px;
}
.chat-msg-assistant .chat-bubble {
  background: var(--paper-2);
  color: var(--ink);
  border-bottom-left-radius: 3px;
  border: 1px solid var(--rule);
}
.chat-msg-assistant .chat-bubble.error {
  background: oklch(0.97 0.03 25);
  color: oklch(0.45 0.13 25);
  border-color: oklch(0.88 0.05 25);
}

/* Markdown rendering inside bubbles */
.chat-bubble p { margin: 0 0 6px; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble strong { font-weight: 600; }
.chat-bubble code {
  font-family: var(--mono);
  font-size: 12px;
  background: rgba(28,26,23,0.08);
  border-radius: 3px;
  padding: 1px 5px;
}
.chat-msg-user .chat-bubble code { background: rgba(255,255,255,0.15); }
.chat-bubble pre {
  background: rgba(28,26,23,0.07);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 6px 0;
  font-size: 12px;
  font-family: var(--mono);
  line-height: 1.5;
}
.chat-bubble pre code { background: none; padding: 0; font-size: inherit; }
.chat-bubble ul, .chat-bubble ol { margin: 4px 0 4px 18px; padding: 0; }
.chat-bubble li { margin-bottom: 2px; }

/* Typing indicator */
.chat-typing {
  display: flex; gap: 5px; align-items: center;
  padding: 12px 14px;
}
.chat-typing-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ink-3);
  animation: chat-bounce 1.2s infinite ease-in-out;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* Context bar */
.chat-context-bar {
  padding: 8px 14px;
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  background: var(--paper-2);
}
.chat-context-label {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}
.chat-context-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--card); border: 1px solid var(--rule-2);
  border-radius: 999px; padding: 3px 9px;
  font-size: 12px; font-family: var(--sans); color: var(--ink-2);
  cursor: pointer; transition: all 0.12s ease;
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-context-chip:hover { border-color: var(--accent); color: var(--accent); }
.chat-context-chip.active { background: oklch(0.97 0.03 65); border-color: var(--accent); color: var(--ink); }
.chat-context-chip.active .chat-ctx-dot { background: var(--accent); }
.chat-ctx-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-3); flex-shrink: 0;
  transition: background 0.12s ease;
}

/* Input area */
.chat-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--rule);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  background: var(--card);
}
.chat-textarea {
  flex: 1;
  background: var(--paper-2);
  border: 1px solid var(--rule-2);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: var(--sans);
  color: var(--ink);
  outline: none;
  resize: none;
  max-height: 140px;
  overflow-y: auto;
  line-height: 1.5;
  transition: border-color 0.15s ease;
}
.chat-textarea:focus { border-color: var(--accent); background: #fff; }
.chat-textarea:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-textarea::placeholder { color: var(--ink-3); }

.chat-send-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: var(--ink);
  border: none;
  color: var(--paper);
  display: grid; place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s ease, opacity 0.12s ease;
}
.chat-send-btn:hover:not(:disabled) { background: #2c2924; }
.chat-send-btn:disabled { opacity: 0.35; cursor: not-allowed; }


/* Model selector in chat header */
.chat-model-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  max-width: 180px;
}
.chat-model-wrap::after {
  content: "▾";
  position: absolute;
  right: 9px;
  pointer-events: none;
  font-size: 9px;
  color: var(--ink-3);
  line-height: 1;
}
.chat-model-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 5px 22px 5px 10px;
  color: var(--ink-2);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: border-color 0.12s ease, color 0.12s ease;
}
.chat-model-select:hover { border-color: var(--rule-2); color: var(--ink); }
.chat-model-select:focus { outline: none; border-color: var(--accent); }

/* Topbar toggle button */
.chat-toggle-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent;
  border: 1px solid var(--rule-2);
  border-radius: var(--radius);
  padding: 6px 11px;
  font-size: 13px;
  font-family: var(--sans);
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  transition: all 0.12s ease;
  letter-spacing: 0.01em;
}
.chat-toggle-btn:hover { border-color: var(--accent); color: var(--accent); }
.chat-toggle-btn.active {
  background: var(--ink); color: var(--paper);
  border-color: var(--ink);
}
.chat-toggle-btn.active:hover { background: #2c2924; border-color: #2c2924; }
.chat-toggle-star { font-size: 11px; }

/* Attachment button */
.chat-attach-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: var(--paper-2);
  border: 1px solid var(--rule-2);
  color: var(--ink-3);
  display: grid; place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.chat-attach-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: var(--card); }
.chat-attach-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Attachment preview bar (above input) */
.chat-attach-bar {
  padding: 8px 14px;
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--paper-2);
  flex-shrink: 0;
}
.chat-attach-thumb {
  width: 48px; height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--rule);
}
.chat-attach-doc-chip {
  font-size: 12.5px;
  color: var(--ink-2);
  font-family: var(--sans);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-attach-remove {
  background: none; border: none;
  color: var(--ink-3); font-size: 13px;
  cursor: pointer; padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: background 0.1s ease, color 0.1s ease;
}
.chat-attach-remove:hover { background: rgba(28,26,23,0.08); color: var(--ink); }

/* Attached image in a user bubble */
.chat-attach-img {
  display: block;
  max-width: 100%;
  max-height: 200px;
  border-radius: 6px;
  margin-bottom: 6px;
  object-fit: contain;
}
.chat-attach-doc {
  font-size: 12px;
  font-family: var(--mono);
  color: rgba(255,255,255,0.7);
  margin-bottom: 4px;
}

@keyframes chat-spin { to { transform: rotate(360deg); } }

/* Mobile: full-width panel */
@media (max-width: 500px) {
  .chat-panel { width: 100vw; }
}
