:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --text: #1d2330;
    --muted: #6b7280;
    --line: #e3e6eb;
    --primary: #1f6f5c;
    --primary-ink: #ffffff;
    --danger: #b42318;
    --warn-bg: #fff6e0;
    --warn-ink: #8a5a00;
    --ok-bg: #e8f6ef;
    --ok-ink: #17603f;
    --err-bg: #fdecea;
    --err-ink: #9b1c13;
    --radius: 12px;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; }
.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 60px; }

.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.brand span { color: var(--muted); font-weight: 400; font-size: 13px; }
.topbar-inner { gap: 12px; }
nav { display: flex; white-space: nowrap; overflow-x: auto; }
nav a { text-decoration: none; color: var(--muted); margin-left: 18px; padding: 17px 0; border-bottom: 2px solid transparent; }
nav a.active { color: var(--text); border-bottom-color: var(--primary); }

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.page-head { margin-bottom: 16px; }
.muted { color: var(--muted); }
.hint { display: block; color: var(--muted); font-size: 13px; margin-top: 6px; }

.alert { border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; }
.alert-ok { background: var(--ok-bg); color: var(--ok-ink); }
.alert-error { background: var(--err-bg); color: var(--err-ink); }
.alert-warn { background: var(--warn-bg); color: var(--warn-ink); }

.channels { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.channel { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; }
.channel:has(input:checked) { border-color: var(--primary); background: #f0f8f5; }
.channel input { margin: 0; }
.channel-blocked { opacity: .65; cursor: not-allowed; background: #fafafa; }
.channel-text em { color: var(--danger); font-style: normal; }
.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: none; }
.avatar-empty { background: var(--line); display: inline-block; }
.channel-text { display: flex; flex-direction: column; min-width: 0; }
.channel-text strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-text small { color: var(--muted); }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
textarea, input[type=text], input[type=datetime-local], select {
    width: 100%; font: inherit; color: inherit; background: #fff;
    border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
}
textarea:focus, input:focus, select:focus { outline: 2px solid rgba(31,111,92,.25); border-color: var(--primary); }
.counter { display: block; text-align: right; color: var(--muted); font-size: 12px; margin-top: 4px; }
.counter.over { color: var(--danger); font-weight: 600; }
.row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.row .field { flex: 1; min-width: 180px; }
.check { display: flex; gap: 8px; align-items: center; }

.previews { display: flex; gap: 8px; flex-wrap: wrap; margin: -4px 0 14px; }
.previews figure { margin: 0; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; background: var(--line); position: relative; }
.previews img { width: 100%; height: 100%; object-fit: cover; }
.previews .vid { display: grid; place-items: center; height: 100%; font-size: 12px; color: var(--muted); }
.previews .bad { outline: 2px solid var(--danger); }

.when { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin-bottom: 14px; }
.when-opt { display: flex; gap: 8px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; }
.when-opt:has(input:checked) { border-color: var(--primary); background: #f0f8f5; }
.when-opt span { display: flex; flex-direction: column; }
.when-opt small { color: var(--muted); }

.actions { display: flex; justify-content: flex-end; align-items: center; gap: 14px; flex-wrap: wrap; }
.warn-inline { color: var(--warn-ink); margin: 0; font-size: 14px; }

.btn { font: inherit; border: 1px solid transparent; border-radius: 8px; padding: 9px 16px; cursor: pointer; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--text); }
.btn-danger { background: #fff; border-color: #f1c4bf; color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 13px; }

.post-list { display: flex; flex-direction: column; gap: 10px; }
.post { display: flex; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.post-thumb { width: 72px; height: 72px; flex: none; border-radius: 8px; overflow: hidden; background: var(--line); display: grid; place-items: center; color: var(--muted); font-size: 12px; font-weight: 600; }
.post-thumb img { width: 100%; height: 100%; object-fit: cover; }
.post-body { flex: 1; min-width: 0; }
.post-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.post-text { margin: 6px 0; white-space: pre-line; word-break: break-word; }
.post-thumb .thumb-vid { width: 100%; height: 100%; object-fit: cover; background: #000; }
.post-full summary { list-style: none; cursor: pointer; }
.post-full summary::-webkit-details-marker { display: none; }
.post-full summary .post-text { display: block; margin: 6px 0 2px; }
.post-full .more-link { color: var(--primary); font-size: 14px; font-weight: 600; }
.post-full[open] summary .post-text { display: none; }
.post-full[open] .more-link::before { content: "Thu gọn · "; }
.post-full[open] .more-link { display: inline-block; margin-bottom: 4px; }
.post-error { margin: 6px 0 0; color: var(--err-ink); background: var(--err-bg); padding: 6px 10px; border-radius: 6px; font-size: 13px; }
.post-actions { flex: none; }

.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--text); }
.badge-scheduled { background: #e6effc; color: #1f4f99; }
.badge-sent { background: var(--ok-bg); color: var(--ok-ink); }
.badge-error, .badge-failed { background: var(--err-bg); color: var(--err-ink); }
.badge-draft, .badge-needs_approval { background: var(--warn-bg); color: var(--warn-ink); }
.badge-sending { background: #efe8fb; color: #5b3a99; }
.svc { font-weight: 600; }

input[type=password] { width: 100%; font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
.checklist { margin: 4px 0 0; padding-left: 18px; font-size: 14px; }
.checklist .good { color: var(--ok-ink); }
.checklist .bad { color: var(--err-ink); }
.footer-preview { margin: -6px 0 14px; }
.footer-preview pre { margin: 4px 0 0; padding: 10px 12px; background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; font: inherit; font-size: 14px; white-space: pre-wrap; color: var(--muted); }
.sr-only { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.pill { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 99px; background: var(--accent, #fea419); color: #1d1e20; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; }
.small { font-size: 13px; margin: 4px 0 0; }
.section-title { margin: 28px 0 12px; }
.draft-list { display: flex; flex-direction: column; gap: 4px; }
.draft { display: flex; gap: 18px; }
.draft-img { flex: none; width: 220px; }
.draft-img { display: grid; gap: 4px; align-content: start; }
.draft-img a { position: relative; display: block; }
.draft-img img { width: 100%; border-radius: 6px; display: block; background: var(--line); object-fit: cover; }
.gallery-1 img { min-height: 120px; }
.draft-img video { width: 100%; border-radius: 6px; display: block; background: #000; aspect-ratio: 9 / 16; }
.gallery-2, .gallery-3, .gallery-4 { grid-template-columns: 1fr 1fr; }
.gallery-2 img, .gallery-3 img, .gallery-4 img { aspect-ratio: 1; }
.gallery-3 a:first-child { grid-column: span 2; }
.gallery-3 a:first-child img { aspect-ratio: 2 / 1; }
.draft-img small { grid-column: 1 / -1; }
.draft-img .more { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.45); color: #fff; font-weight: 700; border-radius: 6px; }
.draft-body { flex: 1; min-width: 0; }
.draft-body .post-meta { margin-bottom: 10px; }
.draft-body input[type=datetime-local] { max-width: 260px; }
.draft-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

@media (max-width: 560px) {
    .draft { flex-direction: column; }
    .draft-img { width: 100%; }
    .post { flex-wrap: wrap; }
    .post-actions { width: 100%; }
    nav a { margin-left: 12px; }
    .brand span { display: none; }
    .brand { white-space: nowrap; }
}
