:root {
  --bg-top: #f5f7fb;
  --bg-bottom: #e9eef5;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-dark: #4338ca;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --warn: #b45309;
  --gold: #f59e0b;
  --border: #e5e7eb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px; width: 100%; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar .bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding-top: 12px;
  padding-bottom: 12px;
}

.logo { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: .3px; }
.logo a { color: var(--text); text-decoration: none; }

.search { flex: 1; min-width: 200px; }

.search input,
.editor input,
.modal-box input,
.select {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}

.search input:focus,
.editor input:focus,
.modal-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.select { width: auto; padding: 8px 12px; }

.btn {
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: all .15s;
  white-space: nowrap;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-lg { padding: 12px 24px; font-size: 15px; border-radius: 12px; }

.hidden { display: none !important; }
.muted { color: var(--muted); }

.warn {
  background: #fef3c7;
  color: var(--warn);
  border-bottom: 1px solid #fde68a;
  text-align: center;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
}

.layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  padding-top: 20px;
  flex: 1;
  padding-bottom: 48px;
}

.sidebar {
  width: 210px;
  flex-shrink: 0;
  position: sticky;
  top: 76px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.sb-title { font-size: 12px; color: var(--muted); margin: 4px 8px 8px; letter-spacing: 1px; }

.sb-item {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-item:hover { background: var(--accent-soft); color: var(--accent); }
.sb-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }

.sb-sep { height: 1px; background: var(--border); margin: 8px 0; }

.view { flex: 1; min-width: 0; }

.page-title { margin: 4px 0 16px; }

.list-head { display: flex; justify-content: space-between; align-items: baseline; margin: 8px 0 14px; }
.list-head h2 { font-size: 18px; margin: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
  transition: transform .15s, box-shadow .15s, border-color .15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: #d3d7e3; }
.card-title { margin: 0; font-size: 16px; font-weight: 600; }
.card-snippet { color: var(--muted); font-size: 13px; margin: 0; min-height: 2.4em; overflow: hidden; }
.card-meta { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 12px; }

.chip {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 999px;
}

.badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: 2px;
}

.badge.gold { background: #fef3c7; color: var(--warn); }

.empty-box { text-align: center; padding: 72px 16px; }
.empty-box h2 { font-size: 24px; margin: 0 0 12px; }
.empty { color: var(--muted); margin: 48px 0; text-align: center; }

.detail-head { margin: 16px 0 12px; }
.detail-head h2 { margin: 0 0 6px; font-size: 24px; }
.detail-meta { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 13px; }

.md {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
  line-height: 1.85;
  font-size: 15px;
  word-break: break-word;
  overflow-x: auto;
}

.md p { margin: 12px 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 26px 0 12px; line-height: 1.4; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 17px; }
.md img { max-width: 100%; border-radius: 12px; box-shadow: var(--shadow); height: auto; }
.ql-editor img { max-width: 100%; }
.ql-editor img.ql-selected { outline: 1px dashed var(--accent); }
.md a { color: var(--accent); }
.md code {
  background: #f1f3f5;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: .9em;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
}
.md pre { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 14px; overflow: auto; }
.md pre code { background: none; padding: 0; }
.md ul, .md ol { padding-left: 26px; }
.md blockquote { border-left: 3px solid var(--accent); margin: 12px 0; padding: 4px 16px; color: var(--muted); background: var(--accent-soft); border-radius: 0 8px 8px 0; }
.md table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.md th, .md td { border: 1px solid var(--border); padding: 8px 12px; }
.md th { background: #f8fafc; }

.ops { margin: 16px 0; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.ops.inline { margin: 0; gap: 6px; }

.editor {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
  margin-top: 8px;
  position: relative;
}

.editor-close {
  position: absolute;
  top: 14px;
  right: 18px;
  width: 32px;
  height: 32px;
  border: none;
  background: #f1f3f5;
  color: var(--muted);
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}

.editor-close:hover { background: var(--danger); color: #fff; }

.editor-title { margin: 0 0 18px; font-size: 20px; }
.editor label { display: block; margin-bottom: 18px; font-size: 13px; color: var(--muted); }
.editor input, .editor .select { margin-top: 6px; color: var(--text); }
.editor .check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.editor .check input { width: auto; margin: 0; }
.editor .check .select { width: auto; }

.editor-row { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 18px; }
.editor-row label { margin-bottom: 0; }

.editor-field { display: block; margin-bottom: 18px; font-size: 13px; color: var(--muted); }

.quill-wrap { margin-top: 6px; }
.quill-wrap .ql-toolbar { border-radius: 10px 10px 0 0; background: #f8fafc; }
.quill-wrap .ql-container { border-radius: 0 0 10px 10px; min-height: 320px; font-size: 15px; }
.quill-wrap .ql-editor { min-height: 320px; }

.attach-box { margin: 6px 0 18px; border: 1px dashed var(--border); border-radius: 10px; padding: 14px; }
.attach-title { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.attach-list { margin-bottom: 10px; }
.attach-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  background: #fafbfc;
}

.attach-name { font-size: 14px; font-weight: 500; flex: 1; min-width: 120px; }
.attach-meta { color: var(--muted); font-size: 12px; }

.upload-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.upload-row input[type="file"] { border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; background: #fff; }

.file-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-top: 20px;
}

.file-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.file-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed #eef1f5; }
.file-row:last-child { border-bottom: none; }
.file-name { color: var(--accent); text-decoration: none; font-size: 14px; }
.file-name:hover { text-decoration: underline; }
.file-size { color: var(--muted); font-size: 12px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-val { font-size: 24px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

.bars { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.bar-box { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.bar-label { font-size: 13px; margin-bottom: 8px; }
.bar-track { height: 10px; background: #eef1f5; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s; }
.bar-fill.danger { background: var(--danger); }

.sec-title { margin: 8px 0 10px; font-size: 16px; }
.side-list { display: flex; flex-direction: column; gap: 6px; }
.side-item { display: block; padding: 8px 12px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; color: var(--text); text-decoration: none; font-size: 14px; }
.side-item:hover { border-color: var(--accent); color: var(--accent); }

.rev-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.rev-row span:nth-child(2) { flex: 1; font-weight: 500; }

.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.table th { background: #f8fafc; font-size: 13px; color: var(--muted); }
.table tr:last-child td { border-bottom: none; }
.table td:first-child { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.up-panel,
.store-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.up-panel { border-color: var(--accent); }

.panel-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.panel-desc { font-size: 13px; color: var(--muted); margin-bottom: 12px; }

.store-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.panel-info { font-size: 13px; color: var(--muted); }

.pager { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 16px; }
.pager-info { font-size: 13px; color: var(--muted); }

.img-resize-handle {
  position: fixed;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: nwse-resize;
  z-index: 30;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .35);
  transform: translate(-50%, -50%);
}

.vis-badge { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; }
.vis-pub { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.vis-priv { background: #fef3c7; color: var(--warn); border: 1px solid #fde68a; }

.seg { display: inline-flex; background: #eef1f5; border-radius: 9px; padding: 3px; gap: 3px; }
.seg-btn {
  border: none;
  background: transparent;
  padding: 5px 14px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}
.seg-btn.active { background: var(--accent); color: #fff; }
.seg-btn:not(.active):hover { color: var(--accent); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 16px;
}

.modal.show { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, .2);
}

.modal-box.wide { max-width: 760px; max-height: 85vh; overflow: auto; }
.modal-box h2 { margin: 0 0 14px; font-size: 18px; }
.modal-box label { display: block; margin-bottom: 16px; font-size: 13px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.error { color: var(--danger); font-size: 13px; margin: 4px 0 0; }

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 24px 16px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, .6);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 36px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.toast-item {
  background: #111827;
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .25);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .25s, transform .25s;
  max-width: 90vw;
}

.toast-item.show { opacity: 1; transform: translateY(0); }
.toast-item.error { background: var(--danger); }

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; position: static; }
  .md, .editor { padding: 20px; }
}