:root {
  --text: #1a1a1a;
  --bg: #ffffff;
  --line: #d2d2d2;
  --muted: #707070;
  --soft: #f5f5f5;
  --btn: #111111;
  --danger: #c0392b;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
  --top: 52px;
  --side: 264px;
  --measure: 960px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #e6e6e6;
    --bg: #1a1a1a;
    --line: #3a3a3a;
    --muted: #9a9a9a;
    --soft: #262626;
    --btn: #e6e6e6;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea, select { font: inherit; color: inherit; }

a { color: inherit; text-decoration: underline; }
a:visited { color: inherit; }

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

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand {
  background: none;
  border: 0;
  padding: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  color: var(--text);
}
.brand.static { cursor: default; }

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr);
  align-items: start;
}

.side {
  position: sticky;
  top: var(--top);
  height: calc(100vh - var(--top));
  overflow-y: auto;
  border-right: 1px solid var(--line);
  padding: 14px 16px 40px;
}

.side-block { margin-bottom: 22px; }
.side-label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.main {
  padding: 18px 22px 80px;
  max-width: var(--measure);
  margin: 0 auto;
  width: 100%;
}

/* ---------- 表单 ---------- */
.field {
  width: 100%;
  padding: 9px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.field:focus { border-color: var(--text); }
.field::placeholder { color: var(--muted); }

select.field { background: var(--bg); }
select.field option { background: var(--bg); color: var(--text); }

.search-wrap { position: relative; }

.btn {
  display: inline-block;
  padding: 7px 14px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 0;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
}
.btn:hover { border-color: var(--text); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn.primary { background: var(--btn); color: var(--bg); border-color: var(--btn); }
.btn.tiny { padding: 3px 9px; font-size: 12px; }
.btn.danger { color: var(--danger); border-color: var(--danger); }

.icon-btn {
  background: none;
  border: 0;
  padding: 0 6px;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.icon-btn:hover { color: var(--text); }

label.btn { user-select: none; }

/* ---------- 登录 ---------- */
.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-box { width: 100%; max-width: 280px; }
.auth-box .field { padding: 12px; text-align: center; }
.auth-box.admin-auth .field { text-align: left; margin-bottom: 10px; }
.err { min-height: 20px; margin-top: 8px; color: var(--danger); font-size: 13px; text-align: center; }

/* 不可见提交按钮：让多字段表单支持回车提交，但界面上不出现按钮 */
.ghost-submit {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 编辑器 ---------- */
.editor { border: 1px solid var(--line); padding: 12px; margin-bottom: 26px; }
.editor-area {
  width: 100%;
  min-height: 44px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  overflow-y: auto;
  resize: none;
  line-height: 1.7;
}
.attach-row { display: flex; flex-direction: column; gap: 4px; }
.attach-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: var(--soft);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.attach-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-item .rm { cursor: pointer; background: none; border: 0; color: var(--muted); }
.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

/* ---------- Feed ---------- */
.feed-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.feed-label { font-weight: 600; }
.feed-count { color: var(--muted); font-size: 12px; }
.clear [hidden] { display: none; }

.feed { border-top: 1px solid var(--line); }

.note { padding: 18px 0; border-bottom: 1px solid var(--line); }
.note-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}
.note-time { cursor: default; }

.md p { margin: 0 0 8px; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  margin: 16px 0 8px;
  line-height: 1.4;
  font-weight: 600;
}
.md h1 { font-size: 20px; }
.md h2 { font-size: 18px; }
.md h3 { font-size: 16px; }
.md h4, .md h5, .md h6 { font-size: 14px; }
.md ul, .md ol { margin: 6px 0 10px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md ul.task { list-style: none; padding-left: 2px; }
.md .task-item { display: flex; gap: 8px; align-items: flex-start; }
.md .task-item .box {
  flex: none;
  width: 15px;
  height: 15px;
  margin-top: 3px;
  border: 1px solid var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
}
.md .task-item.done { color: var(--muted); }
.md blockquote {
  margin: 10px 0;
  padding: 2px 0 2px 12px;
  border-left: 2px solid var(--line);
  color: var(--muted);
}
.md pre {
  margin: 10px 0;
  padding: 12px;
  background: var(--soft);
  border: 1px solid var(--line);
  overflow-x: auto;
}
.md pre code { font-family: var(--mono); font-size: 12.5px; }
.md code { font-family: var(--mono); font-size: 0.92em; background: var(--soft); padding: 1px 4px; }
.md pre code { background: none; padding: 0; }
.md img { max-width: 100%; }
.md table {
  border-collapse: collapse;
  margin: 10px 0;
  width: 100%;
  table-layout: fixed;
}
.md th, .md td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  word-break: break-word;
}
.md th { background: var(--soft); font-weight: 600; }
.md hr { margin: 14px 0; }

/* ---------- 附件占位块 ---------- */
.attachments { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.attach-block {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--soft);
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
}
.attach-block:hover { border-color: var(--text); text-decoration: none; }
.attach-block svg { width: 18px; height: 18px; flex: none; color: var(--muted); }
.attach-block .tag {
  flex: none;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  min-width: 38px;
}
.attach-block .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-block .fsize { flex: none; color: var(--muted); font-size: 12px; }

/* ---------- 文末 Links ---------- */
.links {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--soft);
  border: 1px solid var(--line);
  font-size: 13px;
}
.links-title { color: var(--muted); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 6px; }
.links ol { margin: 0; padding-left: 20px; }
.links li { margin: 3px 0; word-break: break-all; }
.links li svg { width: 13px; height: 13px; margin-right: 6px; vertical-align: -1px; color: var(--muted); }

/* ---------- 日历 ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-title { background: none; border: 0; font-weight: 600; cursor: pointer; padding: 0; }
.cal-picker { display: flex; gap: 6px; margin-bottom: 8px; }
.cal-picker .field { padding: 5px 6px; font-size: 12px; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow { font-size: 11px; color: var(--muted); text-align: center; padding: 2px 0; }
.cal-cell {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  border: 1px solid transparent;
  cursor: default;
  color: var(--text);
  position: relative;
}
.cal-cell.empty { visibility: hidden; }
.cal-cell.has { cursor: pointer; }
.cal-cell.has:hover { border-color: var(--text); }
.cal-cell.sel { border-color: var(--text); }
.cal-cell.l1 { background: #f6e6c2; color: #7a5d17; }
.cal-cell.l2 { background: #e0a800; color: #fff; }
.cal-cell.l3 { background: #c0392b; color: #fff; }

@media (prefers-color-scheme: dark) {
  .cal-cell.l1 { background: #5c4a22; color: #f0d9a8; }
  .cal-cell.l2 { background: #c99700; color: #fff; }
  .cal-cell.l3 { background: #e06a5c; color: #fff; }
}

/* ---------- 标签 ---------- */
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }

.tag-items { display: flex; flex-direction: column; }
.tag-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 8px 4px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.tag-item:hover { background: var(--soft); }
.tag-item.active { font-weight: 700; }
.tag-item .c { color: var(--muted); font-size: 12px; }
.tag {
  padding: 3px 9px;
  border: 1px solid var(--line);
  background: transparent;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
}
.tag:hover { border-color: var(--text); }
.tag.active { background: var(--btn); color: var(--bg); border-color: var(--btn); }
.tag .n { color: var(--muted); margin-left: 5px; font-size: 11px; }
.tag.active .n { color: inherit; }

.more-wrap { padding: 18px 0 0; text-align: center; }
.empty { padding: 34px 0; color: var(--muted); text-align: center; }

/* ---------- 后台 ---------- */
.tabs {
  display: flex;
  gap: 0;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  padding: 0 18px;
  position: sticky;
  top: var(--top);
  background: var(--bg);
  z-index: 20;
}
.tab {
  padding: 10px 14px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  color: var(--muted);
}
.tab.active { color: var(--text); border-bottom-color: var(--text); }

.admin-body { padding: 18px 18px 80px; max-width: none; }
.card { border: 1px solid var(--line); padding: 14px; margin-bottom: 16px; }
.card h3 { margin: 0 0 10px; font-size: 14px; letter-spacing: 0.03em; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kv { border: 1px solid var(--line); padding: 10px 12px; }
.kv .k { color: var(--muted); font-size: 12px; }
.kv .v { font-size: 17px; margin-top: 3px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: top; }
table.tbl th { color: var(--muted); font-weight: 500; font-size: 12px; }
table.tbl td.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .field { flex: 1; min-width: 140px; }
.stack { display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.hint { color: var(--muted); font-size: 12px; }
.warn { color: var(--danger); font-size: 12px; }

/* ---------- Toast / Modal ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--btn);
  color: var(--bg);
  padding: 8px 16px;
  font-size: 13px;
  z-index: 90;
}
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-box {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 20px;
  width: 100%;
  max-width: 360px;
}
.modal-box p { margin: 0 0 14px; }
.modal-box .row { justify-content: flex-end; }

.mobile-search { display: none; margin-bottom: 12px; }
.attach-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.mobile-only { display: none; }

/* ---------- 响应式 ---------- */
@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .mobile-search { display: block; }
  .desktop-only { display: none; }
  .mobile-only { display: inline-block; }
  .side.open {
    display: block;
    position: sticky;
    top: var(--top);
    height: auto;
    max-height: 60vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    z-index: 25;
    background: var(--bg);
  }
  .main { padding: 14px 14px 80px; max-width: none; }
  .editor { margin-bottom: 18px; }
  #archive-toggle { display: inline-block; }
}

@media (max-height: 700px) and (min-width: 821px) {
  .side #tags-block .tag:nth-child(n + 6) { display: none; }
}

/* 附件来源选择 */
.sheet .sheet-list { display: flex; flex-direction: column; gap: 8px; }
.sheet .sheet-item { width: 100%; }