/* ============ 聊天视图（含桌面角色卡分栏） ============ */
#chatView { flex-direction: row; background: #ededed; }

.sidebar { display: none; }
@media (min-width: 768px) {
  .sidebar {
    display: flex; flex-direction: column;
    width: 230px; flex-shrink: 0;
    background: linear-gradient(180deg, #2e6fb5 0%, #1c4f92 100%);
    color: #fff; padding: 20px 16px 20px;
  }
  .sidebar-head {
    font-size: 13px; font-weight: 700; color: rgba(255,255,255,0.85);
    margin: 0 6px 10px;
  }
  .side-char-list { display: flex; flex-direction: column; gap: 6px; }
  .side-char-item {
    display: flex; align-items: center; gap: 10px; width: 100%;
    border: none; background: rgba(255,255,255,0.08); border-radius: 12px;
    padding: 8px 10px; cursor: pointer; color: #fff;
    font-family: inherit; text-align: left;
    transition: background 0.15s;
  }
  .side-char-item:hover { background: rgba(255,255,255,0.15); }
  .side-char-item.active {
    background: rgba(255,255,255,0.22);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25);
  }
  .side-char-avatar {
    width: 36px; height: 36px; border-radius: 50%; background: #fff;
    display: flex; align-items: center; justify-content: center; overflow: hidden;
    font-size: 18px; flex-shrink: 0;
  }
  .side-char-avatar img { width: 100%; height: 100%; object-fit: cover; }
  .side-char-name {
    font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .sidebar-tip {
    margin-top: auto; font-size: 12px; color: rgba(255,255,255,0.65);
    text-align: center; line-height: 1.7;
  }
}

/* 手机端角色切换横向条（桌面端隐藏） */
.char-strip {
  display: flex; gap: 10px; overflow-x: auto;
  padding: 8px 12px; background: #fff;
  border-bottom: 1px solid #eee; flex-shrink: 0;
}
.char-strip::-webkit-scrollbar { display: none; }
.char-strip-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: none; background: none; cursor: pointer; flex-shrink: 0; width: 56px;
  font-family: inherit;
}
.char-strip-item .strip-avatar {
  width: 44px; height: 44px; border-radius: 50%; background: #eef4ff;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  font-size: 22px; border: 2px solid transparent;
}
.char-strip-item .strip-avatar img { width: 100%; height: 100%; object-fit: cover; }
.char-strip-item.active .strip-avatar { border-color: #07c160; }
.char-strip-item .strip-name {
  font-size: 10px; color: #666; max-width: 56px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (min-width: 768px) { .char-strip { display: none; } }

.chat-panel {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  background: #ededed;
}
.header {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  background: #ededed; padding: 12px 12px;
  border-bottom: 1px solid #d5d5d5; font-weight: bold; font-size: 16px;
  color: #333; flex-shrink: 0;
}
.header > span {
  position: absolute; left: 0; right: 0;
  text-align: center; pointer-events: none;
}
.back-btn {
  background: none; border: none; font-size: 22px; color: #333; cursor: pointer;
  padding: 4px 10px; border-radius: 10px; line-height: 1; flex-shrink: 0;
  margin-left: -6px;
}
.header .back-btn { position: relative; z-index: 1; }
.back-btn:active { background: rgba(0,0,0,0.08); }

/* 聊天模型选择条 */
.model-bar {
  padding: 6px 12px; background: #f7f7f7;
  border-bottom: 1px solid #e0e0e0; flex-shrink: 0;
}
.model-bar select {
  width: 100%; border: 1px solid #ddd; border-radius: 8px;
  padding: 6px 8px; font-size: 12px; background: #fff; color: #333;
}

.chat-area {
  flex: 1; padding: 50px 12px 12px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
}
.bubble {
  max-width: 80%; padding: 10px 14px; border-radius: 18px;
  line-height: 1.4; word-break: break-word; animation: fadeIn 0.2s;
  -webkit-touch-callout: none;
}
@media (min-width: 768px) { .bubble { max-width: 70%; } }
.user { align-self: flex-end; background: #95d469; color: #000; border-bottom-right-radius: 4px; }
.oc { align-self: flex-start; background: #fff; color: #000; border-bottom-left-radius: 4px; }
.input-area {
  display: flex; padding: 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: #f7f7f7; border-top: 1px solid #d5d5d5;
}
.input-area input {
  flex: 1; border: 1px solid #ccc; border-radius: 20px;
  padding: 10px 15px; outline: none; font-size: 16px; background: #fff;
}
.input-area button {
  margin-left: 8px; background: #07c160; color: white; border: none;
  border-radius: 50%; width: 40px; height: 40px; font-size: 20px;
  cursor: pointer; flex-shrink: 0;
}

.hint { text-align: center; font-size: 12px; color: #999; margin: 4px 0; }
.bubble.press-hint { box-shadow: 0 0 0 2px #07c160; }
.bubble.editing { border: 2px solid #07c160; }
.msg-menu {
  position: fixed; z-index: 1000; background: #fff; border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25); padding: 6px 0; min-width: 130px;
}
.msg-menu-item { padding: 10px 16px; font-size: 14px; color: #333; cursor: pointer; }
.msg-menu-item:active { background: #f0f0f0; }
.msg-menu-item.danger { color: #e64340; }
.edit-input {
  width: 100%; box-sizing: border-box; border: 1px solid #ccc; border-radius: 8px;
  padding: 6px 8px; font-size: 14px; font-family: inherit; resize: none;
  min-height: 40px; background: #fff; color: #000;
}
.edit-btns { display: flex; gap: 6px; margin-top: 6px; }
.edit-btns button { flex: 1; border: none; border-radius: 8px; padding: 6px 0; font-size: 12px; cursor: pointer; }
.edit-btns button:first-child { background: #07c160; color: #fff; }
.edit-btns button:last-child { background: #eee; color: #333; }

/* 轻提示 */
.toast {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,0.78); color: #fff; font-size: 13px;
  padding: 10px 18px; border-radius: 999px; z-index: 2000;
  opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none;
  max-width: 80%; text-align: center; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 左卡：角色信息（桌面端 sidebar 内） */
.info-char { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.info-char .info-avatar {
  width: 72px; height: 72px; border-radius: 50%; background: #fff;
  font-size: 36px; display: flex; align-items: center; justify-content: center;
  overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}
.info-char .info-avatar img { width: 100%; height: 100%; object-fit: cover; }
.info-char .info-name { font-size: 17px; font-weight: 700; margin-top: 4px; }
.info-char .info-gender { font-size: 12px; color: rgba(255,255,255,0.7); }
.info-char .info-setting {
  font-size: 12px; line-height: 1.7; color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.1); border-radius: 12px; padding: 10px;
  margin-top: 6px; width: 100%;
}

/* 右卡：角色状态（桌面端显示，手机端隐藏） */
.status-side {
  display: none;
  width: 220px; flex-shrink: 0;
  background: #f0f4fa; border-left: 1px solid #e0e0e0;
  padding: 16px; overflow-y: auto;
}
@media (min-width: 768px) { .status-side { display: block; } }
.status-head { font-size: 13px; font-weight: 700; color: #555; margin-bottom: 12px; }
.status-body { display: flex; flex-direction: column; gap: 10px; }
.status-item {
  background: #fff; border-radius: 12px; padding: 10px 12px;
  font-size: 12px; color: #555; box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* 中间聊天卡：输入区 + 弹出菜单 */
.input-wrap { position: relative; }
.chat-popup {
  position: absolute; bottom: calc(100% + 8px); left: 12px; right: 12px;
  background: #fff; border-radius: 14px; box-shadow: 0 8px 28px rgba(0,0,0,0.16);
  padding: 12px; z-index: 60;
}
.chat-popup .popup-title { font-size: 12px; color: #999; margin-bottom: 10px; }
.chat-popup-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.chat-popup-grid .popup-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: none; background: #f7f9fc; border-radius: 10px; padding: 8px 2px;
  font-size: 11px; color: #555; cursor: pointer; font-family: inherit;
}
.chat-popup-grid .popup-item .pi-icon { font-size: 22px; }
.chat-popup-grid .popup-item:active { background: #eef2f7; }
.chat-popup-emoji { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.chat-popup-emoji button {
  border: none; background: none; font-size: 24px; cursor: pointer; padding: 4px;
  font-family: inherit;
}
.chat-popup-emoji button:active { background: #f0f4fa; border-radius: 8px; }
.chat-menu-btn, .chat-emoji-btn {
  border: none; background: #fff; border-radius: 50%;
  width: 38px; height: 38px; font-size: 18px; cursor: pointer;
  flex-shrink: 0; box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  line-height: 1;
}
.chat-menu-btn:active, .chat-emoji-btn:active { background: #eef2f7; }

/* 左右卡双视图切换 */
.side-view { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
.side-switch-btn {
  margin-top: auto; width: 100%; border: none; cursor: pointer;
  background: rgba(255,255,255,0.14); color: #fff; border-radius: 10px;
  padding: 9px 0; font-size: 13px; font-family: inherit; flex-shrink: 0;
}
.side-switch-btn:active { background: rgba(255,255,255,0.24); }

/* 桌面端：三张独立浮动卡片（居中 / 限宽 / 20:60:20 / 圆角 / 阴影） */
@media (min-width: 768px) {
  /* 工作区：两侧各留白约 60px，水平居中，卡片间距 46px */
  #chatDetailView .chat-cards {
    width: calc(100% - 120px);
    max-width: none;
    margin-left: auto; margin-right: auto;   /* 水平居中 */
    gap: 46px; padding: 12px;
  }
  /* 三栏：25 : 50 : 25（中间卡 50% 固定，两侧卡各平分剩余） */
  #chatDetailView .sidebar,
  #chatDetailView .status-side,
  #chatDetailView .chat-panel {
    width: auto; flex-shrink: 1;
  }
  #chatDetailView .sidebar { flex: 1 1 0; min-width: 150px; }
  #chatDetailView .chat-panel { flex: 0 1 50%; min-width: 380px; }
  #chatDetailView .status-side { flex: 1 1 0; min-width: 150px; }

  #chatDetailView .sidebar {
    border-radius: 18px; box-shadow: 0 10px 28px rgba(56, 77, 115, 0.14);
  }
  #chatDetailView .chat-panel {
    border-radius: 18px; box-shadow: 0 10px 28px rgba(56, 77, 115, 0.14);
    overflow: hidden; background: #f7f9fc;
  }
  #chatDetailView .status-side {
    display: flex; flex-direction: column;
    border-radius: 18px; box-shadow: 0 10px 28px rgba(56, 77, 115, 0.14);
    background: #fff;
  }
  #chatDetailView .status-side .side-switch-btn { background: #eef2f7; color: #555; }
  #chatDetailView .status-side .side-switch-btn:active { background: #e2e8f0; }
}

/* 桌面端功能区一行三栏：返回键 | 子导航居中 | 标题靠右 */
.zone-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: #ededed;
  border-bottom: 1px solid #d5d5d5; flex-shrink: 0;
}
.zone-header .back-btn {
  position: static; flex-shrink: 0; margin-left: -6px;
}
.zone-header .chat-subnav {
  flex: 1; min-width: 0; order: 0;
  padding: 0; background: transparent;
  border: none; justify-content: center; gap: 6px;
}
.zone-header .subnav-item {
  flex: none; padding: 7px 14px; font-size: 12px;
}
.zone-header .zone-title {
  position: static; /* 覆盖 .header > span 的 absolute，回到 flex 流靠右 */
  flex-shrink: 0; font-size: 14px; font-weight: 700; color: #333;
  white-space: nowrap;
}
/* 桌面/手机双版 header：桌面显示 zone-header，手机显示原版 */
.desktop-only { display: none !important; }
.mobile-only { display: flex; }
@media (min-width: 768px) {
  .desktop-only { display: flex !important; }
  .mobile-only { display: none !important; }
}

#chatView, #momentsView, #chatDetailView { flex-direction: column; background: #f0f4fa; }
/* 聊天详情：顶部导航栏占整行，下方三张浮动卡片横向排列 */
#chatDetailView .chat-cards {
  flex: 1; min-height: 0; display: flex; flex-direction: row;
}
/* 子导航：手机端在底部，桌面端在顶部 */
.chat-subnav {
  display: flex; gap: 6px; padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid #e8e8e8;
  order: 2; flex-shrink: 0;
}
.subnav-item {
  flex: 1; border: none; cursor: pointer; font-family: inherit;
  background: #f1f3f5; border-radius: 10px; padding: 9px 0;
  font-size: 13px; color: #555;
}
.subnav-item.active { background: #07c160; color: #fff; }
.chat-sub {
  flex: 1; min-height: 0; display: none; flex-direction: column; order: 1;
}
.chat-sub.active { display: flex; }
.sub-head {
  padding: 14px 16px 6px; font-size: 18px; font-weight: 700; color: #333;
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
}
.rolelist-body {
  flex: 1; overflow-y: auto; padding: 10px 16px 20px;
  display: flex; flex-direction: column; gap: 10px;
}
.rolelist-body .role-card { cursor: pointer; transition: box-shadow 0.15s; }
.rolelist-body .role-card:hover { box-shadow: 0 6px 18px rgba(0,0,0,0.10); }
@media (min-width: 768px) {
  .chat-subnav {
    order: 0; border-top: none; border-bottom: 1px solid #e8e8e8;
    justify-content: center; gap: 8px; padding: 10px 16px;
  }
  .subnav-item { flex: none; padding: 8px 22px; }
  .rolelist-body {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px; align-content: start;
  }
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ============ 手机端聊天页改造（第一阶段） ============ */
/* 手机顶部导航 ☰ 按钮（居中标题右侧） */
.drawer-open-btn {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; font-size: 24px; color: #333; cursor: pointer;
  padding: 4px 8px; border-radius: 8px; line-height: 1; z-index: 2;
}
.drawer-open-btn:active { background: rgba(0,0,0,0.08); }

/* 聊天消息行（气泡 + 角色头像），供手机端区分来源 */
.bubble-row { display: flex; align-items: flex-end; gap: 8px; width: 100%; }
.bubble-row.user-row { justify-content: flex-end; }
.bubble-row.oc-row { justify-content: flex-start; }
.bubble-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: #eef4ff;
  overflow: hidden; align-items: center; justify-content: center;
  font-size: 15px; flex-shrink: 0; display: none;
}
.bubble-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* 手机端：隐藏模型配置条与角色横条（角色切换走侧滑菜单），突出聊天 */
@media (max-width: 767px) {
  .model-bar { display: none; }
  .char-strip { display: none; }
  .bubble-avatar { display: flex; }
  /* 手机端：表情菜单改 4 列，图标居中且不溢出面板 */
  .chat-popup-emoji { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .chat-popup-emoji button {
    display: flex; align-items: center; justify-content: center;
    font-size: 26px; padding: 6px 4px; line-height: 1; overflow: hidden;
  }
}
/* 桌面端：聊天头像由"角色设置"里的开关控制（body.show-chat-avatar 时显示） */
@media (min-width: 768px) {
  body.show-chat-avatar .bubble-avatar { display: flex; }
}

/* 角色设置里的模型选择 / 头像开关 */
.status-select {
  width: 100%; margin-top: 6px; border: 1px solid #e0e0e0; border-radius: 8px;
  padding: 7px 8px; font-size: 13px; background: #fff; color: #333;
}
.status-toggle {
  margin-top: 6px; border: none; cursor: pointer;
  background: #eef2f7; border-radius: 8px; padding: 7px 12px; font-size: 13px; color: #555;
}
.status-toggle.on { background: #07c160; color: #fff; }
.status-label { font-size: 12px; color: #999; }

/* 手机端左侧角色切换菜单 */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  z-index: 1200; display: none; opacity: 0; transition: opacity 0.25s;
}
.drawer-mask.open { display: block; opacity: 1; }
.char-drawer {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: min(240px, 70%);
  background: #fff; z-index: 1300; overflow: hidden;
  display: none;                /* 默认彻底隐藏，避免被 flex/定位泄漏到页面侧边 */
  transform: translateX(-100%);
  box-shadow: 4px 0 24px rgba(0,0,0,0.15);
}
.char-drawer.open { display: block; transform: translateX(0); animation: drawerIn 0.28s ease; }
@keyframes drawerIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }

/* 角色设置面板（右侧滑入，与左侧角色列表对称） */
.settings-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  z-index: 1200; display: none; opacity: 0; transition: opacity 0.25s;
}
.settings-mask.open { display: block; opacity: 1; }
.char-settings-panel {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: min(240px, 70%);
  background: #fff; z-index: 1300; overflow: hidden;
  display: none; transform: translateX(100%);
  box-shadow: -4px 0 24px rgba(0,0,0,0.15);
}
.char-settings-panel.open { display: block; transform: translateX(0); animation: settingsIn 0.28s ease; }
@keyframes settingsIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.settings-head {
  padding: 16px; font-weight: 700; color: #333;
  border-bottom: 1px solid #eee;
}
.settings-char {
  padding: 14px 16px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid #f5f5f5;
}
.settings-char .sc-avatar {
  width: 48px; height: 48px; border-radius: 50%; background: #eef4ff;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  font-size: 24px; flex-shrink: 0;
}
.settings-char .sc-avatar img { width: 100%; height: 100%; object-fit: cover; }
.settings-char .sc-name { font-size: 15px; font-weight: 700; color: #333; }
.settings-list { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.settings-item {
  background: #f5f7fa; border-radius: 12px; padding: 11px 12px;
  font-size: 13px; color: #555;
}

/* 角色实时状态弹窗（点击角色头像打开，点空白关闭） */
.status-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 1400; display: none; align-items: center; justify-content: center; padding: 20px;
}
.status-overlay.open { display: flex; }
.status-card {
  width: 100%; max-width: 300px;
  background: #fffdf4; border-radius: 14px; padding: 24px 20px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.22);
  text-align: center;
}
.status-card .sc-avatar-lg {
  width: 72px; height: 72px; border-radius: 50%; background: #eef4ff;
  margin: 0 auto 8px; display: flex; align-items: center; justify-content: center;
  font-size: 36px; overflow: hidden;
}
.status-card .sc-avatar-lg img { width: 100%; height: 100%; object-fit: cover; }
.status-card .sc-name-lg { font-size: 16px; font-weight: 700; color: #333; margin-bottom: 16px; }
.status-row {
  text-align: left; background: rgba(255,255,255,0.65);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
}
.status-row .status-label { font-size: 12px; color: #999; }
.status-row .status-value { font-size: 14px; color: #444; margin-top: 2px; }
.drawer-head {
  padding: 16px; font-weight: 700; color: #333;
  border-bottom: 1px solid #eee;
}
.drawer-char-list { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.drawer-char-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: none; background: #f5f7fa; border-radius: 12px;
  padding: 10px; cursor: pointer; font-family: inherit; text-align: left;
}
.drawer-char-item.active { background: #e8f9ef; box-shadow: inset 0 0 0 1px #07c160; }
.drawer-char-item .dc-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: #fff;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  font-size: 20px; flex-shrink: 0;
}
.drawer-char-item .dc-avatar img { width: 100%; height: 100%; object-fit: cover; }
.drawer-char-item .dc-name { font-size: 14px; color: #333; }
