:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e3e6ea;
  --text: #1f2329;
  --muted: #8a909a;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-size: 20px; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.nav .who { color: var(--muted); }
.langsel {
  width: auto;
  padding: 5px 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.container { max-width: 760px; margin: 24px auto; padding: 0 16px; }
.container.wide { max-width: 1080px; }

/* Flarum-style top loading bar */
#progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(37, 99, 235, .6);
  z-index: 100;
  opacity: 0;
  transition: width .2s ease, opacity .35s ease;
}
#progress.active { opacity: 1; }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 32px 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
}

.post-item { display: block; }
.post-item:hover { text-decoration: none; border-color: #c9d4ee; }
.post-title { font-size: 17px; font-weight: 600; color: var(--text); margin: 0 0 6px; }
.meta { color: var(--muted); font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; }

/* ---- avatars / author ---- */
.avatar { border-radius: 50%; object-fit: cover; background: #e5e9f0; flex-shrink: 0; vertical-align: middle; display: inline-block; }
.avatar.sm { width: 22px; height: 22px; }
.avatar.lg { width: 96px; height: 96px; }
.avatar.ph { display: inline-flex; align-items: center; justify-content: center; color: #fff; background: var(--accent); font-weight: 600; }
.avatar.sm.ph { font-size: 12px; }
.avatar.lg.ph { font-size: 40px; }
.meta .author { display: inline-flex; align-items: center; gap: 6px; }
.author.link { cursor: pointer; }
.author.link:hover { color: var(--accent); text-decoration: underline; }

.avatar-preview { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.profile-grid { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; }
.profile-fields { flex: 1; min-width: 240px; }
.profile-head { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; }
.profile-head-info { flex: 1; min-width: 240px; }
.profile-head-info .page-title { margin: 0; }
.profile-head-info .meta { margin-top: 8px; }
.profile-bio { margin: 12px 0 0; white-space: pre-wrap; word-break: break-word; }

.post-body, .reply-body {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 12px 0;
}

/* ---- rendered markdown ---- */
.markdown { white-space: normal; }
.markdown p { margin: 0 0 12px; white-space: pre-wrap; }
.markdown h1, .markdown h2, .markdown h3,
.markdown h4, .markdown h5, .markdown h6 { margin: 18px 0 10px; line-height: 1.3; }
.markdown h1 { font-size: 22px; }
.markdown h2 { font-size: 19px; color: var(--text); }
.markdown h3 { font-size: 17px; }
.markdown ul, .markdown ol { margin: 0 0 12px; padding-left: 24px; }
.markdown li { margin: 2px 0; }
.markdown blockquote {
  margin: 0 0 12px; padding: 4px 14px; color: var(--muted);
  border-left: 3px solid var(--border); background: #fafbfc;
}
.markdown code {
  background: #f1f3f5; border-radius: 4px; padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em;
}
.markdown pre {
  background: #f6f8fa; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; overflow-x: auto; margin: 0 0 12px;
}
.markdown pre code { background: none; padding: 0; font-size: .9em; }
.markdown img { max-width: 100%; border-radius: 6px; }
.markdown a { color: var(--accent); }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.markdown > :last-child { margin-bottom: 0; }

/* ---- markdown editor ---- */
.md-editor { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.md-tabs { display: flex; gap: 2px; background: #f6f8fa; border-bottom: 1px solid var(--border); }
.md-tab {
  border: none; background: none; padding: 8px 16px; cursor: pointer;
  font-family: inherit; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent;
}
.md-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.md-toolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 8px; background: #fbfcfd; border-bottom: 1px solid var(--border); }
.md-btn {
  min-width: 30px; height: 28px; padding: 0 8px; border: 1px solid var(--border);
  background: #fff; border-radius: 6px; cursor: pointer; font-size: 14px; font-family: inherit; color: var(--text);
}
.md-btn:hover { background: #eef2ff; border-color: var(--accent); }
.md-editor .md-input { border: none; border-radius: 0; min-height: 220px; }
.md-editor .md-input:focus { outline: none; }
.md-preview { min-height: 220px; padding: 12px 14px; margin: 0; }
.md-hint { padding: 6px 10px; background: #fbfcfd; border-top: 1px solid var(--border); margin: 0; }

h1.page-title { font-size: 22px; margin: 0 0 16px; }
h2.section { font-size: 16px; margin: 24px 0 12px; color: var(--muted); }

.btn {
  display: inline-block;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn.danger { background: #fff; color: var(--danger); border-color: #f0c4c4; padding: 4px 10px; font-size: 13px; }
.btn.danger:hover { background: #fdecec; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--muted); }
input[type=text], input[type=password], textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; min-height: 120px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }

.row { display: flex; align-items: center; gap: 12px; }
.spread { justify-content: space-between; }
.actions { display: flex; gap: 10px; margin-top: 8px; }

.notice { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; }
.notice.error { background: #fdecec; color: var(--danger); border: 1px solid #f0c4c4; }
.notice.empty { color: var(--muted); text-align: center; padding: 40px 0; }

.pager { display: flex; justify-content: center; gap: 16px; align-items: center; margin: 20px 0; }
.pager .page-info { color: var(--muted); font-size: 14px; }

.table-scroll { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; }
table.users th, table.users td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; white-space: nowrap; }
table.users th { color: var(--muted); font-weight: 600; }
table.users td.email { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
table.users .actions { flex-wrap: nowrap; }
/* ---- search ---- */
.search-snippet { color: var(--muted); font-size: 14px; margin: 4px 0 8px; word-break: break-word; }
mark { background: #fff3b0; color: inherit; border-radius: 2px; padding: 0 1px; }
.post-title mark { background: #fde68a; }
.reply-card { transition: background-color .3s ease, box-shadow .3s ease; }
.reply-card.flash { background: #fffbe6; box-shadow: 0 0 0 2px #fde68a; }

/* ---- notifications ---- */
.notif-wrap { position: relative; display: inline-flex; }
.notif-btn {
  position: relative; border: none; background: none; cursor: pointer;
  font-size: 18px; line-height: 1; padding: 4px; color: var(--text);
}
.notif-badge {
  position: absolute; top: -2px; right: -4px; min-width: 16px; height: 16px;
  padding: 0 4px; border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 11px; line-height: 16px; text-align: center; font-weight: 600;
}
.notif-panel {
  position: absolute; top: 130%; right: 0; width: 320px; max-height: 70vh; overflow-y: auto;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.14); z-index: 50;
}
.notif-head { padding: 10px 14px; font-weight: 600; border-bottom: 1px solid var(--border); }
.notif-empty { padding: 24px 14px; text-align: center; color: var(--muted); }
.notif-item { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.notif-item:last-child { border-bottom: none; }
.notif-item.link { cursor: pointer; }
.notif-item.link:hover { background: #f6f8fa; }
.notif-item.unread { background: #f0f6ff; }
.notif-item.unread:hover { background: #e6f0ff; }
.notif-msg { font-size: 14px; color: var(--text); word-break: break-word; }
.notif-time { font-size: 12px; color: var(--muted); margin-top: 3px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; cursor: pointer; }
.checkbox-row input { width: auto; margin: 0; }

.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #eef2ff; color: var(--accent); }
.tag.admin { background: #fef3c7; color: #b45309; }
.tag.off { background: #fee2e2; color: var(--danger); }

/* ---- tags / chips ---- */
.filterbar .tg-row { margin-top: 10px; }
.tg-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.tg-name { font-size: 14px; color: var(--muted); min-width: 72px; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); }
.clear-link { font-size: 13px; }

.chip {
  display: inline-block;
  font-size: 13px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.chip:hover { text-decoration: none; border-color: #c9d4ee; }
.chip.toggle.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip.mini { font-size: 12px; padding: 1px 9px; background: #eef2ff; color: var(--accent); border-color: transparent; cursor: default; }
.chip.removable { background: #f1f3f5; }
.chip.removable:hover { background: #fde8e8; color: var(--danger); }
.chips.inline { display: inline-flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.post-item .chips.inline { margin-top: 10px; }

/* ---- modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 22px;
  width: 92%; max-width: 360px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
.modal-card h3 { margin: 0 0 14px; font-size: 17px; }
