:root {
  --bg: #ffffff; --bg2: #f5f6f8; --line: #e3e5ea; --fg: #1d2129; --fg2: #5b6270; --fg3: #8a909c;
  --accent: #1b5fbf; --accent-fg: #fff; --accent-soft: #e8f0fc;
  --loi: #c62f2f; --canhbao: #b86e00; --goiy: #3f7d58;
  --c-chinhta: #c62f2f; --c-noidung: #7a3fb8; --c-trinhbay: #1b5fbf; --c-theothuc: #0f7a72;
  --del-bg: #fde7e7; --ins-bg: #e2f4e8; --hl-para: #fff8d6; --mark: #ffd84d;
  --ai: #6b3fd1;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f2127; --bg2: #272a31; --line: #393d47; --fg: #e8eaee; --fg2: #aab0bc; --fg3: #7f8693;
    --accent: #6ea4ff; --accent-fg: #0d1626; --accent-soft: #24324a;
    --loi: #ff7a7a; --canhbao: #f2b453; --goiy: #7ccf9b;
    --c-chinhta: #ff7a7a; --c-noidung: #c49bff; --c-trinhbay: #6ea4ff; --c-theothuc: #5fd0c5;
    --del-bg: #4a2427; --ins-bg: #1f3d2b; --hl-para: #3a3420; --mark: #8a6d00; --ai: #b69bff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 13px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; color: var(--fg); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.layout { height: 100%; display: flex; }
.pane { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }
.demo-pane { display: none; }
body.demo .demo-pane { display: flex; flex-direction: column; flex: 1.4; min-width: 0; background: var(--bg2); border-right: 1px solid var(--line); }
body.demo .pane { flex: 0 0 380px; }
@media (max-width: 760px) { body.demo .layout { flex-direction: column; } body.demo .demo-pane { flex: 0 0 45%; border-right: 0; border-bottom: 1px solid var(--line); } body.demo .pane { flex: 1; } }
.demo-bar { padding: 8px 14px; font-size: 12px; color: var(--fg2); border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.demo-bar .mini { margin-left: auto; }
.paper { overflow: auto; flex: 1; padding: 18px; }
#demoDoc { background: #fff; color: #111; max-width: 680px; margin: 0 auto; padding: 36px 40px 36px 56px; box-shadow: 0 1px 3px rgba(0,0,0,.12); border-radius: 2px; min-height: 100%; }
#demoDoc p { margin: 0 0 6px; text-align: justify; border-radius: 3px; transition: background .2s; }
#demoDoc mark { background: var(--mark); color: inherit; border-radius: 2px; }
@media (prefers-color-scheme: dark) { #demoDoc { background: #fbfbf9; } #demoDoc p[style*="hl-para"] { background: #fff2b8 !important; } #demoDoc mark { background: #ffd84d; } }

.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 8px; }
.brand { display: flex; gap: 8px; align-items: center; }
.brand img { width: 26px; height: 26px; }
.brand h1 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.brand span { font-size: 11px; color: var(--fg3); }
.icon { border: 0; background: transparent; width: 30px; height: 30px; border-radius: 6px; cursor: pointer; font-size: 16px; color: var(--fg2); }
.icon:hover { background: var(--bg2); }

.actions { display: flex; gap: 8px; padding: 0 14px; }
.btn { border: 1px solid var(--line); background: var(--bg); padding: 7px 14px; border-radius: var(--radius); cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--bg2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); flex: 1; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ai { color: var(--ai); border-color: color-mix(in srgb, var(--ai) 45%, var(--line)); flex: 1; }
.row-type { display: flex; align-items: center; gap: 8px; padding: 10px 14px 0; font-size: 12px; color: var(--fg2); }
.row-type select { flex: 1; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.docinfo { padding: 6px 14px 0; font-size: 11.5px; color: var(--fg3); min-height: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 10px; border-bottom: 1px solid var(--line); }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; color: var(--fg2); }
.chip b { color: var(--fg); margin-left: 2px; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--fg); }
.chip.c-chinhta.on { border-color: var(--c-chinhta); } .chip.c-noidung.on { border-color: var(--c-noidung); }
.chip.c-trinhbay.on { border-color: var(--c-trinhbay); } .chip.c-theothuc.on { border-color: var(--c-theothuc); }

.busy { display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: var(--accent-soft); font-size: 12px; }
.busy .mini { margin-left: auto; }
.spin { width: 14px; height: 14px; border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; animation: sp .8s linear infinite; flex: none; }
@keyframes sp { to { transform: rotate(360deg); } }

.list { flex: 1; overflow: auto; padding: 4px 0 40px; }
.empty { padding: 28px 18px; color: var(--fg2); text-align: center; }
.empty.ok { color: var(--goiy); font-weight: 600; }
h3.cat { margin: 14px 14px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--fg3); display: flex; align-items: center; gap: 6px; }
h3.cat::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
h3.c-chinhta { color: var(--c-chinhta); } h3.c-noidung { color: var(--c-noidung); } h3.c-trinhbay { color: var(--c-trinhbay); } h3.c-theothuc { color: var(--c-theothuc); }

.grp { margin: 0 8px 4px; border-radius: var(--radius); }
.grp > header { display: flex; align-items: center; gap: 6px; padding: 6px 6px; cursor: pointer; border-radius: 6px; user-select: none; }
.grp > header:hover { background: var(--bg2); }
.tw { width: 12px; color: var(--fg3); font-size: 11px; }
.gt { flex: 1; font-weight: 600; min-width: 0; }
.badge { font-size: 11px; font-weight: 700; padding: 0 7px; border-radius: 999px; line-height: 18px; color: #fff; background: var(--fg3); }
.badge.s-loi { background: var(--loi); } .badge.s-canhbao { background: var(--canhbao); } .badge.s-goiy { background: var(--goiy); }
@media (prefers-color-scheme: dark) { .badge { color: #1f2127; } }
.mini { border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 2px 8px; font-size: 11.5px; cursor: pointer; white-space: nowrap; }
.mini:hover { background: var(--bg2); }
.mini.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.items { padding: 2px 0 6px 18px; }
.it { border-left: 3px solid var(--fg3); padding: 6px 8px 6px 10px; margin: 4px 0; background: var(--bg2); border-radius: 0 6px 6px 0; cursor: pointer; }
.it.s-loi { border-left-color: var(--loi); } .it.s-canhbao { border-left-color: var(--canhbao); } .it.s-goiy { border-left-color: var(--goiy); }
.it:hover { outline: 1px solid var(--line); }
.it.sel { outline: 2px solid var(--accent); }
.ctx { font-family: "Times New Roman", Georgia, serif; font-size: 14px; line-height: 1.4; word-break: break-word; }
.ctx del { background: var(--del-bg); color: var(--loi); text-decoration: line-through; border-radius: 2px; padding: 0 1px; }
.ctx ins { background: var(--ins-bg); color: var(--goiy); text-decoration: none; border-radius: 2px; padding: 0 2px; margin-left: 2px; font-weight: 600; }
.ctx ins::before { content: "→ "; font-weight: 400; color: var(--fg3); }
.ws { color: var(--fg3); }
.msg { font-size: 12px; color: var(--fg2); margin-top: 3px; }
.gt { margin-top: 4px; font-size: 12px; }
.gt summary { cursor: pointer; color: var(--accent); width: max-content; list-style: none; }
.gt summary::-webkit-details-marker { display: none; }
.gt summary::before { content: "ⓘ "; }
.gt[open] summary { margin-bottom: 4px; }
.gt-row { padding: 3px 6px; border-radius: 4px; margin: 2px 0; background: var(--bg); line-height: 1.4; }
.gt-row b { font-weight: 600; }
.gt-nen b { color: var(--goiy); } .gt-tranh b { color: var(--loi); } .gt-meo b { color: var(--accent); }
.gt-vidu { font-family: "Times New Roman", Georgia, serif; font-size: 13px; }
.gt-vidu b { font-family: "Segoe UI", system-ui, sans-serif; font-size: 12px; }
.gt-src { font-size: 11px; color: var(--fg3); margin-top: 3px; }
.aitag { font-size: 10px; font-weight: 700; color: var(--ai); border: 1px solid var(--ai); border-radius: 4px; padding: 0 4px; margin-right: 5px; }
.acts { display: flex; gap: 4px; margin-top: 5px; flex-wrap: wrap; align-items: center; }
.pn { font-size: 11px; color: var(--fg3); margin-right: auto; }
.more { display: block; margin: 6px auto; border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 12px; }

.sheet { position: fixed; inset: 0; background: rgba(15, 18, 24, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 20; padding: 16px 10px; overflow: auto; }
.card { background: var(--bg); border-radius: 12px; padding: 14px 16px; width: 100%; max-width: 440px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.card.small { max-width: 360px; margin-top: 40px; }
.card h2 { font-size: 15px; margin: 0 0 8px; }
.sheet-h { display: flex; align-items: center; justify-content: space-between; }
.sheet-f { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.sheet-f .btn.primary { flex: 0 0 auto; min-width: 90px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 10px 0 0; padding: 8px 10px 10px; }
fieldset.dim > *:not(legend):not(.inline) { opacity: .5; }
legend { font-weight: 600; padding: 0 4px; font-size: 12px; color: var(--fg2); }
fieldset > label, .card > label { display: block; margin-top: 8px; font-size: 12px; color: var(--fg2); }
fieldset input:not([type=checkbox]), fieldset select, fieldset textarea, #pasteText {
  display: block; width: 100%; margin-top: 3px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }
#pasteText { font-family: "Times New Roman", serif; font-size: 14px; }
.with-btn { display: flex; gap: 6px; align-items: center; margin-top: 3px; }
.with-btn input { margin-top: 0 !important; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin-top: 10px; }
.checks label, label.inline { font-size: 12.5px; color: var(--fg); display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.note { font-size: 11.5px; color: var(--fg3); margin: 6px 0 0; }
.note.warn { color: var(--canhbao); background: color-mix(in srgb, var(--canhbao) 10%, transparent); padding: 6px 8px; border-radius: 6px; }
.pre { white-space: pre-wrap; }
code { font-size: 11px; background: var(--bg2); padding: 0 3px; border-radius: 3px; }

.toast { position: fixed; left: 10px; right: 10px; bottom: 10px; background: #222831; color: #fff; padding: 9px 12px; border-radius: 8px; font-size: 12.5px; opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; z-index: 30; }
.toast.show { opacity: 1; transform: none; }
.toast.ok { background: #1f6b43; } .toast.warn { background: #8a5a00; } .toast.err { background: #a52a2a; }
body.demo .toast { left: auto; width: 360px; }
