:root {
  --bg: #f4f5f7; --surface: #fff; --text: #1c1e21; --muted: #65676b; --line: #dfe1e5;
  --brand: #1b6ef3; --brand-ink: #fff; --ok: #1f8a4c; --err: #c62828; --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121417; --surface: #1c1f24; --text: #e7e9ec; --muted: #9aa0a6; --line: #30343a; --brand: #4c8dff; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.app { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; padding: 16px; height: 100vh; }
@media (max-width: 1000px) { .app { grid-template-columns: 1fr; height: auto; } }

.browser { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.url { flex: 1; display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 2px 4px 2px 14px; }
.url input { flex: 1; border: 0; background: transparent; color: inherit; font: inherit; outline: none; min-width: 0; }
.conn { font-size: 12px; color: var(--muted); white-space: nowrap; }
.conn.on { color: var(--ok); }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 999px; border: 0; background: transparent; color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--line); }

.screen-wrap { flex: 1; min-height: 0; display: grid; place-items: center; }
.screen { position: relative; width: 100%; max-height: 100%; aspect-ratio: 1280 / 800; background: #000; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
@supports (width: min(1px, 1px)) { .screen { width: min(100%, calc((100vh - 130px) * 1.6)); } }
canvas { width: 100%; height: 100%; display: block; outline: none; cursor: default; }
canvas:focus { box-shadow: inset 0 0 0 2px var(--brand); }
.cursor { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; border: 2px solid #ff3b6b; background: rgba(255,59,107,.25); pointer-events: none; transition: left .25s ease, top .25s ease; display: none; }
.cursor.show { display: block; }
.badge { position: absolute; top: 10px; left: 10px; background: rgba(0,0,0,.7); color: #fff; padding: 4px 10px; border-radius: 999px; font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.panel { display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow: auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card h2 { margin: 0; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.row { display: flex; gap: 8px; }
input:not([type]), input[type=text], textarea, select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: inherit; font: inherit; }
textarea { resize: vertical; }
.btn { display: inline-flex; gap: 6px; align-items: center; justify-content: center; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: inherit; font: inherit; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.ghost { align-self: flex-start; }
.link { display: inline-flex; gap: 6px; align-items: center; border: 0; background: none; color: var(--brand); cursor: pointer; padding: 0; font: inherit; align-self: flex-start; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; }
.thumb { position: relative; width: 64px; height: 64px; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; cursor: pointer; padding: 0; }
.thumb button svg { width: 12px; height: 12px; }
.opts { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.opts label { display: flex; flex-direction: column; gap: 4px; }
.opts .check { flex-direction: row; align-items: flex-start; gap: 8px; }
.log { margin: 0; max-height: 220px; overflow: auto; font: 12px/1.5 ui-monospace, Menlo, monospace; white-space: pre-wrap; color: var(--muted); }

.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 10; }
.toast { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--brand); padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.15); max-width: 360px; }
.toast.ok { border-left-color: var(--ok); } .toast.err { border-left-color: var(--err); }

.ripple { position: absolute; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%; background: rgba(27,110,243,.45); pointer-events: none; animation: rip .5s ease-out forwards; }
@keyframes rip { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
body.expanded .app { grid-template-columns: 1fr; }
body.expanded .panel { display: none; }
body.expanded .screen { width: min(100%, calc((100vh - 110px) * 1.6)); }
@media (max-width: 1000px) { .screen { width: 100%; } .conn { display: none; } }

/* ô nhận phím ẩn (vẫn focus được để bộ gõ tiếng Việt hoạt động) */
.kbd { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; resize: none; pointer-events: none; }
.kbd-status { position: absolute; right: 10px; bottom: 10px; background: rgba(31,138,76,.9); color: #fff; font-size: 12px; padding: 3px 10px; border-radius: 999px; pointer-events: none; display: none; }
.kbd-status.on { display: block; }

/* ---- lịch đăng bài ---- */
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.sm svg, .icon-btn.sm svg { width: 16px; height: 16px; }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn:disabled, .btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn.confirm { background: var(--err); color: #fff; }
.editor { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px dashed var(--brand); border-radius: 8px; }
.editor[hidden] { display: none; }
.editor .row .f { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.editor input[type=date], .editor input[type=time] { width: 100%; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: inherit; font: inherit; }
.row.end { justify-content: flex-end; }
.days { display: flex; flex-direction: column; gap: 14px; }
.empty { color: var(--muted); font-size: 13px; margin: 0; }
.day h3 { margin: 0 0 6px; font-size: 13px; display: flex; justify-content: space-between; color: var(--text); }
.day h3 span { color: var(--muted); font-weight: 400; }
.day.past h3 { color: var(--muted); }
.post { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 6px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); }
.post-top { display: flex; justify-content: space-between; align-items: center; }
.time { font-variant-numeric: tabular-nums; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); }
.post.posted .chip { background: rgba(31,138,76,.15); color: var(--ok); }
.post.failed .chip { background: rgba(198,40,40,.15); color: var(--err); }
.post.posting .chip { background: rgba(27,110,243,.15); color: var(--brand); }
.post.posted { opacity: .75; }
.snippet { margin: 0; font-size: 13px; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.mini { display: flex; gap: 4px; flex-wrap: wrap; }
.mini:empty { display: none; }
.mini img { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); }
.err { margin: 0; font-size: 12px; color: var(--err); }
.actions { display: flex; gap: 4px; align-items: center; justify-content: flex-end; }

/* ---- quản lý group ---- */
.count { color: var(--muted); font-weight: 400; }
.groups { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow: auto; }
.groups li { display: flex; align-items: center; gap: 2px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.groups li.empty { border: 0; background: none; padding: 0; color: var(--muted); font-size: 13px; }
.g-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.g-info b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-info a { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none; }
.editor .f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.pick-head { display: flex; justify-content: space-between; align-items: center; }
.link.sm { font-size: 12px; }
.pick { display: flex; flex-direction: column; gap: 4px; max-height: 140px; overflow: auto; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.pick .check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 13px; }
.targets { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; font-size: 12px; }
.targets li { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.targets .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.targets .gname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.targets .gst { color: var(--muted); }
.targets li.posted .dot { background: var(--ok); } .targets li.posted .gst { color: var(--ok); }
.targets li.failed .dot { background: var(--err); } .targets li.failed .gst { color: var(--err); }
.targets li.posting .dot { background: var(--brand); } .targets li.posting .gst { color: var(--brand); }
.targets small.err { flex-basis: 100%; padding-left: 13px; }

/* ---- trang đăng nhập ---- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.card.login { width: min(360px, 100%); gap: 14px; }
.card.login h1 { margin: 0; font-size: 18px; display: flex; gap: 8px; align-items: center; }
.card.login .f { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.card.login input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.card.login .err { margin: 0; font-size: 13px; }
