:root {
  --bg: #f4f8ef;
  --surface: #ffffff;
  --surface-alt: #eff6e8;
  --line: #dde8d2;
  --line-strong: #c8d9b9;
  --ink: #26312a;
  --muted: #6e7c6c;
  --primary: #3f6f33;
  --primary-hover: #345c2a;
  --primary-soft: #e7f0dc;
  --warn: #a97a26;
  --warn-soft: #fbf4e4;
  --radius: 16px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 26px 30px 34px;
}

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 13px; }

.mark {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 500;
  flex: none;
}

.brand-text h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 500;
  letter-spacing: .4px;
}

.brand-text p {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.statusbar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.pill .dot, .status-line .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #a9b4a5; flex: none;
}
.pill.ok .dot { background: #5a9a48; }
.pill.warn .dot { background: #cf9a3a; }

/* 提示条 */
.banner {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--warn-soft);
  border: 1px solid #ecdcb8;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 12.5px;
  color: #7a5c1c;
}
.banner strong { font-weight: 500; }
.banner code {
  background: #fff;
  border: 1px solid #ecdcb8;
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 11.5px;
}

/* 卡片网格 */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  margin-top: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  min-height: 286px;
  transition: border-color .18s ease;
}
.card:hover { border-color: var(--line-strong); }

.card-head { display: flex; align-items: center; gap: 12px; }

.icon {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: var(--surface-alt);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
.icon svg {
  width: 20px; height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.card:first-child .icon svg { fill: currentColor; stroke: none; }

.head-text { min-width: 0; }
.head-text h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
}
.head-text p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.tag {
  margin-left: auto;
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  white-space: nowrap;
}
.tag.warn { background: var(--warn-soft); color: var(--warn); }

.card-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 18px;
  flex: 1;
}

/* 表单 */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); }

input[type="text"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fcfdfa;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13.5px;
  color: var(--ink);
  font-family: inherit;
  outline: none;
  transition: border-color .15s ease, background .15s ease;
}
input[type="text"]:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  background: #fff;
}
input::placeholder, textarea::placeholder { color: #a8b3a4; }
textarea { resize: vertical; line-height: 1.6; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* 按钮 */
.btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 15px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); color: #fff; }
.btn.ghost { border-color: var(--line); color: var(--muted); background: transparent; }
.btn.ghost:hover:not(:disabled) { color: var(--primary); border-color: var(--line-strong); }
.btn.sm { padding: 5px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .42; cursor: not-allowed; }

.link {
  border: none;
  background: none;
  color: var(--primary);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* 状态行 */
.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  background: #fbfcf8;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}
.status-line .dot.playing { background: #5a9a48; animation: breathe 1.8s ease-in-out infinite; }
.status-line .dot.quiz { background: #cf9a3a; }
.status-line .dot.error { background: #b35a49; }
@keyframes breathe { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.spacer { flex: 1; }
.meta { font-size: 11.5px; color: var(--muted); }

/* 习题 */
.quiz-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--warn-soft);
  border: 1px solid #ecdcb8;
  border-radius: 12px;
  padding: 12px;
}
.quiz-title { font-size: 13px; font-weight: 500; color: #7a5c1c; }
.analysis {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-size: 12.8px;
  line-height: 1.75;
  white-space: pre-wrap;
  max-height: 240px;
  overflow-y: auto;
}

/* 预览与结果 */
.preview {
  border: 1px solid var(--line);
  background: #fcfdfa;
  border-radius: 12px;
  padding: 10px 12px;
  max-height: 210px;
  overflow-y: auto;
  font-size: 12.5px;
}
.slide-item { padding: 5px 0; border-bottom: 1px dashed var(--line); }
.slide-item:last-child { border-bottom: none; }
.slide-item b { font-weight: 500; }
.slide-item .pts { color: var(--muted); }

.result {
  border-left: 3px solid var(--primary);
  background: var(--primary-soft);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.7;
  word-break: break-all;
}
.result a { color: var(--primary); }

/* tabs */
.tabs {
  display: inline-flex;
  gap: 4px;
  background: var(--surface-alt);
  padding: 4px;
  border-radius: 10px;
  width: fit-content;
}
.tab {
  border: none;
  background: transparent;
  padding: 5px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
}
.tab.active { background: #fff; color: var(--primary); }

.tab-body { display: flex; flex-direction: column; gap: 12px; }
.inline-select { width: auto; padding: 6px 10px; font-size: 12.5px; }

/* 对话区 */
.chat-panel {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-head { display: flex; align-items: center; gap: 12px; }
.chat-head h2 { margin: 0; font-size: 15px; font-weight: 500; }
.chat-head .hint { font-size: 11.5px; color: var(--muted); }

.messages {
  height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 6px 4px 0;
}
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
}
.msg.bot .bubble {
  background: var(--surface-alt);
  color: var(--ink);
  border-top-left-radius: 5px;
}
.msg.user .bubble {
  background: var(--primary);
  color: #fff;
  border-top-right-radius: 5px;
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 12px;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s ease;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }

.chat-input { display: flex; gap: 10px; }
.chat-input input {
  flex: 1;
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 13.5px;
}

/* 页脚 */
.foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  font-size: 11.5px;
  color: var(--muted);
}
.foot code {
  background: var(--surface-alt);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 11.5px;
}

/* 弹窗 */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(31, 42, 31, .28);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.dialog {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  width: 430px;
  max-width: calc(100vw - 40px);
}
.dialog h3 { margin: 0 0 12px; font-size: 16px; font-weight: 500; }
.dialog-body { font-size: 13px; line-height: 1.75; color: var(--ink); }
.dialog-body .kv { color: var(--muted); font-size: 12.5px; }
.points-note {
  margin-top: 12px;
  background: var(--warn-soft);
  border: 1px solid #ecdcb8;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  color: #7a5c1c;
  line-height: 1.7;
}
.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* toast */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: #26312a;
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 12.5px;
  z-index: 60;
}

@media (max-width: 960px) {
  .page { padding: 20px 16px 28px; }
  .grid { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .statusbar { width: 100%; justify-content: flex-start; margin-left: 0; }
  .topbar { flex-wrap: wrap; }
}

/* ---------- 登录 / 白名单 / 手机访问 ---------- */
.auth-layer {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 26px 26px 22px;
  width: 372px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 2px; }
.auth-brand h2 { margin: 0; font-size: 17px; font-weight: 500; }
.auth-brand p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

.btn.block { width: 100%; padding: 10px 14px; }
.auth-tip { font-size: 11.5px; color: var(--muted); line-height: 1.7; margin: 0; }
.auth-tip.warn { color: var(--warn); }

.dialog.wide { width: 620px; }

.wl-add {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1.1fr auto;
  gap: 8px;
  margin-bottom: 12px;
}
.wl-add input {
  border: 1px solid var(--line);
  background: #fcfdfa;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--ink);
  outline: none;
  min-width: 0;
}
.wl-add input:focus { border-color: var(--primary); background: #fff; }

.wl-list { max-height: 320px; overflow-y: auto; border-top: 1px solid var(--line); }
.wl-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.7fr 1.1fr auto;
  align-items: center;
  gap: 8px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}
.wl-row .name { font-weight: 500; }
.wl-row .sub { font-size: 11.5px; color: var(--muted); }
.wl-row.off { opacity: .55; }
.wl-role {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  width: fit-content;
}
.wl-role.member { background: #f1f3ee; color: var(--muted); }
.wl-actions { display: flex; gap: 6px; justify-content: flex-end; }
.wl-actions button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 11.5px;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
}
.wl-actions button:hover { border-color: var(--primary); color: var(--primary); }
.wl-actions button.danger:hover { border-color: #b35a49; color: #b35a49; }

.lan-body { display: flex; gap: 18px; align-items: center; }
.qr-box {
  width: 132px; height: 132px;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: #fff;
  flex: none;
  overflow: hidden;
}
.qr-box img { width: 120px; height: 120px; display: block; }
.lan-text { min-width: 0; }
.lan-text code {
  display: inline-block;
  background: var(--surface-alt);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  word-break: break-all;
}

/* ---------- 固定网址 ---------- */
.url-list { margin-top: 14px; border-top: 1px solid var(--line); }
.url-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.url-row .url-label { font-size: 12.5px; }
.url-row .sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.url-row code {
  background: var(--surface-alt);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 12px;
  word-break: break-all;
}
.addr-edit { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line-strong); }

/* ---------- AI 通道 ---------- */
.agent-list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.agent-row {
  display: grid;
  grid-template-columns: 1fr 70px 70px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}
.agent-row:last-child { border-bottom: none; }
.agent-row.off { opacity: .62; }
.agent-row .name { font-weight: 500; display: flex; align-items: center; gap: 8px; }
.agent-row .sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.agent-row .mult {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--warn);
  text-align: right;
}
.agent-row .mult.zero { color: var(--primary); }
.pri {
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 400;
}

/* ---------- 白名单状态 ---------- */
.wl-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.wl-badge.ok { background: var(--primary-soft); color: var(--primary); }
.wl-badge.warn { background: var(--warn-soft); color: var(--warn); }
.wl-badge.lock { background: #fbe9e6; color: #a4453a; }
.wl-badge.off { background: #f1f3ee; color: var(--muted); }
.wl-row.locked { background: #fdf6f4; }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
  line-height: 1.6;
}
.check-row input { margin-top: 3px; }

/* ---------- AI 通道 · 智能体库 ---------- */
.ai-active-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--primary-soft);
  border-radius: 12px;
  padding: 12px 14px;
}
.ai-active-bar .sub { color: var(--muted); }
.ai-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 62px;
  color: var(--primary);
}
.ai-stat span { font-size: 20px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.ai-stat i { font-size: 11px; font-style: normal; color: var(--muted); }

.ai-section { margin-top: 16px; }
.ai-section-head {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 8px;
}
.ai-section-head .meta { font-weight: 400; }

.key-list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.key-row {
  display: grid;
  grid-template-columns: 1fr 200px auto 58px;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}
.key-row:last-child { border-bottom: none; }
.key-info .name { font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.key-info .sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.key-input {
  border: 1px solid var(--line);
  background: #fcfdfa;
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  min-width: 0;
}
.key-input:focus { border-color: var(--primary); background: #fff; }
.key-link { font-size: 11.5px; color: var(--primary); text-decoration: none; white-space: nowrap; }
.key-link:hover { text-decoration: underline; }

.tier-block { margin-bottom: 12px; }
.tier-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.tier-title {
  font-size: 12px;
  font-weight: 500;
  padding: 2px 9px;
  border-radius: 999px;
}
.tier-title.free { background: #e8f5e9; color: #1f6b34; }
.tier-title.low { background: #fdf2e0; color: #8a5a12; }
.tier-title.std { background: #eef0f4; color: #5a6472; }

.agent-row2 {
  display: grid;
  grid-template-columns: 1fr 62px 74px 78px;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 12.5px;
  background: #fff;
}
.agent-row2.off { opacity: .66; }
.agent-row2.is-active { border-color: var(--primary); background: var(--primary-soft); }
.agent-row2 .name { font-weight: 500; display: flex; align-items: center; gap: 8px; }
.agent-row2 .sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.agent-row2 .act { text-align: right; }
.agent-row2 .act button { white-space: nowrap; }

.mult-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.mult-badge.zero { background: #e8f5e9; color: #1f6b34; }
.mult-badge.low { background: #fdf2e0; color: #8a5a12; }
.mult-badge.std { background: #eef0f4; color: #5a6472; }
.mult-cell { text-align: left; }

.now-url {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line-strong);
}
.now-url code {
  display: inline-block;
  background: var(--surface-alt);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 12.5px;
  margin: 6px 8px 0 0;
  word-break: break-all;
}

/* 智能体库弹窗：加宽 + 内容可滚动，避免小屏溢出 */
.dialog.wide { width: 760px; max-width: 100%; max-height: 86vh; overflow-y: auto; }
.key-row { grid-template-columns: 1.15fr 180px auto 54px; }
.agent-row2 { grid-template-columns: 1fr 58px 68px 74px; }
.agent-row2 .sub { line-height: 1.5; }

/* ============================================================
   登录门禁：登录状态确认前不渲染任何界面，避免工作台界面闪现
   ============================================================ */

/* 门禁未解除：主界面与登录层都不渲染，只留遮罩 */
body.gate .page,
body.gate .auth-layer { display: none !important; }

/* 未登录状态：主界面彻底不参与渲染（双保险，即使登录层样式异常也看不到） */
body.locked .page { display: none !important; }

/* 门禁遮罩 */
.boot-mask {
  position: fixed;
  inset: 0;
  z-index: 95;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
body:not(.gate) .boot-mask { display: none !important; }

.boot-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.boot-text {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.5px;
}
.boot-box .mark {
  width: 48px; height: 48px;
  font-size: 21px;
  animation: bootPulse 1.4s ease-in-out infinite;
}
@keyframes bootPulse {
  0%, 100% { opacity: 0.45; transform: scale(0.96); }
  50%      { opacity: 1;    transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .boot-box .mark { animation: none; }
}
