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

:root {
  --sidebar-bg: #1a2535;
  --sidebar-hover: #223347;
  --sidebar-active: #2a4060;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --accent-light: #dbeafe;
  --bg: #f0f4f8;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text2: #64748b;
  --text3: #94a3b8;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 10px;
  --radius-sm: 6px;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

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

/* ── Sidebar ── */
#sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.25s ease;
}

.sidebar-top {
  padding: 16px 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-bottom: 14px;
}

.logo-icon { color: var(--accent); }

.new-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.new-btn:hover { background: var(--accent-dark); }

.sidebar-label {
  padding: 10px 14px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  color: rgba(255,255,255,0.35);
  text-transform: uppercase;
}

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

.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-track { background: transparent; }
.history-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

.history-item {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 9px 30px 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}
.history-item:hover { background: var(--sidebar-hover); }
.history-item.active { background: var(--sidebar-active); }

.history-del {
  position: absolute;
  top: 6px;
  right: 5px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: rgba(255,255,255,0.45);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.history-item:hover .history-del,
.history-del:focus-visible { opacity: 1; }
.history-del:hover { color: var(--red); background: rgba(239,68,68,0.14); }
.history-del:disabled { cursor: default; opacity: 0.3; }

.history-title {
  font-size: 13px;
  color: rgba(255,255,255,0.85);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item.active .history-title { color: #fff; font-weight: 600; }

.history-time {
  font-size: 11px;
  color: rgba(255,255,255,0.3);
  margin-top: 3px;
}

.history-empty {
  font-size: 12px;
  color: rgba(255,255,255,0.25);
  text-align: center;
  padding: 20px 10px;
}

/* ── Main ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  min-height: 52px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text2);
  cursor: pointer;
}
.menu-btn:hover { background: var(--bg); }

.thread-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

.header-right { display: flex; align-items: center; }

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text2);
}

.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text3);
  flex-shrink: 0;
}
.dot.on { background: var(--green); }
.dot.warn { background: var(--amber); }
.dot.err { background: var(--red); }

/* ── Messages ── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Welcome */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 40px 20px;
  gap: 12px;
}

.welcome-icon {
  width: 72px; height: 72px;
  background: var(--accent-light);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  margin-bottom: 4px;
}

.welcome h2 { font-size: 22px; color: var(--text); font-weight: 700; }
.welcome p { font-size: 14px; color: var(--text2); max-width: 420px; line-height: 1.6; }

.welcome-hints { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 520px; }

.hint {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
  text-align: left;
  line-height: 1.5;
  transition: border-color 0.15s, background 0.15s;
}
.hint:hover { border-color: var(--accent); background: var(--accent-light); color: var(--accent-dark); }

/* Message bubbles */
.msg { display: flex; gap: 10px; animation: fadeUp 0.2s ease; }
.msg.user { flex-direction: row-reverse; }

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

.avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  margin-top: 2px;
}
.msg.user .avatar { background: var(--accent); color: #fff; }
.msg.assistant .avatar { background: var(--sidebar-bg); color: #fff; }
.msg.doc .avatar { background: #dcfce7; color: #16a34a; }

.bubble {
  max-width: 72%;
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}
.msg.user .bubble {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius) var(--radius) 2px var(--radius);
}
.msg.assistant .bubble {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) var(--radius) 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.bubble.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}

.thinking {
  font-size: 12px;
  color: var(--text3);
  margin-top: 6px;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--border);
}

.resume-btn {
  display: inline-flex;
  align-items: center;
  margin-top: 10px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.resume-btn:hover { background: var(--accent-light); }

.doc-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #15803d;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
}
.doc-link:hover { background: #dcfce7; }

/* ── Progress ── */
#progress {
  margin: 0 24px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  max-height: 200px;
  overflow-y: auto;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.progress-title { font-size: 13px; font-weight: 700; color: var(--accent); }
.progress-count { font-size: 12px; color: var(--text3); }

.progress-bar-wrap {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 10px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
}

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

.pitem {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text2);
  padding: 2px 0;
}
.pitem .pmark { color: var(--text3); font-size: 11px; width: 14px; }
.pitem.pdone { color: var(--green); }
.pitem.pdone .pmark { color: var(--green); }

/* ── Footer / Input ── */
footer {
  padding: 12px 24px 16px;
  background: var(--card);
  border-top: 1px solid var(--border);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 8px 8px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

#input {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  outline: none;
  max-height: 160px;
  font-family: inherit;
}
#input::placeholder { color: var(--text3); }

.send-btn {
  width: 34px; height: 34px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.send-btn:hover { background: var(--accent-dark); transform: scale(1.05); }
.send-btn:active { transform: scale(0.97); }
.send-btn:disabled { background: var(--text3); cursor: default; transform: none; }

/* 生成中：发送按钮翻成停止按钮（写在 :disabled 之后，停止等待期保持红色） */
.send-btn.stop { background: var(--red); }
.send-btn.stop:hover { background: #dc2626; }

/* ── Overlay (mobile) ── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 10;
}
.overlay.show { display: block; }

/* ── Responsive ── */
@media (max-width: 640px) {
  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 20;
    transform: translateX(-100%);
  }
  #sidebar.open { transform: translateX(0); }
  .menu-btn { display: flex; }
  #messages { padding: 16px 14px 12px; }
  footer { padding: 10px 14px 14px; }
  #progress { margin: 0 14px 10px; }
  .bubble { max-width: 85%; }
  .history-del { opacity: 1; }
}
