/*
 * Mouse — 灰白简约风格（美化版，无Emoji）
 */

:root {
  --bg: #c8c8c8;
  --card: #ececec;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --accent: #1f2937;
  --hover-bg: #f9fafb;
  --user-bubble: #1f2937;
  --user-text: #ffffff;
  --ai-bubble: #fafafa;
  --code-bg: #111827;
  --radius: 16px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --sidebar-width: 280px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ─── 布局 ────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#main {
  display: flex;
  flex: 1;
  overflow: hidden;
  padding: 12px;
  gap: 12px;
}

/* ─── 顶栏 ────────────────────────── */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-left,
.topbar-center,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  gap: 4px;
}

#sidebar-toggle {
  display: none;
}

/* ─── 侧栏 ────────────────────────── */

#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(0, 0, 0, 0.02);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-search {
  padding: 16px 16px 12px 16px;
}

.sidebar-search input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  outline: none;
  font-size: 13px;
  transition: all 0.2s;
}

.sidebar-search input:focus {
  border-color: var(--accent);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

#conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px;
}

.conv-item {
  padding: 12px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 4px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.2s;
}

.conv-item:hover {
  background: var(--hover-bg);
}

.conv-item.active {
  background: var(--user-bubble);
  font-weight: 600;
}

.conv-item.active .conv-title {
  color: #fff;
}

.conv-item.active .conv-date {
  color: rgba(255,255,255,0.6);
}

.conv-item .conv-title {
  display: block;
  color: var(--text-primary);
}

.conv-item .conv-date {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ─── 内容区 ──────────────────────── */

#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(0, 0, 0, 0.02);
}

.view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}

.view.active {
  display: flex;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.view-header h2 {
  font-size: 16px;
  font-weight: 600;
}

/* ─── 聊天视图 ────────────────────── */

#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 28px 12px;
}

.message {
  display: flex;
  position: relative;
  margin-bottom: 16px;
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.message.user {
  justify-content: flex-end;
}

.message:hover .msg-del-btn,
.message:hover .msg-regen-btn {
  opacity: 1;
}

.msg-del-btn,
.msg-regen-btn {
  position: absolute;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 1;
  box-shadow: var(--shadow-sm);
}

.msg-del-btn {
  top: -8px;
  right: -8px;
}

.msg-regen-btn {
  top: -8px;
  right: 20px;
}

.msg-del-btn:hover {
  color: #dc3545;
  border-color: #dc3545;
  background: #fff5f5;
}

.msg-regen-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

.message .bubble {
  max-width: 55%;
  padding: 10px 16px;
  border-radius: var(--radius);
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.user .bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-top-right-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.message.assistant .bubble {
  background: var(--ai-bubble);
  color: var(--text-primary);
  border-top-left-radius: 4px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* Markdown 渲染 */
.message .bubble p {
  margin: 6px 0;
}

.message .bubble p:first-child { margin-top: 0; }
.message .bubble p:last-child { margin-bottom: 0; }

.message .bubble code {
  background: var(--hover-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: "SF Mono", "Cascadia Code", "JetBrains Mono", monospace;
}

.message .bubble pre {
  margin: 12px 0;
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}

.message .bubble pre code {
  display: block;
  padding: 14px 16px;
  background: var(--code-bg);
  color: #e9ecef;
}

.message .bubble ul, .message .bubble ol {
  padding-left: 20px;
  margin: 6px 0;
}

.message .bubble h1, .message .bubble h2, .message .bubble h3 {
  margin: 12px 0 6px;
  font-weight: 600;
}

.message .bubble blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 12px;
  color: var(--text-secondary);
  margin: 8px 0;
}

/* 正在输入光标 */
.typing-cursor::after {
  content: "▊";
  animation: blink 1s step-end infinite;
  color: var(--text-secondary);
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ─── 输入区 ──────────────────────── */

#input-area {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  padding: 20px 32px;
  border-top: 1px solid var(--border);
  background: var(--card);
}

#message-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  resize: none;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  transition: all 0.2s;
}

#message-input:focus {
  border-color: var(--accent);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

/* ─── 按钮 ────────────────────────── */

.btn {
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--hover-bg);
  border-color: #ced4da;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 12px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: #343a40;
  border-color: #343a40;
}

.btn-danger {
  color: #dc3545;
  border-color: #dc3545;
}

.btn-danger:hover {
  background: #fff5f5;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 10px;
  font-size: 16px;
  color: var(--text-secondary);
  border-radius: var(--radius);
  transition: all 0.15s;
}

.icon-btn:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

/* ─── 侧栏世界书区域 ──────────────── */

#sidebar-worldbook {
  border-bottom: 1px solid var(--border);
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.sidebar-section-header:hover {
  background: var(--hover-bg);
}

.wb-header-icon {
  display: flex;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.wb-header-text {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.wb-header-count {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.sidebar-section-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease;
}

#sidebar-worldbook.open .sidebar-section-body {
  max-height: 300px;
  overflow-y: auto;
}

.wb-mini-item {
  display: flex;
  align-items: center;
  padding: 6px 16px 6px 44px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.1s;
  gap: 8px;
}

.wb-mini-item:hover {
  background: var(--hover-bg);
}

.wb-mini-item .wb-mini-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.wb-mini-item .wb-mini-status {
  font-size: 10px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.wb-mini-item .wb-mini-del {
  font-size: 14px;
  line-height: 1;
  color: var(--text-secondary);
  padding: 0 2px;
  opacity: 0;
  transition: opacity 0.1s;
  background: none;
  border: none;
  cursor: pointer;
}

.wb-mini-item:hover .wb-mini-del {
  opacity: 1;
}

.wb-mini-item .wb-mini-del:hover {
  color: #dc3545;
}

.wb-mini-add {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px 8px 44px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.1s;
}

.wb-mini-add:hover {
  color: var(--text-primary);
  background: var(--hover-bg);
}

#sidebar-wb-list {
  padding-bottom: 4px;
}

/* 侧栏世界书分类文件夹 */
.wb-cat-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px 2px 36px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.wb-mini-more {
  padding: 2px 16px 2px 44px;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: default;
}

/* 主视图世界书分类区域 */
.wb-category-section {
  margin-bottom: 4px;
}

.wb-category-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 24px 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}

.wb-category-count {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 1px 7px;
  border-radius: 10px;
}

/* ─── 列表（世界书 / API 线路） ────── */

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  transition: background 0.15s;
}

.list-item:hover {
  background: var(--bg);
}

.list-item .item-info {
  flex: 1;
  min-width: 0;
}

.list-item .item-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.list-item .item-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

.list-item .item-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.default-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  background: var(--hover-bg);
  border-radius: 4px;
  color: var(--text-secondary);
  margin-left: 8px;
}

/* ─── 弹窗 ────────────────────────── */

#modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(2px); /* 增加一点高级的微模糊感 */
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s;
}

#modal-overlay.hidden {
  display: none;
}

#modal-content {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  min-width: 380px;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

#modal-body h3 {
  margin-bottom: 18px;
  font-weight: 600;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  outline: none;
  font-family: inherit;
  font-size: 13px;
  transition: all 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--accent);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group .hint {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-group input[type="checkbox"] {
  width: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ─── 设置弹窗 ────────────────────── */

#settings-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s;
}

#settings-overlay.hidden {
  display: none;
}

#settings-content {
  background: var(--card);
  border-radius: var(--radius);
  width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.settings-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.settings-body {
  padding: 16px 24px 24px;
}

#settings-close {
  font-size: 18px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ─── 响应式 ──────────────────────── */

@media (max-width: 768px) {
  #sidebar {
    display: none;
    position: fixed;
    top: 53px;
    left: 0;
    bottom: 0;
    z-index: 100;
    width: 280px;
    box-shadow: 4px 0 16px rgba(0,0,0,0.05);
    border-radius: 0;
  }

  #sidebar.open {
    display: flex;
  }

  #bottom-nav {
    display: flex;
  }

  #modal-content {
    min-width: 0;
    width: 92vw;
  }
}

/* ─── 滚动条 ──────────────────────── */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ─── 空状态 ──────────────────────── */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state .icon {
  font-size: 32px;
  margin-bottom: 12px;
  color: #ced4da;
}

.empty-state .icon .icon-img {
  width: 48px;
  height: 48px;
  display: inline-block;
  opacity: 0.6;
}

.empty-state p {
  font-size: 14px;
}

/* ─── 匹配测试结果 ────────────────── */

.match-result {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius);
  font-size: 13px;
  border: 1px solid var(--border);
}

.match-result .match-item {
  padding: 4px 0;
}

/* ─── 工具调用状态提示 ────────────── */
.tool-status {
  padding: 8px 24px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  text-align: center;
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ─── Logo 图片 ─────────────────────── */
.logo-img {
  width: 22px;
  height: 22px;
  color: var(--accent);
}
