:root {
  --green: #07c160;
  --green-dark: #06ad56;
  --rail-bg: #2e2e2e;
  --rail-bg-hover: #3d3d3d;
  --list-bg: #ededed;
  --chat-bg: #f5f5f5;
  --white: #ffffff;
  --border: #e2e2e2;
  --text: #1a1a1a;
  --text-sub: #999999;
  --bubble-out: #95ec69;
  --bubble-in: #ffffff;
  --danger: #e64340;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  font-size: 14px;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ============ 登录页 ============ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f0f2f5 0%, #e6ebf0 100%);
}
.login-card {
  width: 380px;
  background: #fff;
  border-radius: 14px;
  padding: 40px 36px 32px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
  text-align: center;
}
.login-logo { margin-bottom: 12px; }
.login-title { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.login-subtitle { font-size: 13px; color: var(--text-sub); margin-bottom: 26px; }
.login-form { text-align: left; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: #666; margin-bottom: 6px; }
.field input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color .15s;
}
.field input:focus { border-color: var(--green); }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* ============ 通用按钮 ============ */
.btn-primary {
  background: var(--green);
  color: #fff;
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 14px;
  transition: background .15s;
}
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-ghost {
  background: #fff;
  color: #333;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  transition: all .15s;
}
.btn-ghost:hover { border-color: var(--green); color: var(--green); }
.btn-danger { color: var(--danger); border-color: #f0c0bf; }
.btn-danger:hover { background: #fff5f5; border-color: var(--danger); color: var(--danger); }
.login-form .btn-primary { width: 100%; height: 44px; font-size: 15px; }

/* ============ 主布局 ============ */
.app-page { overflow: hidden; }
.app { display: flex; height: 100vh; }

.nav-rail {
  width: 62px;
  background: var(--rail-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 0;
  gap: 8px;
  flex-shrink: 0;
}
.rail-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 16px;
  margin-bottom: 14px;
  user-select: none;
}
.rail-btn {
  width: 42px; height: 42px;
  border-radius: 8px;
  color: #9a9a9a;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.rail-btn:hover { background: var(--rail-bg-hover); color: #fff; }
.rail-btn.active { color: var(--green); }
.rail-spacer { flex: 1; }

.main { flex: 1; position: relative; overflow: hidden; background: var(--chat-bg); }
.view { display: none; height: 100%; }
.view.active { display: flex; }

/* ============ 会话列表 ============ */
.conv-panel {
  width: 290px;
  background: var(--list-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.conv-head { padding: 14px 14px 10px; }
.conv-head-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.conv-title { font-size: 16px; font-weight: 600; }
.bot-filter {
  border: none; background: transparent; color: #666;
  font-size: 13px; outline: none; cursor: pointer;
  max-width: 150px;
}
.search-box input {
  width: 100%; height: 32px; border-radius: 6px; border: none;
  background: #dcdcdc; padding: 0 10px; outline: none;
}
.search-box input:focus { background: #fff; }

.conv-list { flex: 1; overflow-y: auto; }
.conv-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; cursor: pointer; position: relative;
  transition: background .12s;
}
.conv-item:hover { background: #e4e4e4; }
.conv-item.active { background: #c9c9c9; }
.conv-avatar {
  width: 42px; height: 42px; border-radius: 6px; flex-shrink: 0;
  background: linear-gradient(135deg, #8fd4a8, #07c160);
  color: #fff; font-size: 17px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.conv-main { flex: 1; min-width: 0; }
.conv-row { display: flex; justify-content: space-between; align-items: baseline; }
.conv-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--text-sub); flex-shrink: 0; margin-left: 6px; }
.conv-preview {
  font-size: 12px; color: var(--text-sub); margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; justify-content: space-between; align-items: center;
}
.conv-bot-tag {
  font-size: 10px; color: #fff; background: #b9b9b9;
  border-radius: 3px; padding: 1px 4px; margin-right: 5px; flex-shrink: 0;
}
.conv-badge {
  background: var(--danger); color: #fff; font-size: 11px;
  min-width: 18px; height: 18px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px; flex-shrink: 0;
}
.empty-tip { text-align: center; color: var(--text-sub); font-size: 13px; padding: 40px 20px; }

/* ============ 聊天区 ============ */
.chat-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; color: #b5b5b5; gap: 14px;
}
.chat-content { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header {
  height: 58px; background: #f5f5f5; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; flex-shrink: 0;
}
.chat-header-title { font-size: 16px; font-weight: 600; }
.chat-header-sub { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.icon-btn { color: #666; padding: 6px; border-radius: 6px; display: flex; }
.icon-btn:hover { background: #e6e6e6; }
.chat-header-actions { display: flex; align-items: center; gap: 8px; }
.chat-unread-tip {
  font-size: 12px; color: #fff; background: var(--danger);
  border-radius: 10px; padding: 2px 8px; white-space: nowrap;
}
.chat-unread-tip:empty { display: none; }
.btn-read {
  display: inline-flex; align-items: center; gap: 4px;
  height: 30px; padding: 0 12px; border-radius: 6px;
  background: var(--green); color: #fff; font-size: 13px;
  transition: background .15s; white-space: nowrap;
}
.btn-read:hover { background: var(--green-dark); }
.btn-read:disabled { opacity: .6; cursor: not-allowed; }

.msg-status { margin-left: 5px; font-size: 11px; }
.msg-status.unread { color: var(--danger); }
.msg-status.read { color: var(--green); }
.msg-status.sent { color: var(--text-sub); }

.chat-body {
  flex: 1; overflow-y: auto; padding: 18px 22px;
  display: flex; flex-direction: column; gap: 14px;
}
.msg-row { display: flex; align-items: flex-start; gap: 10px; max-width: 72%; }
.msg-row.out { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar {
  width: 36px; height: 36px; border-radius: 5px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600; color: #fff; overflow: hidden;
}
.msg-row.in .msg-avatar { background: linear-gradient(135deg, #7cc3f5, #4a90d9); }
.msg-row.out .msg-avatar { background: linear-gradient(135deg, #8fd4a8, #07c160); }
.msg-col { display: flex; flex-direction: column; gap: 4px; }
.msg-row.out .msg-col { align-items: flex-end; }
.msg-bubble {
  background: var(--bubble-in); border-radius: 8px; padding: 9px 13px;
  line-height: 1.5; word-break: break-word; white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(0,0,0,.05); position: relative;
}
.msg-row.out .msg-bubble { background: var(--bubble-out); }
.msg-meta { font-size: 11px; color: var(--text-sub); }
.msg-media img { max-width: 240px; border-radius: 6px; display: block; }
.msg-media audio { max-width: 240px; }
.msg-media video { max-width: 260px; border-radius: 6px; display: block; }
.chat-day { text-align: center; font-size: 11px; color: var(--text-sub); margin: 4px 0; }

.chat-input {
  border-top: 1px solid var(--border); background: #fafafa;
  padding: 10px 16px; display: flex; gap: 10px; align-items: flex-end;
  flex-shrink: 0;
}
.attach-btn {
  width: 34px; height: 36px; flex-shrink: 0; margin-bottom: 2px;
  display: flex; align-items: center; justify-content: center;
  color: #666; border-radius: 6px;
}
.attach-btn:hover { background: #e6e6e6; color: #333; }
.attach-btn:disabled { opacity: .5; cursor: not-allowed; }
.chat-input textarea {
  flex: 1; height: 70px; resize: none; border: none; outline: none;
  background: transparent; padding: 6px 4px; line-height: 1.5;
}
.send-btn { height: 36px; padding: 0 22px; margin-bottom: 2px; }

/* ============ 管理面板 ============ */
.admin-panel { flex: 1; display: flex; flex-direction: column; background: var(--chat-bg); }
.admin-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; border-bottom: 1px solid var(--border); background: #fff;
}
.admin-head h2 { font-size: 17px; }
.admin-body { flex: 1; overflow-y: auto; padding: 24px 28px; }

.bot-list { display: flex; flex-direction: column; gap: 14px; max-width: 900px; }
.bot-card {
  background: #fff; border-radius: 10px; padding: 18px 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap;
}
.bot-card-main { flex: 1; min-width: 260px; }
.bot-card-name { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.bot-card-name .dot { width: 8px; height: 8px; border-radius: 50%; background: #bbb; }
.bot-card-name .dot.on { background: var(--green); }
.bot-card-name .dot.off { background: #d0d0d0; }
.bot-meta { font-size: 12.5px; color: #666; margin-top: 8px; line-height: 1.9; }
.bot-meta code {
  background: #f2f2f2; padding: 1px 5px; border-radius: 4px;
  font-family: "SFMono-Regular", Consolas, monospace; word-break: break-all;
}
.bot-card-actions { display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 4px; background: #eef7f1; color: var(--green); }
.tag.warn { background: #fdf3e3; color: #c47f16; }
.tag.off { background: #f2f2f2; color: #888; }

/* ============ 设置表单 ============ */
.settings-form { max-width: 720px; display: flex; flex-direction: column; gap: 20px; }
.settings-group {
  background: #fff; border-radius: 10px; padding: 20px 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.settings-group h3 { font-size: 15px; margin-bottom: 6px; }
.settings-group .hint { font-size: 12.5px; color: var(--text-sub); margin-bottom: 14px; }
.form-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.form-row label { width: 130px; flex-shrink: 0; font-size: 13.5px; color: #444; }
.form-row input[type=text], .form-row input[type=password], .form-row input[type=number] {
  flex: 1; height: 36px; padding: 0 10px; border: 1px solid var(--border);
  border-radius: 6px; outline: none; background: #fff;
}
.form-row input:focus { border-color: var(--green); }
.form-row input[type=number] { max-width: 140px; }
.form-row .unit { font-size: 12.5px; color: var(--text-sub); }
.switch-row { justify-content: flex-start; }
.switch-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--green); cursor: pointer; }

/* ============ 弹窗 ============ */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal {
  width: 520px; max-width: 92vw; background: #fff; border-radius: 12px;
  max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; }
.modal-close { font-size: 24px; color: #999; line-height: 1; padding: 0 4px; }
.modal-close:hover { color: #333; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-body .form-row label { width: 150px; }
.modal-body .form-row input[type=text] { width: 100%; }
.modal-body .form-row { flex-direction: column; align-items: stretch; gap: 6px; }
.modal-body .form-row label { width: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}

/* ============ Toast ============ */
.toast {
  position: fixed; top: 24px; left: 50%; transform: translateX(-50%) translateY(-20px);
  background: rgba(0,0,0,.8); color: #fff; padding: 10px 20px; border-radius: 8px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 2000;
  max-width: 70vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: rgba(200,50,50,.92); }
.toast.success { background: rgba(7,193,96,.95); }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.3); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 720px) {
  .conv-panel { width: 100%; }
  .chat-panel { display: none; }
  .main.mobile-chat .conv-panel { display: none; }
  .main.mobile-chat .chat-panel { display: flex; }
}
