* { box-sizing: border-box; }

:root {
  --ink: #0c1222;
  --ink-2: #3b4463;
  --muted: #6b7591;
  --line: #e3e7f0;
  --bg: #f4f6fb;
  --card: #ffffff;
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --ok: #0f9d6e;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 18px 40px -28px rgba(12, 18, 34, .45);
}

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: radial-gradient(1100px 520px at 8% -12%, #e8ecff 0%, transparent 62%), var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

a { color: inherit; }

code, pre { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  padding: 0 max(20px, calc((100vw - 1180px) / 2));
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: -.2px;
}

.brand .logo {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 14px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
}

.brand em {
  font-style: normal;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.topbar-right { display: flex; align-items: center; gap: 14px; }
.link { color: var(--muted); text-decoration: none; font-size: 13px; }
.link:hover { color: var(--brand); }
.user-email { color: var(--ink-2); font-size: 13px; }

/* ---------- 按钮 ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  background: #fff;
  color: var(--ink);
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }
.btn-line { border-color: var(--line); color: var(--ink-2); }
.btn-line:hover { border-color: #c9d0e4; }
.btn-small { padding: 5px 10px; font-size: 12.5px; border-color: var(--line); }
.btn.danger { color: var(--danger); border-color: #f3d2d2; }
.btn.danger:hover { background: #fff5f5; }
.btn[disabled] { opacity: .6; cursor: not-allowed; transform: none; }

/* ---------- 布局 ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 20px 60px; }

/* ---------- 登录 ---------- */
.auth { display: grid; place-items: center; min-height: calc(100vh - 160px); }

.auth-card {
  width: min(430px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 30px 28px;
  box-shadow: var(--shadow);
}

.auth-card h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.4px; }
.auth-card .sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 6px; padding: 4px; background: #eef1f8; border-radius: 10px; margin-bottom: 18px; }

.tabs .tab {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.tabs .tab.active { background: #fff; color: var(--ink); box-shadow: 0 6px 16px -12px rgba(12, 18, 34, .5); }

label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--ink-2); font-weight: 500; }

input, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcff;
  font: inherit;
  color: var(--ink);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

input:focus, textarea:focus { border-color: #b9b3f6; box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }
textarea { resize: vertical; }

.auth-card .btn-primary { width: 100%; margin-top: 4px; }
.error { margin: 0 0 10px; color: var(--danger); font-size: 12.5px; }
.hint { margin: 16px 0 0; color: var(--muted); font-size: 12px; }

/* ---------- 控制台 ---------- */
.dash { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 20px; align-items: start; }

.side {
  position: sticky;
  top: 88px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.side-head { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }

.site-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 4px; }

.site-list button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  padding: 9px 10px;
  border-radius: 9px;
  font: inherit;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-list button:hover { background: #f3f5fc; }
.site-list button.active { background: #eef0fe; border-color: #dcd9fd; color: var(--brand); font-weight: 600; }

.side-foot { border-top: 1px dashed var(--line); padding-top: 10px; }
.plan { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.plan-sub { font-size: 12px; color: var(--muted); }

.main { min-width: 0; }

.empty {
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}

.site-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.site-head h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: -.3px; }
.site-key { margin: 0; color: var(--muted); font-size: 12.5px; }
.site-key code { background: #eef0fe; color: var(--brand); padding: 2px 7px; border-radius: 6px; font-size: 12px; }

.stats { display: flex; gap: 22px; }
.stats div { display: grid; justify-items: end; }
.stats strong { font-size: 20px; letter-spacing: -.5px; }
.stats span { font-size: 12px; color: var(--muted); }

.tabs-line { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }

.tabs-line .tab {
  border: 0;
  background: transparent;
  padding: 9px 14px;
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tabs-line .tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h3 { margin: 0 0 12px; font-size: 15px; }

.muted { color: var(--muted); font-size: 12.5px; }

pre {
  margin: 12px 0;
  padding: 14px 16px;
  background: #0d1226;
  color: #d6dcff;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

pre code { color: inherit; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.row { display: flex; align-items: center; gap: 12px; margin-top: 6px; }

.kb-list { display: grid; gap: 10px; }

.kb-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fbfcff;
}

.kb-item header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.kb-item .kw { display: flex; flex-wrap: wrap; gap: 6px; }
.kb-item .kw span { background: #eef0fe; color: var(--brand); border-radius: 999px; padding: 1px 9px; font-size: 11.5px; }
.kb-item p { margin: 4px 0 0; white-space: pre-wrap; color: var(--ink-2); font-size: 13px; }
.kb-item .src { margin-top: 6px; color: var(--muted); font-size: 11.5px; }
.kb-item .del { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; }
.kb-item .del:hover { color: var(--danger); }

.conv-list { display: grid; gap: 10px; }

.conv-item { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fbfcff; }
.conv-item header { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.conv-item .msg { display: flex; gap: 8px; margin-top: 6px; font-size: 12.5px; }
.conv-item .msg b { flex: 0 0 34px; color: var(--muted); font-weight: 500; }
.conv-item .msg.user b { color: var(--brand); }
.conv-item .msg span { white-space: pre-wrap; color: var(--ink-2); }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(8px);
  background: #0d1226;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 60;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 860px) {
  .dash { grid-template-columns: 1fr; }
  .side { position: static; }
  .grid2 { grid-template-columns: 1fr; }
  .site-head { align-items: flex-start; }
  .stats { gap: 16px; }
}
