:root {
  --bg: #f4f1ea;
  --paper: #fcfbf8;
  --sidebar: #16181d;
  --ink: #16181d;
  --muted: #5a6170;
  --line: #e4dfd4;
  --copper: #c96a2b;
  --teal: #0f766e;
  --danger: #dc2626;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
body {
  font-family: "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.55; min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* 登录页 */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
}
.login-card {
  width: 100%; max-width: 400px; background: var(--paper); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px; box-shadow: 0 20px 50px rgba(22,24,29,.08);
}
.login-head { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.brand-bar { width: 5px; height: 34px; border-radius: 4px; background: var(--copper); }
.login-head h1 { font-size: 20px; font-weight: 900; }
.login-head p { font-size: 12.5px; color: var(--muted); }
.login-form { display: grid; gap: 14px; }
.login-foot { margin-top: 18px; text-align: center; font-size: 13px; color: var(--muted); }
.login-foot a:hover { color: var(--ink); text-decoration: underline; }
.err-msg { padding: 9px 12px; border-radius: 8px; background: #fef2f2; color: var(--danger); font-size: 13px; border: 1px solid #fecaca; }

/* 主布局 */
.admin-app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: #d1d5db; padding: 22px 14px;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sb-top { padding: 4px 10px 16px; border-bottom: 1px solid rgba(255,255,255,.1); margin-bottom: 14px; }
.sb-top strong { display: block; color: #fff; font-size: 16px; }
.sb-top span { font-size: 12px; color: #ffbe8f; font-family: Consolas, monospace; }
.sb-nav { display: grid; gap: 5px; }
.sb-btn {
  text-align: left; padding: 10px 12px; border-radius: 9px; font-size: 13.5px; color: #9ca3af;
  transition: all .15s;
}
.sb-btn:hover { background: rgba(255,255,255,.07); color: #fff; }
.sb-btn.active { background: var(--copper); color: #fff; font-weight: 700; }
.sb-foot {
  margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.1);
  display: grid; gap: 6px;
}
.sb-link {
  display: block; text-align: left; padding: 8px 12px; border-radius: 8px; font-size: 13px; color: #9ca3af;
}
.sb-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sb-link.danger:hover { color: #fca5a5; }

.main { padding: 26px 32px; min-width: 0; }
.pw-alert {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: 12px; background: #fff7ed; border: 1px solid #fed7aa;
  color: #9a3412; font-size: 13px; margin-bottom: 20px;
}
.page-head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 14px;
  margin-bottom: 20px;
}
.page-head h2 { font-size: 21px; font-weight: 900; }
.page-head p { font-size: 13px; color: var(--muted); }

.btn-primary {
  padding: 9px 18px; border-radius: 9px; background: var(--ink); color: #fff;
  font-size: 13.5px; font-weight: 700; transition: opacity .15s;
}
.btn-primary:hover { opacity: .88; }
.btn-primary.full { width: 100%; padding: 11px; }
.btn-soft {
  padding: 6px 12px; border-radius: 8px; background: #fff; border: 1px solid #d8d2c5;
  color: var(--ink); font-size: 12.5px; font-weight: 600;
}
.btn-soft:hover { border-color: var(--ink); }
.danger-text { color: var(--danger); }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; }
.kpi span { font-size: 12.5px; color: var(--muted); }
.kpi strong { display: block; font-size: 24px; font-family: Consolas, monospace; margin-top: 3px; }

.card-box { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.card-box.pad { padding: 22px; }
.card-box h3 { font-size: 15px; font-weight: 800; margin-bottom: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; padding: 12px 14px; background: #efece4; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
td { padding: 12px 14px; border-bottom: 1px solid #eeeae0; vertical-align: middle; }
.mini-cover {
  width: 60px; height: 38px; border-radius: 6px; overflow: hidden; background: #16181d;
  color: #fff; font-size: 10px; display: grid; place-items: center;
}
.mini-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.tag.free { background: #e6f6f4; color: var(--teal); }
.tag.paid { background: #fdf0e6; color: var(--copper); }
.tag.draft { background: #e5e7eb; color: #4b5563; }

/* 表单组件 */
.field { display: grid; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 700; color: #374151; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #d5cfc2; border-radius: 9px;
  background: #fff; color: var(--ink); font-size: 13.5px; font-family: inherit; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--ink); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.settings-grid .card-box { display: grid; gap: 13px; }
.upload-row { display: flex; gap: 8px; flex-wrap: wrap; }
.img-preview-sm { margin-top: 8px; }
.img-preview-sm img { max-width: 140px; max-height: 140px; border-radius: 10px; border: 1px solid var(--line); display: block; }

/* 分类管理 */
.cat-add-row { display: flex; gap: 8px; margin-bottom: 16px; }
.cat-add-row input { padding: 8px 11px; border: 1px solid #d5cfc2; border-radius: 9px; background: #fff; font-size: 13.5px; flex: 1; }
.cat-list { display: grid; gap: 8px; }
.cat-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 10px; background: var(--bg); border: 1px solid var(--line);
}
.cat-item input { padding: 6px 9px; border: 1px solid #d5cfc2; border-radius: 7px; background: #fff; font-size: 13px; }

/* 右侧工具编辑抽屉 */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(22,24,29,.5); backdrop-filter: blur(4px);
  z-index: 100; display: none; justify-content: flex-end;
}
.drawer-mask.open { display: flex; }
.drawer {
  width: 100%; max-width: 720px; height: 100vh; background: var(--paper);
  display: flex; flex-direction: column; box-shadow: -12px 0 40px rgba(0,0,0,.22);
}
.drawer-head {
  padding: 16px 24px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.drawer-head strong { font-size: 17px; }
.drawer-body {
  padding: 20px 24px 36px; overflow-y: auto; display: grid; gap: 14px;
}
.box-section {
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
}
.box-section.free-tone { background: #f2f9f8; border-color: #c5e6e1; }
.box-section.paid-tone { background: #fdf7f2; border-color: #f0d3be; }
.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.cover-preview-box {
  border-radius: 10px; border: 1px dashed #ccc4b4; background: #fff;
  min-height: 110px; display: grid; place-items: center; overflow: hidden;
  font-size: 12.5px; color: var(--muted);
}
.cover-preview-box img { width: 100%; max-height: 240px; object-fit: cover; display: block; }
.gallery-admin { display: flex; flex-wrap: wrap; gap: 10px; }
.g-thumb {
  position: relative; width: 100px; height: 66px; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line); background: #fff;
}
.g-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.g-del {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,.72); color: #fff; font-size: 12px; line-height: 20px; text-align: center;
}
.pkg-status {
  margin-top: 8px; padding: 9px 12px; border-radius: 8px; background: #fff;
  border: 1px solid var(--line); font-size: 12.5px; color: var(--muted); font-family: Consolas, monospace;
}
.dyn-row {
  display: grid; grid-template-columns: 1fr 110px 1.4fr auto; gap: 8px; align-items: center;
}
.drawer-actions {
  position: sticky; bottom: 0; background: var(--paper); padding-top: 12px;
  border-top: 1px solid var(--line); display: flex; gap: 10px;
}

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(14px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 300;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 960px) {
  .admin-app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid, .row2, .row3 { grid-template-columns: 1fr; }
  .dyn-row { grid-template-columns: 1fr; }
}
