/* ============================================================
   EchoChat Lite · 终极 UI
   暗黑毛玻璃 + 霓虹社交感 · 遵循 emil-design-eng 动效规范
   - 只动 transform/opacity · 自定义缓动 · :active 反馈
   - 尊重 prefers-reduced-motion
   ============================================================ */

:root {
  --bg: #0a0a0b;
  --surface: rgba(255, 255, 255, 0.055);
  --surface-2: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.10);
  --text: #f4f4f5;
  --text-dim: #a1a1aa;
  --accent: #22d3ee;                 /* 霓虹青蓝（config 可换） */
  --neon-user: linear-gradient(135deg, #22d3ee, #a855f7);  /* 用户气泡 */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);            /* iOS 抽屉 */
  --r-lg: 20px; --r-md: 14px; --r-sm: 10px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --chat-bg: #0a0a0b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

/* 字体（系统原生栈，零版权风险）+ 字阶 */
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue",
    "Microsoft Yahei", "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.625;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- 视图 ---------- */
.view {
  max-width: 680px; margin: 0 auto; height: 100dvh;
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
  background: var(--chat-bg);
  background-size: cover; background-position: center;
  transition: background 200ms ease;
}
.view.hidden { display: none; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center;
  padding: calc(12px + var(--safe-top)) 20px 12px;
  background: rgba(12, 12, 14, 0.66);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; flex: 1; }
.logo-mark {
  width: 34px; height: 34px; border-radius: 11px;
  background: linear-gradient(145deg, #22d3ee, #a855f7);
  box-shadow: 0 6px 18px rgba(34, 211, 238, 0.4);
  position: relative;
}
.logo-mark::after { content: ""; position: absolute; inset: 8px; border-radius: 6px; border: 2px solid rgba(10,10,11,0.5); }
.brand-name { font-size: 16px; font-weight: 650; letter-spacing: 0.2px; }
.brand-slogan { font-size: 12px; color: var(--text-dim); margin-top: 1px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.chip { font-size: 12px; color: var(--text-dim); padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }

/* 聊天顶栏：左 中 右 三栏，中间绝对居中 */
.chat-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
.chat-top .icon-btn:first-child { justify-self: start; }
.chat-top > .icon-btn:last-child { justify-self: end; }
.peer-center {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 0; padding: 0 8px;
}
.peer {
  width: 42px; height: 42px; border-radius: 50%; border: none; padding: 0;
  background: var(--surface-2); cursor: pointer; overflow: hidden;
  box-shadow: 0 0 0 2px rgba(34,211,238,.35), 0 0 18px rgba(34,211,238,.35);
  transition: transform 140ms var(--ease-out), box-shadow 160ms ease;
}
.peer:active { transform: scale(0.94); }
.peer img { width: 100%; height: 100%; object-fit: cover; }
.peer-name-wrap { text-align: center; min-width: 0; max-width: 40vw; }
.peer-name {
  font-size: 15px; font-weight: 600; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  outline: none; border-radius: 6px; padding: 1px 4px;
  transition: background 150ms ease;
}
.peer-name:hover { background: var(--surface-2); }
.peer-name[contenteditable="true"] { background: var(--surface-2); }
.peer-status { font-size: 12px; color: var(--text-dim); line-height: 1.2; }

/* ---------- 图标按钮 ---------- */
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; border: none;
  background: transparent; color: var(--text-dim);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform 120ms var(--ease-out), color 150ms ease, background 150ms ease;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn:hover { color: var(--text); background: var(--surface); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- 聊天列表 ---------- */
.list-body { flex: 1; overflow-y: auto; padding: 8px 12px 12px; }
.chat-card {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 12px; margin-bottom: 6px;
  background: var(--surface); border: 1px solid transparent; border-radius: var(--r-md);
  cursor: pointer; text-align: left;
  transition: transform 140ms var(--ease-out), background 160ms ease, border-color 160ms ease;
}
.chat-card:active { transform: scale(0.98); }
.chat-card:hover { background: var(--surface-2); border-color: var(--border); }
.chat-card .ava { width: 46px; height: 46px; border-radius: 14px; object-fit: cover; background: var(--surface-2); flex-shrink: 0; }
.cc-body { flex: 1; min-width: 0; }
.cc-name { font-size: 15px; font-weight: 550; display: flex; align-items: center; gap: 8px; }
.cc-preview { font-size: 13px; color: var(--text-dim); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 10px; color: var(--accent); border: 1px solid rgba(34,211,238,.4); border-radius: 6px; padding: 1px 5px; }
.cc-del { width: 30px; height: 30px; border-radius: 9px; border: none; background: transparent; color: var(--text-dim); cursor: pointer; font-size: 15px; transition: color 150ms ease, transform 120ms var(--ease-out); }
.cc-del:active { transform: scale(0.9); }
.cc-del:hover { color: #f87171; }
.list-footer { padding: 10px 16px calc(14px + var(--safe-bottom)); }

/* ---------- 按钮 ---------- */
.btn-primary {
  width: 100%; padding: 13px; border: none; border-radius: var(--r-md);
  background: linear-gradient(145deg, #22d3ee, #a855f7); color: #0a0a0b;
  font-size: 14px; font-weight: 650; cursor: pointer;
  transition: transform 130ms var(--ease-out), filter 150ms ease, opacity 150ms ease;
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-ghost {
  width: 100%; padding: 11px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; cursor: pointer;
  transition: transform 120ms var(--ease-out), background 150ms ease;
}
.btn-ghost:active { transform: scale(0.97); }
.btn-ghost:hover { background: var(--surface-2); }

.btn-send {
  min-width: 58px; height: 40px; border: none; border-radius: 13px;
  background: linear-gradient(135deg,#22d3ee,#a855f7); color: #0a0a0b;
  font-weight: 650; font-size: 14px; cursor: pointer;
  transition: transform 120ms var(--ease-out), opacity 150ms ease;
}
.btn-send:active { transform: scale(0.95); }
.btn-send:disabled { opacity: 0.35; cursor: not-allowed; }

/* ---------- 聊天窗口 ---------- */
.chat-body {
  flex: 1; overflow-y: auto; padding: 18px 16px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}
.msg { display: flex; align-items: flex-end; gap: 8px; max-width: 82%; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg .mava { width: 28px; height: 28px; border-radius: 9px; object-fit: cover; background: var(--surface-2); flex-shrink: 0; }
.msg .bubble {
  padding: 10px 14px; border-radius: 18px; font-size: 16px; line-height: 1.625;
  white-space: pre-wrap; word-break: break-word;
}
/* AI：深灰半透明毛玻璃 + 微光描边 */
.msg.her .bubble {
  background: rgba(255,255,255,0.07);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(34,211,238,0.22);
  box-shadow: 0 0 14px rgba(34,211,238,0.10), 0 2px 8px rgba(0,0,0,0.3);
  border-bottom-left-radius: 6px;
}
/* 用户：霓虹渐变 */
.msg.me .bubble {
  background: var(--neon-user); color: #0b0b12;
  box-shadow: 0 4px 16px rgba(34,211,238,0.28);
  border-bottom-right-radius: 6px;
  font-weight: 500;
}
.msg .time { font-size: 12px; color: var(--text-dim); align-self: flex-end; padding-bottom: 2px; }

/* 仅最后一条消息入场动画 */
.msg.animate { animation: msgIn 260ms var(--ease-out); }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* 正在输入 */
.typing { display: flex; gap: 5px; padding: 2px 18px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%,70%,100% { opacity: 0.3; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-3px); } }

/* ---------- 输入栏 ---------- */
.inputbar {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 8px 12px calc(10px + var(--safe-bottom));
  background: rgba(12, 12, 14, 0.72);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border-top: 1px solid var(--border);
}
.me-ava-btn { width: 34px; height: 34px; border-radius: 12px; padding: 2px; background: var(--surface-2); overflow: hidden; }
.me-ava-btn img { width: 100%; height: 100%; border-radius: 10px; object-fit: cover; }
.input-wrap { flex: 1; position: relative; }
#input {
  width: 100%; min-height: 40px; max-height: 140px; resize: none;
  padding: 10px 14px; border-radius: 16px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 16px; font-family: inherit; line-height: 1.5;
  outline: none; transition: border-color 150ms ease, background 150ms ease;
}
#input:focus { border-color: rgba(34,211,238,0.5); background: var(--surface-2); }
#input::placeholder { color: var(--text-dim); }

/* ---------- 底部抽屉（65vh） ---------- */
.drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: 65vh; display: flex; flex-direction: column;
  background: rgba(18, 18, 22, 0.92);
  backdrop-filter: blur(30px) saturate(150%);
  -webkit-backdrop-filter: blur(30px) saturate(150%);
  border-top: 1px solid var(--border);
  border-radius: 22px 22px 0 0;
  transform: translateY(100%);
  transition: transform 340ms var(--ease-drawer);
  padding-bottom: var(--safe-bottom);
  will-change: transform;
}
.drawer.open { transform: translateY(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 8px; font-size: 14px; color: var(--text-dim);
}
.drawer-tools { display: flex; gap: 10px; padding: 0 18px 12px; }
.dtool {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 10px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font-size: 13px; cursor: pointer;
  transition: transform 120ms var(--ease-out), background 150ms ease;
}
.dtool:active { transform: scale(0.96); }
.dtool .dtool-ic { font-size: 22px; }
.dtool .soon { font-size: 10px; color: var(--text-dim); }
.emoji-panel {
  flex: 1; overflow-y: auto; padding: 4px 14px 16px;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px;
}
.emoji-panel button {
  background: transparent; border: none; font-size: 24px; padding: 6px 0;
  border-radius: 10px; cursor: pointer;
  transition: transform 100ms var(--ease-out), background 120ms ease;
}
.emoji-panel button:active { transform: scale(0.82); }
.emoji-panel button:hover { background: var(--surface-2); }

/* ---------- 弹窗 / 底部抽屉弹层 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 180ms ease;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 86dvh;
  background: rgba(20, 20, 24, 0.92);
  backdrop-filter: blur(30px) saturate(140%);
  -webkit-backdrop-filter: blur(30px) saturate(140%);
  border: 1px solid var(--border); border-bottom: none;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  display: flex; flex-direction: column;
  animation: sheetIn 300ms var(--ease-out);
  transform-origin: bottom;
  padding-bottom: var(--safe-bottom);
}
.sheet.small { max-width: 380px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.sheet-head h2 { font-size: 16px; font-weight: 600; }
.sheet-body { padding: 8px 18px 22px; overflow-y: auto; }
.sheet-body.center { text-align: center; }
.sheet-body section { margin: 16px 0; }
.sheet-body h3 { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.hint { font-size: 12px; color: var(--text-dim); margin: 6px 0 12px; line-height: 1.5; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetIn { from { opacity: 0; transform: translateY(24px) scale(0.97); } to { opacity: 1; transform: translateY(0) scale(1); } }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.field input[type="text"], .field input[type="password"], .field textarea {
  width: 100%; padding: 11px 13px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 14px; font-family: inherit; outline: none;
  transition: border-color 150ms ease, background 150ms ease;
}
.field input:focus, .field textarea:focus { border-color: rgba(34,211,238,.5); background: var(--surface-2); }
.field textarea { resize: vertical; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }

/* 背景预设 chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.bg-chip {
  flex: 1 1 40%; padding: 12px 8px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  font-size: 12px; cursor: pointer; text-align: center;
  transition: transform 120ms var(--ease-out), border-color 150ms ease, color 150ms ease;
}
.bg-chip:active { transform: scale(0.96); }
.bg-chip.active { border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 1px var(--accent) inset; }

.stack-actions { display: flex; flex-direction: column; gap: 8px; }

.locked { opacity: 0.55; }
.badge-lock { font-size: 10px; color: var(--text-dim); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; }
.locked-block { text-align: center; padding: 28px 12px; color: var(--text-dim); font-size: 14px; }
.locked-block p { margin-bottom: 16px; }
.up-title { font-size: 18px; font-weight: 650; margin: 8px 0; }
.up-list { list-style: none; text-align: left; margin: 16px auto; max-width: 240px; color: var(--text-dim); font-size: 13px; line-height: 2; }
.up-list li::before { content: "✓ "; color: var(--accent); }

/* ---------- 新建聊天向导 ---------- */
.wizard-steps { display: flex; justify-content: center; gap: 22px; padding: 14px 18px 4px; }
.ws { font-size: 13px; color: var(--text-dim); position: relative; padding-bottom: 6px; }
.ws.active { color: var(--accent); }
.ws.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; border-radius: 2px; background: var(--accent); }
.skip-line { text-align: right; margin: 4px 0 8px; }
.skip-line a { font-size: 12px; color: var(--text-dim); text-decoration: none; border-bottom: 1px dashed var(--text-dim); opacity: 0.7; }
.skip-line a:active { opacity: 1; }
.wizard-pane { min-height: 220px; }
.wizard-nav { display: flex; gap: 10px; margin-top: 18px; }
.wizard-nav .btn-ghost, .wizard-nav .btn-primary { width: auto; flex: 1; }
.wiz-select {
  width: 100%; padding: 11px 13px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; font-family: inherit; outline: none; color-scheme: dark;
}
.wiz-select option { color: #111; background: #fff; }

.support-btn { display: block; text-align: center; text-decoration: none; margin-top: 10px; }
.ava-upload { display: flex; align-items: center; gap: 12px; }
.peer-sm {
  width: 56px; height: 56px; border-radius: 18px; border: 1px dashed var(--border);
  background: var(--surface-2); cursor: pointer; overflow: hidden; padding: 0;
  transition: transform 130ms var(--ease-out), border-color 150ms ease;
}
.peer-sm:active { transform: scale(0.94); }
.peer-sm img { width: 100%; height: 100%; object-fit: cover; }
.ava-upload .hint { margin: 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border);
  backdrop-filter: blur(20px); color: var(--text);
  padding: 11px 18px; border-radius: 999px; font-size: 13px;
  z-index: 100; box-shadow: var(--shadow);
  animation: toastIn 220ms var(--ease-out);
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ---------- 减少动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- 响应式：手机竖/横 / 平板 / 桌面 ---------- */
@media (max-width: 480px) {
  body { font-size: 15px; }
  .msg .bubble { font-size: 15px; }
  .peer-name { font-size: 14px; }
  .emoji-panel { grid-template-columns: repeat(7, 1fr); }
}
/* 手机横屏 / 小高度：压紧纵向 */
@media (orientation: landscape) and (max-height: 520px) {
  .chat-top { padding-top: calc(6px + var(--safe-top)); }
  .peer { width: 34px; height: 34px; }
  .list-footer { padding-bottom: 8px; }
  .drawer { height: 72vh; }
}
/* 平板/桌面：居中卡片 + 更宽 */
@media (min-width: 720px) and (max-width: 1023px) {
  .view { max-width: 620px; }
}
@media (min-width: 1024px) {
  .view { max-width: 760px; }
  .bubble { font-size: 16px; }
}
/* 桌面通用 */
@media (min-width: 720px) {
  .view { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  .modal { align-items: center; }
  .sheet { border-radius: var(--r-lg); border-bottom: 1px solid var(--border); }
}
