:root {
  --bg: #e9e9e9;
  --panel: #f7f7f7;
  --panel-2: #ffffff;
  --conv-bg: #f4f4f4;
  --border: #dedede;
  --text: #1f1f1f;
  --muted: #8a8a8a;
  --mine: #95ec69;
  --mine-text: #1f1f1f;
  --theirs: #ffffff;
  --theirs-text: #1f1f1f;
  --sidebar-dark: #2b2b2b;
  --accent: #07c160;
  --notice: #fff8e6;
  --notice-border: #f0d9a0;
  --notice-text: #8a6d20;
}

html[data-theme="dark"] {
  --bg: #171717;
  --panel: #202020;
  --panel-2: #282828;
  --conv-bg: #1c1c1c;
  --border: #333333;
  --text: #e8e8e8;
  --muted: #999999;
  --mine: #3a6b35;
  --mine-text: #f2ffe9;
  --theirs: #2b2b2b;
  --theirs-text: #e8e8e8;
  --sidebar-dark: #181818;
  --accent: #3ba55d;
  --notice: #2b2618;
  --notice-border: #5a4a22;
  --notice-text: #d6bd78;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
button, input { font: inherit; }

.app {
  width: min(1180px, 100%);
  height: min(820px, calc(100vh - 40px));
  display: flex;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .18);
  background: var(--panel-2);
}

/* ---------- sidebar ---------- */
.sidebar {
  width: 300px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
}
.sidebar-head {
  height: 62px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--sidebar-dark);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 600; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 14px;
}
.icon-btn {
  border: 0; background: transparent; color: #ccc;
  font-size: 18px; cursor: pointer; padding: 6px; border-radius: 6px;
}
.icon-btn:hover { background: rgba(255,255,255,.12); color: #fff; }

.search-wrap { position: relative; padding: 12px 12px 6px; }
.search-wrap input {
  width: 100%; height: 34px; border: 0; border-radius: 7px;
  background: var(--panel-2); color: var(--text);
  padding: 0 12px 0 32px; outline: none; font-size: 13px;
}
.search-icon { position: absolute; left: 22px; top: 19px; color: var(--muted); font-size: 17px; }
.side-meta { padding: 4px 16px 8px; font-size: 11px; color: var(--muted); }

.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex; gap: 10px; align-items: center;
  padding: 11px 14px; cursor: pointer; border-left: 3px solid transparent;
}
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--panel-2); border-left-color: var(--accent); }
.chat-item .avatar { width: 40px; height: 40px; font-size: 20px; flex: none; }
.chat-item-body { min-width: 0; flex: 1; }
.chat-item-row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.chat-item-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 10px; color: var(--muted); flex: none; }
.chat-item-preview {
  font-size: 12px; color: var(--muted); margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-foot {
  height: 42px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; font-size: 11px; color: var(--muted);
}
.refresh-btn { border: 0; background: transparent; color: var(--accent); cursor: pointer; font-size: 12px; }
.refresh-btn:hover { text-decoration: underline; }

/* ---------- conversation ---------- */
.conversation { flex: 1; display: flex; flex-direction: column; background: var(--conv-bg); min-width: 0; }
.conv-head {
  height: 62px; flex: none; display: flex; align-items: center; gap: 11px;
  padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--panel-2);
}
.back-btn { display: none; border: 0; background: transparent; color: var(--text); font-size: 28px; cursor: pointer; }
.conv-title { flex: 1; min-width: 0; }
.conv-name { font-size: 15px; font-weight: 600; }
.conv-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.badge { font-size: 11px; color: var(--muted); background: var(--panel); padding: 4px 9px; border-radius: 20px; }

.notice {
  flex: none; margin: 10px 18px 0; padding: 8px 12px;
  background: var(--notice); border: 1px solid var(--notice-border);
  color: var(--notice-text); border-radius: 6px; font-size: 11px;
}

.messages { flex: 1; overflow-y: auto; padding: 18px 22px 28px; }
.empty-state { text-align: center; color: var(--muted); padding-top: 60px; font-size: 13px; }
.date-sep { text-align: center; margin: 12px 0 18px; }
.date-sep span { font-size: 11px; color: var(--muted); background: var(--panel); padding: 3px 10px; border-radius: 5px; }

.msg { display: flex; gap: 10px; margin-bottom: 18px; align-items: flex-start; }
.msg.mine { flex-direction: row-reverse; }
.avatar {
  width: 34px; height: 34px; flex: none; border-radius: 6px;
  display: grid; place-items: center; font-size: 17px;
  background: #fff; border: 1px solid rgba(0,0,0,.06);
}
.avatar.me { background: #5a9bd4; }
.avatar.claude { background: #d97757; }
.avatar-lg { width: 38px; height: 38px; font-size: 19px; }
.msg-stack { max-width: min(78%, 680px); min-width: 0; }
.msg-meta { font-size: 10px; color: var(--muted); margin-bottom: 5px; }
.msg.mine .msg-meta { text-align: right; }
.bubble {
  padding: 10px 13px; border-radius: 8px; line-height: 1.65;
  font-size: 13.5px; background: var(--theirs); color: var(--theirs-text);
  box-shadow: 0 1px 2px rgba(0,0,0,.05); word-break: break-word;
  position: relative;
}
.msg.mine .bubble { background: var(--mine); color: var(--mine-text); }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 15px; margin: 10px 0 6px; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 20px; }
.bubble li { margin: 3px 0; }
.bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; background: rgba(127,127,127,.16); padding: 1px 5px; border-radius: 4px;
}
.bubble pre {
  background: #1e1e1e; color: #e8e8e8; padding: 11px 13px;
  border-radius: 6px; overflow-x: auto; margin: 8px 0;
}
.bubble pre code { background: transparent; padding: 0; color: inherit; }
.bubble blockquote { margin: 8px 0; padding-left: 10px; border-left: 3px solid var(--accent); opacity: .8; }
.bubble table { border-collapse: collapse; font-size: 12px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 4px 8px; }
.bubble a { color: var(--accent); }

.composer {
  height: 96px; flex: none; border-top: 1px solid var(--border);
  background: var(--panel-2); padding: 10px 18px;
  display: flex; flex-direction: column; gap: 8px; position: relative;
}
.composer-tools { font-size: 15px; color: var(--muted); }
.composer-input { font-size: 13px; color: var(--muted); }
.send-btn {
  position: absolute; right: 18px; bottom: 14px;
  background: var(--panel); color: var(--muted); border: 0;
  padding: 7px 18px; border-radius: 5px; cursor: not-allowed;
}

@media (max-width: 760px) {
  body { padding: 0; }
  .app { height: 100vh; border-radius: 0; }
  .sidebar { width: 100%; min-width: 0; }
  .conversation { display: none; }
  .app.show-chat .sidebar { display: none; }
  .app.show-chat .conversation { display: flex; }
  .back-btn { display: block; }
  .msg-stack { max-width: 82%; }
}
