:root {
  --bg: #f2ebe0; --card: #fffdf9; --ink: #3a2c1e; --muted: #97866f;
  --pink: #8a5a34; --pink-d: #6b4529; --green: #7a8a52; --line: #e3d8c6;
  --amber: #b07d3e; --blue: #7d6a52;
  --brown-d: #4a2f1a; --beige: #efe6d8;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
header { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-size: 18px; display: flex; align-items: center; gap: 10px; }
.logo { width: 40px; height: 40px; border-radius: 9px; }
.brand-name { color: var(--brown-d); }
.brand-name b { color: var(--pink); }
.muted { color: var(--muted); font-weight: normal; font-size: 13px; }
select, input, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
textarea { width: 100%; resize: vertical; }

.tabs { display: flex; gap: 4px; padding: 10px 20px 0; flex-wrap: wrap; }
.tab { border: none; background: transparent; padding: 10px 16px; border-radius: 10px 10px 0 0; cursor: pointer; font-size: 14px; color: var(--muted); }
.tab.active { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 -1px 0 var(--line); }
.badge { background: var(--pink); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; margin-left: 4px; }

main { padding: 16px 20px 60px; }
.view.hidden { display: none; }
.split { display: grid; grid-template-columns: 320px 1fr; gap: 18px; }
@media (max-width: 780px) { .split { grid-template-columns: 1fr; } }
.col-head { font-weight: 600; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.mini { font-size: 12px; padding: 4px 8px; border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; }

.product-list { display: flex; flex-direction: column; gap: 8px; }
.prod-item { display: flex; gap: 10px; align-items: center; padding: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.prod-item.active { border-color: var(--pink); box-shadow: 0 0 0 2px #8a5a3433; }
.prod-item img { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; }
.prod-item .name { font-weight: 600; }
.prod-item .sub { font-size: 12px; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.form-col .empty, .empty { color: var(--muted); padding: 40px; text-align: center; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.field { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; color: var(--muted); }
.field input { width: 100%; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

button.primary { background: var(--pink); color: #fff; border: none; padding: 10px 16px; border-radius: 9px; cursor: pointer; font-weight: 600; }
button.primary:hover { background: var(--pink-d); }
button.primary:disabled { opacity: .5; cursor: default; }
button.ghost { background: #fff; border: 1px solid var(--line); padding: 8px 12px; border-radius: 8px; cursor: pointer; }
button.green { background: var(--green); color: #fff; border: none; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; }
button.danger { color: #c0392b; background: #fff; border: 1px solid #f0c9c4; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; align-items: center; }

.posts { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.post { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.post .head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.post .thumbs { align-items: center; gap: 5px; }
.post .thumbs img { width: 78px; height: 78px; }
.post textarea { min-height: 150px; font-size: 14px; line-height: 1.5; }
.post .content-ro { white-space: pre-wrap; font-size: 14px; line-height: 1.55; background: var(--beige); border-radius: 8px; padding: 10px; }
.post .foot { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tagname { background: var(--beige); color: var(--pink-d); border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600; }
.sched { font-size: 12px; }

.settings label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.settings input, .settings textarea { width: 100%; margin-top: 4px; }
.settings .hint { font-size: 12px; color: var(--green); }
.guide { margin-top: 16px; font-size: 13px; }
.guide summary { cursor: pointer; font-weight: 600; }
.guide code { background: #f2f2f2; padding: 1px 5px; border-radius: 4px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #2b2b2b; color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 20; max-width: 90%; }
.toast.err { background: #c0392b; }
.toast.hidden { display: none; }
.spin { display: inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Ô ADN phong cách theo page */
.adn-box { margin-bottom: 18px; border-left: 5px solid var(--brown-d); }
.adn-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; color: var(--brown-d); }
.adn-box textarea { width: 100%; min-height: 130px; line-height: 1.5; }
a { color: var(--pink); }

/* Nút Cài đặt trên header */
.header-right { display: flex; align-items: center; gap: 12px; }
.settings-btn { background: var(--card); border: 1px solid var(--line); color: var(--brown-d); padding: 9px 14px; border-radius: 9px; cursor: pointer; font: inherit; font-weight: 600; }
.settings-btn:hover { background: var(--beige); }
.settings-btn.active { background: var(--brown-d); color: #fff; border-color: var(--brown-d); }
@media (max-width: 640px) { header { flex-wrap: wrap; gap: 10px; } .header-right { width: 100%; justify-content: space-between; } }

/* Số ảnh & đổi ảnh trên bài */
.imgline { display: flex; align-items: center; gap: 8px; }
.imgcount { font-size: 12px; color: var(--brown-d); background: var(--beige); padding: 2px 8px; border-radius: 6px; font-weight: 600; }
label.chk { display: flex; align-items: center; gap: 8px; }
label.chk input { width: auto; margin: 0; }
.img-rule .row2 label { margin-bottom: 6px; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

/* Nút Đăng luôn ở bài Chưa duyệt */
button.postnow { background: var(--pink); color: #fff; border: none; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 700; }
button.postnow:hover { background: var(--pink-d); }
button.postnow:disabled { opacity: .6; cursor: default; }

/* Câu trả lời mẫu Pancake */
.reply-card { margin-top: 14px; border: 1px dashed var(--pink); border-radius: 10px; padding: 12px; background: #fffaf3; }
.reply-h { display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: var(--brown-d); margin: 8px 0 4px; }
.reply-txt { white-space: pre-wrap; font-size: 14px; line-height: 1.55; background: var(--beige); border-radius: 8px; padding: 10px; margin: 0; font-family: inherit; }
.copy { cursor: pointer; }

/* Thu gọn thông tin + ô số bài */
.form-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
#fieldsBlock.hidden { display: none; }
.gen-wrap { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
#genCount { width: 56px; text-align: center; padding: 8px 6px; }

/* Trường POS + nút Up lên POS */
.pos-fields { margin-top: 8px; padding: 10px; border: 1px dashed var(--blue); border-radius: 10px; background: #f6f8fb; }
.pos-label { font-weight: 600; color: var(--blue); margin-bottom: 8px; }
button.pos-btn { background: var(--blue); color: #fff; border: none; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 700; }
button.pos-btn:hover { filter: brightness(0.92); }
button.pos-btn:disabled { opacity: .6; cursor: default; }
.pos-settings label { display: block; margin: 10px 0; }
.pos-settings input { width: 100%; margin-top: 4px; }
.pos-settings .hint { font-size: 12px; color: var(--green); }

/* Thẻ bài gọn: nút icon + đổi ảnh dạng tròn */
.post .thumbs .shuffle { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; padding: 0; flex: none; }
.post .thumbs .shuffle:hover { background: var(--beige); transform: rotate(90deg); transition: .15s; }
.post .foot { gap: 6px; align-items: center; }
.post .foot .when { flex: 1; min-width: 128px; padding: 6px 8px; font-size: 13px; }
button.ic { width: 40px; height: 34px; padding: 0; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; font-size: 15px; flex: none; }
button.ic:hover { filter: brightness(0.95); }
button.ic.go { background: var(--green); color: #fff; border-color: var(--green); }
button.ic.postnow { background: var(--pink); color: #fff; border-color: var(--pink); }
button.ic.del { color: #c0392b; }
.post { padding: 12px; gap: 7px; }

/* Lightbox phóng to ảnh */
.thumbs img { cursor: zoom-in; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.82); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.lightbox.hidden { display: none; }
.lightbox img { max-width: 95%; max-height: 92%; border-radius: 10px; box-shadow: 0 8px 40px rgba(0,0,0,.5); object-fit: contain; }
.lb-close { position: absolute; top: 16px; right: 22px; color: #fff; font-size: 30px; cursor: pointer; line-height: 1; opacity: .85; }
.lb-close:hover { opacity: 1; }
