:root {
  --bg: #0e1116;
  --bg-soft: #141922;
  --panel: #171d27;
  --panel-2: #1d2430;
  --line: #2a3340;
  --line-soft: #222a35;
  --text: #e8e4da;
  --muted: #9aa3b2;
  --faint: #6d7684;
  --accent: #c9a96a;
  --accent-strong: #e0c188;
  --accent-dim: rgba(201, 169, 106, 0.12);
  --ok: #6fbf8f;
  --warn: #d9a15b;
  --err: #e07979;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
  --sans: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(1200px 700px at 15% -10%, #1b2230 0, var(--bg) 55%) fixed, var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; letter-spacing: 0.01em; margin: 0; }
p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1 1 auto; min-height: 0; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

.boot {
  min-height: 100vh;
  display: grid;
  place-content: center;
  gap: 14px;
  text-align: center;
  color: var(--muted);
}
.boot-mark, .brand-mark {
  width: 58px;
  height: 58px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 16px;
  font-family: var(--serif);
  font-size: 26px;
  background: linear-gradient(145deg, rgba(201, 169, 106, 0.14), transparent);
  box-shadow: inset 0 0 24px rgba(201, 169, 106, 0.08);
}
.brand-mark.small { width: 38px; height: 38px; font-size: 18px; margin: 0; border-radius: 11px; }

/* ---------------------------------------------------------------- auth */
.auth-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 6vw;
  align-items: center;
  padding: 6vh 7vw;
}
.auth-brand h1 { font-size: 42px; margin: 22px 0 14px; }
.auth-brand .muted { max-width: 520px; }
.auth-points { list-style: none; padding: 0; margin: 38px 0 0; display: grid; gap: 14px; max-width: 560px; }
.auth-points li {
  display: flex;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.015);
  color: var(--muted);
  font-size: 14px;
}
.auth-points li span { color: var(--accent); font-family: var(--serif); }
.auth-card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 26px;
  box-shadow: var(--shadow);
}
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--bg-soft); border-radius: 10px; margin-bottom: 22px; }
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.tab.active { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset; }
.form { display: flex; flex-direction: column; gap: 15px; }
.form label { display: flex; flex-direction: column; gap: 7px; color: var(--muted); font-size: 13px; }
input, select, textarea {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; }
.form-note { min-height: 18px; font-size: 13px; color: var(--muted); }
.form-note.err { color: var(--err); }
.code-row { display: flex; align-items: stretch; gap: 8px; }
.code-row input { flex: 1 1 auto; min-width: 0; }
.code-row .btn { flex: 0 0 auto; }
.tabs .tab { font-size: 13px; padding: 9px 6px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:hover { border-color: #3b4656; background: #232c39; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #d9bc82, #b9975a); border-color: #b9975a; color: #17130b; font-weight: 600; }
.btn.primary:hover { background: linear-gradient(180deg, #e6cb94, #c5a468); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: #5a3131; color: #efb0b0; }
.btn.danger:hover { background: #2a1b1b; }
.btn.full { width: 100%; }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; padding: 4px 8px; }
.icon-btn:hover { color: var(--text); }

/* ---------------------------------------------------------------- shell */
.app-shell { display: grid; grid-template-columns: 286px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px 18px;
  border-right: 1px solid var(--line-soft);
  background: rgba(13, 16, 22, 0.72);
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-head { display: flex; align-items: center; gap: 12px; }
.sidebar-head strong { display: block; font-family: var(--serif); font-size: 17px; }
.sidebar-section { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.sidebar-label { font-size: 11.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--faint); padding: 0 8px; }
.nav-item {
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 9px 12px;
  border-radius: 9px;
  cursor: pointer;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.03); color: var(--text); }
.nav-item.active { background: var(--accent-dim); border-color: rgba(201, 169, 106, 0.28); color: var(--accent-strong); }
.project-nav { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.project-nav .nav-item { font-size: 13.5px; display: flex; justify-content: space-between; gap: 8px; }
.project-nav .nav-item small { color: var(--faint); }
.sidebar-foot { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line-soft); padding-top: 14px; }
.user-chip { display: flex; flex-direction: column; gap: 2px; padding: 0 4px; font-size: 13px; }
.user-chip span { color: var(--faint); font-size: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 34px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(14, 17, 22, 0.6);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h2 { font-size: 21px; }
.topbar .crumbs { color: var(--faint); font-size: 12.5px; margin-bottom: 2px; }
.content { padding: 28px 34px 64px; max-width: 1280px; width: 100%; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head h1 { font-size: 30px; }
.page-head p { color: var(--muted); margin-top: 6px; max-width: 720px; }

/* ---------------------------------------------------------------- cards */
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.022), rgba(255, 255, 255, 0.008));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 20px;
}
.card.pad-sm { padding: 14px 16px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-title h3 { font-size: 17px; }
.card-title .hint { color: var(--faint); font-size: 12px; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat b { font-family: var(--serif); font-size: 28px; font-weight: 600; }
.stat span { color: var(--muted); font-size: 12.5px; }
.divider { height: 1px; background: var(--line-soft); margin: 16px 0; }
.notice {
  border: 1px solid rgba(201, 169, 106, 0.26);
  background: var(--accent-dim);
  border-radius: 10px;
  padding: 12px 14px;
  color: #d9c8a3;
  font-size: 13px;
}
.notice.err { border-color: #4c2c2c; background: #241717; color: #e6a8a8; }
.empty { color: var(--faint); text-align: center; padding: 26px 12px; font-size: 13.5px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: #2f4a3a; background: rgba(111, 191, 143, 0.08); }
.badge.warn { color: var(--warn); border-color: #4a3b28; background: rgba(217, 161, 91, 0.08); }
.badge.err { color: var(--err); border-color: #4a2d2d; background: rgba(224, 121, 121, 0.08); }
.badge.gold { color: var(--accent-strong); border-color: rgba(201, 169, 106, 0.3); }

/* ---------------------------------------------------------------- tables */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left;
  color: var(--faint);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.05em;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
}
.table td { padding: 11px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.table tr:hover td { background: rgba(255, 255, 255, 0.018); }
.table tr.clickable { cursor: pointer; }
.table .num { font-family: var(--serif); color: var(--accent-strong); }

/* ---------------------------------------------------------------- project tabs */
.ptabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line-soft); margin-bottom: 22px; overflow-x: auto; }
.ptab { border: 0; background: transparent; color: var(--muted); padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.ptab.active { color: var(--accent-strong); border-bottom-color: var(--accent); }
.ptab:hover { color: var(--text); }

/* ---------------------------------------------------------------- chat */
.chat-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; min-height: 62vh; }
.conv-list { display: flex; flex-direction: column; gap: 4px; }
.conv-item {
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 9px 11px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-item.active { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.chat-main { display: flex; flex-direction: column; min-height: 62vh; border: 1px solid var(--line-soft); border-radius: var(--radius); background: rgba(255, 255, 255, 0.012); overflow: hidden; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 18px; max-height: 56vh; }
.msg { display: flex; gap: 12px; max-width: 92%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar {
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-family: var(--serif); font-size: 13px;
  border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted);
}
.msg.user .msg-avatar { color: var(--accent); border-color: rgba(201, 169, 106, 0.3); }
.msg-body { min-width: 0; }
.msg-content { white-space: pre-wrap; word-break: break-word; background: var(--panel); border: 1px solid var(--line-soft); border-radius: 12px; padding: 12px 15px; }
.msg.user .msg-content { background: #202836; }
.msg-meta { color: var(--faint); font-size: 11.5px; margin-top: 5px; }
.cite-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.cite-chip { border: 1px solid rgba(201, 169, 106, 0.3); color: var(--accent-strong); background: rgba(201, 169, 106, 0.06); border-radius: 999px; padding: 2px 9px; font-size: 11.5px; cursor: pointer; }
.chat-compose { border-top: 1px solid var(--line-soft); padding: 14px; display: flex; flex-direction: column; gap: 9px; background: rgba(13, 16, 22, 0.55); }
.chat-compose textarea { min-height: 74px; }
.chat-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--faint); }
.suggestions { display: flex; flex-wrap: wrap; gap: 7px; }
.suggestion { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 999px; padding: 5px 11px; font-size: 12px; cursor: pointer; }
.suggestion:hover { border-color: var(--accent); color: var(--accent-strong); }
.evidence { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.evidence-item { border: 1px solid var(--line-soft); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; background: rgba(255, 255, 255, 0.012); }
.evidence-item .ev-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.evidence-item .ev-quote { color: var(--muted); font-size: 12px; border-left: 2px solid var(--line); padding-left: 8px; margin-top: 6px; }

/* ---------------------------------------------------------------- forms & lists */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 11px 13px; border: 1px solid var(--line-soft); border-radius: 10px; background: rgba(255, 255, 255, 0.012); }
.list-item .meta { color: var(--faint); font-size: 12px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; color: var(--muted); font-size: 13px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { flex: 1; }

/* ---------------------------------------------------------------- modal */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4, 6, 10, 0.72); backdrop-filter: blur(4px); }
.modal-card { position: relative; width: min(860px, 100%); max-height: 86vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.modal-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line-soft); background: var(--panel); }
.modal-head h3 { font-size: 18px; }
.modal-body { padding: 20px; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 200;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 13.5px;
}
.toast.err { border-color: #5a3131; color: #efb0b0; }
.toast.ok { border-color: #2f4a3a; color: #a9dcbd; }

/* ---------------------------------------------------------------- 备案 */
.site-beian { font-size: 11.5px; color: var(--muted); }
.site-beian a { color: inherit; text-decoration: none; }
.site-beian a:hover { text-decoration: underline; }
.auth-card .site-beian { margin-top: 14px; text-align: center; }

/* ---------------------------------------------------------------- admin */
.admin-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.75fr); gap: 18px; align-items: start; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: 8px; padding: 10px 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

@media (max-width: 1080px) {
  .auth-view { grid-template-columns: 1fr; gap: 32px; padding: 8vh 6vw; }
  .auth-points { margin-top: 22px; }
  .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .project-nav { max-height: 180px; }
  .content { padding: 20px 18px 48px; }
  .topbar { padding: 14px 18px; }
  .chat-layout { grid-template-columns: 1fr; }
  .conv-list { flex-direction: row; overflow-x: auto; }
  .conv-item { flex: 0 0 auto; max-width: 180px; }
  .msg { max-width: 100%; }
  .page-head { flex-direction: column; align-items: flex-start; }
}
