:root {
  --g-50: #eefbf4;
  --g-100: #e2f6ec;
  --g-200: #c9efdd;
  --g-300: #b0e7ce;
  --g-400: #95dcba;
  --g-500: #76d0a3;
  --g-600: #4fb889;
  --g-700: #3aa073;
  --ink: #123024;
  --muted: #517d68;
  --line: #d9ecdf;
  --white: #ffffff;
  --shadow: rgba(38, 83, 61, 0.12);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #eefbf4, #dff5ea);
  overflow: hidden;
}

.setup-warn {
  position: fixed;
  z-index: 30;
  left: 12px;
  right: 12px;
  top: 12px;
  background: #fff7e6;
  border: 1px solid #ffe1a8;
  color: #8a5b00;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
}
.setup-warn code { background: rgba(0,0,0,0.05); padding: 1px 5px; border-radius: 5px; }

/* ---------- 布局 ---------- */
.app-shell {
  display: flex;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  width: 100%;
  background: linear-gradient(180deg, #f6fcf8, #eaf7ef);
  border-right: 1px solid var(--line);
}

.chat {
  display: none;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  background: linear-gradient(160deg, #e7f8ef 0%, #d9f3e6 55%, #c9efdd 100%);
}

.app-shell.view-chat .sidebar { display: none; }
.app-shell.view-chat .chat { display: flex; }

/* 桌面：左右并排 */
@media (min-width: 768px) {
  .app-shell .sidebar { display: flex; width: 320px; }
  .app-shell .chat { display: flex; }
  .app-shell.view-chat .sidebar { display: flex; }
  .app-shell.view-chat .chat { display: flex; }
  .chat .back { display: none; }
}

/* ---------- 侧边栏 ---------- */
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  background: linear-gradient(90deg, #86d5ae, #5bc492);
  color: #0f2a1c;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; }
.brand-ic { font-size: 20px; }

.icon-btn {
  border: 0;
  background: rgba(255,255,255,0.55);
  color: #123024;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,0.8); }
.icon-btn.back { font-size: 28px; }

.contact-list { flex: 1; overflow-y: auto; padding: 8px; }

.contact {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 12px;
  cursor: pointer;
}
.contact:hover { background: #e2f6ec; }
.contact.active { background: #d3f0df; }

.avatar {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #86d5ae, #4fb889);
  user-select: none;
}

.contact-main { flex: 1; min-width: 0; }
.contact-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-preview { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.contact-time { font-size: 12px; color: var(--muted); flex: 0 0 auto; }

.empty { color: var(--muted); text-align: center; padding: 28px 16px; font-size: 14px; }

.profile {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #f2faf5;
}
.profile .avatar { width: 32px; height: 32px; font-size: 14px; }
.profile input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); font-size: 14px; background: #fff; }
.profile input:focus { outline: none; border-color: var(--g-500); }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: #e7f3ec;
  color: var(--ink);
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: #d7ece0; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--g-600); color: #fff; }
.btn.primary:hover { background: var(--g-700); }
.btn.ghost { background: #eef4f0; }
.btn.small { padding: 7px 12px; font-size: 13px; }

/* ---------- 会话区 ---------- */
.chat-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background: linear-gradient(90deg, #86d5ae, #5bc492);
  color: #0f2a1c;
}
.chat-title-wrap { display: flex; flex-direction: column; min-width: 0; }
.chat-title { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { font-size: 12px; opacity: 0.8; }

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
  max-width: 260px;
}

.bubble {
  background: var(--white);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 2px 8px var(--shadow);
  max-width: 92%;
}
.bubble.self { align-self: flex-end; background: #e4f6ec; }
.bubble .b-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.bubble .b-name { font-size: 12px; color: var(--muted); }
.bubble .b-time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.bubble .b-title { font-weight: 650; font-size: 15px; margin-bottom: 2px; word-break: break-word; }
.bubble .b-note { font-size: 13px; color: var(--muted); word-break: break-word; margin-top: 2px; }
.bubble audio { width: 100%; margin-top: 8px; }
.bubble .b-foot { display: flex; justify-content: flex-end; margin-top: 8px; }
.btn.danger { background: #fff0f1; color: #e5484d; }
.btn.danger:hover { background: #ffe3e5; }

/* ---------- 发语音按钮 ---------- */
.rec-fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  border: 0;
  border-radius: 28px;
  background: linear-gradient(90deg, #86d5ae, #4fb889);
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  padding: 14px 20px;
  box-shadow: 0 8px 22px var(--shadow);
  cursor: pointer;
}
.rec-fab:active { transform: translateY(1px); }

/* ---------- 录音面板 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(18, 48, 36, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 520px;
  background: #f6fcf8;
  border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 30px var(--shadow);
}
@media (min-width: 768px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 20px; }
}

.sheet-title { font-size: 18px; font-weight: 700; text-align: center; }
.sheet-hint { text-align: center; color: var(--muted); font-size: 13px; margin: 6px 0 16px; min-height: 18px; }

.rec-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  border: 1px solid #ffd5d7;
  border-radius: 14px;
  background: #fff0f1;
  color: #e5484d;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.rec-btn:hover { background: #ffe3e5; }
.rec-btn.recording { background: #e5484d; color: #fff; border-color: #e5484d; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #e5484d; display: inline-block; }
.rec-btn.recording .rec-dot { background: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.rec-status { color: var(--muted); font-size: 13px; margin-top: 12px; min-height: 18px; text-align: center; }

.preview { display: grid; gap: 10px; margin-top: 16px; }
.preview audio { width: 100%; }
.preview input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 14px;
  background: #fff;
}
.preview input:focus { outline: none; border-color: var(--g-500); }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: rgba(18, 48, 36, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 40;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}
.toast[hidden] { display: none; }
.toast.error { background: #e5484d; }
.toast.success { background: #1f9d55; }

input[type="text"]::-webkit-input-placeholder { color: #9bb2a6; }
