* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; background: #f5f5f5; color: #333; }
button, textarea, input { font: inherit; }
button { border: none; background: none; cursor: pointer; }
.hidden { display: none !important; }

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #d9ecff, #f5f5f5);
}
.login-card {
  width: 90%;
  max-width: 360px;
  background: #fff;
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  text-align: center;
}
.login-card h1 { font-size: 22px; margin-bottom: 8px; }
.login-card p { color: #888; margin-bottom: 20px; font-size: 14px; }
.login-card input {
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 14px;
}
.login-card button {
  width: 100%;
  background: #409eff;
  color: #fff;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
}

.agent-app {
  height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.top-bar {
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid #eee;
  position: relative;
  background: #fff;
  flex-shrink: 0;
}
.top-bar span { font-size: 16px; font-weight: 600; }
.back-btn {
  position: absolute;
  left: 8px;
  font-size: 28px;
  line-height: 1;
  color: #409eff;
  padding: 0 8px;
}

.page-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.page {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  display: none;
  background: #fff;
}
.page.active { display: block; }

.conv-list { padding: 0; }
.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #f0f0f0;
}
.conv-item:active { background: #f8f8f8; }
.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #f0f0f0;
  object-fit: cover;
  flex-shrink: 0;
}
img.conv-avatar { display: block; }
.conv-info { flex: 1; min-width: 0; }
.conv-name { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.conv-preview { font-size: 13px; color: #999; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { text-align: right; }
.conv-time { font-size: 12px; color: #bbb; margin-bottom: 6px; }
.unread-badge {
  display: inline-block;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #f56c6c;
  color: #fff;
  font-size: 11px;
  text-align: center;
}

.empty-tip {
  text-align: center;
  color: #bbb;
  padding: 60px 20px;
  font-size: 14px;
}

#pageChat { display: none; flex-direction: column; }
#pageChat.active { display: flex; }
#pageChat .chat-main {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}
.load-tip { text-align: center; color: #bbb; font-size: 13px; margin-bottom: 16px; }
.message-list { display: flex; flex-direction: column; gap: 14px; }

.msg-row { display: flex; align-items: flex-start; gap: 8px; }
.msg-row.incoming { justify-content: flex-start; }
.msg-row.outgoing { justify-content: flex-end; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: #e8e8e8; object-fit: cover; flex-shrink: 0; }
.avatar.default { display: flex; align-items: center; justify-content: center; font-size: 12px; color: #888; }
.msg-body { max-width: 72%; }
.msg-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 12px; }
.msg-row.outgoing .msg-meta { justify-content: flex-end; }
.msg-name { font-weight: 600; color: #222; font-size: 14px; }
.msg-time { color: #aaa; }
.bubble { display: inline-block; padding: 10px 12px; border-radius: 8px; font-size: 15px; line-height: 1.5; word-break: break-word; background: #f2f2f2; }
.msg-row.outgoing .bubble { background: #d9ecff; }
.bubble img { max-width: 200px; border-radius: 6px; display: block; }
.bubble a { color: #1a6fb5; text-decoration: none; }

.input-panel { border-top: 1px solid #e8e8e8; padding: 8px 10px 10px; background: #fff; flex-shrink: 0; position: relative; z-index: 10; }
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; position: relative; z-index: 11; }
.tool-btn { color: #666; padding: 8px; min-width: 40px; min-height: 40px; display: flex; align-items: center; justify-content: center; -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none; }
.tool-btn svg, .tool-btn svg * { pointer-events: none; }
.file-input-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.tool-text { color: #1a6fb5; font-size: 14px; margin-left: 4px; padding: 8px 4px; min-height: 40px; touch-action: manipulation; }
.send-btn { margin-left: auto; background: #7ec8ff; color: #fff; border-radius: 18px; padding: 8px 18px; min-height: 40px; font-size: 14px; touch-action: manipulation; }
#agentInputBox { width: 100%; border: 1px solid #666; border-radius: 2px; padding: 8px 10px; resize: none; outline: none; font-size: 14px; }

.emoji-panel, .quick-panel {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 130px;
  background: #fff;
  border: 1px solid #e8e8e8;
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
  z-index: 20;
  max-height: 180px;
  overflow-y: auto;
}
.emoji-panel { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.emoji-panel button { font-size: 22px; padding: 4px; }
.quick-panel button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid #f0f0f0;
  font-size: 14px;
}

.qr-card { padding: 24px 16px; text-align: center; }
.qr-title { font-size: 16px; font-weight: 600; margin-bottom: 20px; }
#qrCanvas { margin: 0 auto 16px; display: block; }
.link-box {
  background: #f5f7fa;
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  color: #666;
  word-break: break-all;
  margin-bottom: 16px;
  text-align: left;
}

.primary-btn, .secondary-btn, .danger-btn {
  width: 100%;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  margin-bottom: 10px;
}
.primary-btn { background: #409eff; color: #fff; }
.secondary-btn { background: #ecf5ff; color: #409eff; }
.danger-btn { background: #fef0f0; color: #f56c6c; margin: 16px; width: calc(100% - 32px); }

.quick-form, .form-card { padding: 16px; }
.quick-form input, .form-card input, .quick-form textarea, .form-card textarea {
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 12px;
}
.form-card label { display: block; font-size: 13px; color: #666; margin-bottom: 6px; }

.quick-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
}
.quick-item .info { flex: 1; min-width: 0; }
.quick-item .title { font-weight: 600; margin-bottom: 4px; }
.quick-item .content { font-size: 13px; color: #999; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quick-item .del { color: #f56c6c; font-size: 13px; }

.stats-card {
  margin: 16px;
  background: #f5f7fa;
  border-radius: 12px;
  padding: 20px;
}
.stats-card div { display: flex; justify-content: space-between; padding: 8px 0; font-size: 15px; }

.bottom-nav {
  display: flex;
  border-top: 1px solid #eee;
  background: #fff;
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0 6px;
  color: #666;
  font-size: 11px;
}
.nav-item svg { width: 24px; height: 24px; }
.nav-item.active { color: #409eff; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: rgba(0,0,0,.75);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 100;
}
