:root {
  --bg: #ffffff;
  --bg-soft: #f5f5f7;
  --bg-sink: #fafafa;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e3e8;
  --accent: #0071e3;
  --accent-soft: #e8f2fe;
  --danger: #d70015;
  --ok: #1d9a4e;
  --warn: #b25000;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0d;
    --bg-soft: #16161a;
    --bg-sink: #101013;
    --text: #f5f5f7;
    --muted: #9a9aa2;
    --line: #2a2a31;
    --accent: #4da3ff;
    --accent-soft: #10243a;
    --danger: #ff6b6b;
    --ok: #3ddc84;
    --warn: #ffb020;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg-soft);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- 布局 ---------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px; flex: 0 0 216px;
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 22px 14px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

.brand { padding: 0 8px 18px; }
.brand a { font-size: 17px; font-weight: 650; color: var(--text); letter-spacing: -.2px; }
.brand a:hover { text-decoration: none; }
.brand span {
  display: block; font-size: 12px; color: var(--muted);
  font-weight: 400; margin-top: 2px; letter-spacing: .3px;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: 8px;
  color: var(--muted); font-size: 14px;
}
.sidebar nav a:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 550; }

.side-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; }
.side-foot form { margin: 0 0 8px; }
.side-foot button {
  background: none; border: 0; padding: 6px 8px; color: var(--muted);
  cursor: pointer; font-size: 13px; font-family: inherit;
}
.side-foot button:hover { color: var(--danger); }
.side-foot a { display: block; padding: 6px 8px; color: var(--muted); }

.main { flex: 1; min-width: 0; padding: 26px 34px 60px; max-width: 1180px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.topbar h1 { font-size: 23px; font-weight: 650; margin: 0; letter-spacing: -.3px; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* ---------------- 通用组件 ---------------- */
.card {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; margin-bottom: 18px;
}
.card h2 { font-size: 15px; margin: 0 0 14px; font-weight: 600; }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stat {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px;
}
.stat .k { font-size: 12px; color: var(--muted); letter-spacing: .3px; }
.stat .v { font-size: 26px; font-weight: 650; margin-top: 4px; letter-spacing: -.5px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  padding: 8px 14px; border-radius: 9px; font-size: 14px;
  cursor: pointer; font-family: inherit; transition: .15s;
}
.btn:hover { background: var(--bg-soft); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 550; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); border-color: var(--line); }
.btn.danger:hover { background: rgba(215, 0, 21, .08); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-weight: 550; font-size: 12px; color: var(--muted);
  padding: 9px 10px; border-bottom: 1px solid var(--line); letter-spacing: .4px;
  text-transform: none;
}
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 20px;
  background: var(--bg-soft); color: var(--muted);
  font-size: 12px; margin: 1px 4px 1px 0; border: 1px solid var(--line);
}
.badge { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 550; }
.badge.draft { background: rgba(178, 80, 0, .12); color: var(--warn); }
.badge.live { background: rgba(29, 154, 78, .12); color: var(--ok); }

.empty { color: var(--muted); text-align: center; padding: 40px 10px; font-size: 14px; }

.flash {
  padding: 11px 15px; border-radius: 10px; margin-bottom: 16px; font-size: 14px;
  border: 1px solid var(--line); background: var(--bg);
}
.flash.ok { border-color: rgba(29, 154, 78, .35); color: var(--ok); }
.flash.error { border-color: rgba(215, 0, 21, .35); color: var(--danger); }

/* ---------------- 表单 ---------------- */
label.field { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
label.field > span { display: block; margin-bottom: 5px; letter-spacing: .2px; }
input[type=text], input[type=password], input[type=date], textarea, select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--bg); color: var(--text);
  font: inherit; font-size: 14px; outline: none; transition: .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; font-family: var(--mono); font-size: 13.5px; line-height: 1.7; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); margin: 4px 0 16px; }

/* ---------------- 编辑器 ---------------- */
.editor-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1080px) { .editor-wrap { grid-template-columns: 1fr; } }

.editor-pane { display: flex; flex-direction: column; }
.editor-toolbar {
  display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px;
}
.editor-toolbar button {
  border: 1px solid var(--line); background: var(--bg); color: var(--muted);
  border-radius: 7px; padding: 5px 9px; font-size: 12.5px; cursor: pointer;
  font-family: inherit;
}
.editor-toolbar button:hover { color: var(--text); background: var(--bg-soft); }
#body { min-height: 520px; }

.preview-pane {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); padding: 18px 22px; min-height: 560px;
  overflow: auto; max-height: 78vh;
}
.preview-pane .ph { color: var(--muted); font-size: 13px; }
.preview-pane h1, .preview-pane h2, .preview-pane h3 { line-height: 1.35; margin: 1.2em 0 .5em; }
.preview-pane h2 { font-size: 1.3em; border-bottom: 1px solid var(--line); padding-bottom: .25em; }
.preview-pane pre {
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; overflow: auto; font-family: var(--mono); font-size: 13px;
}
.preview-pane code { font-family: var(--mono); font-size: .92em; }
.preview-pane :not(pre) > code {
  background: var(--bg-soft); padding: .12em .38em; border-radius: 5px;
}
.preview-pane img { max-width: 100%; border-radius: 8px; }
.preview-pane blockquote {
  margin: 1em 0; padding: .2em 1em; border-left: 3px solid var(--line); color: var(--muted);
}
.preview-pane table { margin: 1em 0; }

/* ---------------- 媒体库 ---------------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.media-item {
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: var(--bg); display: flex; flex-direction: column;
}
.media-item .thumb {
  height: 118px; background: var(--bg-soft); display: flex;
  align-items: center; justify-content: center; overflow: hidden;
}
.media-item .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.media-item .meta { padding: 8px 10px; font-size: 12px; color: var(--muted); }
.media-item .meta b { display: block; color: var(--text); font-weight: 500; font-size: 12.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-item .ops { display: flex; gap: 6px; padding: 0 10px 10px; }

.dropzone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 34px;
  text-align: center; color: var(--muted); cursor: pointer; transition: .15s;
  background: var(--bg);
}
.dropzone.hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---------------- 登录页 ---------------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg-soft); padding: 20px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 16px; padding: 30px 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .07);
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; font-weight: 650; }
.login-card p.sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.login-card .err {
  color: var(--danger); font-size: 13px; margin: 0 0 14px;
  background: rgba(215, 0, 21, .07); padding: 9px 12px; border-radius: 8px;
}

.log-box {
  background: var(--bg-sink); border: 1px solid var(--line); border-radius: 9px;
  padding: 12px 14px; font-family: var(--mono); font-size: 12.5px;
  white-space: pre-wrap; max-height: 260px; overflow: auto; color: var(--muted);
}

.meter { height: 7px; background: var(--bg-soft); border-radius: 4px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mb0 { margin-bottom: 0; }
.spacer { height: 8px; }
.inline { display: inline; }
.right { text-align: right; }
