:root {
  --bg: #ededed;
  --surface: #ffffff;
  --bubble-me: #95ec69;
  --bubble-ai: #ffffff;
  --text: #181818;
  --muted: #8a8a8a;
  --accent: #07c160;
  --border: #e4e4e4;
  --danger: #e54d42;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.hidden { display: none !important; }

/* 主容器：布局必须写在 CSS 里，不能用内联 style（CSP 会拦） */
#app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* ---------- 登录 ---------- */
#login {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px; background: var(--surface);
}
#login .logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 16px; }
#login h1 { font-size: 22px; font-weight: 600; margin-bottom: 6px; }
#login p { color: var(--muted); font-size: 14px; margin-bottom: 24px; text-align: center; }
#login input {
  width: 100%; max-width: 320px; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 10px; font: inherit; outline: none;
}
#login input:focus { border-color: var(--accent); }
#login button {
  width: 100%; max-width: 320px; margin-top: 12px; padding: 12px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
#login .err { color: var(--danger); font-size: 13px; margin-top: 12px; }

/* ---------- 顶栏 ---------- */
header.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex: none; padding-top: calc(10px + env(safe-area-inset-top));
}
header.topbar .avatar { width: 40px; height: 40px; border-radius: 8px; }
header.topbar .who { flex: 1; min-width: 0; }
header.topbar .who strong { display: block; font-size: 16px; font-weight: 600; }
header.topbar .who span { font-size: 12px; color: var(--muted); }
header.topbar button {
  background: none; border: 0; font-size: 13px; color: var(--muted);
  padding: 6px 8px; cursor: pointer;
}

/* ---------- 消息区 ---------- */
.messages {
  flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column;
  gap: 10px; -webkit-overflow-scrolling: touch;
}
.day-divider { text-align: center; font-size: 12px; color: var(--muted); margin: 6px 0; }
.row { display: flex; gap: 8px; align-items: flex-start; }
.row.me { flex-direction: row-reverse; }
.row .avatar { width: 36px; height: 36px; border-radius: 6px; flex: none; }
.bubble {
  max-width: 72%; padding: 9px 12px; border-radius: 8px; font-size: 16px;
  word-break: break-word; white-space: pre-wrap; position: relative;
  box-shadow: 0 1px 0 rgba(0,0,0,0.03);
}
.row.ai .bubble { background: var(--bubble-ai); border-radius: 2px 8px 8px 8px; }
.row.me .bubble { background: var(--bubble-me); border-radius: 8px 2px 8px 8px; }
.row .time { font-size: 11px; color: var(--muted); align-self: center; }
.bubble .voice-play {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; padding: 6px 10px;
  border-radius: 8px; background: rgba(7,193,96,.1); color: var(--accent);
  font-size: 13px; border: 0; cursor: pointer; width: 100%;
}
.typing { display: flex; gap: 4px; padding: 10px 14px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: #bbb; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100% { opacity: .3; } 30% { opacity: 1; } }

.disclosure {
  margin: 4px 0; padding: 8px 12px; background: rgba(7,193,96,.08); color: #5a5a5a;
  font-size: 12px; border-radius: 8px; text-align: center;
}

/* ---------- 输入区 ---------- */
.composer {
  flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.composer .input-wrap {
  flex: 1; display: flex; align-items: flex-end; background: #f4f4f4; border-radius: 10px;
  padding: 8px 12px; gap: 6px;
}
.composer textarea {
  flex: 1; border: 0; background: none; resize: none; outline: none; font: inherit;
  max-height: 120px; line-height: 1.4;
}
.composer .icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: none;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: #333;
}
.composer .icon-btn.recording { background: var(--danger); color: #fff; animation: pulse 1s infinite; }
.composer .send {
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; flex: none;
}
.composer .send:disabled { background: #c8c8c8; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }

/* ---------- 设置弹层 ---------- */
.sheet-mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface);
  border-radius: 16px 16px 0 0; z-index: 51; padding: 8px 0 calc(16px + env(safe-area-inset-bottom));
}
.sheet h3 { padding: 14px 16px 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.sheet .item {
  display: flex; align-items: center; justify-content: space-between; padding: 13px 16px;
  border-bottom: 1px solid #f2f2f2; font-size: 16px; cursor: pointer; background: none; border-left: 0; border-right: 0; width: 100%; text-align: left;
}
.sheet .item:active { background: #f7f7f7; }
.sheet .item.danger { color: var(--danger); }
.sheet .switch { position: relative; width: 46px; height: 28px; }
.sheet .switch input { opacity: 0; width: 0; height: 0; }
.sheet .switch i { position: absolute; inset: 0; background: #ddd; border-radius: 28px; transition: .2s; }
.sheet .switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; background: #fff; border-radius: 50%; transition: .2s; }
.sheet .switch input:checked + i { background: var(--accent); }
.sheet .switch input:checked + i::after { transform: translateX(18px); }

.toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); background: rgba(0,0,0,.75);
  color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 14px; z-index: 60; max-width: 80%;
}
