/* AI 南瓜智能伴侣 - 主题样式 */
:root {
  --bg-dark: #1a1510;
  --bg-sidebar: #251c14;
  --bg-card: #2d2218;
  --pumpkin: #e67e22;
  --pumpkin-light: #f39c12;
  --pumpkin-dark: #d35400;
  --amber: #f5b041;
  --text: #fef5e7;
  --text-muted: #b8a88a;
  --user-bubble: #3d2e1f;
  --assistant-bubble: #2d2218;
  --border: rgba(230, 126, 34, 0.2);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Noto Serif SC", serif;
  background: var(--bg-dark);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  height: 100vh;
}

/* ========== 侧边栏 ========== */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.25s ease, min-width 0.25s ease;
  overflow: hidden;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

.sidebar.collapsed .sidebar-header h1,
.sidebar.collapsed .btn-new span:not(.icon),
.sidebar.collapsed .session-item,
.sidebar.collapsed .btn-config span:not(.icon) {
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

/* 侧边栏收缩按钮 */
.sidebar-toggle {
  position: fixed;
  left: 260px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 48px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: left 0.25s ease, background 0.2s, color 0.2s;
}

.sidebar-toggle:hover {
  background: var(--bg-card);
  color: var(--pumpkin-light);
}

.sidebar.collapsed ~ .sidebar-toggle {
  left: 0;
}

.sidebar.collapsed ~ .sidebar-toggle .toggle-icon {
  transform: rotate(180deg);
}

.toggle-icon {
  font-size: 0.7rem;
  transition: transform 0.25s ease;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 2rem;
  display: block;
  margin-bottom: 6px;
}

.sidebar-header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--pumpkin-light);
}

.btn-new {
  margin: 16px;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--pumpkin), var(--pumpkin-dark));
  border: none;
  border-radius: 10px;
  color: white;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-new:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(230, 126, 34, 0.4);
}

.btn-new .icon {
  font-size: 1.2rem;
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px;
}

.session-item {
  padding: 12px 14px;
  margin-bottom: 4px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  transition: background 0.2s, color 0.2s;
}

.session-item:hover {
  background: var(--bg-card);
  color: var(--text);
}

.session-item.active {
  background: rgba(230, 126, 34, 0.15);
  color: var(--pumpkin-light);
}

.session-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item {
  display: flex;
  align-items: center;
  position: relative;
}

.btn-session-menu {
  flex-shrink: 0;
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

.session-item:hover .btn-session-menu,
.session-item.active .btn-session-menu {
  display: flex;
}

.btn-session-menu:hover {
  color: var(--pumpkin-light);
  background: rgba(230, 126, 34, 0.15);
}

.session-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 200;
  min-width: 130px;
  overflow: hidden;
}

.session-menu.open {
  display: block;
}

.session-menu-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  text-align: left;
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.session-menu-item:hover {
  background: rgba(230, 126, 34, 0.1);
  color: var(--text);
}

.session-menu-item.delete:hover {
  background: rgba(200, 50, 50, 0.15);
  color: #e74c3c;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.btn-config {
  width: 100%;
  padding: 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-config:hover {
  border-color: var(--pumpkin);
  color: var(--pumpkin-light);
}

/* ========== 主内容区 ========== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.welcome {
  text-align: center;
  padding: 60px 20px;
}

.welcome-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  opacity: 0.9;
}

.welcome p {
  font-size: 1.2rem;
  color: var(--text-muted);
}

.welcome .sub {
  font-size: 0.95rem;
  margin-top: 8px;
  opacity: 0.7;
}

.messages {
  display: none;
}

.messages.visible {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.welcome.hidden {
  display: none;
}

/* 消息气泡 - 左右布局 */
.msg {
  display: flex;
  gap: 12px;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg .avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.msg.user .avatar {
  background: linear-gradient(135deg, var(--pumpkin), var(--pumpkin-dark));
}

.msg.assistant .avatar {
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.msg .bubble {
  padding: 14px 18px;
  border-radius: 14px;
  line-height: 1.6;
  font-size: 0.95rem;
}

.msg.user .bubble {
  background: var(--user-bubble);
  border: 1px solid var(--border);
}

.msg.assistant .bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
}

.msg .bubble pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.88rem;
}

.msg .bubble code {
  font-family: "ZCOOL KuaiLe", monospace;
}

.msg .role {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* 输入区 */
.input-area {
  padding: 16px 24px 24px;
  background: linear-gradient(to top, var(--bg-dark), transparent);
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.input-rag-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--text-muted);
  user-select: none;
  padding-bottom: 4px;
}

.input-rag-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--pumpkin);
  cursor: pointer;
}

.input-rag-toggle span {
  white-space: nowrap;
}

.input-area textarea {
  flex: 1;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  min-height: 48px;
  max-height: 120px;
  transition: border-color 0.2s;
}

.input-area textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.input-area textarea:focus {
  outline: none;
  border-color: var(--pumpkin);
}

.btn-send {
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--pumpkin), var(--pumpkin-dark));
  border: none;
  border-radius: 12px;
  color: white;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-send:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(230, 126, 34, 0.4);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ========== 配置弹窗 ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 90%;
  max-width: 440px;
  box-shadow: var(--shadow);
}

.modal-wide {
  max-width: 520px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-wide .modal-body {
  overflow-y: auto;
  flex: 1;
}

.rag-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.rag-section-title {
  font-size: 1rem;
  color: var(--pumpkin-light);
  margin-bottom: 10px;
  font-weight: 600;
}

.rag-runtime {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.rag-status-line {
  font-size: 0.8rem;
  color: var(--amber);
  margin-bottom: 12px;
}

.btn-ingest {
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--pumpkin-light);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.btn-ingest:hover {
  border-color: var(--pumpkin);
  background: var(--user-bubble);
}

.btn-ingest:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.modal-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.2rem;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.btn-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 20px;
}

.modal-body label {
  display: block;
  margin-bottom: 16px;
}

.modal-body label:last-of-type {
  margin-bottom: 0;
}

.modal-body label span {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.modal-body input,
.modal-body textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

.modal-body textarea {
  resize: vertical;
  min-height: 80px;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.btn-save {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--pumpkin), var(--pumpkin-dark));
  border: none;
  border-radius: 8px;
  color: white;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  transition: opacity 0.2s;
}

/* 打字光标 */
.typing-cursor {
  display: inline-block;
  color: var(--pumpkin-light);
  animation: blink 0.7s step-end infinite;
  font-weight: 300;
  line-height: 1;
}

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

.btn-save:hover {
  opacity: 0.9;
}

/* ========== 消息体容器 ========== */
.msg-body {
  display: flex;
  flex-direction: column;
}

/* ========== 复制按钮 ========== */
.rag-footnote {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 8px;
  padding: 6px 10px;
  background: rgba(230, 126, 34, 0.08);
  border-radius: 8px;
  border: 1px solid rgba(230, 126, 34, 0.15);
  line-height: 1.4;
}

.rag-footnote-error {
  color: #e59866;
  border-color: rgba(229, 152, 102, 0.35);
  background: rgba(229, 152, 102, 0.1);
}

.btn-copy {
  align-self: flex-start;
  margin-top: 6px;
  padding: 3px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.btn-copy:hover {
  border-color: var(--pumpkin);
  color: var(--pumpkin-light);
}

/* ========== Markdown 内容样式 ========== */
.bubble.markdown-body p {
  margin-bottom: 0.6em;
}

.bubble.markdown-body p:last-child {
  margin-bottom: 0;
}

.bubble.markdown-body ul,
.bubble.markdown-body ol {
  padding-left: 1.4em;
  margin-bottom: 0.6em;
}

.bubble.markdown-body li {
  margin-bottom: 0.25em;
}

.bubble.markdown-body h1,
.bubble.markdown-body h2,
.bubble.markdown-body h3,
.bubble.markdown-body h4 {
  margin: 0.8em 0 0.4em;
  color: var(--pumpkin-light);
  line-height: 1.3;
}

.bubble.markdown-body blockquote {
  border-left: 3px solid var(--pumpkin);
  padding-left: 12px;
  color: var(--text-muted);
  margin: 8px 0;
}

.bubble.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 0.9em;
}

.bubble.markdown-body th,
.bubble.markdown-body td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.bubble.markdown-body th {
  background: rgba(230, 126, 34, 0.1);
  color: var(--amber);
}

.bubble.markdown-body strong {
  color: var(--amber);
}

.bubble.markdown-body em {
  color: var(--text-muted);
}

.bubble.markdown-body a {
  color: var(--pumpkin-light);
  text-underline-offset: 2px;
}

.bubble.markdown-body :not(pre) > code {
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: monospace;
  color: var(--amber);
}

.bubble.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}
