/* 私语 · 微信风格配色布局 */

:root {
  --bg: #EDEDED;              /* 消息区背景 */
  --nav-bg: #EDEDED;          /* 顶栏背景 */
  --composer-bg: #F7F7F7;     /* 输入栏背景 */
  --bubble-me: #95EC69;       /* 自己气泡（微信绿） */
  --bubble-me-text: #111111;
  --bubble-peer: #FFFFFF;     /* 对方气泡 */
  --bubble-peer-text: #111111;
  --time-text: #B2B2B2;       /* 气泡下时间 */
  --text: #111111;
  --text-muted: #888888;
  --green: #07C160;           /* 微信绿 */
  --border: #E5E5E5;
  --danger: #FA5151;
  --card: #FFFFFF;
  --input-bg: #FFFFFF;
  --sep-bg: rgba(0,0,0,0.06);
  --sep-text: #999999;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --nav-bg: #1C1C1E;
    --composer-bg: #1C1C1E;
    --bubble-me: #0E5B36;
    --bubble-me-text: #FFFFFF;
    --bubble-peer: #262626;
    --bubble-peer-text: #F2F2F2;
    --time-text: #6E6E70;
    --text: #F2F2F2;
    --text-muted: #8E8E93;
    --green: #07C160;
    --border: #3A3A3C;
    --danger: #FF6B6B;
    --card: #1C1C1E;
    --input-bg: #2C2C2E;
    --sep-bg: rgba(255,255,255,0.08);
    --sep-text: #8E8E93;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- 登录 ---------- */
#login-view {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.login-card {
  background: var(--card);
  border-radius: 12px;
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-card h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}
.login-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 14px;
}
.login-card label { font-size: 0.75rem; color: var(--text-muted); }
.login-card select, .login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  font-size: 0.95rem;
  color: var(--text);
  outline: none;
}
.login-card select:focus, .login-card input:focus { border-color: var(--green); }

button.primary {
  margin-top: 10px;
  padding: 11px;
  border: none;
  border-radius: 6px;
  background: var(--green);
  color: #FFFFFF;
  font-size: 0.95rem;
  cursor: pointer;
}
button.primary:active { opacity: 0.85; }

.login-card .beian { margin-top: 12px; text-align: center; }
.login-card .beian a { font-size: 0.7rem; color: var(--text-muted); text-decoration: none; }

/* ---------- 聊天布局 ---------- */
#chat-view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* 顶栏：微信式，中间标题 */
#chat-header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--nav-bg);
  flex-shrink: 0;
}
.header-title { text-align: center; }
#peer-name { font-size: 1rem; font-weight: 600; line-height: 1.2; }
#peer-status { font-size: 0.7rem; color: var(--text-muted); }
#peer-status.online { color: #8BB97A; }
#peer-status.offline { color: var(--text-muted); }
#btn-settings {
  position: absolute;
  right: 10px;
  top: calc(10px + env(safe-area-inset-top));
  color: var(--text);
}

.icon-btn {
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  border-radius: 8px;
  color: var(--text);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { opacity: 0.6; }

/* ---------- 消息区 ---------- */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

/* 日期分隔条 */
.date-sep {
  text-align: center;
  margin: 10px 0 16px;
  font-size: 0.7rem;
  color: var(--sep-text);
}
.date-sep span {
  background: var(--sep-bg);
  padding: 3px 10px;
  border-radius: 4px;
}

/* 消息行 */
.msg {
  display: flex;
  margin-bottom: 14px;
  animation: fadein 0.15s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.msg.me { justify-content: flex-end; }
.msg.peer { justify-content: flex-start; }
.msg.pending { justify-content: flex-end; opacity: 0.6; }

.msg-avatar {
  width: 38px;
  height: 38px;
  border-radius: 5px;
  object-fit: cover;
  background: var(--border);
  flex-shrink: 0;
}
.msg.me .msg-avatar { order: 2; margin-left: 8px; }
.msg.peer .msg-avatar { order: 1; margin-right: 8px; }

.msg-body {
  order: 2;
  max-width: 66%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.msg.me .msg-body { order: 1; align-items: flex-end; }
.msg.peer .msg-body { order: 1; align-items: flex-start; }

.bubble {
  padding: 8px 11px;
  font-size: 0.95rem;
  line-height: 1.45;
  word-break: break-word;
  position: relative;
}
.msg.me .bubble {
  background: var(--bubble-me);
  color: var(--bubble-me-text);
  border-radius: 4px 10px 10px 10px;
}
.msg.peer .bubble {
  background: var(--bubble-peer);
  color: var(--bubble-peer-text);
  border-radius: 4px 10px 10px 10px;
}
.msg.pending .bubble { background: var(--bubble-me); color: var(--bubble-me-text); border-radius: 4px 10px 10px 10px; }

/* 气泡小角（微信式） */
.msg.peer .bubble::before,
.msg.me .bubble::before {
  content: '';
  position: absolute;
  top: 0;
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
}
.msg.peer .bubble::before { left: -6px; border-left: 8px solid var(--bubble-peer); }
.msg.me .bubble::before { right: -6px; border-right: 8px solid var(--bubble-me); }
.msg.pending .bubble::before { right: -6px; border-right: 8px solid var(--bubble-me); }

/* 时间：气泡下方小字 */
.msg .time {
  font-size: 0.68rem;
  color: var(--time-text);
  margin-top: 3px;
  padding: 0 2px;
}

.bubble .content.media img { max-width: 100%; }
.media-img {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border-radius: 6px;
}
.media-video {
  display: block;
  max-width: 240px;
  max-height: 240px;
  border-radius: 6px;
  background: #000;
}
.media-audio { width: 190px; max-width: 100%; height: 34px; }

/* ---------- 输入栏（微信式） ---------- */
#composer {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 7px 8px;
  padding-bottom: calc(7px + env(safe-area-inset-bottom));
  background: var(--composer-bg);
  border-top: 0.5px solid var(--border);
  flex-shrink: 0;
}

.input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}
#text-input {
  width: 100%;
  padding: 8px 40px 8px 12px;
  border: 0.5px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  font-size: 0.95rem;
  outline: none;
  color: var(--text);
}
#btn-send {
  position: absolute;
  right: 3px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: var(--green);
  color: #FFFFFF;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#btn-send.show { display: inline-flex; }
#btn-send:active { opacity: 0.85; }

.voice-btn { color: var(--text); }
.voice-btn.recording { color: var(--danger); }
#btn-voice.recording svg { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

/* 附件面板 */
#attach-panel {
  display: none;
  position: absolute;
  bottom: calc(100% + 4px);
  left: 8px;
  background: var(--card);
  border-radius: 8px;
  padding: 6px;
  gap: 4px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  z-index: 5;
}
#attach-panel.show { display: flex; }
#attach-panel button {
  border: none;
  background: var(--bg);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}
#attach-panel button:active { opacity: 0.7; }

/* ---------- 设置 ---------- */
#settings-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}
#settings-modal.show { display: flex; }
.modal-card {
  position: relative;
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-card h2 { font-size: 1.05rem; font-weight: 600; }
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
}
.avatar-row { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 48px;
  height: 48px;
  border-radius: 5px;
  object-fit: cover;
  background: var(--border);
}
.avatar.big { width: 56px; height: 56px; }
button.ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--green);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
}
button.danger {
  border: none;
  background: rgba(250, 81, 81, 0.1);
  color: var(--danger);
  padding: 10px;
  border-radius: 6px;
  font-size: 0.88rem;
  cursor: pointer;
}
.hint { font-size: 0.72rem; color: var(--text-muted); line-height: 1.5; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.75);
  color: #FFFFFF;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.82rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 20;
  max-width: 80%;
  text-align: center;
}
#toast.show { opacity: 1; }

.hidden-input { display: none; }
