/* Rao Vặt Xứ Nghệ — giao diện mới, không phụ thuộc thư viện ngoài */
:root {
  --bg: #f3f5f4;
  --card: #ffffff;
  --text: #1c2421;
  --muted: #66716c;
  --line: #e3e8e5;
  --brand: #0b7a4b;
  --brand-ink: #ffffff;
  --brand-soft: #e5f3ec;
  --accent: #f26b1d;
  --accent-ink: #ffffff;
  --price: #d4380d;
  --danger: #c62828;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 2px 8px rgba(16, 24, 20, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111614; --card: #1a201d; --text: #e6ece9; --muted: #98a39e; --line: #2a322e;
    --brand: #35b07a; --brand-ink: #06130d; --brand-soft: #173126; --price: #ff8a5c;
    --shadow: none; color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.center { text-align: center; }
.hp { position: absolute; left: -9999px; }
.hide-sm { }

/* ---------- Header */
.topbar { background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 20; }
.topbar-in { display: flex; align-items: center; gap: 16px; height: 60px; }
.logo { display: flex; align-items: center; gap: 8px; color: inherit; font-size: 1.1rem; white-space: nowrap; }
.logo:hover { text-decoration: none; }
.logo-mark { background: var(--accent); color: #fff; font-weight: 800; border-radius: 8px; padding: 4px 7px; font-size: .9rem; }
.logo-text b { font-weight: 800; }
.search { flex: 1; display: flex; max-width: 560px; }
.search input {
  flex: 1; min-width: 0; border: 0; border-radius: 8px 0 0 8px; padding: 9px 12px; font: inherit;
  background: #fff; color: #1c2421;
}
.search button { border: 0; background: #fff; color: var(--brand); padding: 0 12px; border-radius: 0 8px 8px 0; cursor: pointer; }
.userbar { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.userbar .link { color: inherit; font-weight: 500; }
.menu { position: relative; }
.menu summary { list-style: none; display: flex; align-items: center; gap: 6px; cursor: pointer; color: inherit; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 8px); background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); min-width: 180px; padding: 6px;
}
.menu-pop a, .menu-pop button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px; color: var(--text);
  background: none; border: 0; font: inherit; cursor: pointer;
}
.menu-pop a:hover, .menu-pop button:hover { background: var(--brand-soft); text-decoration: none; }

/* ---------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: .85rem; }
.btn-lg { padding: 11px 20px; font-size: 1rem; }
.btn-block { width: 100%; }

/* ---------- Layout */
.main { padding-top: 16px; padding-bottom: 32px; min-height: 60vh; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 1.05rem; margin: 0 0 12px; }
.card-h .more { font-size: .85rem; font-weight: 500; }
.list-h { font-size: .9rem; color: var(--muted); font-weight: 500; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head p { margin: 0; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a { color: var(--muted); }
.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; border: 1px solid; }
.alert-ok { background: var(--brand-soft); border-color: var(--brand); }
.alert-error { background: #fdecea; border-color: #f5c2bd; color: #8a1c13; }
@media (prefers-color-scheme: dark) { .alert-error { background: #3a1b18; border-color: #6b2a24; color: #ffb4ab; } }
.ad { margin-bottom: 16px; text-align: center; overflow: hidden; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

.hero { background: linear-gradient(135deg, var(--brand), #0f9d63); color: #fff; border-radius: var(--radius); padding: 22px 20px; margin-bottom: 16px; }
.hero h1 { font-size: 1.45rem; margin-bottom: 4px; }
.hero p { margin: 0; opacity: .92; }

/* ---------- Home: categories */
.forums { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.forums li { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.f-title { font-weight: 600; }
.f-count { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.f-last { grid-column: 1 / -1; font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-cta { background: var(--brand-soft); border-color: transparent; }
.side-cta p { margin: 0 0 12px; color: var(--muted); }
.stats { margin: 0; display: grid; gap: 8px; }
.stats div { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-weight: 500; }
.chip small { color: var(--muted); }

/* ---------- Thread list */
.tlist { list-style: none; margin: 0; padding: 0; }
.titem { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.titem:first-child { border-top: 0; padding-top: 0; }
.titem.is-sticky { background: linear-gradient(90deg, var(--brand-soft), transparent 70%); border-radius: 8px; padding-left: 8px; }
.is-deleted { opacity: .55; }
.tthumb {
  flex: 0 0 112px; height: 84px; border-radius: 8px; overflow: hidden; background: var(--brand-soft);
  display: flex; align-items: center; justify-content: center;
}
.tthumb img { width: 100%; height: 100%; object-fit: cover; }
.tthumb.noimg::after { content: "📷"; font-size: 1.6rem; opacity: .35; }
.noimg-ico { font-size: 2rem; font-weight: 800; color: var(--brand); opacity: .5; }
.tbody { min-width: 0; flex: 1; }
.ttitle { font-size: 1rem; margin: 0 0 2px; font-weight: 600; }
.ttitle a { color: var(--text); }
.ttitle a:hover { color: var(--brand); }
.tprice { color: var(--price); font-weight: 700; font-size: .95rem; }
.texcerpt { margin: 2px 0; color: var(--muted); font-size: .88rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tmeta { font-size: .8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.tmeta a { color: var(--muted); }
.tstats { margin-left: auto; white-space: nowrap; }
.tag { display: inline-block; font-size: .7rem; font-weight: 700; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; background: var(--line); color: var(--muted); vertical-align: 2px; }
.tag-pin { background: var(--accent); color: #fff; }
.tag-del { background: var(--danger); color: #fff; }

/* ---------- Pager */
.pager { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0 16px; }
.pager a, .pager span { min-width: 36px; padding: 6px 10px; border-radius: 8px; text-align: center; border: 1px solid var(--line); background: var(--card); }
.pager .cur { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 700; }
.pager .gap { border: 0; background: none; }

/* ---------- Thread */
.thread-head h1 { font-size: 1.5rem; margin-bottom: 6px; }
.thread-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; color: var(--muted); font-size: .9rem; margin-bottom: 12px; }
.price-big { color: var(--price); font-size: 1.3rem; font-weight: 800; }
.modbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; padding: 8px; border: 1px dashed var(--line); border-radius: 10px; }
.modbar select { max-width: 200px; }
.post { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 16px; }
.post-first { border-color: var(--brand); }
.post-user { text-align: center; font-size: .85rem; border-right: 1px solid var(--line); padding-right: 12px; }
.post-user .avatar { margin: 0 auto 6px; }
.uname { font-weight: 700; word-break: break-word; }
.urole { font-size: .78rem; color: var(--muted); }
.role-admin, .role-moderator { color: var(--danger); font-weight: 600; }
.role-vip { color: var(--accent); font-weight: 600; }
.uinfo { color: var(--muted); font-size: .75rem; margin-top: 4px; }
.post-top { display: flex; justify-content: space-between; font-size: .8rem; margin-bottom: 8px; }
.post-body { font-size: 1rem; overflow-wrap: anywhere; }
.sig { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 8px; font-size: .85rem; color: var(--muted); max-height: 120px; overflow: hidden; }
.post-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: .85rem; }
.post-actions form { display: inline; }
.act { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; cursor: pointer; }
.act:hover { color: var(--brand); text-decoration: underline; }
.act-del:hover { color: var(--danger); }
.reply textarea { min-height: 120px; }
.form-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.form-row .btn-primary { margin-left: auto; }
.file-btn { cursor: pointer; color: var(--brand); font-weight: 600; }
.grid-related { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.rel { display: flex; flex-direction: column; gap: 4px; color: var(--text); }
.rel-img { aspect-ratio: 4 / 3; background: var(--brand-soft); border-radius: 8px; overflow: hidden; }
.rel-img img { width: 100%; height: 100%; object-fit: cover; }
.rel-title { font-size: .88rem; font-weight: 600; }

/* ---------- BBCode content */
.bb img.bb-img { display: block; max-height: 720px; margin: 8px 0; border-radius: 6px; }
.bb blockquote.bb-quote { margin: 8px 0; padding: 8px 12px; border-left: 4px solid var(--brand); background: var(--brand-soft); border-radius: 0 8px 8px 0; }
.quote-by { font-weight: 700; font-size: .85rem; margin-bottom: 4px; }
.bb pre.bb-code { background: #0f1512; color: #d9e6df; padding: 12px; border-radius: 8px; overflow: auto; font-size: .85rem; }
.bb ul, .bb ol { padding-left: 1.4em; margin: 6px 0; }
.bb-video { position: relative; aspect-ratio: 16 / 9; max-width: 640px; margin: 8px 0; }
.bb-video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 8px; }
.bb-spoiler { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin: 6px 0; }
.bb-spoiler summary { cursor: pointer; font-weight: 600; }
.mention { font-weight: 600; }

/* ---------- Poll */
.poll-opt { display: grid; grid-template-columns: auto 1fr 2fr auto; align-items: center; gap: 8px; margin-bottom: 6px; }
.poll-bar { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.poll-bar i { display: block; height: 100%; background: var(--brand); }

/* ---------- Avatars */
.avatar { width: var(--s, 48px); height: var(--s, 48px); border-radius: 50%; object-fit: cover; display: inline-block; flex: none; }
img.avatar { background: var(--line); }
.avatar-letter {
  display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 700;
  font-size: calc(var(--s) * .45); background: hsl(var(--h), 45%, 45%);
}
.topbar .avatar { --s: 30px; width: 30px; height: 30px; border: 2px solid rgba(255,255,255,.6); }

/* ---------- Profile, members */
.profile { display: flex; gap: 20px; align-items: flex-start; }
.profile .avatar { --s: 96px; width: 96px; height: 96px; }
.profile h1 { margin-bottom: 2px; }
.pstats { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 12px 0; }
.pstats dt { font-size: .75rem; color: var(--muted); }
.pstats dd { margin: 0; font-weight: 600; }
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.mcard { display: flex; gap: 10px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); }
.mcard span { display: flex; flex-direction: column; min-width: 0; }
.mcard b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mcard small { color: var(--muted); }

/* ---------- Forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; }
.field > span { display: block; }
.req { color: var(--danger); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; width: 100%; font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
input[type=checkbox], input[type=radio] { width: auto; }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
textarea { resize: vertical; min-height: 80px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; }
.auth-box { max-width: 420px; margin: 24px auto; }
.search-form { flex-direction: row; flex-wrap: wrap; }
.search-form input { flex: 2 1 240px; }
.search-form select { flex: 1 1 180px; width: auto; }
.search-inline { display: flex; gap: 8px; max-width: 420px; margin: 16px auto; }
.dropzone { display: flex; align-items: center; justify-content: center; border: 2px dashed var(--line); border-radius: 10px; padding: 18px; cursor: pointer; color: var(--muted); font-weight: 500; position: relative; }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.thumbs-preview { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs-preview img { width: 80px; height: 80px; object-fit: cover; border-radius: 6px; }

.editor { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.editor textarea { border: 0; border-radius: 0; min-height: 160px; }
.editor-bar { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px; background: var(--bg); border-bottom: 1px solid var(--line); }
.editor-bar button { background: none; border: 0; padding: 4px 9px; border-radius: 6px; cursor: pointer; color: var(--text); font: inherit; font-size: .9rem; }
.editor-bar button:hover { background: var(--line); }
.ml-auto { margin-left: auto; }
.editor-preview { padding: 12px; min-height: 160px; }

/* ---------- Admin, misc */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin: 0 0 4px; }
.kpis dt { color: var(--muted); font-size: .85rem; }
.kpis dd { margin: 4px 0 0; font-size: 1.6rem; font-weight: 800; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.row-form { display: flex; gap: 6px; }
.row-form select { width: auto; padding: 4px 8px; }
.inline-forms { display: flex; gap: 8px; flex-wrap: wrap; }
.cat-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px; }
.cat-form input[name=title] { flex: 1 1 200px; }
.cat-form input[name=slug] { flex: 1 1 160px; }
.cat-form select { width: auto; }
.cat-form textarea { flex: 1 1 100%; min-height: 38px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid-2 .card { margin: 0; }
.avatar-edit { display: flex; gap: 12px; align-items: center; }
.avatar-edit .avatar { --s: 96px; width: 96px; height: 96px; }
.prose { max-width: 760px; margin: 0 auto; }
.prose li { margin-bottom: 6px; }
.error-page { text-align: center; padding: 40px 16px; }
.error-code { font-size: 4rem; font-weight: 800; color: var(--brand); line-height: 1; }

/* ---------- Admin v2 */
.alert-warn { background: #fff7e0; border-color: #f2d48a; color: #6b4b00; }
.alert-notice { background: var(--brand-soft); border-color: var(--brand); }
@media (prefers-color-scheme: dark) { .alert-warn { background: #3a2f10; border-color: #6b5520; color: #ffd98a; } }
.tag-ok { background: var(--brand-soft); color: var(--brand); }
.tag-warn { background: #f2b230; color: #3a2800; }
.is-moderated { background: rgba(242, 178, 48, .08); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .72rem; line-height: 18px; text-align: center; }
.admin-tabs { overflow-y: hidden; scrollbar-width: thin; }
.admin-tabs a.active { color: var(--brand); box-shadow: inset 0 -2px 0 var(--brand); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input, .filters select { width: auto; flex: 1 1 160px; }
.filters .check { flex: 0 0 auto; white-space: nowrap; }
.filters input[type=checkbox] { flex: none; }
.bulkbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.bulkbar select { width: auto; padding: 5px 8px; font-size: .88rem; }
.bulkbar .muted { margin-right: auto; }
.table .num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.user-cell { display: flex; align-items: center; gap: 8px; }
.chip-on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.report-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.report-reason { margin-top: 4px; color: var(--danger); font-weight: 600; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.help { margin: -8px 0 0 26px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; }
.settings .card { margin-bottom: 16px; }
.cat-card { padding: 10px; margin-bottom: 8px; }
.cat-card .cat-form { padding: 0; }
.cat-group-row { border-left: 4px solid var(--brand); }
.cat-del { margin-top: 6px; }
.cat-del summary { cursor: pointer; }
.chart { width: 100%; height: 170px; display: block; }
.chart rect { fill: var(--brand); }
.chart-b rect { fill: var(--accent); }
.chart rect:hover { opacity: .75; }
.chart text { fill: var(--muted); font-size: 11px; }
.grid-2 > .card, .grid-2 > div > .card { margin-bottom: 16px; }

/* ---------- Footer */
.footer { background: var(--card); border-top: 1px solid var(--line); padding: 20px 0 12px; color: var(--muted); font-size: .9rem; }
.footer-in { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.footer p { margin: 4px 0 0; }
.footer nav { display: flex; gap: 16px; flex-wrap: wrap; }
.copy { margin-top: 12px; font-size: .8rem; }

/* ---------- Mobile */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .topbar-in { flex-wrap: wrap; height: auto; padding-top: 8px; padding-bottom: 8px; gap: 8px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .logo-text { font-size: 1rem; }
  .hide-sm { display: none; }
  .userbar { gap: 8px; }
  .userbar .btn { padding: 6px 10px; font-size: .85rem; }
  .card { padding: 12px; border-radius: 10px; }
  .tthumb { flex-basis: 88px; height: 72px; }
  .tstats { margin-left: 0; }
  .post { grid-template-columns: 1fr; gap: 8px; }
  .post-user { display: flex; align-items: center; gap: 10px; text-align: left; border-right: 0; border-bottom: 1px solid var(--line); padding: 0 0 8px; }
  .post-user .avatar { --s: 40px; width: 40px; height: 40px; margin: 0; }
  .field-row { grid-template-columns: 1fr; }
  .profile { flex-direction: column; align-items: center; text-align: center; }
  .pstats { justify-content: center; }
  .hero { padding: 16px; }
  .hero h1 { font-size: 1.2rem; }
  .poll-opt { grid-template-columns: auto 1fr auto; }
  .poll-bar { grid-column: 1 / -1; }
}
