:root {
  --bg: #f4f4f6; --panel: #ffffff; --line: #e2e2e8; --text: #1b1b20; --muted: #777784;
  --accent: #2f6fed; --dark: #111; --warn: #f0a020; --sel: #ff3d71; --ok: #24a148;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 13px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button, .btn, select, input, textarea { font: inherit; color: inherit; }
button, .btn { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
  cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
button:hover, .btn:hover { background: #f0f0f4; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.dark, .btn.dark { background: var(--dark); color: #fff; border-color: var(--dark); }
button.on { background: #e8efff; border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
select, input, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; background: #fff; }
textarea { width: 100%; resize: vertical; }
label { display: block; margin: 8px 0; }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: 3px; }
.muted { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.pad { padding: 8px 12px; }

#app { display: grid; grid-template-columns: 220px 1fr 360px; height: 100vh; }
#left, #right { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#right { border-right: 0; border-left: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 17px; padding: 14px 12px 6px; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.proj-box { padding: 4px 12px; }
.proj-box select { width: 100%; margin-bottom: 6px; }
#pages { flex: 1; overflow: auto; padding: 4px 8px; }
.pg { display: flex; gap: 8px; padding: 6px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; align-items: center; }
.pg:hover { background: #f4f4f8; }
.pg.on { background: var(--dark); color: #fff; }
.pg img { width: 48px; height: 68px; object-fit: cover; border-radius: 4px; background: #ddd; flex: none; }
.pg .meta { font-size: 11px; line-height: 1.5; min-width: 0; }
.pg .meta b { font-size: 12px; display: block; }
.pg .fn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; opacity: .8; }
.tag { display: inline-block; padding: 0 6px; border-radius: 10px; font-size: 10px; background: #eee; color: #333; }
.tag.ok { background: #dff3e4; color: #1d6b34; }
.tag.wait { background: #fff1d6; color: #8a5a00; }
#dropHint { display: none; }
body.dragging #dropHint { display: block; position: fixed; inset: 0; background: rgba(47,111,237,.15); border: 3px dashed var(--accent);
  z-index: 50; font-size: 22px; display: flex; align-items: center; justify-content: center; pointer-events: none; }

#center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#toolbar { display: flex; gap: 10px; padding: 8px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
#toolbar .grp { display: flex; gap: 4px; align-items: center; }
#toolbar .grp.right { margin-left: auto; }
.chk { display: inline-flex; gap: 4px; margin: 0; align-items: center; }
#zoomLbl { min-width: 44px; text-align: center; }
#saveState { color: var(--muted); font-size: 12px; min-width: 70px; }
#stage { flex: 1; overflow: auto; position: relative; background: #e9e9ee; }
#canvasWrap { position: relative; margin: 20px auto; width: max-content; box-shadow: 0 2px 12px rgba(0,0,0,.15); background: #fff; }
#pageImg { display: block; user-select: none; -webkit-user-drag: none; }
#overlay { position: absolute; inset: 0; }
#overlay.draw { cursor: crosshair; }
#empty { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; color: var(--muted); font-size: 15px; }
.rg { position: absolute; border: 2px solid rgba(47,111,237,.75); border-radius: 3px; cursor: move; }
.rg.bubble { border-style: solid; }
.rg.free { border-color: rgba(240,160,32,.9); }
.rg.skip { border-color: rgba(150,150,150,.8); border-style: dashed; }
.rg.sel { border-color: var(--sel); box-shadow: 0 0 0 2px rgba(255,61,113,.25); }
.rg .num { position: absolute; left: -11px; top: -11px; width: 20px; height: 20px; border-radius: 50%; background: var(--accent);
  color: #fff; font-size: 11px; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.rg.sel .num { background: var(--sel); }
.rg .hd { position: absolute; right: -6px; bottom: -6px; width: 12px; height: 12px; background: #fff; border: 2px solid var(--sel); border-radius: 3px; cursor: nwse-resize; display: none; }
.rg.sel .hd { display: block; }
.hidebox .rg { border-color: transparent !important; box-shadow: none !important; }
.hidebox .rg .num { opacity: .35; }
.drawrect { position: absolute; border: 2px dashed var(--sel); background: rgba(255,61,113,.08); pointer-events: none; }
#jobBar { position: relative; height: 26px; background: #fff; border-top: 1px solid var(--line); }
#jobFill { position: absolute; left: 0; top: 0; bottom: 0; background: #dbe7ff; width: 0; transition: width .3s; }
#jobMsg { position: relative; padding: 0 10px; line-height: 26px; font-size: 12px; }

.tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; }
.tab { display: none; overflow: auto; flex: 1; padding: 8px 12px; }
.tab.on { display: block; }
.card { border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 8px; margin-bottom: 10px; background: #fff; }
.card.sel { border-color: var(--sel); border-left-color: var(--sel); background: #fff8fa; }
.card.skip { opacity: .6; border-left-color: #aaa; }
.card .top { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.card .top .n { font-weight: 700; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 11px; flex: none; }
.card.sel .top .n { background: var(--sel); }
.card .top select { flex: 1; min-width: 0; }
.card .lbl { font-size: 10px; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; margin: 6px 0 2px; display: flex; justify-content: space-between; align-items: center; }
.card textarea.src { background: #f4f4f7; font-size: 12px; }
.card textarea.dst { font-size: 14px; }
.card .mini { padding: 2px 7px; font-size: 11px; border-radius: 6px; }
.card details summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 6px; }
.stylegrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; }
.stylegrid label { margin: 0; font-size: 11px; color: var(--muted); }
.stylegrid .full { grid-column: 1 / -1; }
.preview { font-size: 22px; padding: 4px 6px; border: 1px dashed var(--line); border-radius: 6px; min-height: 34px; overflow: hidden; white-space: nowrap; }
.toggles { display: flex; gap: 4px; flex-wrap: wrap; }
.toggles button { padding: 3px 8px; font-size: 12px; }

dialog { border: 0; border-radius: 12px; padding: 18px 20px; width: min(560px, 94vw); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog h3 { margin: 0 0 8px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; }
legend { color: var(--muted); padding: 0 4px; }
#styleTable .st { display: grid; grid-template-columns: 90px 1fr 46px 50px 60px; gap: 6px; align-items: center; margin: 6px 0; }
#styleTable .st .preview { grid-column: 2 / -1; font-size: 18px; }
#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 9px 14px;
  border-radius: 8px; display: none; z-index: 99; max-width: 70vw; }
#toast.err { background: #b3261e; }

.rg.sfxn { border-color: rgba(200, 40, 200, .85); border-style: dotted; }
.card .note { font-size: 11px; background: #f3f3f6; border-radius: 6px; padding: 5px 7px; margin-bottom: 4px; color: #555; }
.card .sfxmode { font-size: 12px; margin: 2px 0 4px; }

/* bản web */
#jobBar #btnStop { position: absolute; right: 6px; top: 2px; padding: 1px 8px; font-size: 11px; }
#pageImg { image-rendering: auto; }
.busy { cursor: progress; }

/* bản web */
#jobBar #btnStop { position: absolute; right: 6px; top: 2px; padding: 1px 8px; font-size: 11px; }
.chk > input { display: inline-block; width: auto; margin: 0; }
