/* 土豆聊天 —— 设计规范实现（主题色：黄色）
   主色 #FFC300（白底激活色 #C98A00）/ 自己气泡 #FFE082 / 对方气泡 #FFFFFF / 页面背景 #EDEDED
   主文字 #191919 / 次要 #888888 / 占位 #B2B2B2 / 分割 rgba(0,0,0,0.08) / 错误 #FA5151
   圆角统一 4px；禁止渐变、阴影、玻璃效果、霓虹色、大圆角胶囊
   支持黑夜模式：body.dark 覆盖同一套变量 */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #FFC300;
  --primary-pressed: #E5A100;
  --primary-strong: #C98A00;      /* 白底上的文字/图标/描边（保证对比度） */
  --bubble-self: #FFE082;
  --bg: #EDEDED;
  --surface: #FFFFFF;
  --surface-2: #F7F7F7;
  --text: #191919;
  --bubble-text: #191919;
  --sub: #888888;
  --placeholder: #B2B2B2;
  --divider: rgba(0, 0, 0, 0.08);
  --error: #FA5151;
  --link: #576B95;
  --radius: 4px;
  --input-border: #E5E5E5;
  --bubble-other: #FFFFFF;
  --toast-bg: rgba(0, 0, 0, 0.72);
  --tabbar-height: 56px;
  --fs-body: 14px;
}

body.dark {
  --bg: #101010;
  --surface: #1B1B1B;
  --surface-2: #242424;
  --text: #E5E5E5;
  --bubble-text: #E5E5E5;
  --sub: #8A8A8A;
  --placeholder: #6E6E6E;
  --divider: rgba(255, 255, 255, 0.08);
  --link: #8AA1D6;
  --input-border: #333333;
  --bubble-other: #2A2A2A;
  --bubble-self: #FFE082;
  --toast-bg: #4A4A4A;
}

html, body { height: 100%; }

body {
  font-family: "PingFang SC", system-ui, -apple-system, "Microsoft YaHei", sans-serif;
  font-size: var(--fs-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
a { color: var(--link); text-decoration: none; }
[hidden] { display: none !important; }

.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: #fff;
  font-size: 16px;
  flex: none;
  user-select: none;
}
.avatar-40 { width: 40px; height: 40px; font-size: 15px; }
.avatar-48 { width: 48px; height: 48px; font-size: 18px; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--text);
}
.icon-btn:hover { color: var(--primary-strong); }

/* ==================== 登录 / 注册 ==================== */

.auth {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.auth-card {
  width: 400px;
  max-width: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 48px 40px 32px;
}

.auth-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  background: var(--primary);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-brand {
  margin-top: 16px;
  text-align: center;
  font-size: 17px;
  color: var(--text);
}

.auth-form { margin-top: 40px; }

.field { position: relative; margin-bottom: 16px; }

.field input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--input-border);
  border-radius: var(--radius);
  font-size: 15px;
  outline: none;
}
.field input::placeholder { color: var(--placeholder); }
.field input:focus { border-bottom-color: var(--primary-strong); }

.eye {
  position: absolute;
  right: 8px;
  top: 12px;
  color: var(--sub);
  display: flex;
}

.auth-error {
  color: var(--error);
  font-size: 12px;
  margin-bottom: 12px;
}

.btn-primary {
  width: 100%;
  height: 44px;
  background: var(--primary);
  color: #191919;
  font-size: 17px;
  border-radius: var(--radius);
}
.btn-primary:active { background: var(--primary-pressed); }
.btn-primary:disabled { background: var(--input-border); color: var(--placeholder); cursor: default; }

.auth-switch { margin-top: 24px; text-align: center; font-size: 13px; }
.auth-switch a { color: var(--link); }
.auth-lite { display: block; margin-top: 10px; font-size: 12px; color: var(--sub); }
.auth-lite a { color: var(--link); }

/* ==================== 主界面框架 ==================== */

.main { height: 100%; display: flex; }

.rail {
  display: none;
  width: 60px;
  background: var(--bg);
  border-right: 1px solid var(--divider);
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
}
.rail-btn {
  position: relative;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sub);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.rail-btn.is-active { color: var(--primary-strong); }
.rail-dot {
  position: absolute;
  top: 4px; right: 4px;
  width: 8px; height: 8px;
  background: var(--error);
  border-radius: 50%;
}
.rail-me { margin-top: auto; display: flex; flex-direction: column; align-items: center; gap: 8px; }

.list-pane {
  display: flex;
  flex-direction: column;
  width: 100%;
  background: var(--surface);
  border-right: 1px solid var(--divider);
  overflow: hidden;
}

.topbar {
  position: relative;
  height: 56px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.topbar-title { font-size: 17px; font-weight: 600; }

.menu {
  position: absolute;
  top: 48px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  z-index: 20;
  min-width: 120px;
}
.menu-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  text-align: left;
  font-size: 15px;
  color: var(--text);
}
.menu-item + .menu-item { border-top: 1px solid var(--divider); }
.menu-item:hover { background: var(--bg); }

.search-wrap { padding: 0 16px 8px; flex: none; }
.search {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  background: var(--bg);
  border-radius: var(--radius);
  color: var(--placeholder);
}
.search-solid {
  background: var(--surface);
  border-bottom: 1px solid var(--input-border);
}
body.dark .search-solid { background: var(--surface-2); }
.search input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 14px;
  color: var(--text);
}
.search input::placeholder { color: var(--placeholder); }

.list-content { flex: 1; overflow-y: auto; }

/* 会话列表项 */
.conv {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 72px;
  padding: 0 16px;
  cursor: pointer;
}
.conv:hover { background: var(--bg); }
.conv-body { flex: 1; min-width: 0; }
.conv-row1 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.conv-name { font-size: 17px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--placeholder); flex: none; }
.conv-row2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.conv-preview {
  font-size: 14px;
  color: var(--sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.badge {
  flex: none;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--error);
  color: #fff;
  font-size: 12px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 分组标题 / 空状态 */
.group-title {
  padding: 12px 16px 6px;
  font-size: 13px;
  color: var(--sub);
}
.empty { padding: 48px 16px; text-align: center; font-size: 13px; color: var(--placeholder); }

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
}
.list-row:hover { background: var(--bg); }
.list-row .name { font-size: 15px; color: var(--text); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .meta { font-size: 12px; color: var(--placeholder); }

/* ==================== 内容区（聊天等页面） ==================== */

.content-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.content { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* 页面导航栏（返回 / 标题 / 操作） */
.navbar {
  position: relative;
  height: 56px;
  flex: none;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--divider);
}
.navbar-back { display: flex; align-items: center; color: var(--text); }
.navbar-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 17px;
  font-weight: 600;
  max-width: 60%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.navbar-side { margin-left: auto; font-size: 15px; color: var(--text); }
.navbar-side.is-disabled { color: var(--placeholder); cursor: default; }
.navbar-side:not(.is-disabled) { color: var(--primary-strong); }
button.navbar-side { padding: 0; font-family: inherit; font-size: 13px; }

.page-scroll { flex: 1; overflow-y: auto; }
.page-pad { padding: 16px; }

.btn-block {
  display: block;
  width: 100%;
  height: 44px;
  background: var(--primary);
  color: #191919;
  font-size: 17px;
  border-radius: var(--radius);
}
.btn-block:disabled { background: var(--input-border); color: var(--placeholder); cursor: default; }

.btn-outline {
  padding: 6px 14px;
  border: 1px solid var(--primary-strong);
  color: var(--primary-strong);
  font-size: 13px;
  border-radius: var(--radius);
  background: var(--surface);
}
.btn-ghost {
  padding: 6px 14px;
  border: 1px solid var(--input-border);
  color: var(--placeholder);
  font-size: 13px;
  border-radius: var(--radius);
  background: var(--surface);
  cursor: default;
}

/* ==================== 聊天页 ==================== */

.chat-nav { background: var(--surface); border-bottom-color: var(--divider); }
body.dark .chat-nav { background: var(--surface); }

.msg-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--bg);
}

.day-sep { text-align: center; font-size: 12px; color: var(--placeholder); margin: 16px 0 8px; }
.day-sep:first-child { margin-top: 0; }

.msg { display: flex; gap: 8px; margin-top: 16px; }
.msg:first-child { margin-top: 0; }
.msg.same { margin-top: 8px; }
.msg.self { flex-direction: row-reverse; }

.msg-col { max-width: 70%; min-width: 0; }
.msg-sender { font-size: 13px; color: var(--sub); margin-bottom: 4px; }
.msg.self .msg-sender { text-align: right; }

.bubble {
  background: var(--bubble-other);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 17px;
  line-height: 1.4;
  color: var(--bubble-text);
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.self .bubble { background: var(--bubble-self); color: #191919; }

/* 已读/未读标记 */
.bubble-meta { margin-top: 4px; text-align: right; }
.read-mark { font-size: 11px; color: #B2B2B2; }
.read-mark.read { color: #C98A00; }

/* 底部输入栏 */
.chat-input {
  flex: none;
  min-height: 56px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg);
  border-top: 1px solid var(--divider);
}
.chat-input textarea {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 12px;
  background: var(--surface);
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  outline: none;
  color: var(--text);
}
.chat-input textarea::placeholder { color: var(--placeholder); }
.btn-send {
  flex: none;
  height: 40px;
  padding: 0 16px;
  background: var(--primary);
  color: #191919;
  font-size: 15px;
  border-radius: var(--radius);
}
.btn-send:active { background: var(--primary-pressed); }

.chat-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--placeholder);
  font-size: 13px;
}

/* ==================== 好友 / 群聊选择 ==================== */

.pick {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
}
.pick:hover { background: var(--surface-2); }
.checkbox {
  width: 20px;
  height: 20px;
  flex: none;
  border: 1px solid var(--placeholder);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.pick.is-checked .checkbox { background: var(--primary); border-color: var(--primary); color: #191919; }

.result-btn { flex: none; }

/* ==================== 设置页 ==================== */

.set-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--divider);
}
.set-profile .set-name { font-size: 17px; color: var(--text); }
.set-profile .set-sub { font-size: 13px; color: var(--sub); margin-top: 4px; }

.set-group { margin-top: 12px; background: var(--surface); border-top: 1px solid var(--divider); border-bottom: 1px solid var(--divider); }
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 8px 16px;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
}
.set-row + .set-row { border-top: 1px solid var(--divider); }
.set-row:hover { background: var(--bg); }
.set-row .set-desc { font-size: 12px; color: var(--placeholder); margin-top: 3px; }
.set-row .set-left { min-width: 0; }
.set-row .set-value { font-size: 14px; color: var(--sub); flex: none; display: flex; align-items: center; gap: 6px; }
.set-row.danger { justify-content: center; color: var(--error); }
.set-row.static { cursor: default; }
.set-row.static:hover { background: transparent; }

/* 开关（4px 圆角，不用胶囊） */
.switch {
  position: relative;
  width: 44px;
  height: 26px;
  flex: none;
  background: var(--input-border);
  border-radius: var(--radius);
  transition: background 0.15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: var(--radius);
  transition: left 0.15s;
}
.switch.is-on { background: var(--primary); }
.switch.is-on::after { left: 21px; }

.chevron { color: var(--placeholder); display: flex; }

/* ==================== 提示 / 弹窗 ==================== */

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: var(--radius);
  z-index: 100;
  max-width: 80%;
  text-align: center;
}

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal {
  width: 300px;
  max-width: calc(100% - 48px);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 20px 16px;
}
.modal-title { font-size: 17px; text-align: center; margin-bottom: 16px; }
.modal-text { font-size: 14px; line-height: 1.6; color: var(--sub);
  margin: -6px 0 14px; text-align: left; white-space: pre-wrap; }
.notice-text { max-height: 50vh; overflow-y: auto; word-break: break-word;
  color: var(--text); }
.modal input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: none;
  border-bottom: 1px solid var(--input-border);
  border-radius: var(--radius);
  font-size: 15px;
  outline: none;
  background: var(--surface);
  color: var(--text);
}
.modal input::placeholder { color: var(--placeholder); }
.modal input:focus { border-bottom-color: var(--primary-strong); }
.modal-actions { display: flex; gap: 12px; margin-top: 24px; }
.modal-actions button { flex: 1; height: 40px; border-radius: var(--radius); font-size: 15px; }
.modal-cancel { background: var(--bg); color: var(--text); }
.modal-ok { background: var(--primary); color: #191919; }

/* ==================== 手机端底部标签栏 ==================== */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--tabbar-height);
  display: none;
  background: var(--surface);
  border-top: 1px solid var(--divider);
  z-index: 30;
}
.tab-btn {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--sub);
}
.tab-btn.is-active { color: var(--primary-strong); }
.tab-label { font-size: 11px; line-height: 1; }
.tab-btn .rail-dot { top: 6px; right: calc(50% - 18px); }

/* ==================== 响应式 ==================== */

/* 手机端：一次只显示列表或内容；顶层页面显示底部标签栏 */
body[data-page="chat"] .list-pane,
body[data-page="addfriend"] .list-pane,
body[data-page="newgroup"] .list-pane,
body[data-page="requests"] .list-pane,
body[data-page="settings"] .list-pane { display: none; }

body[data-page="chats"] .content-pane,
body[data-page="contacts"] .content-pane { display: none; }

@media (max-width: 767px) {
  /* 底部标签栏仅手机端、仅顶层页面（消息/通讯录/设置）显示 */
  body[data-page="chats"] .tabbar,
  body[data-page="contacts"] .tabbar,
  body[data-page="settings"] .tabbar { display: flex; }

  /* 标签栏占位，避免遮挡列表/设置内容 */
  body[data-page="chats"] .list-content,
  body[data-page="contacts"] .list-content,
  body[data-page="settings"] .content { padding-bottom: var(--tabbar-height); }

  .auth-card { margin: 0 16px; padding: 40px 24px 28px; }
  .msg-col { max-width: 75%; }
}

@media (min-width: 768px) {
  .rail { display: flex; }
  .list-pane { width: 280px; flex: none; }

  /* 桌面端：三栏，列表与内容同时可见 */
  body[data-page="chat"] .list-pane,
  body[data-page="addfriend"] .list-pane,
  body[data-page="newgroup"] .list-pane,
  body[data-page="requests"] .list-pane,
  body[data-page="settings"] .list-pane { display: flex; }

  body[data-page="chats"] .content-pane,
  body[data-page="contacts"] .content-pane { display: flex; }
}
