:root {
  --bg: #eef0f3;
  --card: #ffffff;
  --ink: #1c1e22;
  --muted: #6b7280;
  --border: #e3e5e9;
  --accent: #9e1a1a;
  --accent-dark: #490000;
  --header-bg: #14161a;
  --header-ink: #f4f4f5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 17, 20, 0.06), 0 4px 16px rgba(16, 17, 20, 0.05);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

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

/* ---------- Topbar ---------- */
.topbar {
  background: var(--header-bg);
  color: var(--header-ink);
  position: sticky;
  top: 0;
  z-index: 40;
  flex: 0 0 auto;
}
.topbar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 58px;
}
.brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
  white-space: nowrap;
}
.brand span { color: var(--accent); }
.brand:hover { text-decoration: none; }

.mainnav { display: flex; align-items: center; gap: 4px; flex: 1; }
.mainnav a, .dropdown-toggle {
  color: #cfd2d8;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.92rem;
  font-weight: 500;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.mainnav a:hover, .dropdown-toggle:hover { background: rgba(255,255,255,0.08); text-decoration: none; color: #fff; }
.mainnav a.active, .dropdown-toggle.active { background: var(--accent); color: #fff; }

.dropdown { position: relative; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--card);
  color: var(--ink);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 180px;
  padding: 6px;
  margin-top: 4px;
}
.dropdown-menu a { display: block; padding: 8px 12px; border-radius: 6px; color: var(--ink); font-size: 0.9rem; font-weight: 500; }
.dropdown-menu a:hover, .dropdown-menu a:focus { background: var(--accent); color: #fff; text-decoration: none; }
.dropdown.open .dropdown-menu { display: block; }

.searchbox { display: flex; align-items: center; background: rgba(255,255,255,0.1); border-radius: 8px; padding: 2px; }
.searchbox input {
  background: transparent;
  border: none;
  color: #fff;
  padding: 7px 10px;
  width: 190px;
  font-size: 0.88rem;
  outline: none;
}
.searchbox input::placeholder { color: #9aa0aa; }
.searchbox button { background: transparent; border: none; color: #cfd2d8; cursor: pointer; padding: 6px 10px; font-size: 0.95rem; }

.logout-btn { color: #cfd2d8; font-size: 1.2rem; padding: 6px 10px; border-radius: 6px; }
.logout-btn:hover { color: #fff; background: rgba(255,255,255,0.08); text-decoration: none; }
.mobile-search-btn { display: none; }

/* ---------- Page layout ---------- */
.page { max-width: 1600px; width: 100%; margin: 0 auto; padding: 20px; box-sizing: border-box; flex: 0 0 auto; }
.page-layout { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.page-layout--full { grid-template-columns: 1fr; }
.page-main { min-width: 0; }
.page-layout--full .page-main { display: flex; flex-direction: column; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.92rem; }
.flash-error { background: #fdecea; color: #a3301f; border: 1px solid #f6cbc4; }
.flash-success { background: #eafaf1; color: #1e7d46; border: 1px solid #bdeed1; }

/* ---------- Cards / widgets ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 20px; }
.card-header {
  background: var(--accent);
  color: #fff;
  padding: 12px 18px;
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-header a { color: #fff; opacity: .9; font-size: 0.82rem; }
.card-body { padding: 18px; }

.widget { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 20px; }
.widget h3 {
  margin: 0 0 12px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-left: 3px solid var(--accent);
  padding-left: 8px;
}
.online-list { display: flex; flex-wrap: wrap; gap: 6px; }
.online-chip { background: var(--bg); padding: 4px 10px; border-radius: 999px; font-size: 0.82rem; }
.recent-item { padding: 8px 0; border-bottom: 1px solid var(--border); }
.recent-item:last-child { border-bottom: none; }
.recent-title { font-weight: 600; font-size: 0.9rem; display: block; }
.recent-meta { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.muted { color: var(--muted); font-size: 0.88rem; }

/* ---------- Breadcrumb ---------- */
.breadcrumb { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 0.85rem; color: var(--muted); margin-bottom: 16px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb .sep { opacity: .5; }
.breadcrumb .current { color: var(--ink); font-weight: 600; }

/* ---------- Forum / topic lists ---------- */
.forum-list, .topic-list { display: flex; flex-direction: column; }
.forum-cat-title {
  background: var(--accent);
  color: #fff;
  padding: 12px 18px;
  font-weight: 600;
  border-radius: var(--radius) var(--radius) 0 0;
}
.forum-row, .topic-row {
  display: grid;
  grid-template-columns: auto 1fr auto minmax(0, 200px);
  gap: 16px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}
.forum-row:last-child, .topic-row:last-child { border-bottom: none; border-radius: 0 0 var(--radius) var(--radius); }
.row-icon { font-size: 1.4rem; color: var(--accent); width: 28px; text-align: center; }
.row-main .row-title { font-weight: 600; font-size: 0.98rem; }
.row-main .row-desc { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
.row-main .subforums { font-size: 0.78rem; margin-top: 6px; color: var(--muted); }
.row-main .subforums a { margin-right: 10px; }
.row-stats { text-align: center; font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.row-stats strong { display: block; color: var(--ink); font-size: 0.95rem; }
.row-last { font-size: 0.8rem; color: var(--muted); text-align: right; }
.row-last a { font-weight: 600; }
.forum-row--nested { padding-left: 44px; background: #fbfbfc; }
.topic-preview { display: flex; gap: 10px; align-items: flex-start; margin-top: 8px; }
.topic-preview img { width: 100px; height: 100px; object-fit: cover; border-radius: 6px; flex: 0 0 auto; }
.topic-preview-text {
  font-size: 0.82rem; color: var(--muted); line-height: 1.4; overflow: hidden;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 5;
}

/* ---------- Topic view / posts ---------- */
.post {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 20px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.post-author { text-align: center; }
.post-author img, .avatar-img {
  width: 72px; height: 72px; border-radius: 50%; object-fit: cover; background: var(--border);
}
.post-author .name { font-weight: 700; margin-top: 8px; }
.post-author .badge { display: inline-block; margin-top: 6px; }
.post-author .stat { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.post-body { min-width: 0; }
.post-meta { font-size: 0.78rem; color: var(--muted); display: flex; justify-content: space-between; margin-bottom: 10px; }
.link-button { background: none; border: none; padding: 0; font: inherit; font-size: 0.78rem; color: #a3301f; cursor: pointer; }
.link-button:hover { text-decoration: underline; }
.post-content { font-size: 0.95rem; word-wrap: break-word; }
.post-content p { margin: 0 0 0.35em; }
.post-content p:last-child { margin-bottom: 0; }
.post-thanks { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.thanks-btn {
  border: 1px solid var(--border); background: var(--bg); color: var(--ink); cursor: pointer;
  border-radius: 999px; padding: 5px 14px; font-size: 0.8rem; font-weight: 600;
}
.thanks-btn:hover { border-color: var(--accent); color: var(--accent); }
.thanks-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.thanks-names { background: none; border: none; padding: 0; font: inherit; font-size: 0.78rem; color: var(--muted); cursor: pointer; text-align: left; }
.thanks-names:hover { color: var(--accent); text-decoration: underline; }
.thanks-dialog { border: none; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; max-width: 320px; width: 90%; color: var(--ink); background: var(--card); }
.thanks-dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.thanks-list { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.thanks-list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.thanks-list img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--border); flex: 0 0 auto; }
/* A blank spacer line (<p><br></p>) needs far less height than a real line of text - several of them in a row (common in pasted release logs) shouldn't stack into a huge gap. */
.post-content p:has(> br:only-child) { line-height: 0.45; margin: 0 0 0.35em; }
.post-content img { max-width: 100%; border-radius: 6px; }
.post-content .ql-align-center { text-align: center; }
.post-content .ql-align-right { text-align: right; }
.post-content .ql-align-justify { text-align: justify; }
.bbcode-quote { border-left: 3px solid var(--accent); background: var(--bg); padding: 8px 12px; margin: 8px 0; border-radius: 0 6px 6px 0; }
.bbcode-code { background: #1c1e22; color: #e5e7eb; padding: 10px; border-radius: 6px; overflow-x: auto; font-size: 0.85rem; }
.bbcode-spoiler { border: 1px solid var(--border); border-radius: 6px; margin: 8px 0; padding: 2px 12px; }
.bbcode-spoiler summary { cursor: pointer; font-weight: 600; padding: 8px 0; color: var(--accent); }
.bbcode-spoiler[open] summary { border-bottom: 1px solid var(--border); }
.bbcode-video { position: relative; width: 100%; max-width: 560px; aspect-ratio: 16 / 9; margin: 8px auto; }
.bbcode-video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 6px; }
.post-pending { border: 1px dashed var(--accent); }
.pending-tag { color: var(--accent); font-weight: 600; font-size: 0.75rem; }

.badge {
  display: inline-block;
  background: var(--badge-color, var(--muted));
  color: #fff;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
textarea.form-control { min-height: 140px; resize: vertical; }
.form-hint { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }

.editor-toolbar.ql-toolbar.ql-snow {
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: var(--bg);
}
.editor-body.ql-container.ql-snow {
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  background: #fff;
  font-family: inherit;
  font-size: 0.92rem;
  min-height: 160px;
}
.editor-body .ql-editor { min-height: 160px; }
.editor-body .ql-editor img { max-width: 100%; border-radius: 6px; }
.editor-hidden-input { display: none; }

.editor-html-toggle {
  width: 28px; height: 24px; border: none; background: transparent; cursor: pointer;
  font-family: monospace; font-size: 0.8rem; color: #444; border-radius: 4px;
}
.editor-html-toggle:hover { background: #e8e8e8; }
.editor-html-toggle.active { background: var(--accent); color: #fff; }
.editor-source {
  width: 100%; min-height: 160px; border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 8px 8px; font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem; padding: 12px; box-sizing: border-box; background: #fbfbfc; color: var(--ink);
}
.form-error { font-size: 0.78rem; color: var(--accent); margin-top: 4px; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--accent-dark); text-decoration: none; color: #fff; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); color: var(--ink); }
.btn-small { padding: 6px 12px; font-size: 0.8rem; }
.btn-danger { background: #a3301f; }

.login-wrap { max-width: 380px; margin: 60px auto; }
.login-wrap .card-body { padding: 28px; }
.login-wrap h1 { margin-top: 0; font-size: 1.3rem; text-align: center; }

/* ---------- Pagination ---------- */
.pagination { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 16px 0 20px; }
.pagination a, .pagination span {
  padding: 7px 12px; border-radius: 6px; font-size: 0.85rem; background: var(--card); box-shadow: var(--shadow);
}
.pagination .current { background: var(--accent); color: #fff; }

/* ---------- Members ---------- */
.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.member-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; text-align: center; }
.member-card img { width: 64px; height: 64px; border-radius: 50%; margin-bottom: 10px; }
.member-card .name { font-weight: 700; }

.profile-header { display: flex; gap: 20px; align-items: center; }
.profile-header img { width: 96px; height: 96px; border-radius: 50%; }
.profile-stats { display: flex; gap: 24px; margin-top: 14px; }
.profile-stats div strong { display: block; font-size: 1.2rem; }
.profile-stats div span { font-size: 0.78rem; color: var(--muted); }

/* ---------- Messages / chat ---------- */
.chat-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; height: calc(100vh - 168px); min-height: 420px; }
.chat-list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow-y: auto; }
.chat-list-item {
  display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.chat-list-item:hover { background: var(--bg); text-decoration: none; }
.chat-list-item.active { background: #fdecea; }
.chat-list-item img { width: 36px; height: 36px; border-radius: 50%; }
.chat-list-item .cname { font-weight: 600; font-size: 0.9rem; }
.chat-list-item .clast { font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.chat-unread { background: var(--accent); color: #fff; border-radius: 999px; font-size: 0.7rem; padding: 1px 7px; margin-left: auto; }
.pm-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); vertical-align: middle; }
.pm-dot[hidden] { display: none; }

.pm-toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 1000;
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius);
  border-left: 3px solid var(--accent); padding: 12px 14px; max-width: 320px;
  animation: pm-toast-in 0.2s ease-out;
}
.pm-toast[hidden] { display: none; }
.pm-toast a { display: block; color: var(--ink); flex: 1 1 auto; min-width: 0; }
.pm-toast strong { display: block; font-size: 0.88rem; margin-bottom: 2px; }
.pm-toast span { display: block; font-size: 0.82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pm-toast button { background: none; border: none; color: var(--muted); font-size: 1.1rem; line-height: 1; cursor: pointer; padding: 0; flex: 0 0 auto; }
.pm-toast button:hover { color: var(--ink); }
@keyframes pm-toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.chat-window { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; }
.chat-window-head { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 700; flex: 0 0 auto; }
.chat-messages { flex: 1 1 auto; padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.chat-bubble { max-width: 70%; padding: 9px 14px; border-radius: 14px; font-size: 0.9rem; }
.chat-bubble.mine { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble.theirs { align-self: flex-start; background: var(--bg); border-bottom-left-radius: 4px; }
.chat-bubble time { display: block; font-size: 0.68rem; opacity: .7; margin-top: 4px; }
.chat-form { display: flex; gap: 8px; padding: 14px; border-top: 1px solid var(--border); }
.chat-form input { flex: 1; padding: 10px 12px; border-radius: 999px; border: 1px solid var(--border); font-family: inherit; }
.chat-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); }

/* ---------- Admin ---------- */
.admin-shell { display: grid; grid-template-columns: 220px 1fr; gap: 20px; }
.admin-nav { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; height: fit-content; }
.admin-nav a { display: block; padding: 9px 12px; border-radius: 6px; font-size: 0.88rem; color: var(--ink); font-weight: 500; }
.admin-nav a:hover { background: var(--bg); text-decoration: none; }
.admin-nav a.active { background: var(--accent); color: #fff; }
.admin-nav .section-label { font-size: 0.72rem; text-transform: uppercase; color: var(--muted); padding: 10px 12px 4px; }

.visibility-dialog { border: none; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; max-width: 340px; width: 90%; color: var(--ink); background: var(--card); }
.visibility-dialog::backdrop { background: rgba(0, 0, 0, 0.4); }

.data-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.data-table th, .data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.88rem; }
.data-table th { background: var(--bg); font-size: 0.76rem; text-transform: uppercase; color: var(--muted); }
.data-table th a { color: var(--muted); }
.data-table th a:hover { color: var(--accent); text-decoration: underline; }
.data-table tr:last-child td { border-bottom: none; }
.table-actions { display: flex; gap: 6px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; text-align: center; }
.stat-card strong { font-size: 1.6rem; display: block; }
.stat-card span { font-size: 0.8rem; color: var(--muted); }
.stat-card .stat-icon { display: block; font-size: 1.3rem; margin-bottom: 6px; }

/* ---------- Error pages ---------- */
.error-page { max-width: 480px; margin: 80px auto; text-align: center; }
.error-page .error-code { font-size: 5rem; font-weight: 800; color: var(--accent); line-height: 1; }
.error-page h1 { font-size: 1.4rem; margin: 10px 0 6px; }
.error-page p { color: var(--muted); margin-bottom: 24px; }

/* ---------- Misc ---------- */
.sitefooter { box-sizing: border-box; height: 70px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.82rem; flex: 0 0 auto; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }

@media (max-width: 900px) {
  .page-layout, .chat-layout, .admin-shell { grid-template-columns: 1fr; }
  .searchbox input { width: 120px; }
  .post { grid-template-columns: 1fr; }
  .post-author { display: flex; align-items: center; gap: 12px; text-align: left; }
}

@media (max-width: 640px) {
  .topbar-inner { gap: 8px; padding: 0 12px; }
  .brand { font-size: 1rem; }
  .mainnav { gap: 0; overflow-x: auto; flex: 0 1 auto; scrollbar-width: none; }
  .mainnav::-webkit-scrollbar { display: none; }
  .mainnav a, .dropdown-toggle { padding: 8px 8px; font-size: 0.82rem; white-space: nowrap; }
  .searchbox { display: none; }
  .mobile-search-btn { display: inline-block; }
  .dropdown-menu { right: 0; left: auto; }
  .forum-row, .topic-row { grid-template-columns: auto 1fr; row-gap: 6px; }
  .row-stats, .row-last { grid-column: 2; text-align: left; }
}
