/* MossChat · 模思 —— 统一手机模式布局
 * 电脑端与手机端一致：单列全屏应用壳（居中限宽）+ 列表/聊天全屏切换 +
 * 聊天界面上下分屏：上半对话（消息+输入），下半常驻 AI 辅助面板。
 * 所有设备体验等同手机聊天 App。 */
:root {
  --brand: #07c160;
  --brand-dark: #06ad56;
  --bubble-own: #95ec69;
  --bubble-peer: #ffffff;
  --bg: #efeff1;
  --border: #e6e6e6;
  --text: #1a1a1a;
  --text-sub: #999;
  --danger: #fa5151;
  --header-h: 52px;
  --shell-w: 560px; /* 桌面端应用壳限宽 */
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background: #e2e5ea;
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, .peer-item, .sugg-item, .ai-entry, .retry, .back-btn, .icon-btn { touch-action: manipulation; }

/* —— 登录视图 —— */
#view-login {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #f3faf6 0%, #e6f4ec 100%);
  padding: 24px 12px;
}
.login-card {
  width: min(92vw, 380px); background: #fff; border-radius: 14px;
  padding: 28px 22px; box-shadow: 0 8px 32px rgba(0,0,0,.08);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand h1 { font-size: 25px; color: var(--brand); letter-spacing: 1px; }
.login-brand .sub { color: var(--text-sub); font-size: 12px; margin-top: 4px; }
.login-card .field { margin-bottom: 14px; }
.login-card label { display: block; font-size: 12px; color: var(--text-sub); margin-bottom: 6px; }
.login-card input {
  width: 100%; height: 46px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 16px; /* 防 iOS 聚焦缩放 */
  outline: none; transition: border-color .15s;
}
.login-card input:focus { border-color: var(--brand); }
.login-tip { min-height: 20px; font-size: 12px; color: var(--danger); margin-bottom: 10px; word-break: break-all; }
.login-actions { display: flex; gap: 12px; }
.btn {
  flex: 1; height: 46px; border: none; border-radius: 8px;
  font-size: 15px; cursor: pointer; user-select: none; transition: background .15s;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: #f2f2f2; color: var(--text); }
.btn-ghost:hover { background: #e6e6e6; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* —— 内置测试账号快捷登录 —— */
.qa-divider { display: flex; align-items: center; gap: 10px; margin: 20px 0 12px; color: var(--text-sub); font-size: 12px; }
.qa-divider::before, .qa-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.qa-list { display: flex; flex-direction: column; gap: 8px; }
.qa-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 12px 14px; background: #f7f9fb; border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer; color: var(--text); transition: border-color .15s, background .15s;
}
.qa-btn:hover { border-color: var(--brand); background: #eef8f2; }
.qa-btn:active { background: #e6f3ec; }
.qa-name { font-weight: 600; font-size: 15px; flex-shrink: 0; color: var(--brand); }
.qa-sub { font-size: 12px; color: var(--text-sub); flex: 1; }

/* —— 主视图：单列应用壳 —— */
#view-chat { display: none; height: 100%; }
#view-chat.show {
  display: flex; position: relative;
  width: 100%; max-width: var(--shell-w); margin: 0 auto;
  overflow: hidden; background: #fff;
  box-shadow: 0 0 24px rgba(0,0,0,.10);
}

/* —— 会话列表：全屏抽屉（进入聊天后滑出）—— */
.sidebar {
  position: absolute; top: 0; bottom: 0; left: 0; width: 100%;
  z-index: 30; background: #fff;
  display: flex; flex-direction: column;
  transform: translateX(0); transition: transform .24s ease;
}
#view-chat.in-chat .sidebar { transform: translateX(-100%); }
.sidebar-head {
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 14px 0; display: flex; align-items: center;
  gap: 8px; border-bottom: 1px solid var(--border);
}
.sidebar-head .me { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-head .btn-settings { border: none; background: none; cursor: pointer; font-size: 18px; color: var(--text-sub); padding: 8px; line-height: 1; border-radius: 8px; }
.sidebar-head .btn-settings:hover { color: var(--text); }
.sidebar-head .logout { border: none; background: none; color: var(--text-sub); cursor: pointer; font-size: 14px; padding: 6px 8px; border-radius: 8px; }
.sidebar-head .logout:hover { color: var(--danger); }
.ai-entry {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  cursor: pointer; border-bottom: 1px solid #f5f5f5; user-select: none;
  font-weight: 600; color: #7b3f00;
}
.ai-entry:hover { background: #f7f7f7; }
.ai-entry.active { background: #ececec; }
.ai-entry .ai-icon { font-size: 16px; flex-shrink: 0; }
.online-title { padding: 12px 16px 8px; font-size: 12px; color: var(--text-sub); }
#online-list { flex: 1; overflow-y: auto; }
.peer-item {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  cursor: pointer; border-bottom: 1px solid #f5f5f5; user-select: none;
}
.peer-item:hover { background: #f7f7f7; }
.peer-item.active { background: #ececec; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); flex-shrink: 0; }
.peer-item .name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-item .tag { font-size: 11px; color: var(--text-sub); }
.badge-unread {
  min-width: 18px; height: 18px; border-radius: 9px; background: var(--danger);
  color: #fff; font-size: 11px; line-height: 18px; text-align: center; padding: 0 5px;
}
.empty-tip { padding: 32px 16px; color: var(--text-sub); font-size: 13px; text-align: center; }

/* —— 聊天区 —— */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; width: 100%; }
.chat-head {
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 10px 0; display: flex; align-items: center;
  gap: 6px; background: #fff; border-bottom: 1px solid var(--border);
  flex-shrink: 0; z-index: 5;
}
.back-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex-shrink: 0; margin-left: -8px;
  border: none; background: none; color: var(--text); border-radius: 8px;
  font-size: 28px; line-height: 1;
}
.back-btn:active { background: #f0f0f0; }
.chat-head .peer-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.chat-head .state { font-size: 11px; color: var(--text-sub); max-width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .state.fail { color: var(--danger); }
.chat-head .retry {
  flex-shrink: 0; height: 32px; padding: 0 12px; font-size: 12px;
  border: 1px solid var(--brand); color: var(--brand); background: #fff;
  border-radius: 16px; cursor: pointer;
}
.chat-head .retry:hover { background: #e8f8ef; }

/* —— 聊天上部（消息 + 输入框，占上半屏）—— */
.chat-main { flex: 1 1 0; min-height: 0; min-width: 0; position: relative; display: flex; flex-direction: column; background: var(--bg); }
#msg-list { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 10px; background: var(--bg); }
.no-chat { height: 100%; display: flex; align-items: center; justify-content: center; color: var(--text-sub); font-size: 13px; padding: 0 24px; text-align: center; }
.msg { display: flex; margin-bottom: 12px; }
.msg.own { justify-content: flex-end; }
.msg .bubble {
  max-width: 75%; padding: 10px 12px; border-radius: 8px; font-size: 15px;
  line-height: 1.5; word-break: break-word; white-space: pre-wrap; position: relative;
}
.msg.own .bubble { background: var(--bubble-own); }
.msg.peer .bubble { background: var(--bubble-peer); box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.msg.peer .bubble.ai-error { background: #fff3f3; color: var(--danger); border: 1px solid #ffd9d9; }

.chat-input-wrap {
  background: #fff; border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  display: flex; gap: 10px; align-items: flex-end; flex-shrink: 0;
}
.chat-input-wrap textarea {
  flex: 1; resize: none; height: 44px; max-height: 120px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 16px;
  font-family: inherit; outline: none; line-height: 1.4; background: #fff;
}
.chat-input-wrap textarea:focus { border-color: var(--brand); }
#send-btn { flex-shrink: 0; width: 64px; height: 44px; }

/* —— 聊天下部：常驻 AI 辅助面板（占 2/3 屏，所有设备一致）—— */
.ai-panel {
  flex: 2 1 0; min-height: 0; min-width: 0;
  background: #f7f8fa; border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.panel-head {
  height: var(--header-h); padding: 0 14px; display: flex; align-items: center;
  gap: 8px; border-bottom: 1px solid var(--border); background: #fff;
  flex-shrink: 0;
}
.ai-target {
  margin-left: auto; font-size: 12px; color: var(--text-sub);
  background: #f0f2f5; border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 55%;
}
.panel-title { flex: 1; font-weight: 600; font-size: 14px; }
.icon-btn {
  border: none; background: none; cursor: pointer; font-size: 16px;
  color: var(--text-sub); padding: 8px; border-radius: 8px;
}
.icon-btn:hover { color: var(--brand); background: #e8f8ef; }
.panel-body { flex: 1; overflow-y: auto; padding: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
.panel-sec { margin-bottom: 16px; }
.panel-sec-title { font-size: 12px; color: var(--text-sub); margin-bottom: 6px; }
.panel-text {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 14px; line-height: 1.6; color: var(--text);
  white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow-y: auto;
}
#sugg-list { display: flex; flex-direction: column; gap: 6px; }
.sugg-item {
  display: flex; align-items: flex-start; gap: 8px; text-align: left;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; cursor: pointer; font-size: 14px; line-height: 1.5;
  color: var(--text); transition: border-color .15s;
}
.sugg-item:hover { border-color: var(--brand); }
.sugg-item .sugg-text { flex: 1; word-break: break-word; }
.sugg-item .sugg-style {
  flex-shrink: 0; font-style: normal; font-size: 11px; color: var(--brand);
  background: #e8f8ef; border-radius: 10px; padding: 1px 8px; margin-top: 1px;
}
.sugg-more {
  border: 1px dashed var(--text-sub); background: none; color: var(--text-sub);
  border-radius: 8px; padding: 8px 0; font-size: 13px; cursor: pointer;
}
.sugg-more:hover { border-color: var(--brand); color: var(--brand); }
.chip-hint { font-size: 13px; color: var(--text-sub); line-height: 1.6; }
.ask-tip { color: var(--danger); font-size: 13px; line-height: 1.6; }
.panel-ask #panel-input {
  width: 100%; resize: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 16px; font-family: inherit; outline: none;
  margin-bottom: 8px; line-height: 1.5;
}
.panel-ask #panel-input:focus { border-color: var(--brand); }
.panel-send { flex: none; width: 100%; height: 42px; font-size: 14px; }

.hidden { display: none !important; }

/* —— 设置弹窗：居中卡片（全设备统一）—— */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal-card {
  width: min(92vw, 400px); max-height: 86vh; overflow-y: auto;
  background: #fff; border-radius: 12px;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
}
.modal-card h3 { font-size: 17px; margin-bottom: 16px; }
.modal-card label { display: block; font-size: 13px; color: var(--text-sub); margin: 12px 0 6px; }
.modal-card input {
  width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 16px; outline: none;
}
.modal-card input:focus { border-color: var(--brand); }
.key-state { font-size: 12px; color: var(--brand); }
.modal-card .tip { font-size: 12px; color: var(--text-sub); line-height: 1.6; margin-top: 14px; }
.set-msg { min-height: 18px; font-size: 12px; color: var(--danger); margin-top: 8px; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

/* —— 服务日志弹窗 —— */
.btn-log-link { width: 100%; margin-top: 12px; }
.log-hint { font-size: 12px; color: var(--text-sub); line-height: 1.6; margin-bottom: 10px; }
.log-list { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.log-empty { font-size: 13px; color: var(--text-sub); line-height: 1.6; padding: 12px 0; }
.log-item {
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  background: #fafbfc;
}
.log-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.log-tag {
  font-size: 11px; color: #fff; border-radius: 10px; padding: 1px 8px;
  flex-shrink: 0; line-height: 1.6;
}
.log-tag-suggest { background: #07c160; }
.log-tag-analysis { background: #576b95; }
.log-tag-panel { background: #fa9d3b; }
.log-tag-ai { background: #8e71ff; }
.log-time { font-size: 12px; color: var(--text-sub); }
.log-subject {
  font-size: 12px; color: var(--text-sub); min-width: 0; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right;
}
.log-question {
  font-size: 13px; color: var(--text-sub); line-height: 1.5; margin-bottom: 4px;
  word-break: break-word;
}
.log-conclusion {
  font-size: 13px; color: var(--text); line-height: 1.6; white-space: pre-wrap;
  word-break: break-word; max-height: 140px; overflow-y: auto;
}

/* —— 超高屏微调 —— */
@supports (height: 100dvh) {
  #view-login, #view-chat { height: 100dvh; }
}