/* MOP 用户端网页 UI 流程预览 - 公共样式（iOS 风格 + 鎏金主色） */
:root {
  --bg-page: #F2F2F7;
  --bg-card: #fff;
  --text-primary: #1a1a1a;
  --text-secondary: #666;
  --border: rgba(212,175,55,0.6);
  --primary: #D4AF37;
  --primary-hover: #B8860B;
  --danger: #ee0a24;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --list-hover: #fafafa;
  /* 主列最大宽度：手机单列；大屏见下方 @media（对话页 .chat-page 单独铺满父级，不用此值顶宽） */
  --layout-max: 480px;
  /* 单条气泡可读宽度上限（避免宽屏/分栏 iframe 里气泡拉成一整条） */
  --chat-bubble-max: 560px;
}

/* 浅色主题（Flutter 注入 data-theme="light" 或独立打开时的默认） */
[data-theme="light"] {
  --bg-page: #F2F2F7;
  --bg-card: #fff;
  --text-primary: #1a1a1a;
  --text-secondary: #666;
  --border: rgba(212,175,55,0.6);
  --primary: #D4AF37;
  --primary-hover: #B8860B;
  --danger: #ee0a24;
  --list-hover: #fafafa;
}

/* 深色主题（Flutter 注入 data-theme="dark" 或 prefers-color-scheme 回退） */
[data-theme="dark"] {
  --bg-page: #1C1C1E;
  --bg-card: #2C2C2E;
  --text-primary: #E8E8ED;
  --text-secondary: #98989D;
  --border: rgba(212,175,55,0.5);
  --primary: #D4AF37;
  --primary-hover: #F5E6C8;
  --danger: #ff6b6b;
  --list-hover: rgba(255,255,255,0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg-page: #1C1C1E;
    --bg-card: #2C2C2E;
    --text-primary: #E8E8ED;
    --text-secondary: #98989D;
    --border: rgba(212,175,55,0.5);
    --primary: #D4AF37;
    --primary-hover: #F5E6C8;
    --danger: #ff6b6b;
    --list-hover: rgba(255,255,255,0.08);
  }
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); font-size: 16px; color: var(--text-primary); background: var(--bg-page); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* 布局（含左右安全区，适配刘海/圆角屏） */
/* 整页主列：顶栏与列表同宽居中，避免大屏「全宽头 + 窄身」 */
.page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--layout-max);
  margin-left: auto;
  margin-right: auto;
  background: var(--bg-page);
}
/* 主界面两栏：整页可宽于单列；窄屏仍单列全宽 */
.page-main-split {
  max-width: none;
  width: 100%;
}
.main-split {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.main-split-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.main-split-left {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
.main-split-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.main-split-right {
  display: none;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  background: var(--bg-page);
  position: relative;
}
/* 主站右栏：工具页（embed）顶栏，与 iframe 内隐藏子页 header 配合 */
.split-panel-chrome {
  display: none;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.split-panel-chrome.is-visible {
  display: flex;
}
.split-panel-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
}
.split-panel-close {
  padding: 4px 10px;
  font-size: 22px;
  line-height: 1;
  font-weight: 300;
}

/* 嵌入主站右栏时隐藏子页自带顶栏（?embed=1 且位于 iframe 内） */
html.mop-embed body.page > header.header {
  display: none !important;
}

.main-chat-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.5;
}
.main-chat-iframe {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: none;
  background: var(--bg-page);
}
.list-item-wrap.is-chat-active {
  background: rgba(212, 175, 55, 0.12);
}
html[data-theme="dark"] .list-item-wrap.is-chat-active,
body[data-theme="dark"] .list-item-wrap.is-chat-active {
  background: rgba(212, 175, 55, 0.15);
}
@media (min-width: 900px) {
  .page-main-split {
    max-width: min(100%, 1180px);
  }
  .main-split-body {
    flex-direction: row;
    align-items: stretch;
  }
  .main-split-left {
    width: 340px;
    max-width: 38%;
    flex: 0 0 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg-page);
  }
  .main-split-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .main-split-right {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }
}
@media (max-width: 899px) {
  .main-split-right {
    display: none !important;
  }
}
.container {
  max-width: none;
  margin: 0 auto;
  width: 100%;
  padding: 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  /* 避免底部按钮（如设置页「退出登录」）被刘海/Home 指示条遮挡 */
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.header { background: var(--bg-card); padding: 12px 16px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); padding-top: max(12px, env(safe-area-inset-top)); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.header h1 { margin: 0; font-size: 18px; font-weight: 600; }
/* 主界面頂欄：與 App 一致——標題 + 搜尋（展開）+ 圖標操作，不在內容區再放「搜尋框」避免與查找好友混淆 */
.header-main-appbar .header-title-slot { flex: 1; min-width: 0; }
.header-main-appbar .header-title-slot h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-search-slot {
  flex: 1;
  display: none;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.header-search-field {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-size: 16px;
  font-family: inherit;
  color: var(--text-primary);
  padding: 6px 4px;
  outline: none;
}
.header-search-field::placeholder { color: var(--text-secondary); }
.header-search-apply { flex-shrink: 0; }
.header-actions { display: flex; align-items: center; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.header-add-friend { text-decoration: none; color: inherit; }
.header-search-slot .btn-toolbar { padding: 6px 12px; }

/* 按钮：图标 + 文字、圆角胶囊、细描边 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.25;
  letter-spacing: 0.02em;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}
a.btn { text-decoration: none; color: inherit; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ic {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: block;
  color: currentColor;
  opacity: 0.92;
}
.btn-txt { white-space: nowrap; }
/* 顶栏/工具条：浅底 + 细边 */
.btn-toolbar {
  padding: 8px 14px;
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.08);
  color: var(--text-primary);
}
html[data-theme="dark"] .btn-toolbar,
body[data-theme="dark"] .btn-toolbar {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
}
.btn-toolbar:hover:not(:disabled) {
  background: var(--list-hover);
  border-color: rgba(212, 175, 55, 0.35);
}
.btn-ghost.btn-toolbar,
.btn.btn-ghost:not(.btn-primary):not(.btn-danger) {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.08);
}
html[data-theme="dark"] .btn-ghost.btn-toolbar,
html[data-theme="dark"] .btn.btn-ghost:not(.btn-primary):not(.btn-danger),
body[data-theme="dark"] .btn-ghost.btn-toolbar,
body[data-theme="dark"] .btn.btn-ghost:not(.btn-primary):not(.btn-danger) {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--list-hover);
  border-color: rgba(212, 175, 55, 0.35);
}
.btn-primary {
  background: linear-gradient(180deg, #e0c456 0%, var(--primary) 55%, #b8942f 100%);
  color: #fff;
  border-color: rgba(180, 140, 40, 0.45);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.btn-primary .btn-ic { opacity: 1; color: #fff; }
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #e8ca5e 0%, var(--primary-hover) 50%, #a67c28 100%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}
.btn-danger {
  background: linear-gradient(180deg, #ff5c6c 0%, var(--danger) 100%);
  color: #fff;
  border-color: rgba(200, 30, 50, 0.35);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.btn-danger:hover:not(:disabled) {
  filter: brightness(1.06);
}
/* 块级主按钮（登录等） */
.btn-block {
  width: 100%;
  border-radius: 12px;
  padding: 14px 20px;
  font-size: 16px;
}
.chat-input-bar .btn-send.btn-labeled {
  padding: 0 16px 0 14px;
  gap: 6px;
  border-radius: 999px;
  min-height: 44px;
}
.chat-header .btn-chat-attach {
  padding: 6px 12px;
  font-size: 13px;
}
@media (max-width: 380px) {
  .header-actions .btn-toolbar .btn-txt {
    display: none;
  }
  .header-actions .btn-toolbar {
    padding: 10px;
    border-radius: 50%;
    min-width: 40px;
    min-height: 40px;
  }
  .header-actions .btn-toolbar .btn-ic {
    margin: 0;
  }
}

/* 表单 */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; color: var(--text-secondary); font-size: 14px; }
.form-group input[type="text"],
.form-group input[type="password"] { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 16px; }
.form-group input:focus { outline: none; border-color: var(--primary); }
.form-hint { display: block; margin-top: 4px; font-size: 12px; color: var(--text-secondary); }
.checkbox-wrap { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 16px; }
.checkbox-wrap input { margin-top: 4px; width: 18px; height: 18px; }
.checkbox-wrap label { cursor: pointer; user-select: none; }

/* 用户须知区域 */
.terms-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; max-height: 200px; overflow-y: auto; margin-bottom: 16px; font-size: 14px; color: var(--text-secondary); }

/* 主界面 Tab（左右安全区） */
.tabs { display: flex; background: var(--bg-card); border-bottom: 1px solid var(--border); padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.tabs a { flex: 1; padding: 12px; text-align: center; color: var(--text-secondary); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 0; }
.toolbar .search-input { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: 20px; font-size: 14px; }
.toolbar .search-input:focus { outline: none; border-color: var(--primary); }
.toolbar-add-friend { flex-shrink: 0; white-space: nowrap; padding: 10px 14px; font-size: 14px; text-decoration: none; }
.header-spacer { display: inline-block; width: 60px; flex-shrink: 0; }

/* 列表项（会话/联系人） */
.list { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-item { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--list-hover); }
.list-item .avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--border); margin-right: 12px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.list-item .avatar img { width: 100%; height: 100%; object-fit: cover; }
.list-item .avatar-initial { font-size: 18px; font-weight: 500; color: #fff; background: var(--primary); width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.list-item .meta { flex: 1; min-width: 0; }
.list-item .title { font-weight: 500; margin-bottom: 2px; }
.list-item .sub { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .time { font-size: 12px; color: var(--text-secondary); flex-shrink: 0; }
.list-item-wrap { display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.list-item-wrap:last-child { border-bottom: none; }
.list-item-wrap:hover { background: var(--list-hover); }
.list-item-wrap .list-item { flex: 1; min-width: 0; }
.btn-remark { flex-shrink: 0; padding: 8px 12px; border: none; background: none; color: var(--text-secondary); font-size: 18px; cursor: pointer; line-height: 1; }
.btn-remark:hover { color: var(--primary); }
.list-item-wrap.is-filtered-out { display: none !important; }
a.btn-profile { flex-shrink: 0; padding: 6px 8px; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); text-decoration: none; min-width: 40px; }
a.btn-profile:hover { color: var(--primary); }
a.btn-profile .btn-ic { width: 22px; height: 22px; }
a.list-item { color: inherit; text-decoration: none; }
a.list-item:hover { text-decoration: none; }

/* 设置页 */
.settings-section { background: var(--bg-card); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; box-shadow: var(--shadow); }
.settings-item { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.settings-item:last-child { border-bottom: none; }
.settings-item a { color: inherit; }
.settings-arrow { color: var(--text-secondary); font-size: 18px; margin-left: auto; }
.qr-placeholder { width: 160px; height: 160px; background: var(--border); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; color: var(--text-secondary); font-size: 14px; margin: 16px auto; }

/* 语言切换 */
.lang-options { display: flex; gap: 8px; }
.lang-options button { padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-card); cursor: pointer; font-size: 14px; }
.lang-options button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* 查找添加好友（与 App AddFriendScreen：Outline 输入 + 列表行 + FilledButton.tonal 一致） */
.add-friend-page { padding-top: 8px; }
.add-friend-hint { margin: 0 0 12px; color: var(--text-secondary); font-size: 14px; line-height: 1.45; }
.add-friend-search-row { display: flex; align-items: stretch; gap: 8px; margin-bottom: 16px; }
.add-friend-field {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 16px;
  font-family: inherit;
  background: var(--bg-card);
  color: var(--text-primary);
}
.add-friend-field:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.add-friend-search-btn { flex-shrink: 0; padding: 10px 18px; min-width: 88px; position: relative; }
.add-friend-search-btn.is-loading { color: transparent; }
.add-friend-search-btn.is-loading::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: mop-spin .65s linear infinite;
}
@keyframes mop-spin { to { transform: rotate(360deg); } }
.add-friend-error { color: var(--danger); font-size: 14px; margin: -8px 0 12px; }
.add-friend-results { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.add-friend-empty { padding: 32px 16px; text-align: center; color: var(--text-secondary); font-size: 15px; }
.add-friend-tile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  min-height: 56px;
  border-bottom: 1px solid var(--border);
}
.add-friend-tile:last-child { border-bottom: none; }
.add-friend-tile-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.add-friend-tile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.add-friend-tile-initial {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.add-friend-tile-body { flex: 1; min-width: 0; }
.add-friend-tile-title { font-size: 16px; font-weight: 500; line-height: 1.25; }
.add-friend-tile-sub { font-size: 14px; color: var(--text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-tonal {
  flex-shrink: 0;
  padding: 8px 16px;
  border: none;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  background: rgba(212, 175, 55, 0.2);
  color: var(--primary);
}
.btn-tonal:hover { filter: brightness(1.05); }
.btn-tonal:disabled { opacity: .5; cursor: not-allowed; }

/* IM 附件：与 App 底部 ModalBottomSheet 一致（语音/视频/拍照/相册/文件/取消） */
.attach-sheet {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: none;
}
.attach-sheet.open { display: block; }
.attach-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.4);
}
.attach-sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  background: var(--bg-card);
  border-radius: 16px 16px 0 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 24px rgba(0,0,0,.12);
  max-height: min(85vh, 520px);
  overflow-y: auto;
}
.attach-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 10px auto 6px;
}
.attach-sheet-item {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 14px 20px;
  border: none;
  background: none;
  font-size: 17px;
  font-family: inherit;
  text-align: left;
  color: var(--text-primary);
  cursor: pointer;
}
.attach-sheet-item:hover { background: var(--list-hover); }
.attach-sheet-icon { font-size: 22px; width: 28px; text-align: center; flex-shrink: 0; line-height: 1; }
.attach-sheet-label { flex: 1; }
.attach-sheet-divider { height: 1px; background: var(--border); margin: 0; border: none; }
.attach-sheet-cancel {
  width: 100%;
  padding: 14px 20px;
  border: none;
  background: none;
  font-size: 17px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-primary);
  cursor: pointer;
}
.attach-sheet-cancel:hover { background: var(--list-hover); }

/* 聊天页：随 WebView / iframe / 浏览器窗口铺满，不沿用主列表的 layout-max 窄列 */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  max-width: 100%;
  margin: 0;
  background: var(--bg-page);
}
.chat-header { background: var(--bg-card); padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chat-header .back-link { color: var(--text-primary); font-size: 18px; text-decoration: none; }
.chat-header .chat-title { flex: 1; font-size: 18px; font-weight: 600; margin: 0; min-width: 0; }
.chat-header .btn-icon,
.chat-header .btn-toolbar { padding: 8px 12px; font-size: 14px; flex-shrink: 0; }
.chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 16px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 10px; }
.chat-msg {
  max-width: min(80%, var(--chat-bubble-max));
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.4;
  word-break: break-word;
}
.chat-msg.received { align-self: flex-start; background: var(--bg-card); border: 1px solid var(--border); }
.chat-msg.sent { align-self: flex-end; background: var(--primary); color: #fff; }
.chat-msg .time { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }
.chat-msg.sent .time { color: rgba(255,255,255,.8); }
.chat-input-bar { background: var(--bg-card); padding: 10px 12px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); padding-bottom: max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: center; flex-shrink: 0; min-height: 56px; box-sizing: border-box; }
.chat-input-bar input { flex: 1; min-width: 0; min-height: 44px; height: 44px; padding: 12px 14px; margin: 0; border: 1px solid var(--border); border-radius: 22px; font-size: 16px; box-sizing: border-box; -webkit-appearance: none; appearance: none; }
.chat-input-bar input:focus { outline: none; border-color: var(--primary); }
.chat-input-bar .btn-send {
  height: 44px;
  min-height: 44px;
  padding: 0 16px 0 14px;
  margin: 0;
  line-height: 1.25;
  border-radius: 999px;
  flex-shrink: 0;
  font-size: 15px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  -webkit-appearance: none;
  appearance: none;
}
.chat-input-bar .btn-attach { padding: 10px 14px; border-radius: 20px; flex-shrink: 0; }
.chat-attach-menu { position: absolute; bottom: 100%; left: 0; margin-bottom: 4px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 140px; z-index: 10; display: none; }
.chat-attach-menu.show { display: block; }
.chat-attach-menu button { display: block; width: 100%; padding: 10px 16px; text-align: left; border: none; background: none; font-size: 14px; cursor: pointer; font-family: inherit; }
.chat-attach-menu button:hover { background: var(--list-hover); }
.chat-attach-divider { height: 1px; background: var(--border); margin: 4px 0; }
.chat-msg .msg-image { font-size: 13px; color: var(--text-secondary); }
.chat-msg.sent .msg-image { color: rgba(255,255,255,.9); }
/* 文件消息：图标+文件名卡片样式（参考微信/Telegram） */
.chat-msg .msg-file { display: inline-flex; align-items: center; gap: 10px; padding: 10px 14px; min-width: 140px; max-width: 260px; background: rgba(0,0,0,.05); border: 1px solid var(--border); border-radius: 8px; text-decoration: none; color: inherit; font-size: 14px; transition: background .2s; }
.chat-msg .msg-file:hover { background: rgba(0,0,0,.08); }
.chat-msg .msg-file-icon { font-size: 24px; flex-shrink: 0; }
.chat-msg .msg-file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.chat-msg.sent .msg-file { background: rgba(255,255,255,.2); border-color: rgba(255,255,255,.4); }
.chat-msg.sent .msg-file:hover { background: rgba(255,255,255,.25); }

/* 设置页弹窗：矮视口/大屏内可滚动，保证底部「取消/保存」可操作 */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 360px;
  padding: 20px;
  max-height: min(85vh, calc(100vh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  max-height: min(85dvh, calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
}
.modal-title { font-size: 18px; font-weight: 600; margin-bottom: 12px; }
.modal-textarea { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 15px; font-family: inherit; resize: vertical; min-height: 80px; box-sizing: border-box; }
.modal-textarea:focus { outline: none; border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 16px; }
.modal-actions .btn { border-radius: 10px; padding: 10px 18px; font-size: 15px; }
.modal-input { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 15px; box-sizing: border-box; }
.modal-input:focus { outline: none; border-color: var(--primary); }
.modal-hint { font-size: 12px; color: var(--text-secondary); margin-top: 6px; }
.card { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); }

/* 小屏：主界面工具栏换行、按钮缩小 */
@media (max-width: 360px) {
  .toolbar { flex-wrap: wrap; }
  .toolbar .btn { font-size: 14px; padding: 8px 14px; }
}

/* 大屏（PC）：略加宽主列、两侧留白渐变、主列圆角+阴影，避免「一条顶栏横跨整屏」 */
@media (min-width: 900px) {
  :root {
    --layout-max: 600px;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  }
  body {
    background: linear-gradient(165deg, #e4e2e8 0%, var(--bg-page) 42%, #ebe9f0 100%);
  }
  html[data-theme="dark"] body,
  body[data-theme="dark"] {
    background: linear-gradient(165deg, #121214 0%, var(--bg-page) 40%, #18181a 100%);
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) body {
      background: linear-gradient(165deg, #121214 0%, var(--bg-page) 40%, #18181a 100%);
    }
  }
  /* 登录/主列表/设置等：主列「手机壳」；IM 全屏高由 .chat-page 单独处理，避免 margin 撑破 100% 高度 */
  .page:not(.chat-page) {
    margin-top: 20px;
    margin-bottom: 28px;
    min-height: calc(100vh - 48px);
    min-height: calc(100dvh - 48px);
    border-radius: 16px;
    overflow: hidden;
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.06),
      0 12px 40px rgba(0, 0, 0, 0.1);
  }
  /* 非主列表窄页：限制高度并在主内容区滚动，避免 overflow:hidden 裁掉设置页底部按钮 */
  .page:not(.chat-page):not(.page-main-split) {
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
  }
  .page:not(.chat-page):not(.page-main-split) > .header {
    flex-shrink: 0;
  }
  .page:not(.chat-page):not(.page-main-split) > .container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  html[data-theme="dark"] .page:not(.chat-page),
  body[data-theme="dark"] .page:not(.chat-page) {
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.06),
      0 12px 40px rgba(0, 0, 0, 0.45);
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .page:not(.chat-page) {
      box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.06),
        0 12px 40px rgba(0, 0, 0, 0.45);
    }
  }
  .chat-page {
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.06),
      0 8px 32px rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    overflow: hidden;
  }
  html[data-theme="dark"] .chat-page,
  body[data-theme="dark"] .chat-page {
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.06),
      0 8px 32px rgba(0, 0, 0, 0.4);
  }
  .list {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  }
  html[data-theme="dark"] .list,
  body[data-theme="dark"] .list {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .list {
      box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    }
  }
}
