:root {
  --bg: #f4f0ea;
  --bg-soft: #fbf8f4;
  --sidebar: #f7efe4;
  --accent: #e46b4f;
  --accent-dark: #c8543b;
  --accent-soft: #fbe0d5;
  --ink: #2f2a26;
  --muted: #8a7c70;
  --line: #eadfce;
  --user-bubble: #e46b4f;
  --assistant-bubble: #ffffff;
  --shadow: 0 16px 40px rgba(91, 65, 43, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 20%, #fdf4e7, var(--bg) 60%);
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { display: block; }

.app {
  display: grid;
  grid-template-columns: 290px 1fr;
  height: 100vh;
  height: 100dvh;
  max-width: 1280px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 22px 16px 16px;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 18px; }
.brand-avatar {
  width: 52px; height: 52px; border-radius: 18px; object-fit: cover;
  box-shadow: 0 8px 20px rgba(160, 100, 60, 0.22);
}
.brand-text h1 { margin: 0; font-size: 22px; letter-spacing: 1px; }
.brand-text p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

.new-chat-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #f08a66);
  color: white; font-weight: 600; font-size: 15px;
  box-shadow: 0 10px 22px rgba(228, 107, 79, 0.28);
  transition: transform .15s ease, filter .15s ease;
}
.new-chat-btn:hover { filter: brightness(1.04); transform: translateY(-1px); }
.new-chat-btn:active { transform: translateY(0); }
.plus { font-size: 18px; line-height: 1; }

.list-label { margin: 20px 6px 8px; font-size: 12px; color: var(--muted); letter-spacing: .08em; }
.conversation-list { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; padding-right: 2px; }

.conversation-item {
  position: relative; display: flex; align-items: center;
  border-radius: 12px; background: rgba(255,255,255,0.55); transition: background .15s ease;
}
.conversation-item:hover { background: rgba(255,255,255,0.9); }
.conversation-item.active { background: #fff; box-shadow: 0 6px 16px rgba(91, 65, 43, 0.08); }
.conversation-select {
  flex: 1; text-align: left; padding: 12px 30px 12px 12px; min-width: 0;
  font-size: 14px; color: var(--ink); border-radius: 12px;
}
.conversation-select .title {
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conversation-select .meta {
  display: block; margin-top: 3px; font-size: 11px; color: var(--muted);
}
.conversation-delete {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px; border-radius: 8px; color: var(--muted);
  font-size: 18px; line-height: 1; display: none; align-items: center; justify-content: center;
}
.conversation-item:hover .conversation-delete { display: flex; }
.conversation-delete:hover { background: var(--accent-soft); color: var(--accent-dark); }

.sidebar-footer {
  display: flex; align-items: center; gap: 7px; padding: 14px 6px 2px;
  font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); margin-top: 12px;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #4dbb78; box-shadow: 0 0 0 3px rgba(77,187,120,.15); }

/* Chat */
.chat-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-soft); }
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 22px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.7);
}
.chat-peer { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar-wrap { position: relative; }
.avatar-wrap img { width: 46px; height: 46px; border-radius: 16px; object-fit: cover; }
.online-dot {
  position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px;
  border-radius: 50%; background: #4dbb78; border: 2px solid white;
}
.chat-peer h2 { margin: 0; font-size: 18px; }
.chat-peer p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  background: #fff; border: 1px solid var(--line); transition: .15s ease;
}
.icon-btn:hover { background: #fbe9e2; border-color: #f2c6b4; }

.messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 24px 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}
.empty-state {
  margin: auto; text-align: center; max-width: 360px; padding: 24px;
}
.empty-state img { width: 92px; height: 92px; border-radius: 28px; object-fit: cover; margin: 0 auto 16px; box-shadow: 0 12px 28px rgba(160,100,60,.2); }
.empty-state h3 { margin: 0 0 8px; font-size: 22px; }
.empty-state p { margin: 6px 0; color: var(--muted); line-height: 1.7; }
.empty-tips { font-size: 13px; }

.message { display: flex; gap: 10px; max-width: 86%; animation: rise .25s ease; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }
.msg-avatar { width: 36px; height: 36px; border-radius: 12px; object-fit: cover; flex: 0 0 auto; }
.message.user .msg-avatar { display: none; }

.bubble {
  padding: 12px 14px; border-radius: 6px 18px 18px 18px;
  background: var(--assistant-bubble); box-shadow: 0 6px 16px rgba(91,65,43,.06);
  line-height: 1.75; font-size: 15px; white-space: pre-wrap; word-break: break-word;
}
.message.user .bubble {
  background: var(--user-bubble); color: white;
  border-radius: 18px 6px 18px 18px; box-shadow: 0 8px 18px rgba(228,107,79,.2);
}
.bubble strong { color: var(--accent-dark); }
.message.user .bubble strong { color: #fff5d8; }

.reasoning {
  margin-top: 9px; background: #f7f1e9; border: 1px dashed #e2cbb5;
  border-radius: 12px; padding: 9px 11px; font-size: 13px; color: #7a6a5c;
}
.reasoning summary { cursor: pointer; font-weight: 600; color: #9a6b50; }
.reasoning .reasoning-body { margin-top: 8px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }

.typing-bubble { display: flex; gap: 5px; align-items: center; height: 44px; padding: 0 16px; }
.typing-bubble span {
  width: 7px; height: 7px; border-radius: 50%; background: #cfae94;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-bubble span:nth-child(2) { animation-delay: .15s; }
.typing-bubble span:nth-child(3) { animation-delay: .3s; }
.hidden { display: none !important; }

@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity:.6 } 30% { transform: translateY(-6px); opacity:1 } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Composer */
.composer { padding: 12px 22px 16px; background: linear-gradient(to top, rgba(255,255,255,.85), rgba(255,255,255,0)); }
.composer-inner {
  display: flex; align-items: flex-end; gap: 10px; background: #fff;
  border: 1px solid var(--line); border-radius: 18px; padding: 9px 9px 9px 14px;
  box-shadow: 0 10px 24px rgba(91,65,43,.08); transition: border .15s ease, box-shadow .15s ease;
}
.composer-inner:focus-within { border-color: #e8b7a5; box-shadow: 0 10px 26px rgba(228,107,79,.12); }
#input {
  flex: 1; resize: none; border: none; outline: none; font-size: 15px; line-height: 1.6;
  max-height: 150px; min-height: 24px; font-family: inherit; color: var(--ink); background: transparent;
}
.send-btn {
  padding: 10px 16px; border-radius: 13px; background: var(--accent); color: white;
  font-weight: 600; font-size: 14px; transition: filter .15s ease, transform .15s ease;
}
.send-btn:hover:not(:disabled) { filter: brightness(1.05); }
.send-btn:active:not(:disabled) { transform: scale(.97); }
.send-btn:disabled { opacity: .55; cursor: not-allowed; }
.composer-hint { margin: 7px 2px 0; font-size: 11px; color: var(--muted); }

/* Scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #d9c7b1; border-radius: 9px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 760px) {
  .app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
  }

  .sidebar {
    height: auto;
    max-height: 188px;
    flex: 0 0 auto;
    padding: 10px 12px 8px;
    border-right: none;
    border-bottom: 1px solid var(--line);
    overflow: hidden;
  }

  .brand {
    padding: 0 68px 8px 2px;
    gap: 9px;
  }
  .brand-avatar {
    width: 42px;
    height: 42px;
    border-radius: 13px;
  }
  .brand-text h1 { font-size: 19px; }
  .brand-text p { display: none; }

  .new-chat-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 8px 12px;
    font-size: 13px;
    border-radius: 12px;
  }
  .sidebar { position: relative; }

  .list-label { display: none; }

  .conversation-list {
    flex: 0 0 auto;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 6px;
    padding-bottom: 2px;
  }
  .conversation-item {
    flex: 0 0 auto;
    max-width: 180px;
    background: rgba(255,255,255,0.75);
  }
  .conversation-select {
    padding: 8px 26px 8px 10px;
    white-space: nowrap;
  }
  .conversation-select .title { max-width: 112px; }
  .conversation-select .meta { display: none; }

  .sidebar-footer { display: none; }

  .chat-panel {
    flex: 1 1 auto;
    min-height: 0;
  }
  .chat-header {
    padding: 10px 12px;
  }
  .avatar-wrap img {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }
  .chat-peer h2 { font-size: 16px; }
  .chat-peer p { font-size: 11px; }
  .icon-btn {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }

  .messages {
    flex: 1 1 0;
    min-height: 0;
    padding: 12px 10px 10px;
    gap: 14px;
  }
  .message { max-width: 96%; }
  .msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 10px;
  }
  .bubble {
    font-size: 14px;
    line-height: 1.65;
    padding: 10px 12px;
  }
  .reasoning { font-size: 12px; padding: 8px 9px; }

  .composer {
    padding: 8px 10px 12px;
  }
  .composer-inner {
    padding: 7px 7px 7px 11px;
    border-radius: 15px;
  }
  #input { font-size: 14px; }
  .send-btn {
    padding: 9px 13px;
    font-size: 13px;
    border-radius: 11px;
  }
  .composer-hint { display: none; }

  .empty-state img {
    width: 72px;
    height: 72px;
    border-radius: 22px;
  }
  .empty-state h3 { font-size: 19px; }
  .empty-state p { font-size: 13px; }
}
