:root {
  --bg: #FAF8F5;
  --surface: #FFFFFF;
  --ink: #1C1917;
  --muted: #78716C;
  --line: #E7E5E4;
  --accent: #C45C26;
  --accent-soft: #F3E6DE;
  --ok: #3F6212;
  --danger: #9F1239;
  --radius: 5px;
  --font: "Songti SC", "Noto Serif SC", "Source Han Serif SC", Georgia, "Times New Roman", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  min-height: 100%;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

a { color: var(--accent); }

#app { min-height: 100vh; }

/* ----- Login ----- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 40px 32px;
}
.login-card .brand {
  font-family: var(--font);
  font-size: 28px;
  letter-spacing: 0.04em;
  margin: 0 0 6px;
}
.login-card .sub {
  color: var(--muted);
  margin: 0 0 28px;
  font-size: 13px;
}
.field { margin-bottom: 16px; }
.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: #FFFEFB;
  outline: none;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: #D6D3D1;
}
.field textarea {
  min-height: 120px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  resize: vertical;
}
.err {
  color: var(--danger);
  font-size: 13px;
  margin: 0 0 12px;
  min-height: 1.2em;
}
.ok-msg {
  color: var(--ok);
  font-size: 13px;
  margin: 8px 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #FFFEFB;
  border-radius: var(--radius);
  padding: 9px 16px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { opacity: 0.92; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost {
  background: transparent;
  color: var(--ink);
}
.btn.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn.accent {
  background: var(--accent);
  border-color: var(--accent);
}
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 12px; }

/* ----- Layout ----- */
.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 28px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.sidebar .brand {
  font-family: var(--font);
  font-size: 22px;
  margin: 0 0 4px;
  padding: 0 8px;
}
.sidebar .hint {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 24px;
  padding: 0 8px;
}
.nav-btn {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--ink);
  margin-bottom: 2px;
}
.nav-btn:hover { background: var(--bg); }
.nav-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav-btn.logout {
  margin-top: 28px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  border-radius: 0;
  padding-top: 18px;
}

.main {
  padding: 28px 32px 48px;
  max-width: 1100px;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-family: var(--font);
  font-size: 26px;
  font-weight: 500;
  margin: 0;
}
.page-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}
th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  background: #FBF9F6;
}
tr:last-child td { border-bottom: none; }
.thumb {
  width: 56px;
  height: 36px;
  object-fit: cover;
  border-radius: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.badge.on {
  background: #ECFCCB;
  border-color: #D9F99D;
  color: var(--ok);
}
.badge.off {
  background: #F5F5F4;
  color: var(--muted);
}
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

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

/* ----- Modal ----- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.35);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px;
  overflow: auto;
  z-index: 50;
}
.modal {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 24px;
}
.modal.wide { max-width: 720px; }
.modal h2 {
  font-family: var(--font);
  font-size: 20px;
  font-weight: 500;
  margin: 0 0 18px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}
.preview {
  margin-top: 8px;
  max-width: 100%;
  max-height: 160px;
  border-radius: 3px;
  border: 1px solid var(--line);
}

/* ----- Textbook ----- */
.tb-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.tb-block h3 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
}
.meta-line {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 12px;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: relative;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .nav-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }
  .nav-btn {
    width: auto;
    flex: 0 0 auto;
  }
  .nav-btn.logout {
    margin-top: 8px;
    border-top: none;
    padding-top: 10px;
  }
  .main { padding: 20px 16px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
  table { min-width: 520px; }
}

.menu-toggle {
  display: none;
  margin-bottom: 12px;
}
@media (max-width: 860px) {
  .menu-toggle { display: inline-flex; }
  .sidebar.collapsed .nav-row { display: none; }
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.sort-input {
  width: 72px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
  background: #FFFEFB;
}

/* ----- AI 调优 ----- */
.ai-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}
.ai-tab {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  color: var(--muted);
}
.ai-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.stat-cards {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center;
}
.stat-num {
  font-family: var(--font);
  font-size: 22px;
  line-height: 1.2;
}
.stat-label {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}
.prompt-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.prompt-block.readonly {
  background: #FBF9F6;
}
.prompt-block h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.prompt-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.prompt-pre,
.prompt-edit {
  width: 100%;
  max-height: 320px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #FFFEFB;
  margin: 10px 0 0;
}
.prompt-edit {
  max-height: none;
  min-height: 220px;
  resize: vertical;
}
@media (max-width: 860px) {
  .stat-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
