:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }

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", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button { font-family: inherit; font-size: 14px; cursor: pointer; }

input, textarea, select {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 11px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  padding: 7px 13px;
  border-radius: 8px;
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: #f9fafb; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f3f4f6; color: var(--text); }
.btn-danger { color: var(--red); border-color: #fecaca; background: #fff; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 4px 9px; font-size: 13px; border-radius: 6px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #e8efff 0%, var(--bg) 60%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, .08);
  padding: 32px 28px;
}
.login-card h1 { font-size: 20px; margin: 0 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 7px; }
.login-card input { width: 100%; margin-bottom: 16px; }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; }

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

.sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 4px 10px 18px; font-weight: 600; }
.brand-dot {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 700;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px; border-radius: 8px;
  color: #374151; text-decoration: none; font-size: 14px;
}
.nav a:hover { background: #f3f4f6; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.nav svg { width: 16px; height: 16px; flex: none; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 4px; }
.sidebar-footer .site-link { font-size: 12px; color: var(--muted); word-break: break-all; text-decoration: none; }
.sidebar-footer .site-link:hover { color: var(--primary); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 28px;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; }
.topbar .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.view { padding: 24px 28px 60px; max-width: 1180px; width: 100%; }

/* ---------- 统计卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 600; margin-top: 2px; }

/* ---------- 列表 ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.tabs { display: inline-flex; background: #eef0f3; border-radius: 9px; padding: 3px; }
.tabs button {
  border: none; background: transparent; padding: 6px 13px; border-radius: 7px; color: var(--muted); font-size: 13px;
}
.tabs button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); font-weight: 500; }
.search { flex: 1; min-width: 180px; max-width: 320px; }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.post-row {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 16px; border-bottom: 1px solid #f1f2f4;
}
.post-row:last-child { border-bottom: none; }
.post-row:hover { background: #fafbfc; }
.post-main { min-width: 0; flex: 1; }
.post-title { font-weight: 500; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post-meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.post-actions { display: flex; gap: 6px; flex: none; }
.tag {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: #f3f4f6; color: #4b5563;
}
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 500; }
.badge-published { background: var(--green-soft); color: var(--green); }
.badge-draft { background: var(--amber-soft); color: var(--amber); }
.badge-synced { background: var(--primary-soft); color: var(--primary); }

.empty { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); margin-bottom: 6px; }

/* ---------- 编辑器 ---------- */
.editor-head {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.editor-title input {
  width: 100%; font-size: 19px; font-weight: 600; border: none; padding: 4px 2px; margin-bottom: 8px;
}
.editor-title input:focus { box-shadow: none; }
.meta-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.meta-grid .field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.meta-grid input, .meta-grid select { width: 100%; }
.meta-grid .wide { grid-column: span 3; }

.editor-body { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pane {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; min-height: 460px;
}
.pane-head {
  display: flex; align-items: center; gap: 6px; padding: 7px 10px;
  border-bottom: 1px solid var(--border); background: #fbfbfc;
}
.pane-head .label { font-size: 12px; color: var(--muted); margin-right: auto; }
.md-tool {
  border: none; background: transparent; color: #4b5563; padding: 3px 6px; border-radius: 5px;
  font-size: 13px; line-height: 1;
}
.md-tool:hover { background: #eef0f3; }
#mdInput {
  flex: 1; border: none; border-radius: 0; resize: none; padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13.5px; line-height: 1.75; tab-size: 2;
}
#mdInput:focus { box-shadow: none; }
.preview { flex: 1; overflow: auto; padding: 18px 20px; }

/* markdown 渲染样式 */
.md { font-size: 15px; line-height: 1.8; color: #1f2937; }
.md > *:first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.35; margin: 1.4em 0 .6em; font-weight: 600; }
.md h1 { font-size: 1.6em; border-bottom: 1px solid var(--border); padding-bottom: .3em; }
.md h2 { font-size: 1.3em; }
.md h3 { font-size: 1.12em; }
.md p { margin: .8em 0; }
.md a { color: var(--primary); }
.md code {
  background: #f3f4f6; padding: .15em .4em; border-radius: 4px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em;
}
.md pre { background: #0f172a; color: #e2e8f0; padding: 14px 16px; border-radius: 9px; overflow: auto; }
.md pre code { background: transparent; color: inherit; padding: 0; }
.md blockquote { margin: 1em 0; padding: .2em 1em; border-left: 3px solid #d1d5db; color: #4b5563; background: #fafafa; }
.md img { max-width: 100%; border-radius: 8px; }
.md table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: .95em; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.md th { background: #f9fafb; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.6em 0; }
.md ul, .md ol { padding-left: 1.4em; }

/* ---------- 设置 ---------- */
.settings-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.settings-card h2 { font-size: 15px; margin: 0 0 4px; }
.settings-card .hint { color: var(--muted); font-size: 12.5px; margin: 0 0 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.form-grid .field input { width: 100%; }
.form-grid .wide { grid-column: 1 / -1; }

/* ---------- Toast ---------- */
.toast-host { position: fixed; top: 18px; right: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #111827; color: #fff; padding: 10px 14px; border-radius: 9px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.16); animation: slideIn .18s ease-out; max-width: 360px;
}
.toast.ok { background: #065f46; }
.toast.err { background: #991b1b; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.saving { font-size: 12px; color: var(--muted); }
.spinner {
  width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .editor-body { grid-template-columns: 1fr; }
  .meta-grid { grid-template-columns: 1fr 1fr; }
  .meta-grid .wide { grid-column: span 2; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
}
@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static; flex-direction: row;
    align-items: center; padding: 10px 12px; gap: 8px; border-right: none; border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .brand { padding: 0 8px 0 0; }
  .nav { flex-direction: row; }
  .nav a { padding: 6px 10px; white-space: nowrap; }
  .sidebar-footer { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .sidebar-footer .site-link { display: none; }
  .view { padding: 16px 14px 40px; }
  .topbar { padding: 12px 14px; }
  .post-row { flex-wrap: wrap; }
  .post-actions { width: 100%; }
}
