:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #142033;
  --muted: #6b778c;
  --line: #e2e7ef;
  --brand: #12325c;
  --accent: #f2a541;
  --accent-ink: #3a2400;
  --ok: #1f8a5b;
  --bad: #c0392b;
  --soft: #eef3fb;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
}
a { color: var(--brand); }
h1 { font-size: 1.45rem; margin: 0 0 .35rem; line-height: 1.3; }
h2 { font-size: 1.1rem; margin: 0; }
code { background: var(--soft); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; background: var(--brand); color: #fff; flex-wrap: wrap;
}
.brand { color: #fff; text-decoration: none; font-weight: 800; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.brand small { font-weight: 500; opacity: .7; font-size: .8rem; }
.logo {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-size: .8rem;
}
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { color: #dfe7f5; text-decoration: none; padding: 6px 12px; border-radius: 8px; font-weight: 500; }
.topbar nav a:hover { background: rgba(255,255,255,.1); }
.topbar nav a.active { background: rgba(255,255,255,.16); color: #fff; }
.topbar nav a.muted { color: #9fb0cc; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 0 24px; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card.narrow { max-width: 420px; width: 100%; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h1 { margin: 0; }
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.center-page h1 { display: flex; align-items: center; gap: 10px; }

/* Forms */
.form label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 14px; }
.form input:not([type=checkbox]):not([type=radio]), .form select, .form textarea,
.filter input, .filter select, .regen-box input, .status-select {
  display: block; width: 100%; margin-top: 5px; padding: 10px 12px; font: inherit; font-weight: 400;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
.form textarea { resize: vertical; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; line-height: 1.5; }
input:focus, select:focus, textarea:focus, [contenteditable="true"]:focus { outline: 2px solid #8fb2e6; outline-offset: 1px; }
.row-input { display: flex; gap: 8px; margin-top: 5px; }
.row-input input { margin-top: 0 !important; flex: 1; min-width: 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.span2 { grid-column: span 2; }
.switch { display: flex !important; gap: 10px; align-items: flex-start; font-weight: 400 !important; background: var(--soft); padding: 12px; border-radius: 10px; }
.switch input { margin-top: 4px; width: 18px; height: 18px; flex: none; }
.hint { font-size: .82rem; color: var(--muted); margin: 8px 0 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #b9c6da; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #0d2547; }
.btn.big { padding: 13px 26px; font-size: 1rem; }
.btn.sm { padding: 5px 10px; font-size: .82rem; border-radius: 8px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: .9rem; padding: 4px 6px; border-radius: 6px; }
.icon-btn:hover { color: var(--bad); background: #fbeaea; }

.alert { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; }
.alert.ok { background: #e5f5ec; color: #135c3c; }
.alert.err { background: #fbeaea; color: #8a231a; }

.loading { margin-top: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Suggestions */
.suggest-list { padding: 0; margin: 16px 0 0; list-style: none; counter-reset: s; display: grid; gap: 8px; }
.suggest-item {
  width: 100%; text-align: left; font: inherit; font-weight: 600; padding: 11px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; align-items: center;
}
.suggest-item:hover { border-color: var(--accent); background: #fff8ec; }
.suggest-item small { font-weight: 500; color: var(--muted); white-space: nowrap; font-size: .78rem; }

/* Recent / list */
.recent { list-style: none; padding: 0; margin: 0; }
.recent li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); align-items: center; }
.recent li:last-child { border-bottom: 0; }
.badge { display: inline-block; font-size: .74rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--soft); color: var(--brand); white-space: nowrap; }
.badge.s-approved { background: #e8f0ff; color: #1d4fa8; }
.badge.s-filmed { background: #fff3df; color: #8a5300; }
.badge.s-posted { background: #e5f5ec; color: #135c3c; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { padding: 6px 12px; border-radius: 99px; background: var(--soft); text-decoration: none; color: var(--ink); font-size: .88rem; }
.chip b { color: var(--muted); font-weight: 600; margin-left: 4px; }
.chip.on { background: var(--brand); color: #fff; }
.chip.on b { color: #c9d6ee; }
.filter { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filter input { flex: 1 1 220px; margin: 0; }
.filter select { width: auto; margin: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list .status-select { margin: 0; padding: 5px 8px; width: auto; font-size: .85rem; }
.pager { display: flex; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.pager a { padding: 5px 11px; border-radius: 8px; border: 1px solid var(--line); text-decoration: none; }
.pager a.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.empty { padding: 24px 0; text-align: center; }

/* View page */
.head-card .meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 14px; }
.head-card .meta span { background: var(--soft); padding: 3px 10px; border-radius: 99px; font-size: .82rem; }
.head-card .meta span.muted { background: none; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .status-select { width: auto; margin: 0; font-weight: 600; }
.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.sec-tools { display: flex; gap: 6px; }
.regen-box { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; background: #fff8ec; padding: 10px; border-radius: 10px; }
.regen-box input { flex: 1 1 260px; margin: 0; }
.regen-box .loading { margin: 0; }

.edit { white-space: pre-wrap; word-break: break-word; border-radius: 6px; }
.edit:hover { background: #f7f9fd; }
.edit.block { padding: 10px 12px; border: 1px dashed var(--line); min-height: 44px; }
[contenteditable="true"]:empty::before { content: "…"; color: #b5bfcf; }
#titleEdit { padding: 2px 4px; margin-left: -4px; }

.hooks { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.hooks li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.hooks li.chosen { border-color: var(--accent); background: #fff8ec; }
.hooks .pick { font-size: .8rem; color: var(--muted); white-space: nowrap; display: flex; gap: 4px; align-items: center; padding-top: 2px; cursor: pointer; }
.hooks .edit { flex: 1; font-weight: 600; padding: 2px 4px; }

.scenes td { font-size: .92rem; }
.scenes .c-time { width: 84px; font-weight: 700; color: var(--brand); white-space: nowrap; }
.scenes .onscreen { font-weight: 700; }
.scenes .visual { color: #4a5568; font-style: italic; }
.scenes .c-act { width: 36px; }
.scenes th:nth-child(2) { width: 34%; }
#addScene { margin-top: 10px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.thumb-text { font-weight: 800; font-size: 1.25rem; text-transform: uppercase; letter-spacing: .01em; color: var(--brand); }
.tags { color: #1d4fa8; }
.captions { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cap-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; transition: .2s; z-index: 99; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); }

/* Brands */
.brand-switch select {
  background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.25);
  border-radius: 8px; padding: 6px 10px; font: inherit; font-weight: 600; max-width: 230px;
}
.brand-switch select option { color: var(--ink); }
.brand-tag { display: inline-block; vertical-align: middle; font-size: .8rem; font-weight: 600; background: #fff3df; color: #8a5300; padding: 3px 10px; border-radius: 99px; margin-left: 6px; }
.pill-note { display: inline-block; background: #fff3df; color: #8a5300; font-size: .84rem; padding: 4px 10px; border-radius: 8px; margin: 2px 0 6px; }
.head-card .meta span.brand-meta { background: #fff3df; color: #8a5300; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.small { font-size: .85rem; }
.brand-list { display: grid; gap: 10px; }
.brand-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; flex-wrap: wrap; }
.brand-row.off { opacity: .6; }
.brand-name { font-weight: 700; font-size: 1.05rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.brand-name a { text-decoration: none; }
.brand-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.brand-actions form { display: flex; gap: 6px; flex-wrap: wrap; }
.pillar-row { display: grid; grid-template-columns: 220px 1fr 34px; gap: 8px; margin-bottom: 8px; align-items: center; }
.pillar-row input { margin: 0 !important; }
.kb-box { background: var(--soft); border-radius: 12px; padding: 14px; margin-bottom: 16px; }
.kb-box textarea { background: #fff; }
.kb-box .loading { display: inline-flex; margin: 0 0 0 10px; }
.kb-box .loading.hidden { display: none; }
.kb-report { list-style: none; padding: 0; margin: 10px 0 0; font-size: .86rem; }
.kb-report li.ok { color: var(--ok); }
.kb-report li.bad { color: var(--bad); }
.sticky-save { position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--line); padding: 12px 0; margin-top: 4px; text-align: right; z-index: 5; }

@media (max-width: 760px) {
  .grid2 { grid-template-columns: 1fr; }
  .pillar-row { grid-template-columns: 1fr 34px; }
  .pillar-row input[name="p_desc[]"] { grid-column: 1; }
  .topbar { gap: 8px; }
  .brand-switch { order: 3; width: 100%; }
  .brand-switch select { max-width: none; width: 100%; }
  .grid3, .two-col, .captions { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .row-input { flex-direction: column; }
  .scenes thead { display: none; }
  .scenes tr { display: block; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; padding: 6px; }
  .scenes td { display: block; border: 0; padding: 6px 8px; width: auto !important; }
  .scenes td[data-col]::before { display: block; font-size: .72rem; font-weight: 600; color: var(--muted); font-style: normal; text-transform: uppercase; }
  .scenes td[data-col="voiceover"]::before { content: "Lời đọc"; }
  .scenes td[data-col="onscreen"]::before { content: "Chữ màn hình"; }
  .scenes td[data-col="visual"]::before { content: "Hình ảnh"; }
  .scenes .c-act { text-align: right; }
  .list td:nth-child(2), .list th:nth-child(2), .list td:nth-child(5), .list th:nth-child(5) { display: none; }
}

@media print {
  .no-print, .topbar, .foot, #toast { display: none !important; }
  body { background: #fff; font-size: 12px; }
  .wrap { max-width: none; padding: 0; }
  .card { border: 0; padding: 0 0 10px; margin-bottom: 10px; break-inside: avoid; }
  .edit.block { border: 0; padding: 0; }
  .hooks li { border: 0; padding: 2px 0; }
  .hooks li.chosen { background: none; }
  .hooks li.chosen .edit::after { content: "  ✓"; }
  [contenteditable="true"]:empty::before { content: ""; }
  .scenes tr { break-inside: avoid; }
}
