[hidden]{display:none!important}
:root{
  --bg:#111418; --panel:#1b2027; --panel2:#262d37; --fg:#eef1f5; --muted:#8d98a8;
  --accent:#ff7a2f; --primary:#2f7bff; --danger:#ff5468; --ok:#3ecf8e;
  --sat:env(safe-area-inset-top,0px); --sab:env(safe-area-inset-bottom,0px);
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;height:100%;background:var(--bg);color:var(--fg);
  font:16px/1.35 -apple-system,BlinkMacSystemFont,"SF Pro Text",Roboto,sans-serif;
  overscroll-behavior:none;-webkit-text-size-adjust:100%;-webkit-user-select:none;user-select:none}
#app{height:100vh;height:100dvh;display:flex;flex-direction:column;padding-top:var(--sat)}
.bar{display:grid;grid-template-columns:56px 1fr 56px;align-items:center;padding:6px 10px;min-height:58px}
.bar h1{margin:0;font-size:18px;font-weight:650;text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.slot{display:grid}.slot>*{grid-area:1/1}.slot:first-child{justify-items:start}.slot:last-child{justify-items:end}
.ibtn{display:flex;align-items:center;justify-content:center;width:48px;height:48px;border:0;border-radius:14px;background:var(--panel);color:var(--fg);font-size:26px;line-height:1}
.ibtn svg{display:block;flex:none;width:26px;height:26px;fill:none;stroke:currentColor;overflow:visible;pointer-events:none}
.ibtn:active{filter:brightness(1.3)}
.ibtn[hidden]{display:none}
main{flex:1;min-height:0;position:relative}
.screen{position:absolute;inset:0;display:none;flex-direction:column;gap:8px;padding:0 12px calc(12px + var(--sab));min-height:0}
.screen.active{display:flex}
.muted{color:var(--muted)} .small{font-size:13px} .center{text-align:center} .big{font-size:20px;font-weight:600;margin:0 0 10px}
.err{color:var(--danger);margin:6px 0;font-size:14px}
.hint{margin:0;text-align:center;color:var(--muted);font-size:14px;min-height:20px}
.hint.warn{color:#ffb454}

/* buttons */
button,.btn{font:inherit;color:var(--fg)}
.btn{display:flex;align-items:center;justify-content:center;flex:1;min-width:0;min-height:54px;padding:0 10px;white-space:nowrap;font-size:16px;border:0;border-radius:14px;background:var(--panel2);font-weight:600;text-align:center}
.btn:active,.tools button:active,.chips button:active{filter:brightness(1.25)}
.btn.primary{background:var(--primary)} .btn.accent{background:var(--accent);color:#1a0d02}
.btn.danger,.tools .danger{color:var(--danger)} .btn.wide{flex:none;width:100%}
.btn:disabled,.tools button:disabled{opacity:.4}
.actions{display:flex;gap:10px}
.tools{display:grid;grid-template-columns:repeat(5,1fr);gap:6px}
.tools button{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;min-height:58px;padding:4px 2px;border:0;border-radius:14px;background:var(--panel2);font-size:12px;font-weight:600;white-space:nowrap}
.tools button svg{display:block;flex:none;width:24px;height:24px;fill:none;stroke:currentColor;pointer-events:none}
.tools button.armed{background:var(--danger);color:#fff}
.chips{display:flex;gap:8px}
.chips button{flex:1;min-height:52px;padding:0 12px;border:2px solid transparent;border-radius:16px;font-weight:600;background:var(--panel2);font-size:15px}
.chips button.on{border-color:var(--accent);background:#3a2415}
.chips.small button{min-height:36px;font-size:13px;padding:0 12px}

/* pages */
.strip{display:flex;gap:8px;overflow-x:auto;padding:4px 0;min-height:88px;flex:none;-webkit-overflow-scrolling:touch}
.thumb{position:relative;flex:0 0 auto;width:56px;height:80px;padding:0;border:2px solid transparent;border-radius:8px;background:var(--panel);overflow:hidden}
.thumb.sel{border-color:var(--accent)}
.thumb img{width:100%;height:100%;object-fit:cover;display:block;pointer-events:none}
.thumb span{position:absolute;left:3px;bottom:3px;min-width:20px;padding:0 5px;border-radius:9px;background:#000a;font-size:12px;text-align:center}
.thumb.pend::after{content:"cắt";position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:#000a;font-size:12px}
.bigwrap{flex:1;min-height:0;display:flex;align-items:center;justify-content:center;background:var(--panel);border-radius:14px;overflow:hidden}
.bigwrap img{max-width:100%;max-height:100%;object-fit:contain;background:#fff}
.bigwrap img[hidden]{display:none}
.pager{display:flex;align-items:center;justify-content:center;gap:16px}

/* crop */
.stage{position:relative;flex:1;min-height:0;overflow:hidden;background:#000;border-radius:14px;touch-action:none}
.stage canvas#cropCanvas{position:absolute;display:block;touch-action:none}
.overlay{position:absolute;touch-action:none}
.overlay svg{position:absolute;inset:0;width:100%;height:100%;pointer-events:none;overflow:visible}
.overlay polygon{fill:rgba(47,123,255,.18);stroke:var(--primary);stroke-width:2.5;stroke-linejoin:round}
.overlay.bad polygon{stroke:var(--danger);fill:rgba(255,84,104,.18)}
.handle{position:absolute;width:44px;height:44px;margin:-22px 0 0 -22px;touch-action:none;border-radius:50%}
.handle::after{content:"";position:absolute;left:12px;top:12px;width:20px;height:20px;border-radius:50%;background:#fff;border:3px solid var(--primary);box-shadow:0 0 0 1px #0008}
.loupe{position:absolute;top:8px;left:8px;width:112px;height:112px;border-radius:50%;border:3px solid #fff;box-shadow:0 2px 12px #000a;pointer-events:none;background:#000}
.loupe[hidden]{display:none}

/* export */
.card{background:var(--panel);border-radius:14px;padding:14px}
.lbl{display:block;margin:10px 0 6px;color:var(--muted);font-size:14px}
input[type=text],input[type=email],select{width:100%;min-height:46px;padding:0 12px;border:1px solid #39424f;border-radius:12px;background:var(--bg);color:var(--fg);font-size:16px;-webkit-user-select:text;user-select:text}
input[type=range]{width:100%}
.progress{height:8px;background:var(--panel2);border-radius:4px;overflow:hidden}
.progress i{display:block;height:100%;width:0;background:var(--ok);transition:width .15s}
.row{display:flex;align-items:center;gap:10px;margin:14px 0;font-size:15px}
.row.gap{gap:10px}.row input[type=checkbox]{width:24px;height:24px}

/* sheet / overlays */
.sheet{position:fixed;inset:0;z-index:20}
.sheet[hidden],.busy[hidden],.toast[hidden]{display:none}
.sheet-bg{position:absolute;inset:0;background:#000a}
.sheet-body{position:absolute;left:0;right:0;bottom:0;max-height:88%;overflow:auto;padding:16px 16px calc(16px + var(--sab));background:var(--panel);border-radius:20px 20px 0 0}
.sheet-body h2{margin:0 0 4px;font-size:20px}
.busy{position:fixed;inset:0;z-index:30;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;background:#000b}
.busy .progress{width:60%}
.spin{width:40px;height:40px;border-radius:50%;border:4px solid #fff3;border-top-color:#fff;animation:sp .8s linear infinite}
@keyframes sp{to{transform:rotate(360deg)}}
.toast{position:fixed;left:12px;right:12px;bottom:calc(84px + var(--sab));z-index:40;padding:12px 14px;border-radius:12px;background:#323b48;box-shadow:0 4px 16px #0008;display:flex;gap:12px;align-items:center}
.toast span{flex:1} .toast button{border:0;background:var(--primary);border-radius:10px;min-height:40px;padding:0 14px;font-weight:600}
.vh{position:absolute;width:1px;height:1px;opacity:0;pointer-events:none;left:-10px;top:-10px}

/* pdf library */
.list{flex:1;min-height:0;overflow-y:auto;display:flex;flex-direction:column;gap:10px;-webkit-overflow-scrolling:touch}
.item{background:var(--panel);border-radius:14px;padding:12px}
.item h3{margin:0 0 2px;font-size:16px;word-break:break-all}
.item p{margin:0 0 10px;color:var(--muted);font-size:13px}
.item .acts{display:flex;gap:6px}
.item .acts button{flex:1;min-height:48px;border:0;border-radius:10px;background:var(--panel2);font-size:14px}
.item .acts .danger{color:var(--danger)}

/* page reorder bar: always visible under the preview, disabled when not applicable */
.pgnav{display:grid;grid-template-columns:1fr auto 1fr;align-items:center;gap:8px}
.pgnav button{min-height:44px;border:0;border-radius:12px;background:var(--panel2);font-size:15px;white-space:nowrap}
.pgnav button:disabled{opacity:.35}
.pgnav span{min-width:56px;text-align:center;color:var(--muted);font-weight:600}
/* saved-PDF page editor */
.grid{flex:1;min-height:0;overflow-y:auto;display:grid;grid-template-columns:repeat(3,1fr);gap:10px;align-content:start;-webkit-overflow-scrolling:touch}
.cell{background:var(--panel);border-radius:12px;padding:6px;display:flex;flex-direction:column;gap:6px}
.cell .pv{position:relative;aspect-ratio:210/297;background:#fff;border-radius:6px;overflow:hidden}
.cell .pv.land{aspect-ratio:297/210}
.cell img{width:100%;height:100%;object-fit:contain;display:block}
.cell .num{position:absolute;left:4px;top:4px;min-width:22px;padding:0 6px;border-radius:10px;background:#000b;color:#fff;font-size:12px;text-align:center}
.cell .cb{display:grid;grid-template-columns:1fr 1fr 1fr;gap:4px}
.cell .cb button{min-height:44px;border:0;border-radius:8px;background:var(--panel2);font-size:18px}
.cell .cb button:disabled{opacity:.3}
.cell .cb .danger{color:var(--danger);font-size:15px}
.item .acts{flex-wrap:wrap}.item .acts button{flex:1 1 30%}

/* "new PDF" card at the start of the page strip */
.thumb.new{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;border:2px dashed #4a5566;background:transparent;color:var(--accent)}
.thumb.new b{font-size:30px;line-height:1;font-weight:500}
.thumb.new small{font-size:11px;color:var(--fg);text-align:center;padding:0 3px;line-height:1.15}

/* library thumbnails */
.item .top{display:flex;gap:12px;align-items:center;margin-bottom:10px}
.item .lh{min-width:0;flex:1}.item .lh p{margin:2px 0 0}
.item .lt{flex:0 0 58px;height:82px;border-radius:6px;overflow:hidden;background:var(--panel2);color:var(--muted);font-size:13px;font-weight:700;display:flex;align-items:center;justify-content:center}
.item .lt img{width:100%;height:100%;object-fit:cover;background:#fff}

#fatal{position:fixed;left:8px;right:8px;bottom:8px;max-height:40%;overflow:auto;margin:0;padding:10px;border-radius:10px;background:#5a1620;color:#fff;font-size:12px;white-space:pre-wrap;z-index:99;-webkit-user-select:text;user-select:text}

/* ---- mobile-first redesign ---- */
.empty{display:flex;flex-direction:column;align-items:center;gap:6px;padding:20px;text-align:center}
.empty p{margin:0}.empty .big{margin:6px 0 0}
.empty-ic{display:flex;align-items:center;justify-content:center;width:84px;height:84px;border-radius:50%;background:var(--panel2);color:var(--muted)}
.empty-ic svg{display:block;fill:none;stroke:currentColor}
.actions.main{display:grid;grid-template-columns:1fr 1.5fr 1fr;gap:10px;align-items:stretch}
.actions.main .btn{min-height:64px;flex:none}
.btn .lb{font-size:13px}
.btn.side{flex-direction:column;gap:2px;font-size:15px}
.btn.side svg{display:block;width:24px;height:24px;fill:none;stroke:currentColor;pointer-events:none}
.btn.shoot{gap:10px;font-size:20px;border-radius:32px;box-shadow:0 4px 18px #2f7bff55}
.btn.shoot svg{display:block;fill:none;stroke:currentColor;flex:none;pointer-events:none}
#btnExport.side{font-size:15px}
#cropDone,#pvDone,#exShare,#edSave{flex:1.8}
.actions .btn{min-height:58px}
.strip:empty{display:none}
