/* ==========================================================================
   博客写作后台 —— 与博客主站同一套设计语言
   ========================================================================== */

:root {
  --bg: #f9fafb;
  --card: #ffffff;
  --border: #e5e7eb;
  --border-soft: #f3f4f6;
  --text: #1f2937;
  --text-strong: #111827;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --waning: #d97706;
  --warning-soft: #fffbeb;
  --pill-bg: #f3f4f6;
  --pill-hover: #e5e7eb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, .06);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .10);
  --header-bg: rgba(255, 255, 255, .82);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, "Noto Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

[data-theme="dark"] {
  --bg: #030712;
  --card: #111827;
  --border: #1f2937;
  --border-soft: #1a2333;
  --text: #d1d5db;
  --text-strong: #f3f4f6;
  --text-muted: #9ca3af;
  --text-faint: #6b7280;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-soft: rgba(59, 130, 246, .14);
  --primary-border: rgba(59, 130, 246, .35);
  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, .12);
  --success: #4ade80;
  --success-soft: rgba(34, 197, 94, .12);
  --waning: #fbbf24;
  --warning-soft: rgba(250, 204, 21, .12);
  --pill-bg: #1f2937;
  --pill-hover: #374151;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .35);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
  --header-bg: rgba(17, 24, 39, .82);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--header-bg);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 0 20px;
  height: 58px; display: flex; align-items: center; gap: 14px;
}
.brand { font-size: 18px; font-weight: 700; color: var(--primary); letter-spacing: -.01em; }
.brand-sub { font-size: 13px; color: var(--text-faint); }
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px;
  border: 0; border-radius: var(--radius-sm); background: transparent;
  color: var(--text-muted); font-size: 13.5px;
  transition: background .2s, color .2s;
}
.icon-btn:hover { background: var(--pill-bg); color: var(--primary); }

/* ---------- 布局 ---------- */
.container { max-width: 1240px; margin: 0 auto; padding: 22px 20px 60px; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  transition: background .2s, border-color .2s, color .2s, opacity .2s;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); color: #fff; }
.btn-ghost { background: var(--card); border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { border-color: var(--primary-border); color: var(--primary); }
.btn-danger { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.input, .textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font-size: 14px;
  transition: border-color .2s, box-shadow .2s;
}
.input:focus, .textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
  background: var(--card);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input-hint { font-size: 12.5px; color: var(--text-faint); }

/* ---------- 登录页 ---------- */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; }
.login-card {
  width: 100%; max-width: 380px; margin: 12vh auto 40px; padding: 32px;
  border-radius: 16px; box-shadow: var(--shadow-lg);
}
.login-card h1 { margin: 0 0 6px; font-size: 21px; text-align: center; color: var(--text-strong); }
.login-card .sub { margin: 0 0 26px; text-align: center; font-size: 13.5px; color: var(--text-faint); }
.login-card .btn { width: 100%; height: 44px; font-size: 15px; }

/* ---------- 文章列表 ---------- */
.list-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
.list-head h1 { margin: 0; font-size: 22px; font-weight: 700; color: var(--text-strong); }
.list-head .spacer { flex: 1; }
.search-box { position: relative; display: flex; align-items: center; }
.search-box input {
  height: 38px; padding: 0 14px; width: 240px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card); color: var(--text); font-size: 14px;
}
.search-box input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 9px 14px; border: 0; background: transparent; font-size: 14px;
  color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
  border-radius: 8px 8px 0 0; transition: background .2s, color .2s, border-color .2s;
}
.tab:hover { background: var(--pill-bg); color: var(--primary); }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab .count { font-size: 12px; color: var(--text-faint); margin-left: 4px; }

.posts { display: flex; flex-direction: column; gap: 10px; }
.post-row {
  display: flex; align-items: center; gap: 14px; padding: 16px 20px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  transition: box-shadow .2s, border-color .2s;
}
.post-row:hover { box-shadow: var(--shadow-md); border-color: var(--primary-border); }
.post-main { flex: 1; min-width: 0; }
.post-title {
  font-size: 16px; font-weight: 600; color: var(--text-strong);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.post-meta {
  margin-top: 5px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--text-faint);
}
.post-meta .tag {
  padding: 1px 9px; border-radius: 999px; background: var(--pill-bg); color: var(--text-muted);
}
.post-actions { display: flex; align-items: center; gap: 6px; flex: none; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-published { background: var(--success-soft); color: var(--success); }
.badge-draft { background: var(--warning-soft); color: var(--waning); }
.badge-linked { background: var(--primary-soft); color: var(--primary); }

/* 草稿行：左侧加一条竖线，一眼区分 */
.post-row.is-draft { border-left: 3px solid var(--waning); }
.post-row.is-draft .post-title { color: var(--text-muted); }

/* ---------- 编辑器 ---------- */
.editor-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
.editor-head .spacer { flex: 1; }
.editor-head h1 { margin: 0; font-size: 20px; font-weight: 700; color: var(--text-strong); }

.meta-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px; padding: 18px 20px;
}
.meta-grid .span-2 { grid-column: span 2; }
@media (max-width: 720px) { .meta-grid .span-2 { grid-column: span 1; } }

.editor-body { padding: 0 20px 20px; }
.md-toolbar {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  padding: 8px 10px; border: 1px solid var(--border); border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0; background: var(--border-soft);
}
.md-btn {
  min-width: 32px; height: 30px; padding: 0 8px;
  border: 0; border-radius: 6px; background: transparent;
  color: var(--text-muted); font-size: 13px;
  transition: background .15s, color .15s;
}
.md-btn:hover { background: var(--card); color: var(--primary); }
.md-sep { width: 1px; height: 18px; background: var(--border); margin: 0 5px; }

.editor-split {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden; background: var(--card);
}
@media (max-width: 900px) { .editor-split { grid-template-columns: 1fr; } }
.editor-pane { min-height: 460px; }
.editor-pane + .editor-pane { border-left: 1px solid var(--border); }
@media (max-width: 900px) { .editor-pane + .editor-pane { border-left: 0; border-top: 1px solid var(--border); } }
#mdInput {
  width: 100%; height: 100%; min-height: 460px; padding: 16px 18px;
  border: 0; outline: 0; resize: vertical;
  background: var(--card); color: var(--text);
  font-family: var(--mono); font-size: 14px; line-height: 1.75;
  tab-size: 2;
}
.preview {
  height: 100%; max-height: 720px; overflow: auto; padding: 16px 20px;
  background: var(--bg);
}
.preview-label {
  position: sticky; top: 0; font-size: 11.5px; letter-spacing: .04em;
  color: var(--text-faint); text-transform: uppercase; margin-bottom: 10px;
}
.drop-active { outline: 2px dashed var(--primary); outline-offset: -6px; }

/* 预览区排版（贴近博客正文） */
.preview h1, .preview h2, .preview h3 { color: var(--text-strong); line-height: 1.4; }
.preview h1 { font-size: 22px; margin: 0 0 12px; }
.preview h2 { font-size: 18px; margin: 24px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.preview h3 { font-size: 16px; margin: 20px 0 8px; }
.preview p { margin: 0 0 14px; }
.preview ul, .preview ol { margin: 0 0 14px; padding-left: 24px; }
.preview li { margin: 5px 0; }
.preview blockquote {
  margin: 0 0 14px; padding: 8px 14px; color: var(--text-muted);
  background: var(--border-soft); border-left: 3px solid var(--border);
  border-radius: 0 6px 6px 0;
}
.preview code {
  padding: 2px 6px; font-size: .875em; font-family: var(--mono);
  color: #db2777; background: #fdf2f8; border-radius: 5px;
}
[data-theme="dark"] .preview code { color: #f472b6; background: rgba(244, 114, 182, .12); }
.preview pre {
  padding: 12px 14px; overflow: auto; background: var(--border-soft);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.preview pre code { padding: 0; background: transparent; color: var(--text); }
.preview table { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 14px; }
.preview th, .preview td { padding: 7px 12px; border: 1px solid var(--border); text-align: left; }
.preview th { background: var(--border-soft); }
.preview img { max-width: 100%; border-radius: var(--radius-sm); }
.preview hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
.preview a { border-bottom: 1px solid var(--primary-border); }

/* ---------- 空态 / 提示 ---------- */
.empty { padding: 56px 24px; text-align: center; color: var(--text-faint); }
.empty .big { font-size: 40px; margin-bottom: 10px; opacity: .5; }

.toast-wrap {
  position: fixed; right: 20px; bottom: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
}
.toast {
  padding: 11px 16px; border-radius: var(--radius-sm); font-size: 14px;
  background: var(--card); border: 1px solid var(--border);
  box-shadow: var(--shadow-md); color: var(--text);
  animation: toastIn .25s cubic-bezier(.22,.61,.36,1) both;
  max-width: 460px;
}
.toast.ok { border-color: var(--success); color: var(--success); }
.toast.err { border-color: var(--danger); color: var(--danger); }
.toast pre { margin: 8px 0 0; font-size: 12px; max-height: 200px; overflow: auto; white-space: pre-wrap; color: var(--text-muted); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; z-index: 150; background: rgba(17, 24, 39, .45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  width: 100%; max-width: 380px; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 22px; border: 1px solid var(--border);
}
.modal h2 { margin: 0 0 6px; font-size: 17px; color: var(--text-strong); }
.modal p { margin: 0 0 18px; font-size: 13.5px; color: var(--text-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor;
        border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 下拉框 ---------- */
select.input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
[data-theme="dark"] select.input {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
select.input option { background: var(--card); color: var(--text); }

/* ---------- 分组管理 ---------- */
.taxo-row {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--border-soft);
  transition: background .15s;
}
.taxo-row:last-child { border-bottom: 0; }
.taxo-row:hover { background: var(--border-soft); }

.taxo-cover {
  flex: none; width: 54px; height: 40px; border-radius: 8px; overflow: hidden;
  background: var(--pill-bg); display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
}
.taxo-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.taxo-cover-empty { font-size: 11px; color: var(--text-faint); }

.taxo-main { flex: 1; min-width: 0; }
.taxo-name {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 600; color: var(--text-strong);
}
.taxo-badge {
  flex: none; font-size: 11.5px; font-weight: 400;
  padding: 1px 8px; border-radius: 999px;
  background: var(--pill-bg); color: var(--text-faint);
}
.taxo-badge-w { background: var(--primary-soft); color: var(--primary); }
.taxo-desc {
  margin-top: 3px; font-size: 12.5px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.taxo-desc-empty { color: var(--text-faint); font-style: italic; }

.taxo-count {
  flex: none; width: 62px; text-align: right;
  font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums;
}
.taxo-actions { flex: none; display: flex; gap: 6px; }

/* 分组编辑表单 */
.taxo-editor {
  padding: 18px 20px 20px;
  background: var(--primary-soft);
  border-bottom: 1px solid var(--border);
}
.taxo-editor:last-child { border-bottom: 0; }
.taxo-editor-head {
  font-size: 15px; font-weight: 700; color: var(--text-strong); margin-bottom: 14px;
}
.taxo-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.taxo-grid .span-2 { grid-column: span 2; }
@media (max-width: 640px) { .taxo-grid { grid-template-columns: 1fr; } .taxo-grid .span-2 { grid-column: span 1; } }

.taxo-cover-edit { margin-top: 14px; }
.cover-line { display: flex; align-items: center; gap: 12px; }
.cover-preview {
  width: 120px; height: 74px; border-radius: 8px; overflow: hidden;
  border: 1px dashed var(--border); background: var(--card);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text-faint); flex: none;
}
.cover-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-btns { display: flex; gap: 8px; }

.taxo-editor-actions {
  display: flex; align-items: center; gap: 10px; margin-top: 18px;
}
.taxo-editor-actions .spacer { flex: 1; }

@media (max-width: 560px) {
  .taxo-row { flex-wrap: wrap; gap: 10px; }
  .taxo-count { width: auto; text-align: left; }
  .taxo-actions { width: 100%; }
}

/* ---------- 标签选择器（chips） ---------- */
.tag-picker { position: relative; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.tag-chips:empty { display: none; margin: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 6px 3px 10px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary);
  border: 1px solid var(--primary-border);
  font-size: 13px; line-height: 1.5;
}
.chip-new { background: var(--warning-soft); color: var(--waning); border-color: var(--waning); }
.chip-x {
  border: 0; background: transparent; color: inherit; cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0 3px; opacity: .6; border-radius: 50%;
}
.chip-x:hover { opacity: 1; background: rgba(127, 127, 127, .18); }

.tag-sugg {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 30;
  margin-top: 4px; padding: 5px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  max-height: 240px; overflow: auto;
}
.sugg-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13.5px;
}
.sugg-item:hover { background: var(--primary-soft); color: var(--primary); }
.sugg-count { font-size: 12px; color: var(--text-faint); }

* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }
