:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1f2329;
  --muted: #8a919e;
  --border: #e6e8eb;
  --primary: #2f6fed;
  --primary-d: #2257c4;
  --danger: #e5484d;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 6px 18px rgba(0,0,0,.04);
  --header-h: 56px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 顶部导航 ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: 14px; }
.nav a { color: var(--text); font-size: 14px; }
.nav a:hover { color: var(--primary); text-decoration: none; }
.nav .user { color: var(--muted); font-size: 13px; }
.nav-logout { color: var(--danger) !important; }
.nav-toggle {
  display: none; background: none; border: none; font-size: 22px;
  cursor: pointer; color: var(--text);
}

/* ---------- 布局 ---------- */
.container { max-width: 920px; margin: 0 auto; padding: 20px 16px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-head h1 { font-size: 22px; margin: 0; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 14px;
  transition: .15s; line-height: 1.2;
}
.btn:hover { border-color: #cfd4da; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); border-color: var(--primary-d); }
.btn-danger { color: var(--danger); border-color: #f3c2c4; }
.btn-danger:hover { background: #fdeced; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- 卡片 / 表单 ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 15px; background: #fff; color: var(--text);
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,111,237,.12); }

.auth-wrap { min-height: calc(100vh - var(--header-h)); display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-title { margin: 0 0 18px; font-size: 22px; text-align: center; }
.auth-foot { margin-top: 16px; text-align: center; font-size: 14px; color: var(--muted); }

/* ---------- 提示 ---------- */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; white-space: pre-line; }
.alert-error { background: #fdeced; color: #b42318; border: 1px solid #f3c2c4; }
.alert-success { background: #e8f6ee; color: #1b7a43; border: 1px solid #b7e3c8; }

/* ---------- 随笔列表 ---------- */
.empty { text-align: center; padding: 50px 0; color: var(--muted); }
.empty p { margin-bottom: 16px; }
.entry-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.entry-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; box-shadow: var(--shadow); }
.entry-main { min-width: 0; flex: 1; }
.entry-title { font-size: 17px; font-weight: 600; color: var(--text); display: block; }
.entry-title:hover { color: var(--primary); text-decoration: none; }
.entry-excerpt { color: var(--muted); font-size: 13px; margin: 6px 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-meta { color: var(--muted); font-size: 12px; margin: 0; }
.entry-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ---------- 查看页 ---------- */
.view-article { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 32px; box-shadow: var(--shadow); }
.view-title { font-size: 26px; margin: 0 0 8px; }
.view-meta { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.view-content { font-size: 16px; line-height: 1.9; }
.view-content img { max-width: 100%; height: auto; }

/* ---------- 编辑器 ---------- */
.editor-page {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  /* 编辑器页面独占全宽，不受 container max-width 限制 */
  max-width: none; width: 100%;
}
/* 编辑器页面的容器也要放开 */
body.editor-body .container { max-width: none; padding: 0; margin: 0; }
body.editor-body .site-header { max-width: none; }
.editor-topbar { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.title-input { flex: 1; border: none; font-size: 18px; font-weight: 600; padding: 6px 4px; background: transparent; color: var(--text); min-width: 0; }
.title-input:focus { outline: none; }
.editor-topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.save-status { font-size: 12px; color: var(--muted); }
.save-status.ok { color: #1b7a43; }

.toolbar {
  display: flex; flex-wrap: nowrap; gap: 5px; align-items: center;
  padding: 8px 12px; border-bottom: 1px solid var(--border); background: #fafbfc;
  position: sticky; top: var(--header-h); z-index: 10;
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.toolbar::-webkit-scrollbar { height: 4px; }
.toolbar::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }
.tb-select { height: 36px; border: 1px solid var(--border); border-radius: 6px; background: #fff; font-size: 13px; padding: 0 8px; color: var(--text); max-width: 120px; flex-shrink: 0; }
.tb-btn {
  height: 36px; min-width: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: var(--text); cursor: pointer; font-size: 14px; display: inline-flex; align-items: center; justify-content: center;
  white-space: nowrap; flex-shrink: 0;
}
.tb-btn:hover { background: #f0f3f8; }
.tb-btn.active { background: #e2ecfe; border-color: var(--primary); color: var(--primary); }
.tb-sep { width: 1px; height: 22px; background: var(--border); margin: 0 3px; flex-shrink: 0; }

/* ---------- 自定义下拉（替代原生 select，避免移动端失焦丢选区） ---------- */
.tb-dropdown { position: relative; flex-shrink: 0; display: inline-flex; }
.tb-dd-toggle {
  height: 36px; max-width: 120px; border: 1px solid var(--border); border-radius: 6px; background: #fff;
  font-size: 13px; color: var(--text); padding: 0 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 2px;
  white-space: nowrap; overflow: hidden; flex-shrink: 0;
}
.tb-dd-label { overflow: hidden; text-overflow: ellipsis; max-width: 84px; }
.tb-caret { font-size: 10px; color: var(--muted); margin-left: 2px; }
.tb-menu {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 50;
  min-width: 120px; max-width: 90vw; max-height: 280px; overflow-y: auto;
  background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.12);
  padding: 4px;
}
.tb-dropdown.open .tb-menu { display: block; }
.tb-item {
  padding: 8px 10px; font-size: 13px; border-radius: 5px; cursor: pointer; white-space: nowrap; color: var(--text);
}
.tb-item:hover { background: #f0f3f8; }
.tb-item[data-value=""] { color: var(--muted); }

/* 颜色 */
.tb-color-toggle { position: relative; overflow: hidden; }
#color-indicator {
  display: inline-block; width: 14px; height: 4px; border-radius: 2px; background: #000; margin-left: 4px;
}
.tb-color-menu { display: none; flex-wrap: wrap; gap: 6px; width: 168px; max-width: 80vw; padding: 8px; }
.tb-dropdown.open .tb-color-menu { display: flex; }
.tb-swatch { width: 26px; height: 26px; border-radius: 6px; cursor: pointer; border: 1px solid rgba(0,0,0,.1); }
.tb-swatch:hover { transform: scale(1.08); }
.tb-color-custom { flex-basis: 100%; text-align: center; color: var(--muted); }
#font-color-picker {
  position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: none; padding: 0;
}

.editor-content {
  min-height: calc(100vh - 200px); padding: 28px 32px; font-size: 16px; line-height: 1.9; outline: none;
  overflow-y: auto;
}
.editor-content:empty:before { content: attr(data-placeholder); color: #b8bfca; }

/* ---------- 后台 ---------- */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab { background: none; border: none; padding: 10px 14px; cursor: pointer; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; font-size: 14px; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: #fafbfc; color: var(--muted); font-weight: 600; font-size: 13px; }
.data-table tr:last-child td { border-bottom: none; }
.badge { padding: 2px 8px; border-radius: 20px; font-size: 12px; }
.badge-admin { background: #e2ecfe; color: var(--primary); }

.site-footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; display: flex; flex-direction: column; gap: 4px; }

/* ---------- 移动端适配 ---------- */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .nav { display: none; position: absolute; top: var(--header-h); right: 0; left: 0; flex-direction: column; align-items: stretch; gap: 0; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 12px; }
  .nav.open { display: flex; }
  .nav a { padding: 10px 4px; border-bottom: 1px solid var(--border); }
  .nav .user { padding: 10px 4px; }
  .nav-toggle { display: block; }
  .container { padding: 14px 12px 50px; }
  .page-head h1 { font-size: 19px; }
  .entry-item { flex-direction: column; align-items: stretch; }
  .entry-actions { justify-content: flex-end; }
  .view-article { padding: 18px 16px; }
  .view-title { font-size: 22px; }

  /* 编辑器页面移动端全宽 */
  body.editor-body .container { padding: 0; }
  .editor-topbar { padding: 8px 10px; gap: 8px; }
  .title-input { font-size: 16px; padding: 6px 2px; }
  .toolbar {
    top: var(--header-h); padding: 6px 8px; gap: 4px;
    overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch;
    /* 隐藏滚动条但保留滚动功能 */
    scrollbar-width: none;
  }
  .toolbar::-webkit-scrollbar { display: none; }

  /* 移动端工具栏按钮紧凑化：文字按钮缩短 */
  .tb-btn { height: 34px; min-width: 34px; padding: 0 7px; font-size: 13px; border-radius: 5px; }
  .tb-select { height: 34px; max-width: 100px; font-size: 12px; padding: 0 6px; }
  /* 移动端文字按钮用更短标签 */
  .tb-btn[data-cmd="insertUnorderedList"]::after,
  .tb-btn[data-cmd="insertOrderedList"]::after,
  #btn-indent::after,
  .tb-btn[data-cmd="removeFormat"]::after { content: none; }

  .editor-content { padding: 16px 14px; min-height: calc(100vh - 180px); font-size: 15px; }
  .data-table { font-size: 12px; display: block; overflow-x: auto; white-space: nowrap; }
  .data-table th, .data-table td { padding: 8px 8px; }
}
