/* ====== 设计变量 ====== */
:root {
  --bg-1: #fff4e6;
  --bg-2: #ffe1c4;
  --bg-3: #ffd2b0;
  --ink-1: #2b2118;
  --ink-2: #5b4a3a;
  --ink-3: #8b7a68;
  --line: rgba(60, 40, 20, 0.08);
  --glass: rgba(255, 255, 255, 0.62);
  --glass-strong: rgba(255, 255, 255, 0.82);
  --accent: #ff7a3d;
  --accent-2: #ffb066;
  --accent-soft: #ffe6d4;
  --live: #22c55e;
  --shadow-1: 0 10px 30px -10px rgba(255, 122, 61, 0.35);
  --shadow-2: 0 20px 60px -20px rgba(120, 60, 20, 0.25);
  --radius-l: 24px;
  --radius-m: 16px;
  --radius-s: 10px;
  --font-cn: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-en: "Nunito", system-ui, sans-serif;
}

/* ====== 基础 ====== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-cn);
  color: var(--ink-1);
  background: linear-gradient(135deg, var(--bg-1) 0%, var(--bg-2) 50%, var(--bg-3) 100%);
  background-attachment: fixed;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ====== 背景装饰 ====== */
.bg-decor {
  position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none;
}
.blob {
  position: absolute; border-radius: 50%; filter: blur(60px); opacity: 0.6;
}
.blob-1 { width: 420px; height: 420px; background: #ffb585; top: -120px; left: -120px; }
.blob-2 { width: 360px; height: 360px; background: #ffd0a3; bottom: -100px; right: -100px; }
.blob-3 { width: 280px; height: 280px; background: #ffe0c2; top: 40%; left: 50%; transform: translate(-50%, -50%); opacity: 0.5; }

/* ====== 玻璃面板 ====== */
.glass {
  background: var(--glass);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: var(--shadow-2);
}

/* ====== 主体布局 ====== */
.app {
  position: relative; z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  height: 100vh;
  max-width: 1080px;
  margin: 0 auto;
}

/* ====== 左侧：聊天面板 ====== */
.chat-panel {
  flex: 1 1 auto;
  display: flex; flex-direction: column;
  border-radius: var(--radius-l);
  overflow: hidden;
  min-height: 0;
}

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,0.5), rgba(255,255,255,0.2));
}
.chat-title { display: flex; align-items: center; gap: 10px; }
.chat-title h1 {
  margin: 0; font-size: 17px; font-weight: 700; letter-spacing: 0.2px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.dot.live { background: var(--live); box-shadow: 0 0 0 4px rgba(34,197,94,0.18); }

.chat-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.6);
  color: var(--ink-2);
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .15s ease;
}
.icon-btn:hover { background: #fff; color: var(--accent); transform: translateY(-1px); }

.messages {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto;
  padding: 22px 20px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: rgba(255,122,61,0.25); border-radius: 8px; }
.messages::-webkit-scrollbar-track { background: transparent; }

.msg { display: flex; gap: 10px; align-items: flex-end; max-width: 86%; }
.msg .bubble {
  padding: 11px 14px; border-radius: 16px; line-height: 1.6; font-size: 14.5px;
  word-wrap: break-word; white-space: pre-wrap; box-shadow: 0 4px 14px -8px rgba(0,0,0,0.12);
}
.msg .meta { font-size: 11px; color: var(--ink-3); margin: 0 4px 4px; }

.msg.assistant { align-self: flex-start; }
.msg.assistant .bubble {
  background: #ffffff; color: var(--ink-1);
  border-top-left-radius: 4px;
  border: 1px solid rgba(255,255,255,0.8);
}
.msg.assistant .mini-avatar {
  width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: 0 0 32px;
  box-shadow: 0 2px 8px rgba(255,122,61,0.25);
}

.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-top-right-radius: 4px;
}

.msg.error .bubble {
  background: #fff1f0; color: #b91c1c; border: 1px solid #fecaca;
}

/* 打字光标 */
.cursor {
  display: inline-block; width: 7px; height: 14px; background: var(--accent);
  margin-left: 2px; border-radius: 2px; vertical-align: -2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,0.45);
}
#input {
  flex: 1; resize: none; max-height: 140px; min-height: 42px;
  padding: 11px 14px; font-size: 14.5px; line-height: 1.5;
  border: 1px solid var(--line); border-radius: 14px;
  background: #fff; color: var(--ink-1);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
#input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(255,122,61,0.15); }
.send-btn {
  width: 44px; height: 44px; flex: 0 0 44px; border: none; border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-1); transition: transform .12s ease, box-shadow .12s ease;
}
.send-btn:hover { transform: translateY(-1px); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ====== 顶部：头像与状态 ====== */
.profile-top {
  flex: 0 0 auto;
  border-radius: var(--radius-l);
  display: flex; align-items: center; gap: 18px;
  padding: 14px 20px;
}
.avatar-wrap {
  position: relative; width: 78px; height: 78px; flex: 0 0 78px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #ffd9b8, #ffb47a, #ffd9b8);
  padding: 4px;
  box-shadow: 0 10px 26px -12px rgba(255,122,61,0.55);
}
.avatar {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block;
  border: 3px solid #fff;
}
.status-pulse {
  position: absolute; right: 2px; bottom: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--live);
  border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgba(34,197,94,0.5);
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
  70% { box-shadow: 0 0 0 12px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

.profile-info { flex: 1 1 auto; min-width: 0; }
.name {
  margin: 0 0 2px; font-size: 21px; font-weight: 800; letter-spacing: 0.4px;
  background: linear-gradient(135deg, #ff7a3d, #ffb066);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { margin: 0 0 7px; color: var(--ink-3); font-size: 13px; }

.status-card {
  flex: 0 0 auto;
  display: flex; flex-direction: row; gap: 8px;
}
.status-row {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--ink-2);
  padding: 8px 13px;
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--line);
  border-radius: 12px;
  white-space: nowrap;
}
.status-label { display: inline-flex; align-items: center; gap: 5px; }
.status-row .status-val { font-weight: 700; color: var(--ink-1); font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.status-dot.live { background: var(--live); box-shadow: 0 0 0 3px rgba(34,197,94,0.2); }

.chips {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.chip {
  font-size: 12px; padding: 5px 11px; border-radius: 999px;
  background: #fff; border: 1px solid var(--line); color: var(--ink-2);
  box-shadow: 0 2px 6px -4px rgba(0,0,0,0.08);
}
.cta-villa {
  display: inline-flex; align-items: center; gap: 6px;
  align-self: flex-start;
  padding: 8px 16px; border-radius: 999px;
  background: linear-gradient(135deg, #ff7a3d, #ffb066);
  color: #fff; text-decoration: none; font-size: 13px; font-weight: 700;
  box-shadow: 0 6px 16px -4px rgba(255,122,61,0.5);
  transition: transform 0.12s ease, box-shadow 0.15s ease;
  margin: 2px 0 8px;
}
.cta-villa:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 22px -4px rgba(255,122,61,0.6);
}
.cta-villa:active { transform: translateY(0); }

/* ====== 模态框 ====== */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-mask {
  position: absolute; inset: 0;
  background: rgba(40, 25, 10, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: 88vh;
  border-radius: var(--radius-l);
  background: var(--glass-strong);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: pop .22s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,0.4);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field .muted { font-weight: 400; color: var(--ink-3); }
.field input, .field textarea {
  padding: 10px 12px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink-1);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(255,122,61,0.15); }
.field textarea { resize: vertical; min-height: 90px; line-height: 1.55; }

.presets { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.preset {
  padding: 6px 10px; font-size: 12.5px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  transition: all .15s;
}
.preset:hover { border-color: var(--accent); color: var(--accent); }

.btn-primary, .btn-ghost {
  padding: 9px 18px; font-size: 14px; font-weight: 600;
  border-radius: 10px; border: 1px solid transparent; transition: all .15s;
}
.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow-1);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-ghost { background: #fff; color: var(--ink-2); border-color: var(--line); }
.btn-ghost:hover { color: var(--accent); border-color: var(--accent); }

/* ====== Toast ====== */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  z-index: 60;
  padding: 10px 16px; border-radius: 12px;
  background: rgba(40, 25, 10, 0.88); color: #fff;
  font-size: 13.5px; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  animation: toastIn .2s ease;
}
.toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ====== 响应式 ====== */
@media (max-width: 900px) {
  body { overflow: auto; }
  .app { padding: 12px; gap: 12px; height: auto; min-height: 100vh; }
  .chat-panel { height: 72vh; min-height: 480px; }
  .profile-top { flex-wrap: wrap; }
  .status-card { width: 100%; justify-content: space-between; }
}
@media (max-width: 480px) {
  .chat-header { padding: 12px 14px; }
  .chat-title h1 { font-size: 15px; }
  .messages { padding: 16px 14px; }
  .composer { padding: 10px 12px; }
  .profile-top { padding: 12px 14px; gap: 12px; }
  .avatar-wrap { width: 60px; height: 60px; flex-basis: 60px; }
  .name { font-size: 18px; }
  .chips { display: none; }
  .status-row { padding: 6px 10px; font-size: 11px; }
  .status-row .status-val { font-size: 12px; }
}
