:root {
  --paper: #f6f3ec;
  --surface: #fffdf9;
  --surface-2: #f1ede4;
  --ink: #1c1a16;
  --ink-soft: #57534b;
  --muted: #8d877c;
  --line: #e6e0d4;
  --accent: #c2542e;
  --accent-ink: #9c3f1e;
  --accent-soft: #f6e6dd;
  --success: #3f7d5b;
  --success-soft: #e4f0e9;
  --warn: #b07d2b;
  --danger: #b23b3b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(28,26,22,.04), 0 12px 30px -18px rgba(28,26,22,.25);
  --shadow-lg: 0 24px 60px -24px rgba(28,26,22,.4);
  --font-display: "Fraunces", "Songti SC", "Noto Serif SC", serif;
  --font-body: "Inter", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
/* 关键：带 display 的类（.login/.shell/.modal 等）会覆盖 [hidden] 默认 display:none，
   必须用 !important 让 hidden 属性始终生效，否则未登录也会显示后台与弹窗 */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- 通用按钮 ---------- */
.btn {
  border: 1px solid transparent; border-radius: 999px;
  padding: 10px 20px; font-size: 14px; font-weight: 500;
  transition: transform .18s cubic-bezier(.22,1,.36,1), background .18s, box-shadow .18s;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--ink); color: #fff; }
.btn--primary:hover { background: #2c2922; box-shadow: var(--shadow); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: #9c2f2f; box-shadow: var(--shadow); }
.btn--block { width: 100%; }
.link-btn { background: none; border: none; color: var(--muted); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--accent); }
.icon-btn { background: none; border: none; font-size: 18px; color: var(--muted); width: 32px; height: 32px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- 登录 ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(120% 120% at 100% 0%, #fbf8f2 0%, var(--paper) 55%),
    var(--paper);
}
.login__card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 22px; padding: 40px 34px;
  box-shadow: var(--shadow-lg); animation: rise .5s cubic-bezier(.22,1,.36,1) both;
}
.login__mark, .brand__mark {
  width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-family: var(--font-display); font-size: 24px; font-weight: 600;
}
.login__title { font-family: var(--font-display); font-size: 32px; font-weight: 600; margin: 22px 0 4px; letter-spacing: -.5px; }
.login__sub { color: var(--muted); margin: 0 0 26px; font-size: 14px; }
.login__form { display: grid; gap: 16px; }
.login__error { color: var(--danger); font-size: 13px; margin: 4px 0 0; text-align: center; }

/* ---------- 字段 ---------- */
.field { display: grid; gap: 7px; }
.field > span { font-size: 12.5px; color: var(--ink-soft); font-weight: 500; }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--radius-sm); padding: 11px 13px; outline: none; resize: vertical;
  transition: border-color .18s, box-shadow .18s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- 布局 ---------- */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 24px 18px; position: sticky; top: 0; height: 100vh; min-width: 0;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 22px; }
.brand__name { font-family: var(--font-display); font-size: 19px; font-weight: 600; letter-spacing: -.3px; }
.nav { display: grid; gap: 4px; }
.nav__item {
  text-align: left; background: none; border: none; color: var(--ink-soft);
  padding: 11px 14px; border-radius: 10px; font-size: 14.5px; font-weight: 500;
  transition: background .16s, color .16s;
}
.nav__item:hover { background: var(--surface-2); color: var(--ink); }
.nav__item.is-active { background: var(--ink); color: #fff; }
.sidebar__foot { margin-top: auto; padding: 14px 8px 4px; border-top: 1px solid var(--line); display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.who { font-size: 13px; color: var(--ink-soft); font-weight: 500; }
.who-box { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.foot-actions { display: flex; align-items: center; gap: 14px; }
.role-pill {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.role-pill--super { background: var(--accent); color: #fff; border-color: transparent; }

.main { padding: 38px 44px 60px; width: 100%; min-width: 0; }
.view__head { margin-bottom: 26px; }
.view__head--row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.view__title { font-family: var(--font-display); font-size: 30px; font-weight: 600; margin: 0; letter-spacing: -.5px; }
.view__desc { color: var(--muted); margin: 6px 0 0; font-size: 14px; }

/* ---------- 仪表盘 ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow); animation: rise .45s cubic-bezier(.22,1,.36,1) both;
}
.stat__label { font-size: 13px; color: var(--muted); }
.stat__num { font-family: var(--font-display); font-size: 38px; font-weight: 600; line-height: 1.1; margin-top: 8px; letter-spacing: -1px; }
.stat__num small { font-size: 15px; color: var(--muted); font-family: var(--font-body); margin-left: 4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.panel__title { font-size: 14px; font-weight: 600; color: var(--ink-soft); margin: 0 0 18px; }

.bars { display: grid; gap: 13px; }
.bar { display: grid; grid-template-columns: 88px 1fr 36px; align-items: center; gap: 12px; font-size: 13px; }
.bar__track { height: 9px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar__fill { height: 100%; background: var(--accent); border-radius: 999px; width: 0; transition: width .9s cubic-bezier(.22,1,.36,1); }
.bar__count { text-align: right; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.recent { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.recent li { display: flex; align-items: center; justify-content: space-between; padding: 11px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.recent li:last-child { border-bottom: none; }
.recent__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.recent__views { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- 工具栏 / 表格 ---------- */
.toolbar { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.search { flex: 1; min-width: 240px; display: flex; align-items: center; gap: 9px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 0 16px; color: var(--muted); transition: border-color .18s, box-shadow .18s; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { border: none; outline: none; background: none; padding: 11px 0; width: 100%; color: var(--ink); }
.select { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 11px 16px; color: var(--ink-soft); outline: none; }
.select:focus { border-color: var(--accent); }
.inline { display: flex; gap: 10px; align-items: center; }
.cat-add { display: flex; gap: 10px; }
.cat-add input { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 10px 16px; outline: none; min-width: 180px; }
.cat-add input:focus { border-color: var(--accent); }
.cat-name { font-weight: 500; }
.col-drag { width: 30px; text-align: center; color: var(--muted); }
.drag-handle { cursor: grab; user-select: none; font-size: 16px; line-height: 1; }
.drag-handle:active { cursor: grabbing; }
#catBody tr { cursor: default; }
#catBody tr.dragging { opacity: .45; background: var(--accent-soft); }
#catBody tr.drag-before { box-shadow: inset 0 3px 0 var(--accent); }
#catBody tr.drag-after { box-shadow: inset 0 -3px 0 var(--accent); }
#catBody tr.drag-before, #catBody tr.drag-after { background: #fbf3ee; }

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
.table--wide { min-width: 880px; }
.table thead th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.table tbody td { padding: 15px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background .14s; }
.table tbody tr:hover { background: #fbf8f2; }
.res-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.res-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 资源表：固定列宽比例，杜绝 auto 布局在临界宽度下把资源列压窄、操作列(三按钮)挤换行 */
#resTable { table-layout: fixed; }
#resTable th, #resTable td { box-sizing: border-box; }
#resTable th:nth-child(1), #resTable td:nth-child(1) { width: 30%; }
#resTable th:nth-child(2), #resTable td:nth-child(2) { width: 10%; }
#resTable th:nth-child(3), #resTable td:nth-child(3) { width: 13%; }
#resTable th:nth-child(4), #resTable td:nth-child(4) { width: 11%; }
#resTable th:nth-child(5), #resTable td:nth-child(5) { width: 7%; }
#resTable th:nth-child(6), #resTable td:nth-child(6) { width: 9%; }
#resTable th:nth-child(7), #resTable td:nth-child(7) { width: 20%; }
/* 两行布局（标题+描述）与三按钮操作列顶部对齐、操作列兜底宽度 */
#resBody td { vertical-align: top; }
#resBody td:first-child { min-width: 220px; }
#resBody .row-actions { min-width: 168px; }
.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; background: var(--surface-2); padding: 3px 8px; border-radius: 6px; font-size: 12.5px; color: var(--ink-soft); }

.tag-pill { display: inline-block; font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 500; }
.badge { font-size: 12px; padding: 3px 10px; border-radius: 999px; font-weight: 500; }
.badge--on { background: var(--success-soft); color: var(--success); }
.badge--off { background: var(--surface-2); color: var(--muted); }
.badge--muted { background: #efe2dd; color: #a15a3c; }
.badge--super { background: var(--accent); color: #fff; }
.badge--plain { background: var(--accent-soft); color: var(--accent-ink); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.self-tag { font-size: 11px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; margin-left: 6px; font-weight: 400; vertical-align: 1px; }
.form-hint { font-size: 12.5px; color: var(--muted); margin: -2px 0 0; }

/* 用户列表头像 */
.cell-user { display: flex; align-items: center; gap: 10px; }
.u-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--surface-2); border: 1px solid var(--line); flex-shrink: 0; }
.u-avatar--ph { display: inline-flex; align-items: center; justify-content: center; background: var(--accent); color: #fff; font-weight: 600; font-size: 14px; }
.mini { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 11px; font-size: 13px; color: var(--ink-soft); }
.mini:hover { border-color: var(--accent); color: var(--accent); }
.mini--danger:hover { border-color: var(--danger); color: var(--danger); }

.empty { padding: 60px 20px; text-align: center; color: var(--muted); }
.empty p { font-size: 16px; color: var(--ink-soft); margin: 0 0 6px; font-family: var(--font-display); }
.empty span { font-size: 13px; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 18px; font-size: 13px; color: var(--muted); }
.pager button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px; color: var(--ink-soft); }
.pager button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- 分类视图 ---------- */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.cat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); animation: rise .4s cubic-bezier(.22,1,.36,1) both; }
.cat-card__name { font-family: var(--font-display); font-size: 20px; font-weight: 600; }
.cat-card__count { color: var(--muted); font-size: 13px; margin-top: 6px; }
.cat-card__bar { height: 6px; background: var(--surface-2); border-radius: 999px; margin-top: 16px; overflow: hidden; }
.cat-card__bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(28,26,22,.42); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 24px; overflow-y: auto; -webkit-overflow-scrolling: touch; animation: fade .2s ease both; }
.modal__panel { width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; margin: auto; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg); animation: rise .35s cubic-bezier(.22,1,.36,1) both; }
.modal__panel--sm { max-width: 420px; }
.dialog__body { padding: 22px 26px; }
.dialog__msg { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.65; }
.dialog__body .field-input { margin-top: 14px; }
.field-input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm); padding: 11px 13px; color: var(--ink); outline: none; transition: border-color .18s, box-shadow .18s; }
.field-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cat-edit-input { max-width: 220px; }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 22px 26px; border-bottom: 1px solid var(--line); }
.modal__head h3 { margin: 0; font-family: var(--font-display); font-size: 22px; font-weight: 600; }
.editor__form { padding: 24px 26px; display: grid; gap: 16px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal__foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow-lg); z-index: 60; animation: rise .3s cubic-bezier(.22,1,.36,1) both; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
  .main { padding: 32px 28px 56px; }
}
/* 大屏：用满宽度并给出更舒展的留白，避免右侧大片空白 */
@media (min-width: 1440px) {
  .main { padding: 44px 64px 72px; }
  .stats { gap: 20px; }
  .grid-2 { gap: 20px; }
}
@media (min-width: 1920px) {
  .main { padding: 52px 92px 84px; }
  .stats { gap: 24px; }
  .grid-2 { gap: 24px; }
}
/* 窄屏：降低表格最小宽度，减少横向滚动幅度 */
@media (max-width: 480px) {
  .table--wide { min-width: 720px; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 14px; padding: 12px 16px; flex-wrap: wrap; }
  .nav { flex-direction: row; flex: 1; gap: 4px; overflow-x: auto; }
  .nav__item { white-space: nowrap; }
  .sidebar__foot { border: none; padding: 0; margin-left: auto; }
  .main { padding: 24px 18px 50px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
  .view__head--row { flex-wrap: wrap; }
  .view__head--row .btn { width: 100%; justify-content: center; }
  .cat-add { width: 100%; }
  .cat-add input { flex: 1; min-width: 0; }
}
@media (max-width: 560px) {
  .sidebar { gap: 10px; }
  .brand__name { display: none; }
  .stats { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .select { width: 100%; }
  .search { min-width: 0; }
  .pager { justify-content: center; flex-wrap: wrap; }
  /* 弹窗与小屏表单紧凑化，避免内容溢出/顶部被裁切 */
  .modal { padding: 12px; }
  .modal__panel { max-height: 94vh; border-radius: 16px; }
  .modal__head { padding: 18px 16px; }
  .editor__form { padding: 18px 16px; gap: 14px; }
  .dialog__body { padding: 18px 16px; }
  .modal__foot { flex-direction: column-reverse; }
  .modal__foot .btn { width: 100%; }
  .rte__toolbar { gap: 3px; padding: 6px 8px; }
  .rte__toolbar button { padding: 4px 7px; min-width: 28px; font-size: 12.5px; }
  .rte__editor { min-height: 100px; max-height: 240px; }
  .field input, .field select, .field textarea { padding: 10px 12px; }
  .view__head--row .btn { width: 100%; justify-content: center; }
}

/* ---------- 系统设置 ---------- */
.config-form { max-width: 720px; display: flex; flex-direction: column; gap: 18px; }
.config-form .panel { margin: 0; }
.cfg-secret { font-size: 12px; font-weight: 400; color: var(--muted); }

/* ---------- 资源多链接编辑器 ---------- */
.links-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.btn--sm { padding: 6px 14px; font-size: 12.5px; border-radius: 999px; }
.link-list { display: flex; flex-direction: column; gap: 12px; }
.link-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "pan  pan"
    "link link"
    "code pwd"
    "free del";
  gap: 10px; align-items: center;
  background: #fffdf9; border: 1px solid #e6e0d4; border-radius: 12px; padding: 14px;
}
.link-row .lk-pan { grid-area: pan; }
.link-row .lk-link { grid-area: link; }
.link-row .lk-code { grid-area: code; }
.link-row .lk-pwd { grid-area: pwd; }
.link-row .lk-free { grid-area: free; display: flex; align-items: center; gap: 6px; font-size: 13px; color: #57534b; white-space: nowrap; }
.link-row .lk-del { grid-area: del; justify-self: end; padding: 8px 14px; }
.link-row .lk-pan, .link-row .lk-link, .link-row .lk-code, .link-row .lk-pwd {
  height: 38px; border: 1px solid #e0d9cb; border-radius: 8px; padding: 0 12px; font-size: 14px; background: #fff; min-width: 0; width: 100%;
}
.muted { color: #9b9384; font-size: 13px; }

/* ---------- 富文本编辑器（资源描述） ---------- */
.rte { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; transition: border-color .18s, box-shadow .18s; }
.rte:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rte__toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.rte__toolbar button { border: 1px solid transparent; background: var(--surface); color: var(--ink-soft); border-radius: 7px; padding: 5px 9px; font-size: 13px; line-height: 1; min-width: 30px; }
.rte__toolbar button:hover { border-color: var(--line); background: #fff; color: var(--ink); }
.rte__sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.rte__editor { min-height: 120px; max-height: 320px; overflow: auto; padding: 12px 14px; outline: none; font-size: 14px; line-height: 1.6; color: var(--ink); }
.rte__editor:empty:before { content: attr(data-placeholder); color: var(--muted); }
.rte__editor p { margin: 0 0 0.6em; }
.rte__editor h2 { font-size: 1.25em; font-weight: 700; margin: 0.7em 0 0.3em; }
.rte__editor h3 { font-size: 1.1em; font-weight: 700; margin: 0.6em 0 0.3em; }
.rte__editor ul, .rte__editor ol { padding-left: 1.4em; margin: 0.4em 0; }
.rte__editor blockquote { border-left: 3px solid var(--line); padding-left: 0.8em; margin: 0.5em 0; color: var(--muted); }
.rte__editor a { color: var(--accent); }
