/* 消息 Tab：列表 / 系统消息 / 会话。视觉对应 MessagesScreen.swift 与 messages.png。 */

/* 本组页面自己控制底部留白（底栏 / 输入栏） */
.app-view.messages-list-view,
.app-view.messages-detail-view { padding-bottom: 0; }

/* ---------- 列表 ---------- */
.messages-page { padding: 18px 16px calc(92px + env(safe-area-inset-bottom)); }

.messages-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 2px;
}
.messages-head h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.4px;
  color: var(--ink);
}
.messages-actions { display: flex; align-items: center; gap: 3px; margin-right: -7px; }
.messages-actions .nav-icon { width: 36px; height: 36px; color: var(--ink); }

/* 最近联系：外圈渐变 = 未读 */
.avatar-rail {
  display: flex;
  gap: 14px;
  margin: 16px -16px 12px;
  padding: 3px 16px 2px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.avatar-rail::-webkit-scrollbar { display: none; }
.story-item {
  flex: 0 0 auto;
  width: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0;
}
.story-ring {
  position: relative;
  width: 56px;
  height: 56px;
  padding: 2px;
  border-radius: 50%;
  background: #E6EAF2;
  display: grid;
  place-items: center;
  transition: transform 0.12s;
}
.story-item:active .story-ring { transform: scale(0.96); }
.story-inner {
  width: 100%;
  height: 100%;
  padding: 2px;
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
}
.story-item.is-unread .story-ring { background: var(--brand-grad); }
.story-badge {
  position: absolute;
  top: -2px;
  right: -3px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: #F04444;
  border: 1.5px solid #fff;
  color: #fff;
  font-size: 9px;
  font-style: normal;
  font-weight: 800;
  line-height: 14px;
  text-align: center;
}
.story-add .story-ring {
  padding: 0;
  background: #FAFBFD;
  border: 1px dashed #D8DEE8;
  color: var(--faint);
}
.story-add .story-ring .ico { width: 20px; height: 20px; }
.story-label {
  width: 60px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--sub);
  line-height: 1.2;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 系统消息卡片 */
.system-card {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 12px;
  border-radius: 17px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 3px 14px rgba(16, 27, 48, 0.06);
  text-align: left;
  transition: transform 0.12s;
}
.system-card:active { transform: scale(0.992); }
.system-icon {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--brand-grad);
  color: #fff;
  box-shadow: 0 4px 10px rgba(80, 110, 230, 0.22);
}
.system-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.system-copy strong { font-size: 14px; font-weight: 800; color: var(--ink); line-height: 1.25; }
.system-copy span {
  font-size: 10.5px;
  color: var(--sub);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.system-right {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  padding-left: 2px;
}
.system-right em { font-style: normal; font-size: 9.5px; color: var(--faint); line-height: 1.2; }
.system-right i {
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: #F04444;
  color: #fff;
  font-size: 9px;
  font-style: normal;
  font-weight: 800;
  line-height: 17px;
  text-align: center;
}

/* 全部消息 */
.list-label {
  margin: 20px 2px 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--sub);
}
.conv-list { display: flex; flex-direction: column; }
.conv-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 0;
  text-align: left;
}
.conv-row + .conv-row { margin-top: 1px; }
.conv-row:active { opacity: 0.72; }
.conv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.conv-main strong {
  font-size: 14.5px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-main span {
  font-size: 11px;
  color: var(--sub);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-meta {
  flex: 0 0 auto;
  min-width: 40px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.conv-meta em { font-style: normal; font-size: 9.5px; color: var(--faint); line-height: 1.2; }
.conv-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #F04444;
  color: #fff;
  font-size: 9px;
  font-style: normal;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}

/* ---------- 系统消息页 ---------- */
.sys-page { background: var(--canvas); min-height: 100vh; min-height: 100dvh; padding-bottom: 30px; }
.sys-nav {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  grid-template-columns: none;
}
.sys-nav .detail-nav-title {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 170px);
}
.sys-nav .nav-link { color: var(--sub); font-size: 12px; font-weight: 600; padding: 8px 10px 8px 6px; white-space: nowrap; }
.sys-list { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.sys-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px;
  border-radius: 15px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 3px 12px rgba(16, 27, 48, 0.05);
}
.sys-row.is-read { background: #FBFCFE; box-shadow: none; border-color: var(--border-soft); }
.sys-row-icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #EDF3FF;
  color: var(--brand-deep);
}
.sys-row-icon.audit { background: #EAF8EF; color: #138A4E; }
.sys-row-icon.energy { background: #FFF7E6; color: var(--gold); }
.sys-row-icon.rule { background: #F1F4F9; color: var(--sub); }
.sys-row-body { flex: 1; min-width: 0; padding-right: 10px; }
.sys-row-body strong { display: block; font-size: 13px; font-weight: 800; color: var(--ink); line-height: 1.3; }
.sys-row-body p { margin: 4px 0 0; font-size: 11px; color: var(--sub); line-height: 1.55; }
.sys-row-body span { display: block; margin-top: 5px; font-size: 9.5px; color: var(--faint); }
.unread-dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  margin-top: 5px;
  border-radius: 50%;
  background: #F04444;
}

/* ---------- 会话 ---------- */
.chat-page {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(74px + env(safe-area-inset-bottom));
  background: var(--canvas);
}
/* 输入栏固定，聊天头部也固定，避免长对话滚动时标题条被带走 */
.chat-room { padding-top: 52px; }
.chat-nav {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 36;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: var(--sheet);
  min-height: 52px;
  padding: 0 8px;
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--divider);
  backdrop-filter: saturate(1.8) blur(16px);
  -webkit-backdrop-filter: saturate(1.8) blur(16px);
}
.chat-nav-left { display: flex; align-items: center; z-index: 2; }
.chat-nav-left .nav-icon { width: 36px; height: 36px; color: var(--ink); }
.chat-nav-title {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 150px);
  max-width: 250px;
  text-align: center;
  pointer-events: none;
}
.chat-nav-title strong {
  display: block;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: -0.3px;
  color: var(--ink);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-nav-title span {
  display: block;
  margin-top: 1px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--green);
  line-height: 1.2;
}
.chat-nav-actions { display: flex; align-items: center; gap: 1px; margin-left: auto; z-index: 2; }
.chat-nav-actions .nav-icon { width: 34px; height: 34px; color: var(--ink); }
.chat-tip {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #FBF3E4;
  color: #B07B18;
  transition: transform 0.12s;
}
.chat-tip:active { transform: scale(0.94); }

.chat-viewport { padding: 12px 14px 18px; }
.chat-group-avatars {
  display: flex;
  justify-content: center;
  padding: 5px 0 9px;
}
.chat-group-avatars .ava { margin-left: -8px; border: 2px solid var(--canvas); }
.chat-group-avatars .ava:first-child { margin-left: 0; }
.chat-notice {
  margin: 2px auto 14px;
  max-width: 86%;
  text-align: center;
  font-size: 10.5px;
  color: var(--faint);
  line-height: 1.6;
}
.chat-empty { padding: 26px 0; text-align: center; font-size: 11px; color: var(--faint); }

.chat-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 14px;
  animation: chatIn 0.18s ease;
}
@keyframes chatIn { from { opacity: 0; transform: translateY(4px); } }
.chat-row.is-mine { flex-direction: row-reverse; }
.chat-bubble-wrap {
  min-width: 0;
  max-width: 74%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.chat-row.is-mine .chat-bubble-wrap { align-items: flex-end; }
.chat-name { margin: 0 0 4px 3px; font-size: 10px; color: var(--sub); line-height: 1.2; }
.chat-bubble {
  padding: 9px 13px;
  border-radius: 16px;
  background: #F1F4F9;
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.62;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-row.is-mine .chat-bubble {
  background: var(--brand-grad);
  color: #fff;
  box-shadow: 0 4px 12px rgba(80, 110, 230, 0.18);
}
.chat-time { margin: 4px 3px 0; font-size: 8.5px; color: var(--faint); line-height: 1.2; }

/* 输入栏 */
.chat-composer {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 36;
  width: 100%;
  max-width: var(--sheet);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--divider);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
}
.composer-icon {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink);
}
.composer-icon:active { background: var(--field); }
.chat-composer input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--field);
  color: var(--ink);
  outline: none;
  font-size: 16px;
  -webkit-appearance: none;
}
.chat-composer input::placeholder { color: var(--faint); }
.chat-composer input:focus { background: #fff; box-shadow: inset 0 0 0 1px rgba(63, 142, 247, 0.35); }
.chat-send {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #C8D2E4;
  color: #fff;
  transition: background 0.18s, box-shadow 0.18s, transform 0.12s;
}
.chat-send.is-ready {
  background: var(--brand-grad);
  box-shadow: 0 4px 12px rgba(80, 110, 230, 0.28);
}
.chat-send:active:not(:disabled) { transform: scale(0.94); }
.chat-send:disabled { cursor: default; }

/* ---------- 会话设置弹层 ---------- */
.cs-sheet { padding: 3px 14px 10px; }
.cs-grab { width: 36px; height: 4px; margin: 3px auto 10px; border-radius: 999px; background: #DDE3EC; }
.cs-head { text-align: center; padding-bottom: 14px; }
.cs-head h2 { margin: 0; font-size: 20px; font-weight: 900; letter-spacing: -0.4px; color: var(--ink); }
.cs-head p { margin: 5px 0 0; font-size: 12px; color: var(--sub); }

.cs-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 3px 12px rgba(16, 27, 48, 0.04);
  overflow: hidden;
}
.cs-card + .cs-card, .cs-search-block, .cs-search-block + .cs-card { margin-top: 12px; }
.cs-profile { display: flex; align-items: center; gap: 11px; padding: 14px; }
.cs-profile > div { min-width: 0; }
.cs-profile strong { display: block; font-size: 14px; font-weight: 800; color: var(--ink); line-height: 1.3; }
.cs-profile span { display: block; margin-top: 3px; font-size: 11px; color: var(--sub); }
.cs-divider { height: 1px; margin-left: 14px; background: var(--divider); }
.cs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
}
.cs-switch {
  position: relative;
  flex: 0 0 auto;
  width: 51px;
  height: 31px;
  border-radius: 999px;
  background: #E3E6EB;
  transition: background 0.18s;
}
.cs-switch i {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(16, 27, 48, 0.22);
  transition: transform 0.18s;
}
.cs-switch.is-on { background: #3F8EF7; }
.cs-switch.is-on i { transform: translateX(20px); }

.cs-actions { padding: 0; }
.cs-action {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 0 14px;
  text-align: left;
  font-size: 13.5px;
  color: var(--ink);
}
.cs-action:active { background: var(--field); }
.cs-action-icon { display: grid; place-items: center; width: 20px; color: var(--faint); }
.cs-action-label { flex: 1; min-width: 0; }
.cs-action .cs-chevron { color: #C6CDD8; transition: transform 0.18s; }
.cs-action .cs-chevron.is-open { transform: rotate(90deg); }
.cs-action.is-danger { color: #E05555; }
.cs-action.is-danger .cs-action-icon { color: #E05555; }

.cs-search-block[hidden] { display: none; }
.cs-search-block {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
}
.cs-search-box {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--field);
  color: var(--muted);
}
.cs-search-box input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  outline: none;
  font-size: 16px;
  color: var(--ink);
}
.cs-search-box input::placeholder { color: var(--faint); font-size: 12.5px; }
.cs-search-results { display: flex; flex-direction: column; }
.cs-search-row { padding: 8px 2px; border-bottom: 1px solid var(--divider); }
.cs-search-row:last-child { border-bottom: 0; }
.cs-search-row em { display: block; font-style: normal; font-size: 10px; font-weight: 600; color: var(--faint); }
.cs-search-row p { margin: 2px 0 0; font-size: 12.5px; line-height: 1.55; color: var(--ink); word-break: break-word; }
.cs-search-empty { padding: 12px 0; text-align: center; font-size: 12px; color: var(--sub); }

@media (min-width: 480px) {
  .chat-nav { top: 18px; border-radius: 28px 28px 0 0; }
  .chat-composer { bottom: 18px; border-radius: 0 0 28px 28px; }
}

/* 搜索与筛选标签（对齐当前 MessagesScreen.swift） */
.msg-search {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  margin: 10px 14px 2px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--field);
  color: var(--muted);
}
.msg-search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: none;
  background: none;
  font-size: 16px;
  color: var(--ink);
}
.msg-search input::placeholder { color: var(--faint); font-size: 12.5px; }
.story-caption {
  max-width: 60px;
  overflow: hidden;
  color: var(--faint);
  font-size: 9px;
  font-style: normal;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-tabs {
  display: flex;
  gap: 18px;
  padding: 13px 16px 2px;
  border-bottom: 1px solid var(--divider);
}
.msg-tab {
  position: relative;
  padding: 0 0 9px;
  color: var(--sub);
  font-size: 13px;
  font-weight: 600;
}
.msg-tab.is-on { color: var(--ink); font-weight: 900; }
.msg-tab.is-on::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 18px;
  height: 3px;
  margin-left: -9px;
  border-radius: 2px;
  background: var(--brand);
}
.conv-row[hidden] { display: none; }

/* 会话卡片（当前 SwiftUI 用白卡列表） */
.conv-list { gap: 8px; display: flex; flex-direction: column; padding-top: 2px; }
.conv-row {
  padding: 11px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid rgba(238, 241, 247, 0.9);
  box-shadow: 0 2px 8px rgba(16, 27, 48, 0.03);
}
.conv-row:active { background: #FAFBFD; }
