/* ============ 后台 ============ */
/* 主站为了做「桌面」把页面锁成不可滚动；后台要改回普通网页的整页滚动。
   body 不能再是滚动容器，也要允许滚动向外传递，否则滚轮和手指滑动会被吞掉。 */
html { height: auto; min-height: 100%; overflow-y: auto; overscroll-behavior: auto; }
body { height: auto; min-height: 100%; overflow: visible; overscroll-behavior: auto; }
body {
  user-select: text; -webkit-user-select: text;
  background:
    radial-gradient(60% 50% at 10% 0%, color-mix(in srgb, #4c7dff 22%, transparent), transparent 70%),
    radial-gradient(50% 40% at 100% 100%, color-mix(in srgb, #9a6bff 18%, transparent), transparent 70%),
    var(--surface-solid);
  background-attachment: fixed;
  color: var(--text);
}
[data-theme="light"] body { --surface-solid: #f3f4f8; --card: #fff; }
[data-theme="dark"] body { --surface-solid: #14151b; --card: #1d1e26; }
.muted { color: var(--text-2); }
code { font-family: var(--mono); font-size: .9em; padding: 1px 5px; border-radius: 5px; background: var(--hover); }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 10px; white-space: nowrap;
  font-size: 13px; font-weight: 600; color: var(--text); cursor: pointer;
  background: var(--card); box-shadow: inset 0 0 0 1px var(--line-2);
  transition: background .15s, transform .2s var(--ease-spring), opacity .15s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn .glyph { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #fff); }
.btn.ghost { background: none; box-shadow: none; color: var(--accent); padding: 0 8px; }
.btn.danger { color: #ef4444; }
.btn.danger:hover { background: color-mix(in srgb, #ef4444 12%, transparent); }

/* 登录 */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(360px, 100%); display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  padding: 34px 28px 26px; border-radius: 26px; background: var(--card);
  box-shadow: 0 30px 80px -20px rgba(20, 30, 80, .35), inset 0 0 0 1px var(--line);
}
.login-logo {
  width: 64px; height: 64px; border-radius: 19px; display: grid; place-items: center; color: #fff;
  background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, .4), transparent 55%), linear-gradient(140deg, #4c7dff, #9a6bff);
  box-shadow: 0 10px 26px rgba(76, 125, 255, .4);
}
.login-logo .logo { width: 58%; height: 58%; }
.login-card h1 { margin: 6px 0 0; font-size: 21px; }
.login-card p { margin: 0; font-size: 13px; }
.login-card input {
  width: 100%; height: 42px; padding: 0 14px; border: 0; border-radius: 12px; font-size: 15px;
  background: var(--surface-solid); box-shadow: inset 0 0 0 1px var(--line-2);
}
.login-card input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.login-card .btn { width: 100%; height: 42px; font-size: 15px; }
.login-err, .login-warn { color: #ef4444; font-weight: 600; }
.login-back { font-size: 13px; color: var(--text-2); margin-top: 6px; }

/* 布局 */
.ad { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.ad-side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px;
  padding: 18px 12px; border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 55%, transparent);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.ad-brand { display: flex; align-items: center; gap: 9px; padding: 4px 8px 18px; }
.ad-logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff; background: linear-gradient(140deg, #4c7dff, #9a6bff); }
.ad-logo .logo { width: 60%; height: 60%; }
.ad-brand b { font-size: 15px; }
.ad-brand small { font-size: 11px; font-weight: 700; color: var(--text-3); padding: 1px 6px; border-radius: 6px; background: var(--hover); }
.ad-nav { display: flex; flex-direction: column; gap: 2px; }
.ad-nav button {
  display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 12px; border-radius: 10px;
  font-size: 14px; font-weight: 500; cursor: pointer; text-align: left;
}
.ad-nav button .glyph { width: 18px; height: 18px; }
.ad-nav button small { margin-left: auto; font-size: 12px; color: var(--text-3); }
.ad-nav button:hover { background: var(--hover); }
.ad-nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.ad-side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.ad-side-foot a, .ad-side-foot button {
  display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; border-radius: 9px;
  font-size: 13px; color: var(--text-2); cursor: pointer; text-decoration: none;
}
.ad-side-foot .glyph { width: 16px; height: 16px; }
.ad-side-foot a:hover, .ad-side-foot button:hover { background: var(--hover); color: var(--text); }

.ad-main { min-width: 0; display: flex; flex-direction: column; }
.ad-top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 14px;
  padding: 14px 28px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-solid) 80%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(1.6); backdrop-filter: blur(20px) saturate(1.6);
}
.ad-title { margin: 0; font-size: 20px; }
.ad-dirty { font-size: 12px; font-weight: 600; color: #f59e0b; margin-left: auto; }
.ad-dirty[hidden] + .btn { margin-left: auto; }
.ad-content { padding: 24px 28px 60px; }

.ad-form { max-width: 820px; display: flex; flex-direction: column; gap: 18px; }
.ad-card { background: var(--card); border-radius: 18px; padding: 20px 22px; box-shadow: inset 0 0 0 1px var(--line), 0 6px 20px -12px rgba(0, 0, 0, .2); }
.ad-card h2 { margin: 0 0 14px; font-size: 15px; }

/* 字段 */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.f-label { font-size: 13px; font-weight: 600; }
.f-hint { font-size: 12px; color: var(--text-3); }
.f-input {
  width: 100%; border: 0; border-radius: 10px; padding: 9px 12px; font-size: 14px; line-height: 1.6;
  background: var(--surface-solid); box-shadow: inset 0 0 0 1px var(--line-2); resize: vertical;
}
input.f-input, select.f-input { height: 38px; padding-top: 0; padding-bottom: 0; }
.f-input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.md-src { font-family: var(--mono); font-size: 13px; }

.f-media { display: flex; gap: 14px; align-items: flex-start; }
.f-thumb {
  width: 96px; height: 96px; flex: none; border-radius: 14px; overflow: hidden; display: grid; place-items: center;
  background: var(--surface-solid); box-shadow: inset 0 0 0 1px var(--line-2); color: var(--text-3);
}
.f-thumb img { width: 100%; height: 100%; object-fit: cover; }
.f-thumb .glyph { width: 28px; height: 28px; }
.f-thumb.wide { width: 100%; height: auto; aspect-ratio: 16 / 9; max-width: 420px; }
.f-media-side { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.f-media-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.f-progress { position: relative; height: 22px; border-radius: 8px; overflow: hidden; background: var(--surface-solid); box-shadow: inset 0 0 0 1px var(--line-2); }
.f-progress i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent-soft); transition: width .2s; }
.f-progress span { position: relative; font-size: 12px; font-weight: 600; padding-left: 10px; line-height: 22px; color: var(--accent); }

.f-images { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.f-img { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface-solid); box-shadow: inset 0 0 0 1px var(--line-2); }
.f-img img { width: 100%; height: 100%; object-fit: cover; }
.f-img button {
  position: absolute; top: 5px; right: 5px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(0, 0, 0, .6); color: #fff; cursor: pointer;
}
.f-img button .glyph { width: 13px; height: 13px; stroke-width: 2.6; }
.f-img.add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--text-2); font-size: 12px; cursor: pointer; border: 0; }
.f-img.add .glyph { width: 22px; height: 22px; }
.f-img.add:hover { color: var(--accent); }

.f-video { display: flex; flex-direction: column; gap: 8px; }
.f-video video { width: 100%; max-width: 480px; border-radius: 12px; background: #000; }

.f-colors { display: flex; align-items: center; gap: 8px; }
.f-colors input { width: 42px; height: 34px; border: 0; padding: 0; background: none; cursor: pointer; }
.f-colors-prev { width: 120px; height: 34px; border-radius: 10px; }
.f-glyph { display: flex; gap: 8px; align-items: center; }
.f-glyph-prev { width: 38px; height: 38px; flex: none; border-radius: 10px; display: grid; place-items: center; background: var(--accent); color: #fff; }
.f-glyph-prev .glyph { width: 20px; height: 20px; }

.f-check { position: relative; display: inline-flex; width: 42px; height: 24px; cursor: pointer; }
.f-check input { position: absolute; opacity: 0; }
.f-check span { position: absolute; inset: 0; border-radius: 999px; background: var(--line-2); transition: background .2s; }
.f-check span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); transition: transform .25s var(--ease-spring); }
.f-check input:checked + span { background: #34c759; }
.f-check input:checked + span::after { transform: translateX(18px); }

.f-rows { display: flex; flex-direction: column; gap: 8px; }
.f-row { display: flex; gap: 10px; align-items: flex-end; padding: 10px 12px; border-radius: 12px; background: var(--surface-solid); box-shadow: inset 0 0 0 1px var(--line); }
.f-row .field { margin: 0; flex: 1; min-width: 0; }
.f-row .f-input { background: var(--card); }
.f-cell { flex: 1; min-width: 0; }
.f-cell-glyph { flex: 0 0 150px; }
.f-cell-check { flex: 0 0 auto; }
.f-cell-check .field { align-items: center; }
.f-row-act { display: flex; gap: 2px; padding-bottom: 4px; }
.f-row-act button, .ad-editor-tools .icon {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: var(--text-2); cursor: pointer;
}
.f-row-act button:hover:not(:disabled), .ad-editor-tools .icon:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.f-row-act button:disabled, .ad-editor-tools .icon:disabled { opacity: .3; cursor: default; }
.f-row-act .glyph, .ad-editor-tools .icon .glyph { width: 16px; height: 16px; }
.f-add { align-self: flex-start; }

.md { display: flex; flex-direction: column; gap: 6px; }
.md-bar { display: flex; gap: 6px; }
.md-bar button {
  display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px; border-radius: 8px;
  font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface-solid); box-shadow: inset 0 0 0 1px var(--line-2); cursor: pointer;
}
.md-bar button:hover { color: var(--accent); }
.md-bar .glyph { width: 14px; height: 14px; }
.md-preview { min-height: 200px; padding: 6px 14px; border-radius: 10px; background: var(--surface-solid); box-shadow: inset 0 0 0 1px var(--line-2); }
.prose { line-height: 1.8; font-size: 14.5px; }
.prose h2, .prose h3, .prose h4 { margin: 18px 0 6px; }
.prose img { max-width: 100%; border-radius: 10px; }
.prose blockquote { margin: 0 0 12px; padding: 6px 14px; border-left: 3px solid var(--accent); color: var(--text-2); }

/* 列表 + 编辑器 */
.ad-collection { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
.ad-list { position: sticky; top: 90px; max-height: calc(100vh - 110px); overflow: auto; display: flex; flex-direction: column; gap: 4px; padding: 2px; }
.ad-new { margin-bottom: 8px; }
.ad-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; cursor: pointer; }
.ad-item:hover { background: var(--hover); }
.ad-item.active { background: var(--card); box-shadow: inset 0 0 0 1px var(--line-2), 0 4px 14px -8px rgba(0, 0, 0, .25); }
.ad-item-thumb { width: 44px; height: 44px; flex: none; border-radius: 10px; overflow: hidden; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.ad-item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ad-item-thumb .glyph { width: 20px; height: 20px; }
.ad-item-text { min-width: 0; display: flex; flex-direction: column; }
.ad-item-text b { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ad-item-text small { font-size: 12px; color: var(--text-3); }
.ad-empty { font-size: 13px; padding: 10px; }
.ad-editor { min-width: 0; max-width: 820px; }
.ad-editor-head { display: flex; align-items: center; margin-bottom: 12px; }
.ad-editor-tools { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.ad-back { display: none; }

.ad-toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 50; transform: translateX(-50%);
  padding: 10px 18px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--text); color: var(--surface-solid); box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  animation: toast-in .25s var(--ease-spring);
}
.ad-toast.bad { background: #ef4444; color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* 手机 */
@media (max-width: 760px) {
  .ad { grid-template-columns: 1fr; }
  .ad-side {
    position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center;
    padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto;
  }
  .ad-brand { padding: 0 6px 0 0; }
  .ad-brand b, .ad-brand small { display: none; }
  .ad-nav { flex-direction: row; }
  .ad-nav button { height: 34px; padding: 0 10px; gap: 6px; }
  .ad-nav button small { display: none; }
  .ad-side-foot { margin: 0 0 0 auto; flex-direction: row; }
  .ad-side-foot a, .ad-side-foot button { font-size: 0; gap: 0; padding: 0 9px; }
  .ad-top { top: 51px; padding: 10px 14px; }
  .ad-title { font-size: 18px; }
  .ad-content { padding: 14px 12px 60px; }
  .ad-card { padding: 16px 14px; }
  .ad-collection { grid-template-columns: 1fr; }
  .ad-list { position: static; max-height: none; }
  .ad-collection.editing .ad-list { display: none; }
  .ad-collection:not(.editing) .ad-editor { display: none; }
  .ad-back { display: inline-flex; }
  .f-row { flex-wrap: wrap; }
  .f-cell { flex: 1 1 40%; }
  .f-cell-glyph { flex: 1 1 100%; }
  .f-media { flex-direction: column; }
}
