:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e4e7ec;
  --text: #1f2329;
  --text-2: #5c6470;
  --text-3: #98a1ae;
  --brand: #2563eb;
  --brand-soft: #eef3ff;
  --danger: #d92d20;
  --danger-soft: #fef3f2;
  --ok: #067647;
  --ok-soft: #ecfdf3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }

button { cursor: pointer; }

a { color: var(--brand); text-decoration: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { background: #fafbfc; border-color: #d3d8e0; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-danger { color: var(--danger); border-color: #f3c6c2; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; border-radius: 6px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: #f0f2f5; }

.input, .textarea, .select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 11px;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 100px;
  font-size: 12px;
  background: #f0f2f5;
  color: var(--text-2);
  white-space: nowrap;
}
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-off { background: #f4f4f5; color: var(--text-3); }
.tag-warn { background: #fffaeb; color: #b54708; }

.muted { color: var(--text-3); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------------- 登录页 ---------------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #f7f9fc 0%, #eef1f6 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, .08);
  padding: 32px 28px;
}
.login-card h1 { margin: 0 0 6px; font-size: 20px; font-weight: 600; }
.login-card .sub { color: var(--text-3); margin-bottom: 22px; font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.form-error {
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

/* ---------------- 对话页 ---------------- */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
}
.side {
  background: #fbfcfd;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-head {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.brand-dot {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.side-body { flex: 1; overflow-y: auto; padding: 10px; }
.side-title { font-size: 12px; color: var(--text-3); padding: 6px 6px 8px; }
.hist-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-2);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hist-item:hover { background: #f1f3f7; color: var(--text); }
.side-foot { border-top: 1px solid var(--line); padding: 10px 12px; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; flex: none;
}

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .8);
  backdrop-filter: blur(6px);
}
.topbar h2 { font-size: 14px; font-weight: 600; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-scroll { flex: 1; overflow-y: auto; padding: 24px 20px 8px; }
.chat-inner { max-width: 760px; margin: 0 auto; }

.msg { display: flex; gap: 10px; margin-bottom: 20px; }
.msg.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.msg.user .msg-avatar { background: #e8edf7; color: #35507d; }
.msg.bot .msg-avatar { background: var(--brand-soft); color: var(--brand); }
.bubble {
  max-width: 82%;
  padding: 11px 14px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
  line-height: 1.7;
}
.msg.user .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot .bubble {
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}
.msg.bot .bubble.error { background: var(--danger-soft); border-color: #f7d4d1; color: #912018; }
.msg-tools { margin-top: 6px; display: flex; gap: 12px; opacity: .75; }
.msg-tools button {
  border: 0; background: none; padding: 0; color: var(--text-3); font-size: 12px;
}
.msg-tools button:hover { color: var(--brand); }

.img-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.img-card {
  width: 216px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  cursor: zoom-in;
}
.img-card img { width: 100%; height: 138px; object-fit: cover; display: block; background: #f4f5f7; }
.img-card .cap { padding: 6px 8px; font-size: 12px; color: var(--text-2); line-height: 1.4; }

.typing { display: inline-flex; gap: 4px; align-items: center; color: var(--text-3); }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: #b8c0cc;
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer { border-top: 1px solid var(--line); background: #fff; padding: 12px 20px 16px; }
.composer-inner { max-width: 760px; margin: 0 auto; }
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 8px 8px 12px;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.composer-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
.composer textarea {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  max-height: 132px;
  min-height: 24px;
  line-height: 1.6;
  padding: 4px 0;
  background: transparent;
}
.composer-hint { display: flex; justify-content: space-between; margin-top: 6px; color: var(--text-3); font-size: 12px; }

.empty {
  text-align: center;
  color: var(--text-3);
  padding: 48px 0 24px;
}
.empty h3 { color: var(--text-2); font-weight: 600; font-size: 16px; margin: 0 0 6px; }
.suggests { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.suggest {
  border: 1px solid var(--line); background: #fff; border-radius: 100px;
  padding: 6px 14px; font-size: 13px; color: var(--text-2);
}
.suggest:hover { border-color: #c8d3ea; color: var(--brand); background: var(--brand-soft); }

/* 图片放大 */
.lightbox {
  position: fixed; inset: 0; background: rgba(12, 16, 24, .78);
  display: flex; align-items: center; justify-content: center;
  z-index: 60; padding: 32px; cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 88vh; border-radius: 6px; background: #fff; }

/* ---------------- 后台 ---------------- */
.admin { min-height: 100vh; display: flex; flex-direction: column; }
.admin-top {
  height: 56px; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 20;
}
.admin-body { flex: 1; padding: 20px 24px 48px; max-width: 1180px; width: 100%; margin: 0 auto; }
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tab {
  border: 0; background: none; padding: 10px 14px; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 14px;
}
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .k { color: var(--text-3); font-size: 12px; }
.stat .v { font-size: 22px; font-weight: 600; margin-top: 2px; }

.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card-body { padding: 14px 16px; }
.card-body.scroll { max-height: 560px; overflow: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid #f0f2f5; vertical-align: top; }
th { color: var(--text-3); font-weight: 500; font-size: 12px; background: #fafbfc; position: sticky; top: 0; }
tr:hover td { background: #fafbfc; }
td.wrap { max-width: 420px; word-break: break-word; }
.actions { display: flex; gap: 6px; flex-wrap: nowrap; align-items: center; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 440px;
  box-shadow: 0 20px 40px rgba(16, 24, 40, .18); overflow: hidden;
}
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 600; }
.modal-body { padding: 16px 18px; max-height: 62vh; overflow: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #1f2329; color: #fff; padding: 8px 16px; border-radius: 8px;
  font-size: 13px; z-index: 80; opacity: 0; transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .bubble { max-width: 88%; }
  .chat-scroll { padding: 16px 12px 4px; }
  .composer { padding: 10px 12px 14px; }
  .img-card { width: calc(50% - 5px); }
}
