:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #1a2332;
  --muted: #6b7a90;
  --line: #e6ebf2;
  --brand: #1f6feb;
  --brand-soft: #e8f0fe;
  --ok: #1a7f37;
  --ok-soft: #e6f6ea;
  --warn: #9a6700;
  --warn-soft: #fff8e6;
  --danger: #cf222e;
  --danger-soft: #ffebe9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  height: 56px;
  background: #0f172a;
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,0.06);
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-right: 12px;
  color: #fff;
  text-decoration: none;
}
.topbar .brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  display: grid;
  place-items: center;
  font-size: 14px;
}
.topbar nav {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}
.topbar nav a {
  color: rgba(255,255,255,0.72);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.92rem;
  white-space: nowrap;
}
.topbar nav a:hover { color: #fff; background: rgba(255,255,255,0.08); text-decoration: none; }
.topbar nav a.active { color: #fff; background: rgba(59,130,246,0.28); }
.topbar .logout {
  color: rgba(255,255,255,0.72);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
}
.topbar .logout:hover { color: #fff; background: rgba(255,255,255,0.08); text-decoration: none; }

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-header h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
}
.page-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.grid {
  display: grid;
  gap: 16px;
}
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 860px) {
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-body { padding: 20px 22px; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
}
.card-head h2 {
  margin: 0;
  font-size: 1.05rem;
}
.card-head .sub {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

.stat {
  padding: 22px;
}
.stat .label {
  color: var(--muted);
  font-size: 0.88rem;
}
.stat .value {
  margin-top: 8px;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--brand);
}
.stat .hint {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.8rem;
}

.form-section + .form-section {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}
.form-section h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}
.form-section .desc {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.85rem;
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.86rem;
  color: #334155;
  font-weight: 600;
}
.field .hint {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 640px) {
  .row-2 { grid-template-columns: 1fr; }
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="time"],
input[type="date"],
input[type="search"],
textarea,
select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid #d0d7e2;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.25;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
select {
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7a90' d='M1.1 1.2 6 6.1l4.9-4.9 1.1 1.1L6 8.3.0 2.3z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
}
input[type="date"] {
  min-width: 148px;
}
input[type="search"] {
  /* 去掉 WebKit 默认放大镜与清除按钮造成的高度不一致 */
}
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.15);
}
textarea {
  height: auto;
  min-height: 96px;
  padding: 10px 12px;
  resize: vertical;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
}
.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  font-weight: 500;
}
.checkbox input { width: auto; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  box-sizing: border-box;
}
.btn:hover { filter: brightness(1.05); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary {
  background: #fff;
  color: var(--ink);
  border-color: #d0d7e2;
}
.btn-danger {
  background: var(--danger);
}
.btn-sm {
  height: 32px;
  padding: 0 10px;
  font-size: 0.85rem;
}
.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
}
table.data th, table.data td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  vertical-align: middle;
}
table.data th {
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
  white-space: nowrap;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #fafbfd; }

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.tag-on { background: var(--ok-soft); color: var(--ok); }
.tag-off { background: var(--danger-soft); color: var(--danger); }
.tag-muted { background: #eef2f7; color: #64748b; }

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.92rem;
}
.alert-ok { background: var(--ok-soft); color: var(--ok); border: 1px solid #b7ebc6; }
.alert-warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #ffe58f; }
.alert-error { background: var(--danger-soft); color: var(--danger); border: 1px solid #ffccc7; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: #1e40af;
  font-size: 0.8rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
}
.chip:hover { filter: brightness(0.97); }

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(59,130,246,0.18), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, rgba(6,182,212,0.14), transparent 55%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-card h1 {
  margin: 0 0 6px;
  font-size: 1.35rem;
  text-align: center;
}
.login-card .sub {
  text-align: center;
  color: var(--muted);
  margin: 0 0 22px;
  font-size: 0.9rem;
}
.login-card .btn { width: 100%; margin-top: 8px; }

.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }
.muted { color: var(--muted); }
.mt-0 { margin-top: 0; }

.docs-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) {
  .docs-layout { grid-template-columns: 1fr; }
}
.docs-toc {
  position: sticky;
  top: 72px;
}
.docs-toc-title {
  font-weight: 700;
  margin-bottom: 10px;
}
.docs-toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.docs-toc li { margin: 0; }
.docs-toc a {
  display: block;
  padding: 7px 8px;
  border-radius: 6px;
  color: #334155;
  font-size: 0.88rem;
  text-decoration: none;
}
.docs-toc a:hover { background: var(--brand-soft); color: var(--brand); }
.docs-main { display: grid; gap: 16px; }
.docs-section { scroll-margin-top: 72px; }
.cmd-copy {
  border: none;
  background: #f1f5f9;
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.cmd-copy code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.86rem;
  color: #0f172a;
}
.cmd-copy:hover { background: var(--brand-soft); }
.cmd-copy.copied { background: var(--ok-soft); }
.cmd-copy.copied code { color: var(--ok); }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}
.filter-bar > input[type="search"],
.filter-bar > input[type="text"],
.filter-bar > input[type="date"],
.filter-bar > select {
  width: auto;
  flex: 1 1 140px;
  min-width: 140px;
  max-width: 100%;
  margin: 0;
}
.filter-bar > input[type="search"] {
  flex: 2 1 220px;
  min-width: 200px;
}
.filter-bar > input[type="date"] {
  flex: 0 0 158px;
  min-width: 158px;
  max-width: 180px;
}
.filter-bar > select.filter-narrow {
  flex: 0 1 128px;
  min-width: 112px;
}
.filter-bar > select.filter-mid {
  flex: 1 1 160px;
  min-width: 140px;
}
.filter-bar .filter-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 12px;
  margin: 0;
  border: 1px solid #d0d7e2;
  border-radius: 8px;
  background: #fff;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.filter-bar .filter-check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--brand);
  cursor: pointer;
}
.filter-bar .filter-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: auto;
}
.filter-bar .filter-actions .btn {
  height: 40px;
  padding: 0 14px;
  font-size: 0.92rem;
}
@media (max-width: 720px) {
  .filter-bar .filter-actions {
    margin-left: 0;
    width: 100%;
  }
  .filter-bar .filter-actions .btn {
    flex: 1;
  }
}
.pager {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

.chat-layout {
  display: grid;
  grid-template-columns: 1.4fr 0.9fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 960px) {
  .chat-layout { grid-template-columns: 1fr; }
}
.chat-messages {
  max-height: 62vh;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8fafc;
}
.bubble {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
}
.bubble.in { align-self: flex-start; }
.bubble.out {
  align-self: flex-end;
  background: var(--brand-soft);
  border-color: #bfdbfe;
}
.bubble-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.92rem;
  line-height: 1.45;
}

.id-label {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  margin-right: 2px;
  vertical-align: middle;
}
.id-cell {
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: nowrap;
}
.id-meta {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* ── Config tabs ── */
.config-card { overflow: hidden; }
.tabs {
  display: flex;
  gap: 2px;
  padding: 10px 12px 0;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  overflow-x: auto;
}
.tabs .tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 10px 14px 12px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs .tab:hover { color: var(--ink); background: rgba(255,255,255,0.7); }
.tabs .tab.active {
  color: var(--brand);
  background: #fff;
  border-bottom-color: var(--brand);
}
.tab-panels { padding: 0; }
.tab-panel {
  display: none;
  padding: 22px;
}
.tab-panel.active { display: block; }
.panel-intro {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--line);
}
.panel-intro h2 {
  margin: 0;
  font-size: 1.05rem;
}
.panel-intro p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}
.config-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: #fafbfd;
}
.link-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (max-width: 640px) {
  .link-grid { grid-template-columns: 1fr; }
}
.link-tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  text-decoration: none;
  color: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.link-tile:hover {
  border-color: #bfdbfe;
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.08);
  text-decoration: none;
}
.link-tile strong {
  color: var(--brand);
  font-size: 0.98rem;
}
.link-tile span {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}
.info-box {
  padding: 14px 16px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
}
.info-box p { line-height: 1.5; }
.info-box code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.86rem;
  background: #eef2f7;
  padding: 2px 6px;
  border-radius: 4px;
}
