:root {
  --brand: #9d2449;
  --brand-2: #c8406b;
  --brand-soft: #fbe9ef;
  --fb: #1877f2;
  --fb-dark: #0f5fcb;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --err: #b91c1c;
  --err-soft: #fdecec;
  --ink: #1f1a1c;
  --ink-2: #5d5458;
  --ink-3: #8f8589;
  --line: #ebe2e5;
  --bg: #fbf6f7;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 20, 35, .06), 0 4px 16px rgba(60, 20, 35, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--fb-dark); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; text-align: center; color: var(--ink-3); }
.hidden { display: none !important; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

/* ---------- Thanh trên cùng ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(120deg, var(--brand), var(--brand-2));
  color: #fff;
  padding: 10px 16px calc(10px) 16px;
  box-shadow: 0 2px 10px rgba(80, 10, 35, .25);
}
.topbar-row { display: flex; align-items: center; gap: 10px; max-width: 1280px; margin: 0 auto; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .5px; font-size: 17px; margin-right: auto; }
.logo img { width: 34px; height: 34px; border-radius: 9px; background: #fff2; }
.logo small { display: block; font-weight: 500; font-size: 11.5px; opacity: .85; letter-spacing: 0; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.switch {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.3);
  padding: 6px 10px 6px 8px; border-radius: 999px; font-size: 13px; font-weight: 700; color: #fff;
}
.switch .knob { width: 34px; height: 20px; border-radius: 999px; background: rgba(0,0,0,.25); position: relative; transition: .2s; flex: none; }
.switch .knob::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.switch.on .knob { background: #34d399; }
.switch.on .knob::after { left: 16px; }
.btn-sync {
  background: #fff; color: var(--brand); border: 0; border-radius: 999px; padding: 8px 14px;
  font-weight: 800; font-size: 13px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center;
}
.btn-sync .lbl-short { display: none; }
.btn-sync:disabled { opacity: .7; cursor: wait; }
.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.sync-line { max-width: 1280px; margin: 6px auto 0; font-size: 12.5px; opacity: .92; display: flex; gap: 6px; flex-wrap: wrap; }
.sync-line .err { background: #fff; color: var(--err); padding: 1px 8px; border-radius: 6px; font-weight: 600; }

.tabs {
  position: sticky; top: var(--topbar-h, 86px); z-index: 15;
  background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; gap: 2px; overflow-x: auto; padding: 0 12px; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs-inner { display: flex; gap: 2px; max-width: 1280px; margin: 0 auto; width: 100%; }
.tab {
  background: none; border: 0; padding: 12px 14px; font-weight: 700; color: var(--ink-2); cursor: pointer;
  border-bottom: 3px solid transparent; white-space: nowrap; font-size: 14px;
}
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }

/* ---------- Thẻ & khối ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.section { padding: 14px; }
.section-h { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.section-h h2 { font-size: 15px; margin: 0; text-transform: uppercase; letter-spacing: .4px; color: var(--brand); }
.section-h .step { width: 22px; height: 22px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 12px; font-weight: 800; display: grid; place-items: center; flex: none; }
.section-h .right { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.share-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 980px) {
  .share-grid { grid-template-columns: minmax(280px, 1fr) minmax(220px, .7fr) minmax(360px, 1.3fr); align-items: start; }
  .share-grid > .card { position: sticky; top: calc(var(--topbar-h, 86px) + 58px); max-height: calc(100vh - var(--topbar-h, 86px) - 74px); overflow: auto; }
}

/* ---------- Bài viết ---------- */
.posts { display: flex; flex-direction: column; gap: 10px; }
@media (max-width: 979px) {
  .posts { flex-direction: row; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 6px; margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
  .posts .post { flex: 0 0 78%; max-width: 320px; scroll-snap-align: start; }
}
.post {
  border: 2px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; background: #fff;
  text-align: left; padding: 0; display: flex; flex-direction: column; transition: border-color .15s, box-shadow .15s;
}
.post:hover { border-color: #e2c3cf; }
.post.sel { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.post .thumb { position: relative; aspect-ratio: 16 / 9; background: #f3e9ed center / cover no-repeat; display: grid; place-items: center; color: var(--ink-3); font-size: 28px; }
.post .thumb .badge { position: absolute; left: 8px; top: 8px; }
.post .thumb .new { position: absolute; left: auto; right: 8px; top: 8px; background: #ef4444; color: #fff; }
.post .thumb .play { width: 44px; height: 44px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; font-size: 18px; }
.post .body { padding: 9px 11px 11px; display: flex; flex-direction: column; gap: 6px; }
.post .msg { font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.9em; }
.post .meta { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--ink-3); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: rgba(0,0,0,.6); color: #fff; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--brand-soft); color: var(--brand); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--err-soft); color: var(--err); }
.pill.gray { background: #f1edee; color: var(--ink-2); }

/* ---------- Tài khoản ---------- */
.accounts { display: flex; flex-wrap: wrap; gap: 8px; }
@media (min-width: 980px) { .accounts { flex-direction: column; } .accounts .acc { flex: none; } }
.acc {
  display: flex; align-items: center; gap: 10px; border: 2px solid var(--line); background: #fff; border-radius: 12px;
  padding: 8px 10px; cursor: pointer; text-align: left; min-width: 0; flex: 1 1 150px;
}
.acc.sel { border-color: var(--brand); background: var(--brand-soft); }
.acc .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; flex: none; }
.acc .info { min-width: 0; flex: 1; }
.acc .name { display: block; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc .sub { display: block; font-size: 12px; color: var(--ink-3); }
.acc .count { font-weight: 800; font-size: 13px; color: var(--ink-2); }
.acc.complete .count { color: var(--ok); }

/* ---------- Bảng chia sẻ ---------- */
.fb-check { background: var(--warn-soft); color: #7a3e06; border-radius: 10px; padding: 8px 10px; font-size: 13px; margin-bottom: 10px; }
.progress { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.progress .bar { flex: 1; height: 12px; border-radius: 999px; background: #f1e6ea; overflow: hidden; }
.progress .bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--ok), #22c55e); border-radius: 999px; transition: width .3s; }
.progress .num { font-weight: 900; font-size: 20px; color: var(--ink); white-space: nowrap; }
.progress .num small { font-size: 13px; color: var(--ink-3); font-weight: 600; }

.modes { display: flex; gap: 4px; background: #f4eef0; border-radius: 10px; padding: 3px; margin-bottom: 8px; }
.modes button { flex: 1; border: 0; background: none; padding: 7px 4px; border-radius: 8px; font-size: 12.5px; font-weight: 700; color: var(--ink-2); cursor: pointer; }
.modes button.on { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.mode-hint { font-size: 12.5px; color: var(--ink-2); background: #faf7f8; border: 1px dashed var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 12px; }
.mode-hint ol { margin: 4px 0 0; padding-left: 18px; }

.current { border: 2px solid var(--fb); border-radius: 14px; padding: 14px; background: #f5f9ff; margin-bottom: 12px; }
.current .label { font-size: 12px; font-weight: 700; color: var(--fb-dark); text-transform: uppercase; letter-spacing: .4px; }
.current .gname { font-size: 19px; font-weight: 800; margin: 2px 0 2px; word-break: break-word; }
.current .glink { font-size: 12.5px; word-break: break-all; }
.big-btn {
  display: flex; width: 100%; align-items: center; justify-content: center; gap: 10px; border: 0; cursor: pointer;
  border-radius: 14px; padding: 16px 14px; font-size: 18px; font-weight: 900; letter-spacing: .3px; color: #fff;
  background: var(--fb); box-shadow: 0 4px 0 var(--fb-dark); margin-top: 12px; text-transform: uppercase;
}
.big-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--fb-dark); }
.big-btn.green { background: #16a34a; box-shadow: 0 4px 0 #0f7a36; }
.big-btn.green:active { box-shadow: 0 2px 0 #0f7a36; }
.big-btn:disabled { opacity: .55; cursor: not-allowed; }
.row-btns { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 14px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 14px; text-decoration: none; color: var(--ink);
}
.row-btns .btn { flex: 1 1 auto; }
.btn:hover { border-color: #d9c4cc; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.ok { background: #16a34a; color: #fff; border-color: #16a34a; }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.glist { display: flex; flex-direction: column; gap: 6px; }
.gitem {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; text-align: left; width: 100%; cursor: pointer;
}
.gitem.cur { border-color: var(--fb); background: #f5f9ff; }
.gitem .ico { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; flex: none; background: #f1edee; color: var(--ink-2); font-weight: 800; }
.gitem.done .ico { background: var(--ok-soft); color: var(--ok); }
.gitem.skipped .ico { background: #f1edee; color: var(--ink-3); }
.gitem.taken .ico, .gitem.full .ico { background: var(--warn-soft); color: var(--warn); }
.gitem .gi { flex: 1; min-width: 0; }
.gitem .gn { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gitem .gs { font-size: 12px; color: var(--ink-3); }
.gitem.done .gn, .gitem.skipped .gn, .gitem.taken .gn, .gitem.full .gn { color: var(--ink-2); }

.finish { text-align: center; padding: 18px 10px; background: var(--ok-soft); border-radius: 14px; margin-bottom: 12px; }
.finish .big { font-size: 34px; }
.finish h3 { margin: 6px 0 4px; color: var(--ok); }

.empty { text-align: center; color: var(--ink-3); padding: 22px 12px; border: 1px dashed var(--line); border-radius: 12px; background: #fff; }
.empty b { color: var(--ink); }

/* ---------- Danh sách quản lý ---------- */
.page-h { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.page-h h1 { font-size: 20px; margin: 0 auto 0 0; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 12px; align-items: center; padding: 12px 14px; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 700; }
.item .sub { font-size: 13px; color: var(--ink-3); word-break: break-all; }
.item .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.item.off { opacity: .6; }

.hist { display: flex; gap: 10px; padding: 10px 12px; align-items: flex-start; border-bottom: 1px solid var(--line); }
.hist:last-child { border-bottom: 0; }
.hist .when { font-size: 12px; color: var(--ink-3); width: 86px; flex: none; }
.hist .what { flex: 1; min-width: 0; }
.hist .what .l1 { font-weight: 700; }
.hist .what .l2 { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 560px) { .hist { flex-wrap: wrap; } .hist .when { width: 100%; } }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters select { flex: 1 1 160px; }

/* ---------- Form ---------- */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-weight: 700; font-size: 13px; margin-bottom: 4px; color: var(--ink-2); }
input[type=text], input[type=url], input[type=password], input[type=number], select, textarea {
  width: 100%; border: 1px solid #ddd0d5; border-radius: 10px; padding: 10px 12px; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { min-height: 110px; resize: vertical; }
.hint { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }
.checks { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.checks label { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 8px; cursor: pointer; }
.checks label:hover { background: #faf5f7; }
.checks input { width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
.checks .gsub { font-size: 12px; color: var(--ink-3); word-break: break-all; }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; cursor: pointer; }
.radio input { margin-top: 3px; accent-color: var(--brand); }

.settings-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .settings-grid { grid-template-columns: 1fr 1fr; align-items: start; } }
.settings-grid h2 { font-size: 16px; margin: 0 0 10px; }
.status-box { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.status-box.ok { background: var(--ok-soft); color: #14532d; }
.status-box.err { background: var(--err-soft); color: #7f1d1d; }
.status-box.warn { background: var(--warn-soft); color: #7a3e06; }
details.box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: #fff; }
details.box summary { font-weight: 700; cursor: pointer; }
details.box ol { padding-left: 20px; margin: 8px 0; }
details.box li { margin-bottom: 4px; }

/* ---------- Đăng nhập ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #fbe9ef, #fbf6f7 50%); }
.login { width: 100%; max-width: 380px; padding: 26px 22px; text-align: center; }
.login img { width: 64px; height: 64px; border-radius: 16px; }
.login h1 { font-size: 21px; margin: 10px 0 4px; color: var(--brand); letter-spacing: .5px; }
.login p { margin: 0 0 18px; color: var(--ink-2); font-size: 14px; }
.login form { text-align: left; }
.login .btn { width: 100%; padding: 12px; font-size: 16px; }
.form-err { color: var(--err); font-size: 13.5px; min-height: 1.2em; margin: -4px 0 10px; }

/* ---------- Hộp thoại & thông báo ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(30, 10, 18, .45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; padding: 18px; }
.modal h3 { margin: 0 0 14px; font-size: 18px; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.preview-frame { width: 100%; height: 70vh; border: 0; border-radius: 10px; background: #f3f3f3; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: #1f1a1c; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; z-index: 60; transition: .2s;
  max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--err); }
#toast.ok { background: var(--ok); }

@media (max-width: 640px) {
  .logo { font-size: 15px; }
  .logo small { display: none; }
  .logo img { width: 30px; height: 30px; }
  .topbar { position: static; padding: 8px 12px; }
  .tabs { top: 0; }
  .sync-line { font-size: 12px; }
  .sync-line .opt { display: none; }
  .switch .lbl { display: none; }
  .btn-sync .lbl-long { display: none; }
  .btn-sync .lbl-short { display: inline; }
  main { padding: 12px; }
}
