/* ============ 后台管理样式 ============ */
:root {
  --primary: #3688fc;
  --primary-dark: #2a6fd6;
  --bg: #f4f6fa;
  --panel: #ffffff;
  --line: #e8edf4;
  --text: #2c3545;
  --muted: #8593a6;
  --danger: #f2564d;
  --ok: #22a06b;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
code { background: #eef2f8; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--muted); }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #eef4ff 0%, #f7f9fc 55%, #eef7f4 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 16px;
  padding: 34px 30px 26px;
  box-shadow: 0 20px 60px rgba(38, 60, 96, 0.12);
}
.login-logo {
  width: 46px; height: 46px;
  border-radius: 13px;
  background: rgba(54, 136, 252, 0.12);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 16px;
}
.login-logo svg { width: 24px; height: 24px; }
.login-card h1 { font-size: 21px; }
.login-sub { color: var(--muted); margin: 6px 0 22px; font-size: 13px; }
.login-err {
  background: #fff1f0; color: var(--danger);
  border: 1px solid #ffd9d6; border-radius: 8px;
  padding: 9px 12px; font-size: 13px; margin-bottom: 12px;
}
.login-tip { text-align: center; color: var(--muted); font-size: 12px; margin: 16px 0 0; }
.login-tip b { color: var(--text); }
.login-tip a, .login-back {
  color: var(--primary); text-decoration: none; font-size: 13px;
  display: inline-block; padding: 2px 4px; border-radius: 6px;
  transition: color .15s, background .15s;
}
.login-tip a:hover, .login-back:hover { color: var(--primary-dark); background: rgba(54,136,252,.08); }

/* ---------- 表单 ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; font-size: 12.5px; color: #5a6779;
  font-weight: 600; margin-bottom: 6px;
}
.field input[type=text], .field input[type=password], .field input[type=number],
.field input[type=url], .field input:not([type]), .field select, .field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(54, 136, 252, 0.12);
}
.field input:disabled {
  background: #f4f6fa; color: #93a0b2; cursor: not-allowed;
}
.field input[type=color].color-input {
  padding: 3px; height: 38px; width: 70px; cursor: pointer; background: #fff;
  border: 1px solid var(--line); border-radius: 8px;
}
.field textarea { resize: vertical; line-height: 1.6; }
textarea.code-area {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--text);
  font-family: ui-monospace, Consolas, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.7;
  resize: vertical;
}
textarea.code-area:focus {
  outline: none; border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 3px rgba(54, 136, 252, 0.12);
}
.code-area { font-family: ui-monospace, Consolas, Menlo, monospace; font-size: 12.5px; }
.switch-field { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch-field > span { margin: 0; }
.switch-field.inline { margin: 0; }
.switch {
  appearance: none; -webkit-appearance: none;
  width: 42px; height: 24px; border-radius: 999px;
  background: #d7dee9; position: relative; cursor: pointer;
  transition: background .18s; flex: 0 0 42px; margin: 0;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .18s;
}
.switch:checked { background: var(--primary); }
.switch:checked::after { transform: translateX(18px); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #fff; color: #55627a; border-color: var(--line); }
.btn-ghost:hover { border-color: #c9d5e6; color: var(--primary); }
.btn-danger { background: #fff1f0; color: var(--danger); border-color: #ffd9d6; }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; padding: 10px; font-size: 14.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- 布局 ---------- */
.shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 232px; flex: 0 0 232px;
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px 18px;
}
.brand-ic {
  width: 34px; height: 34px; border-radius: 9px;
  background: rgba(54,136,252,.12); color: var(--primary);
  display: flex; align-items: center; justify-content: center; flex: 0 0 34px;
}
.brand-ic svg { width: 18px; height: 18px; }
.brand strong { display: block; font-size: 14.5px; }
.brand small { color: var(--muted); font-size: 11.5px; }

.menu { flex: 1; padding: 6px 10px; overflow-y: auto; }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 11px; margin-bottom: 2px;
  background: transparent; border: 0; border-radius: 8px;
  color: #5d6b80; font-size: 13.5px; font-family: inherit;
  cursor: pointer; text-align: left; transition: all .14s;
}
.menu-item svg { width: 17px; height: 17px; flex: 0 0 17px; opacity: .8; }
.menu-item:hover { background: #f3f6fb; color: var(--primary); }
.menu-item.active { background: rgba(54,136,252,.1); color: var(--primary); font-weight: 600; }
.menu-item.active svg { opacity: 1; }

.sidebar-foot { padding: 12px 10px 16px; border-top: 1px solid var(--line); }
.side-link {
  display: block; width: 100%; text-align: left;
  padding: 8px 11px; border-radius: 8px; border: 0;
  background: transparent; color: #5d6b80; font-size: 13px;
  font-family: inherit; cursor: pointer;
}
.side-link:hover { background: #f3f6fb; color: var(--primary); }
.side-link.danger:hover { background: #fff1f0; color: var(--danger); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 26px;
  background: #fff; border-bottom: 1px solid var(--line);
}
.topbar h2 { font-size: 18px; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.topbar-actions { display: flex; gap: 8px; }

.scroll { flex: 1; overflow-y: auto; padding: 22px 26px 80px; }
.panel { display: none; }
.panel.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #fcfdff;
}
.card-head h3 { font-size: 14.5px; }
.card-body { padding: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.grid-2 .wide { grid-column: 1 / -1; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
@media (max-width: 860px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px;
}
.stat span { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.stat strong { font-size: 24px; letter-spacing: -0.5px; }
.tips { margin: 0; padding-left: 18px; line-height: 2; color: #5d6b80; }
.tips b { color: var(--text); }

.save-bar {
  position: sticky; bottom: 8px;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(20, 32, 50, 0.09);
  backdrop-filter: blur(6px);
}
.save-hint { color: var(--ok); font-size: 13px; }

/* ---------- 列表 ---------- */
.row-list { display: flex; flex-direction: column; gap: 8px; }
.row-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fcfdff;
  transition: border-color .15s, background .15s;
}
.row-item:hover { border-color: #cfe0fb; background: #fff; }
.row-item.off { opacity: .55; }
.row-item .grip { color: #b9c4d4; flex: 0 0 auto; display: flex; flex-direction: column; gap: 2px; }
.row-item .thumb {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: 0 0 34px;
  background: rgba(54,136,252,.1);
  display: flex; align-items: center; justify-content: center;
  color: var(--primary); font-weight: 700;
}
.row-item .thumb svg { width: 17px; height: 17px; }
.row-item .meta { flex: 1; min-width: 0; }
.row-item .meta b { display: block; font-size: 13.5px; font-weight: 600; }
.row-item .meta small {
  display: block; color: var(--muted); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-item .ops { display: flex; gap: 4px; flex: 0 0 auto; }
.icon-btn {
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid var(--line); background: #fff;
  color: #6d7b8f; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; line-height: 1;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }
.icon-btn.del:hover { border-color: var(--danger); color: var(--danger); }
.pill {
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: #eef2f8; color: #6d7b8f; font-weight: 600;
}
.pill.on { background: rgba(34,160,107,.12); color: var(--ok); }
.pill.off { background: #f2f4f7; color: #97a3b4; }

/* 分类块 */
.cat-block {
  border: 1px solid var(--line); border-radius: 10px;
  margin-bottom: 12px; overflow: hidden; background: #fff;
}
.cat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; background: #fbfcfe; border-bottom: 1px solid var(--line);
}
.cat-head .thumb { width: 30px; height: 30px; flex: 0 0 30px; }
.cat-head .meta { flex: 1; min-width: 0; }
.cat-head b { font-size: 14px; }
.cat-head small { color: var(--muted); font-size: 12px; margin-left: 8px; }
.cat-body { padding: 10px 12px; }
.cat-body .row-list { gap: 6px; }
.cat-empty { color: var(--muted); font-size: 13px; padding: 8px 2px; }
.cat-add { margin-top: 8px; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(24, 34, 48, .48);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-box {
  width: 100%; max-width: 560px; max-height: 90vh;
  background: #fff; border-radius: 14px;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 70px rgba(20, 32, 50, .25);
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 15.5px; }
.modal-x {
  background: transparent; border: 0; font-size: 22px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 0 2px;
}
.modal-x:hover { color: var(--danger); }
.modal-body { padding: 18px 20px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--line);
  background: #fcfdff; border-radius: 0 0 14px 14px;
}

/* 图标选择器 */
.icon-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px; max-height: 168px; overflow-y: auto;
  padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe;
}
.icon-cell {
  aspect-ratio: 1; border: 1px solid transparent; border-radius: 7px;
  background: #fff; color: #5d6b80; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-cell svg { width: 18px; height: 18px; }
.icon-cell:hover { border-color: #cfe0fb; color: var(--primary); }
.icon-cell.sel { border-color: var(--primary); color: var(--primary); background: rgba(54,136,252,.08); }

.upload-row { display: flex; gap: 6px; }
.upload-row input { flex: 1; }
.preview { margin-top: 8px; min-height: 0; }
.preview img { max-height: 44px; border-radius: 6px; background: #f6f8fb; padding: 3px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: #2c3545; color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px; z-index: 200;
  box-shadow: 0 8px 30px rgba(20,32,50,.25);
  animation: toastIn .2s ease;
}
.toast.err { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 760px) {
  .shell { flex-direction: column; height: auto; overflow: visible; }
  .sidebar { width: 100%; flex: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .menu { display: flex; overflow-x: auto; padding: 6px 10px 10px; }
  .menu-item { width: auto; white-space: nowrap; margin: 0 2px; }
  .menu-item span { display: inline; }
  .sidebar-foot { display: flex; gap: 8px; border-top: 0; padding: 0 10px 12px; }
  .scroll { padding: 16px 14px 50px; }
  .topbar { padding: 14px 16px; flex-wrap: wrap; }
  .topbar-actions { width: 100%; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
