/* ============================================================
   墨迹博客 · 管理后台样式
   ============================================================ */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --sidebar: #14181f;
  --sidebar-hover: #1e242e;
  --sidebar-text: #9aa4b2;
  --sidebar-active: #ffffff;
  --text: #171a1f;
  --text-soft: #3d434e;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-soft: #eef0f3;
  --accent: #0f7b6c;
  --accent-hover: #0b6357;
  --accent-soft: #e6f4f1;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --warn: #b7791f;
  --warn-soft: #fdf6e3;
  --ok: #2f855a;
  --ok-soft: #e8f5ee;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 4px 16px rgba(16, 24, 40, .08);
  --shadow-lg: 0 18px 44px rgba(16, 24, 40, .16);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 234px;
  --font-sans: -apple-system, BlinkMacSystemFont, "HarmonyOS Sans SC", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------------- 登录 ---------------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2b34 0%, #0e1216 55%, #0b0e12 100%);
}

.login-card {
  width: 100%;
  max-width: 396px;
  background: var(--surface);
  border-radius: 16px;
  padding: 36px 34px 30px;
  box-shadow: var(--shadow-lg);
}
.login-card .logo {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #0b6357);
  color: #fff;
  font-size: 21px;
  font-weight: 700;
  margin-bottom: 18px;
}
.login-card h1 { font-size: 21px; margin: 0 0 6px; }
.login-card .sub { color: var(--muted); font-size: 13.5px; margin: 0 0 24px; }
.login-card .field { margin-bottom: 16px; }
.login-card button[type="submit"] { width: 100%; margin-top: 6px; }
.login-hint {
  margin-top: 18px;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  line-height: 1.7;
}
.login-hint code {
  font-family: var(--font-mono);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* ---------------- 骨架 ---------------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 20px 18px;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.sidebar .brand .mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #0b6357);
  font-size: 15px;
  flex: none;
}
.sidebar .brand small { display: block; font-size: 11px; font-weight: 400; opacity: .55; letter-spacing: .4px; }

.side-nav { padding: 12px 12px; flex: 1; }
.side-nav .group {
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  opacity: .38;
  padding: 14px 10px 7px;
}
.side-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--sidebar-text);
  font-size: 14.5px;
  margin-bottom: 2px;
  transition: .16s;
}
.side-nav a .ico { width: 18px; text-align: center; opacity: .85; font-size: 15px; }
.side-nav a:hover { background: var(--sidebar-hover); color: #e8ecf2; }
.side-nav a.active { background: var(--accent); color: #fff; font-weight: 600; }
.side-nav a .badge {
  margin-left: auto;
  background: rgba(255, 255, 255, .14);
  font-size: 11.5px;
  padding: 1px 7px;
  border-radius: 999px;
}
.side-nav a.active .badge { background: rgba(255, 255, 255, .26); }

.side-foot { padding: 14px 16px 20px; border-top: 1px solid rgba(255, 255, 255, .07); }
.side-foot a, .side-foot button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--sidebar-text);
  padding: 7px 6px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13.5px;
}
.side-foot a:hover, .side-foot button:hover { color: #fff; background: var(--sidebar-hover); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; }
.topbar .spacer { margin-left: auto; }
.topbar .hint { color: var(--muted); font-size: 13px; }

.content { padding: 24px; flex: 1; }
.content.narrow { max-width: 780px; }

/* ---------------- 组件 ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
}
.card > h2 {
  font-size: 15.5px;
  margin: 0 0 4px;
  font-weight: 600;
}
.card > .desc { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .head { padding: 18px 20px 14px; border-bottom: 1px solid var(--border-soft); }
.card.flush > .head h2 { margin: 0; font-size: 15.5px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(174px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat .label { color: var(--muted); font-size: 12.5px; letter-spacing: .3px; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; line-height: 1.2; }
.stat .value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.stat.accent .value { color: var(--accent); }

/* 表单 */

.field { margin-bottom: 16px; }
.field > label {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-soft);
}
.field .tip { font-size: 12.5px; color: var(--muted); margin-top: 5px; }

input[type="text"], input[type="password"], input[type="number"],
input[type="search"], input[type="url"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.7; }

.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > .field { flex: 1 1 220px; margin-bottom: 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 17px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: .16s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f0c8c2; }
.btn.danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--bg); color: var(--text); border-color: transparent; }
.btn.sm { padding: 5px 11px; font-size: 13px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn-row .spacer { margin-left: auto; }

/* 表格 */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
table.data th {
  background: var(--surface-2);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .4px;
  white-space: nowrap;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.actions { text-align: right; white-space: nowrap; }
table.data td.title-cell { min-width: 220px; }
table.data td.title-cell b { font-weight: 600; }
table.data td.title-cell .slug {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.draft { background: var(--warn-soft); color: var(--warn); }
.pill.gray { background: var(--bg); color: var(--muted); font-weight: 500; }
.pill.tag { background: var(--accent-soft); color: var(--accent); }

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
}
.toolbar input[type="search"] { max-width: 240px; }
.toolbar select { max-width: 160px; }

.empty-row { padding: 46px 20px; text-align: center; color: var(--muted); }

/* 编辑器 */

.editor-head {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.editor-head input[type="text"].title-input {
  flex: 1 1 320px;
  font-size: 19px;
  font-weight: 700;
  padding: 10px 14px;
  border-color: transparent;
  background: var(--surface);
}
.editor-head input.title-input:focus { border-color: var(--accent); }

.editor-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  min-height: 460px;
}
.editor-pane { display: flex; flex-direction: column; min-width: 0; }
.editor-pane + .editor-pane { border-left: 1px solid var(--border); }
.pane-head {
  padding: 9px 16px;
  font-size: 12px;
  letter-spacing: .6px;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 10px;
}
.pane-head .spacer { margin-left: auto; }
#mdInput {
  flex: 1;
  border: 0;
  border-radius: 0;
  padding: 18px 20px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.8;
  resize: none;
  min-height: 420px;
  outline: none;
}
#mdInput:focus { box-shadow: none; }
#mdPreview {
  flex: 1;
  padding: 18px 22px;
  overflow-y: auto;
  max-height: 640px;
}

/* 预览区复用的正文排版 */
.prose { font-size: 15.5px; line-height: 1.8; color: var(--text-soft); overflow-wrap: break-word; }
.prose > *:first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  color: var(--text); line-height: 1.4; margin: 1.6em 0 .6em;
}
.prose h1 { font-size: 23px; }
.prose h2 { font-size: 20px; padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.prose h3 { font-size: 17px; }
.prose p { margin: 0 0 1em; }
.prose ul, .prose ol { margin: 0 0 1em; padding-left: 1.5em; }
.prose li { margin: .3em 0; }
.prose li.task { list-style: none; margin-left: -1.3em; }
.prose li.task.done { color: var(--muted); text-decoration: line-through; }
.prose blockquote {
  margin: 0 0 1em; padding: 10px 18px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 1.8em 0; }
.prose code {
  font-family: var(--font-mono); font-size: .875em;
  background: var(--bg); border: 1px solid var(--border-soft);
  padding: .1em .4em; border-radius: 4px; color: var(--accent);
}
.prose img { border-radius: var(--radius-sm); }
.prose .code-block {
  position: relative; margin: 0 0 1.1em; border-radius: var(--radius-sm);
  overflow: hidden; border: 1px solid var(--border); background: #1b1f27;
}
.prose .code-block .code-lang {
  position: absolute; top: 0; right: 0; padding: 3px 10px;
  font-size: 11px; text-transform: uppercase; color: #8b95a5;
  background: rgba(255, 255, 255, .05); border-bottom-left-radius: 8px;
  font-family: var(--font-mono);
}
.prose .code-block pre { margin: 0; padding: 16px 18px; overflow-x: auto; }
.prose .code-block code {
  font-family: var(--font-mono); font-size: 13px; line-height: 1.7;
  color: #dfe6f0; background: none; border: 0; padding: 0; white-space: pre;
}
.prose .table-wrap { overflow-x: auto; margin: 0 0 1.1em; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.prose table { width: 100%; border-collapse: collapse; font-size: 14px; }
.prose th, .prose td { padding: 9px 13px; border-bottom: 1px solid var(--border-soft); text-align: left; }
.prose th { background: var(--bg); font-weight: 600; color: var(--text); }
.prose .ta-center { text-align: center; }
.prose .ta-right { text-align: right; }

/* 提示条 */

.notice {
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 18px;
  background: var(--warn-soft);
  border: 1px solid #f0e0b6;
  color: #7c5c17;
}
.notice.err { background: var(--danger-soft); border-color: #f3c6c0; color: #96352a; }
.notice.ok { background: var(--ok-soft); border-color: #c3e3d0; color: #276749; }
.notice code { font-family: var(--font-mono); }

/* 分类 / 标签列表项 */

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13.5px;
}
.chip-item .n { color: var(--muted); font-size: 12px; }
.chip-item button {
  border: 0; background: none; cursor: pointer;
  color: var(--muted); font-size: 14px; line-height: 1;
  padding: 2px 5px; border-radius: 50%;
}
.chip-item button:hover { color: var(--danger); background: var(--danger-soft); }
.chip-item button.edit:hover { color: var(--accent); background: var(--accent-soft); }

.inline-add { display: flex; gap: 8px; margin-bottom: 16px; }
.inline-add input { max-width: 260px; }

/* 模态 */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(12, 16, 22, .5);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 20px;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 14px;
  padding: 26px 26px 20px;
  box-shadow: var(--shadow-lg);
  animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.modal input { margin-bottom: 18px; }
.modal .btn-row { justify-content: flex-end; }

/* Toast */

.toast-host {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  animation: slideIn .2s ease;
  max-width: 340px;
}
.toast.ok { background: #1f7a52; }
.toast.err { background: #b03a2e; }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

.mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-soft);
}

.hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }

.mobile-bar { display: none; }

/* ---------------- 响应式 ---------------- */

@media (max-width: 1080px) {
  .editor-split { grid-template-columns: 1fr; }
  .editor-pane + .editor-pane { border-left: 0; border-top: 1px solid var(--border); }
}

@media (max-width: 780px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .mobile-bar { display: grid; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .stat { padding: 14px 16px; }
  .stat .value { font-size: 23px; }
}

@media (max-width: 520px) {
  .card { padding: 18px 16px; }
  table.data th, table.data td { padding: 10px 12px; }
  .toolbar { padding: 12px 14px; }
  .toolbar input[type="search"], .toolbar select { max-width: none; flex: 1 1 140px; }
}
