:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2329;
  --muted: #7a8290;
  --line: #e4e7ec;
  --brand: #1f6feb;
  --brand-dark: #1657bd;
  --warn: #b45309;
  --danger: #dc2626;
  --ok: #15803d;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

h1, h2, h3 { margin: 0; }

/* ---------------------------------------------------------------- 顶栏 */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }

.logo {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
}

.brand h1 { font-size: 18px; }
.slogan { margin: 0; color: var(--muted); font-size: 13px; }

.identity { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

/* ---------------------------------------------------------------- 标签页 */

.tabs {
  display: flex;
  gap: 8px;
  padding: 12px 24px 0;
  max-width: 1080px;
  margin: 0 auto;
}

.tab {
  padding: 8px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.tab.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }

.feedback-fab { position: fixed; right: 16px; bottom: 16px; z-index: 60; }

/* ---------------------------------------------------------------- 主体 */

main { max-width: 1080px; margin: 0 auto; padding: 16px 24px 60px; }
.panel { display: none; }
.panel.is-active { display: block; }

h2 { margin: 24px 0 12px; font-size: 16px; }

.hint { color: var(--muted); font-size: 13px; }
.req { color: var(--danger); }

.welcome-steps { margin: 8px 0; padding-left: 20px; color: var(--text); font-size: 14px; line-height: 1.9; }

.empty-state {
  padding: 30px 20px;
  text-align: center;
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
}

.empty-state p { margin: 0 0 14px; }
.empty-state .row-actions { justify-content: center; }

/* ---------------------------------------------------------------- 筛选 */

.filters {
  display: grid;
  grid-template-columns: minmax(240px, 2fr) repeat(2, minmax(140px, 1fr)) auto;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31, 111, 235, 0.25); border-color: var(--brand); }

.btn {
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); color: #fff; }

/* ---------------------------------------------------------------- 图书卡片 */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.card header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card h3 { font-size: 15px; line-height: 1.4; }
.price { color: var(--danger); font-size: 18px; font-weight: 700; }
.meta { margin: 0; color: var(--muted); font-size: 13px; }
.course { margin: 0; font-size: 13px; color: var(--brand); }
.desc { margin: 0; font-size: 13px; color: #4b5563; }
.warn-text { color: var(--warn); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }

.tag {
  padding: 2px 9px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 12px;
}

.tag.warn { background: #fef3c7; color: var(--warn); }

.badge {
  display: inline-block;
  min-width: 16px;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  vertical-align: middle;
}

.trend { display: flex; flex-direction: column; gap: 10px; margin: 10px 0 20px; }
.trend-row { display: flex; align-items: center; gap: 10px; }
.trend-label { width: 42px; color: var(--muted); font-size: 12px; flex: none; }
.trend-bars { display: flex; align-items: flex-end; gap: 3px; height: 48px; flex: 1; }
.trend-bar { flex: 1; min-width: 4px; background: var(--brand); border-radius: 2px 2px 0 0; }
.trend-total { width: 62px; text-align: right; color: var(--muted); font-size: 12px; flex: none; }

.card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.seller { font-size: 13px; color: var(--muted); }
.state { font-size: 13px; color: var(--ok); }

/* ---------------------------------------------------------------- 表单 */

.form {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin: 14px 0;
}

.grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.grid label.wide { grid-column: 1 / -1; }
.grid label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.grid label.check input { width: auto; }

/* ---------------------------------------------------------------- 我的 */

.profile {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.profile h2 { margin: 0 0 4px; font-size: 18px; }
.stats { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); }
.stats strong { color: var(--text); font-size: 15px; }

.list { display: flex; flex-direction: column; gap: 10px; }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.row-main { flex: 1 1 320px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.rate { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.rate select { width: auto; }

/* ---------------------------------------------------------------- 弹层 */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(17, 24, 39, 0.45);
  overflow-y: auto;
}

.modal.is-hidden { display: none; }

.modal-box {
  position: relative;
  width: min(460px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  background: #fff;
  border-radius: 14px;
}

.modal-close-x {
  position: absolute;
  top: 8px;
  right: 10px;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.modal-close-x:hover { background: var(--bg); color: var(--text); }

.modal-box label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.notice-body { font-size: 14px; line-height: 1.75; color: var(--text); }
.notice-body p { margin: 0 0 10px; }
.notice-body ul { margin: 0 0 10px; padding-left: 20px; }
.notice-body li { margin-bottom: 6px; }

.chat-notice { margin: 0; padding: 8px 10px; border-radius: 8px; background: var(--bg); }

.modal-box--wide { width: min(720px, 100%); max-height: 86vh; }
.file-view-img { max-width: 100%; max-height: 70vh; object-fit: contain; }
.pay-code-img { width: 160px; height: 160px; object-fit: contain; cursor: zoom-in; background: var(--bg); border-radius: 8px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; max-height: 60vh; overflow: auto; }
.gallery img { width: 100%; height: 150px; object-fit: cover; border-radius: 8px; cursor: zoom-in; background: var(--bg); }
.card-cover { cursor: zoom-in; }
.legal-content { max-height: 60vh; overflow: auto; padding-right: 6px; color: var(--text); font-size: 14px; line-height: 1.75; }
.legal-content h3 { margin: 18px 0 6px; font-size: 15px; }
.legal-content p { margin: 8px 0; color: var(--text); }

.footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: center;
  padding: 20px 16px 84px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
  background: var(--card);
}

.linklike {
  border: 0;
  background: none;
  padding: 0;
  color: var(--brand);
  font: inherit;
  cursor: pointer;
}

.linklike:hover { text-decoration: underline; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 10px;
  background: #111827;
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--danger); }

@media (max-width: 720px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filters input { grid-column: 1 / -1; }
  main { padding: 12px 14px 40px; }
  .topbar, .tabs { padding-left: 14px; padding-right: 14px; }
}
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.table th, .table td { padding: 10px 12px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--line); }
.table th { background: #f9fafb; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
/* 已结束的订单：整体置灰、内容弱化，但保留操作按钮可点 */
.row.is-closed { background: #fafbfc; border-style: dashed; }
.row.is-closed .row-main { opacity: 0.62; }
.row.is-closed .contact-line { color: var(--brand); opacity: 1; }

/* 表单分组：小标题 + 固定三列，保证每行对齐 */
.form-section {
  margin: 20px 0 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 10px 0 0; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
}

.consent {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
}

.consent .check { display: inline-flex; align-items: center; gap: 6px; color: var(--text); }
.consent.is-done { opacity: 0.72; }
.consent.is-done .linklike { color: var(--muted); }

.captcha-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.captcha-row label { flex: 1 1 200px; }

.captcha-row input[name="captcha_code"] { width: 100%; }

.captcha-img {
  height: 52px;
  width: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

@media (max-width: 900px) {
  .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  .grid--3 { grid-template-columns: minmax(0, 1fr); }
  .form-actions { justify-content: stretch; }
  .form-actions .btn { width: 100%; }
}
.identity #whoami-name { color: var(--muted); }
.btn.is-hidden, [hidden] { display: none; }

/* 移动端适配 */
@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
  .identity { width: 100%; justify-content: space-between; }
  /* 手机端：标签挪到底部固定，拇指更好操作 */
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 50;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    margin: 0;
    max-width: none;
    background: var(--card);
    border-top: 1px solid var(--line);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
  }
  .tab { flex: 0 0 auto; padding: 8px 13px; font-size: 13px; }
  main { padding: 12px 10px 96px; }
  /* 底部要同时避开固定标签栏和右下角反馈按钮 */
  .footer { padding-bottom: 140px; }
  .feedback-fab { bottom: 74px; }
  .filters { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
  .grid, .grid--3 { grid-template-columns: 1fr; }
  .row { flex-direction: column; align-items: stretch; }
  .row-actions { justify-content: flex-start; }
  .modal-box { width: 100%; }
  .table { display: block; overflow-x: auto; white-space: nowrap; }
  .profile { flex-direction: column; align-items: flex-start; }
  .form-actions { justify-content: stretch; }
  .form-actions .btn { flex: 1; }
}
/* 可搜索下拉 */
.combobox { position: relative; }
.combobox-input { width: 100%; }
.combobox-list { display: none; position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0; max-height: 240px; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 8px 20px rgba(0,0,0,0.08); }
.combobox-list.is-open { display: block; }
.combobox-option { padding: 8px 11px; font-size: 14px; cursor: pointer; }
.combobox-option:hover { background: #eef2ff; }
/* 首页数据概览条 */
.stats-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.stats-strip .stat { padding: 6px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; font-size: 13px; color: var(--muted); }
.stats-strip .stat b { color: var(--text); font-size: 15px; }
/* 聊天 */
.chat-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow: auto; padding: 4px; }
.chat-msg { display: flex; flex-direction: column; max-width: 80%; padding: 8px 10px; background: #f1f3f6; border-radius: 10px; font-size: 14px; }
.chat-msg.mine { align-self: flex-end; background: #e7f0ff; }
.chat-meta { color: var(--muted); font-size: 12px; }
.chat-body { white-space: pre-wrap; word-break: break-word; }
.chat-form { display: flex; gap: 8px; margin-top: 12px; }
.chat-form input { flex: 1; }

.chat-quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chat-quick button {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.chat-quick button:hover { border-color: var(--brand); color: var(--brand); }
.chat-date { align-self: center; padding: 2px 10px; border-radius: 999px; background: #eef1f5; color: var(--muted); font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.community-card {
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 10px;
}
.community-qr {
  display: block;
  width: 160px;
  height: 160px;
  object-fit: contain;
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: zoom-in;
}
.textbook-pre {
  max-height: 46vh;
  overflow: auto;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}
.thanks-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: #fff8e6;
  border: 1px solid #f2d79b;
  border-radius: var(--radius);
  color: #8a5a00;
  font-size: 13px;
  cursor: pointer;
}
.thanks-bar:hover { border-color: #d9a83a; }
.thanks-list { max-height: 56vh; overflow: auto; }
.thanks-item {
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 14px;
}
.thanks-item .thanks-name { font-weight: 600; }
.sponsor-progress { margin: 10px 0 14px; }
.progress { height: 8px; background: #eceff3; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--brand); border-radius: 999px; transition: width 0.3s ease; }
.chip {
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.chip.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.card-cover { width: 100%; height: 160px; object-fit: cover; border-radius: 8px; }
