:root {
  --bg: #0d0d0d;
  --sidebar-bg: #111111;
  --surface: #1a1a1a;
  --surface-hover: #222222;
  --border: #2a2a2a;
  --border-light: #333333;
  --text: #ececec;
  --text-secondary: #8e8e8e;
  --text-tertiary: #5a5a5a;
  --accent: #7c5cfc;
  --accent-hover: #6b4fe0;
  --accent-soft: rgba(124,92,252,0.12);
  --user-bubble: #7c5cfc;
  --ai-bubble: #1e1e1e;
  --danger: #e5484d;
  --radius: 20px;
  --radius-sm: 12px;
  --sidebar-w: 280px;
  --font: 'Inter', -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ========== App Layout ========== */
.app { display: flex; height: 100%; }

/* ========== Sidebar ========== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s cubic-bezier(.4,0,.2,1);
  z-index: 20;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 12px;
}
.sidebar-header h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.btn-new {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s;
}
.btn-new:hover { background: var(--accent-hover); }

.session-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.session-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s;
  gap: 10px;
  margin-bottom: 1px;
}
.session-item:hover { background: var(--surface-hover); }
.session-item.active { background: var(--accent-soft); }

.session-icon {
  flex-shrink: 0;
  color: var(--text-tertiary);
}
.session-item.active .session-icon { color: var(--accent); }

.session-title {
  flex: 1;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
}
.session-item.active .session-title { color: var(--text); font-weight: 500; }

.session-del {
  width: 24px; height: 24px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  display: none;
  align-items: center; justify-content: center;
  transition: all 0.12s;
}
.session-item:hover .session-del { display: flex; }
.session-del:hover { background: rgba(229,72,77,0.15); color: var(--danger); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 15;
  backdrop-filter: blur(2px);
}

/* ========== Main Chat ========== */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}

.btn-menu {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s;
}
.btn-menu:hover { background: var(--surface); color: var(--text); }

.chat-title {
  font-size: 15px;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========== Messages ========== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scroll-behavior: smooth;
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 40px 20px;
}
.welcome-avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c5cfc, #c084fc);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  margin-bottom: 20px;
  box-shadow: 0 8px 32px rgba(124,92,252,0.3);
}
.welcome h3 { font-size: 22px; font-weight: 600; margin-bottom: 8px; letter-spacing: -0.02em; }
.welcome p { font-size: 14px; color: var(--text-secondary); max-width: 300px; line-height: 1.5; }

.msg-row {
  display: flex;
  gap: 12px;
  padding: 8px 24px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  animation: msgIn 0.25s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } }

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

.msg-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  margin-top: 4px;
}
.msg-row.user .msg-avatar { background: var(--accent); }
.msg-row.assistant .msg-avatar { background: var(--surface); border: 1px solid var(--border); }

.msg-bubble {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.7;
  max-width: 75%;
  word-break: break-word;
}
.msg-row.user .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.msg-row.assistant .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}

.audio-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  padding: 4px 12px;
  border-radius: 20px;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.12s;
}
.audio-btn:hover { background: rgba(124,92,252,0.25); }

.typing { display: inline-flex; gap: 5px; padding: 4px 0; }
.typing span {
  width: 7px; height: 7px;
  background: var(--text-tertiary);
  border-radius: 50%;
  animation: dot 1.4s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes dot { 0%,80%,100%{opacity:.25} 40%{opacity:1} }

/* ========== Input Area ========== */
.input-area {
  padding: 12px 24px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 4px 6px 4px 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-wrap textarea {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 14.5px;
  font-family: var(--font);
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
  padding: 8px 0;
}
.input-wrap textarea::placeholder { color: var(--text-tertiary); }

.btn-mic, .btn-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.btn-mic {
  background: transparent;
  color: var(--text-secondary);
}
.btn-mic:hover { background: var(--surface-hover); color: var(--text); }
.btn-mic.recording {
  background: var(--danger);
  color: #fff;
  animation: rec-pulse 1.2s infinite;
}
@keyframes rec-pulse { 0%,100%{box-shadow:0 0 0 0 rgba(229,72,77,.4)} 50%{box-shadow:0 0 0 10px rgba(229,72,77,0)} }

.btn-send {
  background: var(--accent);
  color: #fff;
}
.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: .35; cursor: default; }

/* ========== Mobile ========== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.open ~ .sidebar-overlay { display: block; }
  .msg-row { padding: 6px 16px; }
  .msg-bubble { max-width: 88%; }
  .input-area { padding: 8px 12px 14px; }
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ========== Toast ========== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-80px);
  padding: 10px 20px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  z-index: 100;
  transition: transform 0.3s cubic-bezier(.4,0,.2,1);
  pointer-events: none;
  box-shadow: 0 8px 32px rgba(0,0,0,.3);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); color: var(--danger); }
