/* ============ 管理后台样式 ============ */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: 'DM Sans', -apple-system, sans-serif;
  background: #F0EDE8;
  color: #1C2521;
  font-size: 14px;
  line-height: 1.5;
}

.admin-layout { display: flex; min-height: 100vh; }

/* Sidebar nav */
.admin-nav {
  width: 220px; flex-shrink: 0;
  background: #1F4D3A;
  color: white;
  display: flex; flex-direction: column;
  padding: 0;
  position: sticky; top: 0; height: 100vh;
}
.admin-brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.admin-brand-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 18px; font-weight: 700;
  letter-spacing: -0.3px;
}
.admin-brand-sub {
  font-size: 11px; color: rgba(255,255,255,0.5);
  text-transform: uppercase; letter-spacing: 1.5px;
}
.admin-nav-items { padding: 12px 10px; flex: 1; }
.admin-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px; font-weight: 500;
  color: rgba(255,255,255,0.65);
  cursor: pointer;
  width: 100%; text-align: left;
  border: none; background: none; font-family: inherit;
  transition: background 0.15s, color 0.15s;
  margin-bottom: 2px;
}
.admin-nav-item:hover { background: rgba(255,255,255,0.1); color: white; }
.admin-nav-item.active { background: rgba(255,255,255,0.15); color: white; }
.admin-nav-icon { font-size: 16px; width: 20px; text-align: center; }
.admin-nav-footer {
  padding: 14px 10px;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.admin-back-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 12px; color: rgba(255,255,255,0.5);
  cursor: pointer; background: none; border: none;
  font-family: inherit; width: 100%;
  transition: color 0.15s;
}
.admin-back-btn:hover { color: white; }

/* Main content */
.admin-main {
  flex: 1; padding: 28px;
  overflow-y: auto;
}
.admin-page { display: none; }
.admin-page.active { display: block; }

.admin-page-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 24px; font-weight: 600;
  margin: 0 0 6px;
  letter-spacing: -0.3px;
}
.admin-page-sub { font-size: 13px; color: #8B958F; margin: 0 0 24px; }

/* Cards */
.admin-card {
  background: white;
  border: 1px solid #E5DFD3;
  border-radius: 16px;
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: 0 2px 6px rgba(28,37,33,0.04);
}
.admin-card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.admin-card-title { font-weight: 600; font-size: 15px; }

/* Buttons */
.btn-primary {
  padding: 9px 18px;
  background: #1F4D3A; color: white;
  border: none; border-radius: 10px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.88; }
.btn-secondary {
  padding: 9px 18px;
  background: transparent; color: #4A5853;
  border: 1px solid #E5DFD3; border-radius: 10px;
  font-size: 13px; font-weight: 500;
  cursor: pointer; font-family: inherit;
  transition: border-color 0.15s;
}
.btn-secondary:hover { border-color: #1F4D3A; color: #1F4D3A; }
.btn-danger {
  padding: 7px 14px;
  background: rgba(192,74,43,0.1); color: #C04A2B;
  border: 1px solid rgba(192,74,43,0.2);
  border-radius: 8px; font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.btn-danger:hover { background: rgba(192,74,43,0.18); }
.btn-success {
  padding: 7px 14px;
  background: rgba(74,124,66,0.1); color: #2e6b27;
  border: 1px solid rgba(74,124,66,0.2);
  border-radius: 8px; font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.btn-success:hover { background: rgba(74,124,66,0.18); }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
.form-label { font-size: 11px; font-weight: 600; color: #8B958F; text-transform: uppercase; letter-spacing: 0.5px; }
.form-input, .form-select, .form-textarea {
  padding: 9px 12px;
  background: #FBF8F1; border: 1px solid #E5DFD3;
  border-radius: 10px;
  font-size: 13px; color: #1C2521;
  outline: none; font-family: inherit;
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: #1F4D3A; }
.discipline-tree {
  border: 1px solid #E2E8E4;
  border-radius: 10px;
  max-height: 280px;
  overflow-y: auto;
  padding: 8px;
  background: #FAFBFA;
}
.tree-subject { margin-bottom: 10px; }
.tree-subject-head {
  font-size: 12px;
  font-weight: 700;
  color: #1F4D3A;
  padding: 6px 8px;
  background: #EEF4F0;
  border-radius: 6px;
  margin-bottom: 4px;
}
.tree-children { display: flex; flex-direction: column; gap: 2px; padding-left: 4px; }
.tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  font-size: 12px;
  color: #2C3330;
}
.tree-item:hover { border-color: #C5D4CA; background: #F5FAF7; }
.tree-item.selected { border-color: #1F4D3A; background: #E8F2EC; }
.tree-check {
  width: 18px;
  height: 18px;
  border: 1.5px solid #B8C4BE;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}
.tree-item.selected .tree-check {
  background: #1F4D3A;
  border-color: #1F4D3A;
}
.tree-item-label { flex: 1; line-height: 1.35; }
.form-textarea { resize: vertical; min-height: 100px; }
.form-hint { margin: 4px 0 0; font-size: 11px; color: #8B958F; line-height: 1.4; }
.discipline-icon-field { display: flex; flex-direction: column; gap: 10px; }
.discipline-icon-preview-wrap {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  border: 1px solid #E5DFD3;
  background: #FBF8F1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.discipline-icon-preview { width: 100%; height: 100%; object-fit: cover; display: block; }
.discipline-icon-placeholder {
  font-size: 11px;
  color: #8B958F;
  text-align: center;
  padding: 8px;
  line-height: 1.3;
}
.discipline-icon-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.discipline-icon-thumb {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid #E5DFD3;
  background: #FBF8F1;
  vertical-align: middle;
}
.discipline-icon-empty {
  display: inline-flex;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #8B958F;
  background: #F3F0EA;
  border: 1px dashed #D8D2C8;
}

/* Table */
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th {
  text-align: left; padding: 10px 12px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: #8B958F; border-bottom: 1px solid #E5DFD3;
}
.admin-table td { padding: 12px; border-bottom: 1px solid #F0EDE8; font-size: 13px; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: #FBF8F1; }
.td-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

/* Status badges */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 100px;
  font-size: 11px; font-weight: 600;
}
.badge-active { background: #E8F4E8; color: #2e6b27; }
.badge-inactive { background: #F0EDE8; color: #8B958F; }
.badge-admin { background: #E8EFEA; color: #1F4D3A; }
.badge-paid { background: #FBEBDB; color: #8B3F12; }
.badge-free { background: #F0EDE8; color: #8B958F; }

/* Inline expand edit */
.assistant-row td { vertical-align: top; }
.prompt-preview {
  font-size: 11px; color: #8B958F;
  max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: white; border: 1px solid #E5DFD3;
  border-radius: 14px; padding: 18px;
  text-align: center;
}
.stat-num { font-size: 32px; font-weight: 700; color: #1F4D3A; font-family: 'Fraunces', serif; }
.stat-label { font-size: 12px; color: #8B958F; margin-top: 4px; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.dash-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid #EEF2EF;
}
.dash-row:last-child { border-bottom: 0; }
.dash-row span { color: #6B7A72; font-size: 13px; }
.dash-row strong {
  color: #1C2521; font-size: 13px; font-weight: 600;
  text-align: right; word-break: break-word;
}
@media (max-width: 820px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

/* Toast */
.admin-toast {
  position: fixed; bottom: 20px; left: 50%;
  transform: translate(-50%, 80px);
  background: #1C2521; color: white;
  padding: 10px 18px; border-radius: 100px;
  font-size: 13px; z-index: 999;
  opacity: 0; transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
.admin-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Edit drawer */
.edit-drawer {
  background: #FBF8F1; border: 1px solid #E5DFD3;
  border-radius: 14px; padding: 20px;
  margin-top: 10px; display: none;
}
.edit-drawer.open { display: block; }
.edit-drawer-actions { display: flex; gap: 10px; margin-top: 16px; }

/* Config active indicator */
.config-active-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; margin-right: 6px;
}
.config-active-dot.on { background: #4A7C42; }
.config-active-dot.off { background: #E5DFD3; }

/* 多格式提示词：格式徽章 / 标签 / 来源与预览 */
.fmt-badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: #E8EFEA; color: #1F4D3A; font-size: 11px; font-weight: 600;
  vertical-align: middle;
}
.tag-row { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; }
.tag-chip {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: #F0EDE8; color: #6B7A72; font-size: 11px;
}
.btn-xs { padding: 4px 10px; font-size: 12px; }
.prompt-source { border: 1px dashed #D9E0DA; border-radius: 10px; padding: 10px; background: #FAFBFA; }
.prompt-source-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.prompt-preview {
  margin-top: 10px; border-top: 1px solid #EEF2EF; padding-top: 10px;
}
.preview-head { font-size: 12px; color: #6B7A72; margin-bottom: 6px; }
.preview-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.meta-chip {
  padding: 2px 8px; border-radius: 6px; background: #EEF4FF; color: #2C3B8E; font-size: 11px;
}
.meta-chip b { font-weight: 600; }
.preview-warn { font-size: 12px; color: #8B3F12; margin-bottom: 6px; }
.preview-body {
  margin: 0; max-height: 220px; overflow: auto; white-space: pre-wrap; word-break: break-word;
  background: #fff; border: 1px solid #EEF2EF; border-radius: 8px; padding: 10px;
  font-size: 12px; line-height: 1.55; color: #2E3A33; font-family: inherit;
}

/* ============ 学习助手编辑器 ============ */
.ae-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,0.4); backdrop-filter: blur(4px);
  display: none; align-items: flex-start; justify-content: center;
  overflow-y: auto; padding: 4vh 16px;
}
.ae-overlay.open { display: flex; }
.ae-modal {
  background: white; border-radius: 20px; padding: 26px 28px;
  width: min(860px, 94vw);
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  margin-bottom: 4vh;
}
.ae-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.ae-head h3 { font-family: 'Fraunces', Georgia, serif; margin: 0; font-size: 20px; }
.ae-head-actions { display: flex; align-items: center; gap: 8px; }
.ae-section {
  border: 1px solid #E5DFD3; border-radius: 14px;
  padding: 16px 18px; margin-bottom: 14px;
  background: #FDFCF9;
}
.ae-section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 12px;
}
.ae-section-title { font-size: 13px; font-weight: 700; color: #1F4D3A; }
.ae-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ae-toolbar-label { font-size: 11px; font-weight: 600; color: #8B958F; text-transform: uppercase; }
.ae-fmt-select { padding: 5px 8px; font-size: 12px; }
.ae-actions { display: flex; gap: 10px; margin-top: 4px; }
.ae-icon-row { display: flex; align-items: center; gap: 8px; }
.ae-voice-row { display: flex; align-items: center; gap: 8px; }

/* Chip 多选（学科 / 年级） */
.chip-select {
  display: flex; flex-wrap: wrap; gap: 7px;
  padding: 10px; border: 1px solid #E5DFD3; border-radius: 10px;
  background: #FBF8F1;
}
.chip-opt {
  padding: 5px 12px; border-radius: 100px;
  border: 1px solid #E5DFD3; background: white;
  font-size: 12.5px; color: #4A5853; cursor: pointer;
  font-family: inherit; transition: all 0.12s;
  display: inline-flex; align-items: center; gap: 5px;
}
.chip-opt:hover { border-color: #1F4D3A; color: #1F4D3A; }
.chip-opt.selected {
  background: #1F4D3A; border-color: #1F4D3A; color: white; font-weight: 600;
}
.chip-opt.chip-add {
  border-style: dashed; color: #6B7A72; background: transparent;
}
.chip-opt.chip-add:hover { border-color: #1F4D3A; color: #1F4D3A; }

/* 颜色选择器 + 文本输入 */
.color-field { display: flex; align-items: center; gap: 8px; }
.color-swatch {
  width: 38px; height: 38px; padding: 0; flex-shrink: 0;
  border: 1px solid #E5DFD3; border-radius: 10px;
  background: #FBF8F1; cursor: pointer;
}
.color-swatch::-webkit-color-swatch-wrapper { padding: 4px; }
.color-swatch::-webkit-color-swatch { border: none; border-radius: 6px; }
#aeColorHint.warn { color: #8B3F12; }
.ae-icon-preview {
  width: 34px; height: 34px; border-radius: 8px; object-fit: cover;
  border: 1px solid #E5DFD3; background: #FBF8F1; flex-shrink: 0;
}
.ae-visual-placeholder {
  border: 1.5px dashed #D8D2C8; border-radius: 12px;
  padding: 18px; text-align: center;
  font-size: 13px; color: #8B958F; background: #FBF8F1;
  line-height: 1.7;
}
.ae-visual-placeholder span { font-size: 11px; color: #ABB4AE; }

/* 简易代码编辑器：高亮层 + 透明文字 textarea 叠加 */
.code-editor {
  position: relative;
  border: 1px solid #E5DFD3; border-radius: 12px;
  background: #FFFFFF; overflow: hidden;
  height: 300px;
}
.code-editor:focus-within { border-color: #1F4D3A; }
.code-editor-pre, .code-editor-input {
  margin: 0; border: 0; width: 100%; height: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.6;
  padding: 12px 14px;
  white-space: pre-wrap; word-break: break-word;
  tab-size: 2;
}
.code-editor-pre {
  position: absolute; inset: 0;
  overflow: hidden;
  color: #2E3A33;
  pointer-events: none;
}
.code-editor-input {
  position: relative;
  background: transparent;
  color: transparent;
  caret-color: #1C2521;
  resize: none; outline: none;
  overflow: auto;
  display: block;
}
.code-editor-input::placeholder { color: #ABB4AE; }
.code-editor.dragover { border-color: #1F4D3A; }
.code-editor-drop {
  position: absolute; inset: 0; z-index: 3;
  display: none; align-items: center; justify-content: center;
  background: rgba(31,77,58,0.88); color: white;
  font-size: 14px; font-weight: 600; border-radius: 12px;
  pointer-events: none;
}
.code-editor.dragover .code-editor-drop { display: flex; }

/* 高亮 token */
.tok-key { color: #0E6E8C; }
.tok-str { color: #2E7D32; }
.tok-num { color: #B26A00; }
.tok-bool { color: #7B3FA0; font-weight: 600; }
.tok-punc { color: #9AA39D; }
.tok-comment { color: #9AA39D; font-style: italic; }
.tok-head { color: #1F4D3A; font-weight: 700; }
.tok-md-mark { color: #B26A00; }
.tok-code { color: #8B3F12; background: #FBF3E8; border-radius: 3px; }

/* API 配置分组 */
.cfg-group-title {
  font-size: 13px; font-weight: 700; color: #1F4D3A;
  padding: 8px 0; border-bottom: 2px solid #E8EFEA; margin-bottom: 4px;
}
.cfg-default-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 100px;
  background: #E8F4E8; color: #2e6b27; font-size: 11px; font-weight: 700;
}
