:root {
  --brand: #2f8a4b;
  --brand-dark: #256f3c;
  --brand-soft: #e6f4ea;
  --bg: #f6f7f5;
  --card: #ffffff;
  --text: #1f2a24;
  --muted: #6b766f;
  --line: #e3e7e3;
  --danger: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 40, 28, .06), 0 4px 14px rgba(20, 40, 28, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.55; font-size: 15px;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand-dark); }
.hidden { display: none !important; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--card); border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 4px; font-size: 24px; line-height: 1.25; }
.auth-card .sub { color: var(--muted); margin: 0 0 22px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.field input:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.btn { border: 0; background: var(--brand); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 600; }
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; padding: 12px; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--bg); }
.link-btn { background: none; border: 0; color: var(--brand-dark); padding: 0; font-weight: 600; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 10px; }
.switch { text-align: center; margin-top: 16px; color: var(--muted); }

/* ---------- Layout ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1040px; margin: 0 auto; height: 60px; padding: 0 16px; display: flex; align-items: center; gap: 18px; }
.brand { font-weight: 800; font-size: 17px; letter-spacing: -.01em; color: var(--brand-dark); text-decoration: none; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; }
.nav a.on { background: var(--brand-soft); color: var(--brand-dark); }
.top-actions { display: flex; align-items: center; gap: 8px; position: relative; }
.icon-btn { position: relative; width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; font-size: 19px; }
.icon-btn:hover { background: var(--bg); }
.badge { position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.page { min-width: 0; }
.feed-col { max-width: 700px; margin: 0 auto; }

.avatar { flex: none; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; width: 40px; height: 40px; font-size: 16px; }
.avatar.sm { width: 30px; height: 30px; font-size: 13px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.menu { position: absolute; right: 0; top: 46px; width: 340px; max-width: calc(100vw - 32px); background: var(--card); border-radius: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, .16); padding: 6px; z-index: 30; }
.menu .item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px; }
.menu .item:hover { background: var(--bg); }
.menu .item.unread { background: var(--brand-soft); }
.menu .meta { font-size: 12px; color: var(--muted); }
.menu .empty { padding: 18px; text-align: center; color: var(--muted); }

/* ---------- Composer ---------- */
.composer textarea { width: 100%; min-height: 76px; resize: vertical; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fff; }
.composer .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.composer select, .composer input[type=url] { border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; background: #fff; min-width: 0; }
.composer input[type=url] { flex: 1; min-width: 150px; }
.composer .spacer { flex: 1; }
.previews { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.previews .pv { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; background: var(--bg); display: grid; place-items: center; font-size: 12px; color: var(--muted); }
.previews .pv img { width: 100%; height: 100%; object-fit: cover; }
.previews .pv button { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .6); color: #fff; font-size: 12px; line-height: 1; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); padding: 7px 14px; border-radius: 999px; color: var(--muted); font-weight: 600; }
.chip.on { background: var(--text); border-color: var(--text); color: #fff; }
.new-banner { position: sticky; top: 68px; z-index: 5; display: block; margin: 0 auto 12px; }

/* ---------- Post ---------- */
.post-head { display: flex; gap: 10px; align-items: center; }
.post-head .who { flex: 1; min-width: 0; }
.post-head .name { font-weight: 700; }
.post-head .meta { font-size: 12.5px; color: var(--muted); }
.role-tag { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark); margin-left: 6px; vertical-align: 1px; }
.pin-tag { font-size: 12px; color: #a36b00; font-weight: 700; }
.post-body { margin: 12px 0 0; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.media { display: grid; gap: 6px; margin-top: 12px; }
.media.n2, .media.n3, .media.n4 { grid-template-columns: 1fr 1fr; }
.media img, .media video { width: 100%; border-radius: 10px; background: #000; display: block; max-height: 520px; object-fit: cover; cursor: zoom-in; }
.media video { cursor: default; object-fit: contain; }
.media .embed { position: relative; aspect-ratio: 16 / 9; grid-column: 1 / -1; }
.media .embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 10px; }
.stats { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin-top: 12px; min-height: 18px; }
.actions { display: flex; gap: 6px; border-top: 1px solid var(--line); margin-top: 10px; padding-top: 6px; position: relative; }
.act { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.act:hover { background: var(--bg); }
.act.on { color: var(--brand-dark); }
.picker { position: absolute; bottom: 46px; left: 0; background: var(--card); border-radius: 999px; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); padding: 6px 8px; display: flex; gap: 2px; z-index: 10; }
.picker button { border: 0; background: none; font-size: 24px; padding: 4px 6px; border-radius: 8px; transition: transform .1s; }
.picker button:hover { transform: scale(1.25); }
.post-menu { margin-left: auto; position: relative; }

/* ---------- Comments ---------- */
.comments { margin-top: 10px; }
.cmt { display: flex; gap: 8px; margin-top: 10px; }
.cmt .bubble { background: var(--bg); border-radius: 14px; padding: 8px 12px; min-width: 0; }
.cmt .bubble .name { font-weight: 700; font-size: 13.5px; }
.cmt .bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.cmt .sub { font-size: 12px; color: var(--muted); margin: 2px 0 0 10px; display: flex; gap: 12px; align-items: center; }
.cmt .sub button { border: 0; background: none; padding: 0; color: var(--muted); font-weight: 600; font-size: 12px; }
.cmt .sub button.on { color: var(--brand-dark); }
.replies { margin-left: 38px; }
.cmt-form { display: flex; gap: 8px; margin-top: 12px; align-items: flex-end; }
.cmt-form textarea { flex: 1; min-height: 40px; max-height: 140px; resize: vertical; border: 1px solid var(--line); border-radius: 18px; padding: 9px 14px; background: #fff; }
.replying { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

/* ---------- Chat ---------- */
.chat-wrap { max-width: 760px; margin: 0 auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; height: calc(100vh - 100px); min-height: 420px; overflow: hidden; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.chat-head h2 { margin: 0; font-size: 16px; }
.online { font-size: 13px; color: var(--muted); }
.online::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #2ecc71; margin-right: 6px; }
.pinned-msg { padding: 8px 16px; background: #fff8e6; border-bottom: 1px solid #f1e3b8; font-size: 13px; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; gap: 8px; max-width: 86%; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg .bub { background: var(--bg); border-radius: 16px; padding: 7px 12px; min-width: 0; }
.msg.me .bub { background: var(--brand-soft); }
.msg .nm { font-size: 12px; font-weight: 700; color: var(--brand-dark); }
.msg .tx { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .quote { border-left: 3px solid var(--brand); padding: 2px 8px; margin: 3px 0; font-size: 12.5px; color: var(--muted); background: rgba(255, 255, 255, .6); border-radius: 4px; }
.msg img { max-width: 240px; width: 100%; border-radius: 10px; margin-top: 4px; display: block; cursor: zoom-in; }
.msg .tools { font-size: 11.5px; color: var(--muted); display: flex; gap: 10px; margin-top: 2px; }
.msg .tools button { border: 0; background: none; padding: 0; color: var(--muted); }
.msg .tools button:hover { color: var(--text); }
.chat-form { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; gap: 8px; align-items: flex-end; }
.chat-form textarea { flex: 1; resize: none; max-height: 120px; border: 1px solid var(--line); border-radius: 18px; padding: 9px 14px; background: #fff; }
.reply-bar { padding: 6px 16px; background: var(--bg); font-size: 12.5px; display: flex; justify-content: space-between; }

/* ---------- Khung chính & thanh bên ---------- */
.shell { max-width: 1240px; margin: 0 auto; padding: 20px 16px 80px; display: grid; grid-template-columns: 272px minmax(0, 1fr); gap: 24px; align-items: start; }
.sidebar { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; padding-right: 4px; scrollbar-width: thin; }
.side-group { margin-top: 18px; }
.side-title { font-size: 11.5px; font-weight: 800; letter-spacing: .06em; color: var(--muted); padding: 0 12px 6px; text-transform: uppercase; }
.side-link { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 500; line-height: 1.35; }
.side-link .ico { width: 22px; text-align: center; flex: none; }
.side-link:hover { background: rgba(47, 138, 75, .08); }
.side-link.on { background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; }
.side-link.dim { opacity: .5; }
.grow { flex: 1; }
.burger { display: none; }
.scrim { display: none; }

.space-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 14px; }
.space-head h1 { margin: 0; font-size: 22px; line-height: 1.25; }
.space-head p { margin: 4px 0 0; color: var(--muted); }
.big-ico { width: 52px; height: 52px; flex: none; border-radius: 14px; background: var(--brand-soft); display: grid; place-items: center; font-size: 26px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.tag.warn { background: #fff4e0; border-color: #f2d9a6; color: #8a5a00; }
.space-link { color: var(--muted); text-decoration: none; font-weight: 600; }
.space-link:hover { color: var(--brand-dark); text-decoration: underline; }
.hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.edit-area { width: 100%; min-height: 90px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff; resize: vertical; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.row-gap { display: flex; gap: 6px; align-items: center; }

/* ---------- Quản trị ---------- */
.page-title { margin: 0 0 12px; font-size: 22px; }
.admin .chip { display: inline-block; text-decoration: none; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stat .n { font-size: 30px; font-weight: 800; color: var(--brand-dark); line-height: 1.1; }
.stat .l { font-weight: 600; margin-top: 4px; }
.mini { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 4px 9px; font-size: 13px; font-weight: 600; }
.mini:hover { background: var(--bg); }
.mini.danger { color: var(--danger); }
.space-rows { margin: 10px 0 12px; }
.srow { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); margin-top: 6px; background: #fff; }
.srow.dim { opacity: .6; }
.srow .ico { width: 26px; text-align: center; font-size: 18px; }
.srow .tags { margin-top: 3px; }
.inline-form { background: var(--bg); border-radius: 12px; padding: 14px; margin: 10px 0; }
.inline-form .field { margin-bottom: 10px; }
.inline-form select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; font-size: 14px; }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr.dim { opacity: .55; }
.tbl select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.tbl .acts { white-space: nowrap; display: flex; gap: 6px; }
.search { width: 100%; padding: 10px 14px; border: 1px solid var(--line); border-radius: 999px; margin-bottom: 12px; background: #fff; }
.code { display: block; font-size: 22px; font-weight: 800; letter-spacing: .08em; padding: 14px; background: var(--brand-soft); border-radius: 12px; color: var(--brand-dark); margin: 6px 0; word-break: break-all; }
.admin input[type=text], .admin input[type=search] { font-family: inherit; }
.admin .row-gap input[type=text] { flex: 1; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .burger { display: inline-grid; place-items: center; }
  .sidebar { position: fixed; z-index: 40; top: 0; left: 0; bottom: 0; width: 300px; max-width: 86vw; max-height: none; background: var(--card); padding: 70px 12px 20px; box-shadow: 8px 0 30px rgba(0, 0, 0, .18); transform: translateX(-105%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .4); }
  .topbar { z-index: 50; }
  .grid2 { grid-template-columns: 1fr; }
}

/* ---------- Misc ---------- */
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .86); display: grid; place-items: center; z-index: 100; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 8px; }
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; }
.toast { background: #1f2a24; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.center-note { text-align: center; color: var(--muted); padding: 24px; }
@media (max-width: 560px) {
  .brand { font-size: 15px; }
  .nav a { padding: 7px 10px; }
  .msg { max-width: 94%; }
  .chat-wrap { height: calc(100vh - 84px); border-radius: 0; margin: -20px -16px 0; }
  .media.n2, .media.n3, .media.n4 { grid-template-columns: 1fr; }
}
