:root {
  --bg: #f6f5f2; --card: #ffffff; --text: #1f2328; --muted: #6b6f76; --line: #e3e1dc;
  --accent: #2f6f4f; --accent-ink: #ffffff; --warn-bg: #fdf3dc; --warn: #8a5a00;
  --err-bg: #fbe9e9; --err: #a12c2c; --ok-bg: #e6f3ea; --ok: #22663f; --radius: 8px;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--text);
       font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.45rem; margin: .2rem 0; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* layout */
.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .7rem 1.25rem; background: #1f2a24; color: #e9efe9; flex-wrap: wrap; }
.topbar a { color: #e9efe9; text-decoration: none; }
.topbar .brand { font-weight: 700; letter-spacing: .02em; }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { opacity: .75; padding: .2rem 0; }
.topbar nav a.active, .topbar nav a:hover { opacity: 1; border-bottom: 2px solid #9fd3b3; }
.topbar .me { display: flex; align-items: center; gap: .4rem; }
.topbar .me .muted { color: #a9b5ad; }
.topbar button.link { color: #e9efe9; }
.page { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.head-actions { display: flex; gap: .5rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card.narrow { max-width: 560px; }

/* forms */
label { display: flex; flex-direction: column; gap: .25rem; font-weight: 600; font-size: .92rem; margin-bottom: .8rem; }
label.check { flex-direction: row; align-items: center; gap: .35rem; font-weight: 400; margin: 0; }
input, select, textarea { font: inherit; padding: .45rem .55rem; border: 1px solid #cfccc5; border-radius: 6px; background: #fff; color: var(--text); font-weight: 400; }
input[readonly] { background: #f1f0ec; color: var(--muted); }
textarea { resize: vertical; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9fd3b3; border-color: var(--accent); }
.invalid, fieldset.invalid { border-color: var(--err) !important; }
small.err { color: var(--err); font-weight: 400; }
small.muted { font-weight: 400; }
fieldset { border: 1px solid var(--line); border-radius: 6px; padding: .6rem .8rem; margin: 0 0 .8rem; display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
legend { font-weight: 600; font-size: .92rem; padding: 0 .3rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid2 .actions { grid-column: 1 / -1; }
.actions { display: flex; gap: .8rem; align-items: center; margin-top: .4rem; }
button, .button { font: inherit; padding: .45rem .9rem; border-radius: 6px; border: 1px solid #cfccc5; background: #fff; color: var(--text); cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .button:hover { border-color: #9c988f; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--err); border-color: #e2b4b4; }
button.link { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; }
button.danger.link { color: var(--err); }
form.inline { display: inline; }

/* flash, badge */
.flash { padding: .65rem .85rem; border-radius: 6px; margin-bottom: .8rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.flash.error { background: var(--err-bg); color: var(--err); }
.badge { display: inline-block; font-size: .78rem; padding: .1rem .45rem; border-radius: 999px; background: #ecebe7; color: var(--muted); font-weight: 600; vertical-align: middle; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.main { background: var(--accent); color: #fff; }
.chip { display: inline-block; font-size: .82rem; padding: .1rem .45rem; margin: .1rem .2rem .1rem 0; border-radius: 4px; background: #f0efeb; }
.empty { color: var(--muted); padding: .6rem 0; }

/* list */
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.filters input[name=q] { min-width: 240px; flex: 1; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: .6rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.list th { font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #faf9f7; }
table.list th.num, table.list td.num { text-align: right; }
table.list tr:last-child td { border-bottom: none; }
.card table.list th { background: transparent; }
.thumb-cell { width: 84px; }
.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; background: repeating-conic-gradient(#eee 0% 25%, #fff 0% 50%) 50% / 12px 12px; display: block; }
.pager { display: flex; gap: 1rem; justify-content: center; }
.row-form { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.row-form input[name=display_name] { width: 9rem; }

/* images */
.upload { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; }
.upload label { margin: 0; }
.image-grid { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .9rem; }
.image-card { border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem; background: #fff; cursor: grab; display: flex; flex-direction: column; gap: .45rem; }
.image-card.dragging { opacity: .4; }
.image-card.failed { border-color: #e2b4b4; }
.image-box { position: relative; aspect-ratio: 3 / 4; border-radius: 6px; overflow: hidden;
             background: repeating-conic-gradient(#eee 0% 25%, #fff 0% 50%) 50% / 16px 16px; }
.image-box img { width: 100%; height: 100%; object-fit: contain; display: block; }
.image-box .badge.main { position: absolute; top: .4rem; left: .4rem; }
.placeholder { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: .5rem; }
.placeholder.failed { color: var(--err); }
.image-meta { font-size: .82rem; }
.image-form { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.image-form select { flex: 1; min-width: 0; }
.image-actions { display: flex; justify-content: space-between; }
.image-grid.order-error { outline: 2px solid var(--err); }
.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: .4rem 0; border-bottom: 1px solid var(--line); }
.history li:last-child { border-bottom: none; }

/* posts */
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .8rem; }
.tabs a { padding: .35rem .7rem; border-radius: 999px; text-decoration: none; color: var(--text); background: #ecebe7; font-size: .9rem; }
.tabs a.active { background: var(--accent); color: #fff; }
.tabs .count { opacity: .7; margin-left: .2rem; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 34rem; }
.meta-line { margin-top: .2rem; }
.small { font-size: .85rem; }
.mt { margin-top: 1.1rem; }
.pre { white-space: pre-wrap; }
.hook { font-size: 1.1rem; font-weight: 600; margin: 0 0 1rem; }
.caption { background: #faf9f7; border: 1px solid var(--line); border-radius: 6px; padding: .7rem .8rem; }
.hashtags { color: var(--accent); margin: .5rem 0 0; }
.post-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.slide-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .8rem; }
.slide-card img, .slide-placeholder { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 6px; display: block; border: 1px solid var(--line); }
.slide-placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted); background: #f1f0ec; }
.slide-text { font-size: .85rem; margin-top: .35rem; }
.scenes { margin: 0; padding-left: 1.3rem; }
.scenes li { margin-bottom: .35rem; }
.issues { margin: 0; padding-left: 1.1rem; }
.issues li { margin-bottom: .5rem; font-size: .9rem; }
.channel-list, .versions { list-style: none; padding: 0; margin: 0; }
.channel-list li, .versions li { padding: .5rem 0; border-bottom: 1px solid var(--line); }
.channel-list li:last-child, .versions li:last-child { border-bottom: none; }
.versions li.current { background: #f6faf7; margin: 0 -.5rem; padding: .5rem; border-radius: 6px; }
.error-text { white-space: pre-wrap; font-size: .75rem; max-height: 12rem; overflow: auto; background: var(--err-bg); padding: .4rem; border-radius: 4px; }
.badge.status-pending_review { background: var(--warn-bg); color: var(--warn); }
.badge.status-approved, .badge.status-published { background: var(--ok-bg); color: var(--ok); }
.badge.status-partially_published { background: #e7f1fb; color: #24527a; }
.badge.status-failed { background: var(--err-bg); color: var(--err); }

/* kiến thức, quy tắc */
.mono-text { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9rem; line-height: 1.5; }
.prompt-edit { width: 100%; }
.prompt-view { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9rem; background: #faf9f7;
               border: 1px solid var(--line); border-radius: 6px; padding: .8rem; max-height: 70vh; overflow: auto; }
.grow { flex: 1; }
.pick-list { margin: 0; padding-left: 1.3rem; }
.pick-list li { margin-bottom: .35rem; }
.chip.hit { background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.rule-form { display: grid; grid-template-columns: 1.2fr 1fr 2fr 1.3fr auto; gap: .5rem; align-items: start; }
.rule-actions { display: flex; flex-direction: column; gap: .35rem; }
tr.inactive-row { opacity: .55; }
.diff-old { background: var(--err-bg); border-radius: 4px; padding: .4rem; font-size: .8rem; max-height: 16rem; overflow: auto; }
@media (max-width: 960px) { .rule-form { grid-template-columns: 1fr; } }

/* login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.card.login { width: 100%; max-width: 360px; }
.card.login h1 { text-align: center; margin-bottom: 1rem; }
.card.login button { width: 100%; margin-top: .4rem; }

@media (max-width: 960px) {
  .post-layout { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .grid2 { grid-template-columns: 1fr; }
  .topbar nav { order: 3; flex-basis: 100%; }
  .page-head { align-items: flex-start; }
}
