@font-face { font-family: "Inter"; src: url(../fonts/ui/Inter-Regular.woff) format("woff"); font-weight: 400 500; font-display: swap; }
@font-face { font-family: "Inter"; src: url(../fonts/ui/Inter-SemiBold.woff) format("woff"); font-weight: 600 700; font-display: swap; }
@font-face { font-family: "Lora Sig"; src: url(../fonts/ui/Lora-Italic.woff) format("woff"); font-weight: 400 700; font-style: italic; }
/* Font xem trước cho trình soạn thảo (trùng với font nhúng vào PDF) */
@font-face { font-family: "VN Serif"; src: url(../fonts/embed/LiberationSerif-Regular.ttf); font-weight: 400; font-style: normal; }
@font-face { font-family: "VN Serif"; src: url(../fonts/embed/LiberationSerif-Bold.ttf); font-weight: 700; font-style: normal; }
@font-face { font-family: "VN Serif"; src: url(../fonts/embed/LiberationSerif-Italic.ttf); font-weight: 400; font-style: italic; }
@font-face { font-family: "VN Serif"; src: url(../fonts/embed/LiberationSerif-BoldItalic.ttf); font-weight: 700; font-style: italic; }
@font-face { font-family: "VN Sans"; src: url(../fonts/embed/LiberationSans-Regular.ttf); font-weight: 400; font-style: normal; }
@font-face { font-family: "VN Sans"; src: url(../fonts/embed/LiberationSans-Bold.ttf); font-weight: 700; font-style: normal; }
@font-face { font-family: "VN Sans"; src: url(../fonts/embed/LiberationSans-Italic.ttf); font-weight: 400; font-style: italic; }
@font-face { font-family: "VN Sans"; src: url(../fonts/embed/LiberationSans-BoldItalic.ttf); font-weight: 700; font-style: italic; }
@font-face { font-family: "VN Mono"; src: url(../fonts/embed/LiberationMono-Regular.ttf); }

:root {
  --desk: #F5F5FA;
  --paper: #FFFFFF;
  --paper-2: #F7F7FA;
  --ink: #33333B;
  --ink-2: #707078;
  --ink-3: #9A9AA3;
  --line: #E3E3EA;
  --line-2: #EDEDF2;
  --blue: #E5322D;      /* màu chính (đỏ) */
  --blue-2: #FDECEB;
  --blue-ink: #FFFFFF;
  --red: #D62F2A;
  --red-2: #FDECEB;
  --green: #1E8E4E;
  --amber: #B26B00;
  --shadow: 0 2px 10px rgba(72, 72, 90, .07);
  --shadow-lg: 0 10px 30px rgba(72, 72, 90, .14);
  --sheet-shadow: 0 1px 3px rgba(40, 40, 60, .16), 0 6px 16px -8px rgba(40, 40, 60, .25);
  --r-sm: 6px; --r: 12px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --serif: var(--font);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --desk: #18181D; --paper: #232329; --paper-2: #2B2B32; --ink: #EDEDF2; --ink-2: #A7A7B1; --ink-3: #7C7C86;
  --line: #36363F; --line-2: #2E2E36; --blue: #FF5A52; --blue-2: #3A2426; --blue-ink: #FFFFFF;
  --red: #FF6B63; --red-2: #3A2426; --green: #5ACD8B; --amber: #E8B054;
  --shadow: 0 2px 10px rgba(0,0,0,.35); --shadow-lg: 0 10px 30px rgba(0,0,0,.5); --sheet-shadow: 0 1px 2px rgba(0,0,0,.5), 0 10px 24px -14px rgba(0,0,0,.8);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--desk); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }
.ico { display: inline-flex; }
.ico svg { width: 20px; height: 20px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }

/* Thanh trên cùng */
.top { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 8px; height: 64px; padding: 0 max(16px, calc((100vw - 1240px) / 2)); background: color-mix(in srgb, var(--paper) 86%, transparent); backdrop-filter: saturate(1.4) blur(10px); box-shadow: 0 1px 0 var(--line-2), 0 2px 8px rgba(72,72,90,.05); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); margin-right: 18px; flex: none; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--blue); color: #fff; }
.brand-mark svg { width: 22px; height: 22px; }
.brand-text { display: grid; line-height: 1.1; }
.brand-name { font: 800 21px/1 var(--font); letter-spacing: -.02em; }
.brand-name b { color: var(--blue); font-weight: 800; }
.brand-sub { font-size: 11.5px; color: var(--ink-2); font-weight: 500; margin-top: 3px; }
.top-nav { display: flex; gap: 2px; }
.top-nav a { padding: 8px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 600; font-size: 14px; white-space: nowrap; }
.top-nav a:hover { color: var(--blue); }
.top-nav a.on { color: var(--blue); }
.top-search { margin-left: auto; position: relative; width: min(260px, 30vw); }
.top-search .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.top-search .ico svg { width: 17px; height: 17px; }
.top-search input { width: 100%; height: 38px; padding: 0 12px 0 36px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper-2); }
.top-search input:focus { outline: none; border-color: var(--blue); background: var(--paper); }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border: 1px solid transparent; border-radius: 50%; background: transparent; color: var(--ink-2); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.icon-btn svg { width: 19px; height: 19px; }

main { display: block; outline: none; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

/* Trang chủ */
.wrap-home { max-width: 1680px; padding: 0 24px; }
.hero { padding: 56px 0 10px; text-align: center; }
.hero h1 { margin: 0 auto; font: 700 clamp(28px, 4vw, 42px)/1.2 var(--font); letter-spacing: -.02em; max-width: 26ch; text-wrap: balance; }
.hero p { margin: 14px auto 0; color: var(--ink-2); max-width: 62ch; font-size: clamp(16px, 1.6vw, 20px); line-height: 1.5; }
.pills { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 30px 0 30px; }
.pill { height: 40px; padding: 0 18px; border-radius: 999px; border: 1.5px solid var(--ink); background: var(--paper); color: var(--ink); font-weight: 600; font-size: 14.5px; cursor: pointer; }
.pill:hover { background: var(--paper-2); }
.pill.on { background: var(--ink); color: var(--paper); }
.pending-file { margin: 0 auto 22px; max-width: 760px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; padding: 12px 16px; border-radius: var(--r); background: var(--blue-2); color: var(--ink); font-weight: 500; }
.home-drop { position: fixed; inset: 0; z-index: 80; display: none; place-items: center; background: color-mix(in srgb, var(--blue) 12%, transparent); border: 4px dashed var(--blue); pointer-events: none; font: 700 26px var(--font); color: var(--blue); }
.home-drop.on { display: grid; }

.tiles { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.tile { position: relative; display: flex; flex-direction: column; gap: 10px; min-height: 196px; padding: 24px 24px 22px; text-decoration: none; color: var(--ink); background: var(--paper); border-radius: var(--r); border: 1px solid var(--line-2); box-shadow: var(--shadow); transition: box-shadow .18s ease, transform .18s ease; }
.tile:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.tile:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.tile-ico { --c: var(--blue); width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; background: var(--c); color: #fff; margin-bottom: 6px; }
.tile-ico svg { width: 27px; height: 27px; stroke-width: 1.9; }
.tile-title { font-weight: 700; font-size: 19px; line-height: 1.25; }
.tile-desc { color: var(--ink-2); font-size: 14.5px; line-height: 1.5; }
.tile-tag { position: absolute; top: 16px; right: 16px; padding: 2px 9px; border-radius: 6px; background: var(--blue-2); color: var(--blue); font-size: 12px; font-weight: 700; }
.tile[hidden] { display: none; }
.no-result { padding: 30px 0; color: var(--ink-2); text-align: center; }
.why { margin: 72px 0 0; }
.why-title { margin: 0 0 22px; text-align: center; font: 700 clamp(22px, 2.6vw, 28px)/1.25 var(--font); letter-spacing: -.01em; }
.why-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.why-card { --c: var(--blue); position: relative; display: grid; gap: 8px; align-content: start; padding: 24px 22px 22px; border-radius: 16px; overflow: hidden;
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 9%, var(--paper)) 0%, var(--paper) 55%); border: 1px solid color-mix(in srgb, var(--c) 18%, var(--line-2)); box-shadow: var(--shadow); }
.why-card::after { content: ""; position: absolute; right: -36px; top: -36px; width: 110px; height: 110px; border-radius: 50%; background: color-mix(in srgb, var(--c) 10%, transparent); }
.why-ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--c); color: #fff; box-shadow: 0 6px 14px -6px var(--c); margin-bottom: 6px; }
.why-ico svg { width: 23px; height: 23px; stroke-width: 2; }
.why-card b { font-size: 17px; line-height: 1.3; }
.why-card span:last-child { color: var(--ink-2); font-size: 14.5px; line-height: 1.5; }
/* nền mờ nhiều màu (chỉ CSS, không ảnh) */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(38vw 38vw at 8% 6%, rgba(229, 50, 45, .10), transparent 70%),
    radial-gradient(34vw 34vw at 92% 14%, rgba(30, 136, 229, .10), transparent 70%),
    radial-gradient(40vw 40vw at 80% 92%, rgba(126, 74, 224, .08), transparent 70%),
    radial-gradient(36vw 36vw at 12% 88%, rgba(46, 158, 91, .08), transparent 70%); }
:root[data-theme="dark"] body::before { opacity: .55; }
.foot { margin-top: 64px; background: #292931; color: #B9B9C3; font-size: 13.5px; }
.foot .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px 24px; padding-top: 26px; padding-bottom: 26px; }
.foot b { color: #fff; }

/* Trang công cụ */
.tool-head { position: relative; padding: 44px 0 26px; text-align: center; }
.back { position: absolute; left: 0; top: 18px; display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); text-decoration: none; font-size: 14px; font-weight: 500; }
.back:hover { color: var(--blue); }
.back svg { width: 17px; height: 17px; }
.tool-head h1 { margin: 0 0 10px; font: 700 clamp(28px, 3.6vw, 42px)/1.2 var(--font); letter-spacing: -.02em; display: flex; align-items: center; justify-content: center; gap: 14px; }
.tool-head h1 .ico { display: none; }
.tool-head p { margin: 0 auto; color: var(--ink-2); max-width: 64ch; font-size: clamp(15px, 1.5vw, 19px); }
.tool-body { padding-bottom: 120px; }
/* khi đã có file: tiêu đề gọn lại */
.tool-head.slim { padding: 18px 0 14px; text-align: left; }
.tool-head.slim .back { position: static; margin-bottom: 6px; }
.tool-head.slim h1 { justify-content: flex-start; font-size: 24px; margin: 0; }
.tool-head.slim h1 .ico { display: grid; }
.tool-head.slim p { display: none; }
.tool-head h1 .ico { place-items: center; width: 36px; height: 36px; border-radius: 9px; background: var(--c, var(--blue)); color: #fff; }
.tool-head h1 .ico svg { width: 21px; height: 21px; }

/* Vùng chọn file: nút đỏ lớn như iLovePDF */
.drop { position: relative; display: grid; justify-items: center; gap: 14px; padding: 34px 20px 60px; border: 2px dashed transparent; border-radius: 18px; background: transparent; cursor: pointer; text-align: center; transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--blue); background: var(--blue-2); }
.drop-sheet { display: none; }
.drop-title { display: inline-flex; align-items: center; justify-content: center; min-width: min(420px, 90vw); padding: 26px 48px; border-radius: 14px; background: var(--blue); color: #fff; font-weight: 700; font-size: clamp(19px, 2.2vw, 24px); box-shadow: 0 6px 18px rgba(229, 50, 45, .35); transition: filter .15s, transform .15s; }
.drop:hover .drop-title { filter: brightness(1.06); transform: translateY(-1px); }
.drop-hint { color: var(--ink-2); font-size: 15px; }
.drop.compact { padding: 22px 16px; grid-auto-flow: column; justify-content: center; align-items: center; gap: 12px; }

/* Nút, ô nhập */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font-weight: 500; font-size: 14.5px; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn .ico svg { width: 18px; height: 18px; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); font-weight: 700; box-shadow: 0 4px 12px rgba(229, 50, 45, .28); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--blue); }
.btn-big { height: 52px; padding: 0 30px; font-size: 17px; border-radius: 12px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--paper-2); color: var(--ink); border-color: transparent; }
.btn-danger { color: var(--red); }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13.5px; }
.btn-icon { width: 34px; padding: 0; height: 34px; }

.input, select.input, textarea.input { height: 38px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); min-width: 0; width: 100%; }
textarea.input { height: auto; padding: 9px 11px; resize: vertical; }
.input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-2); }
input[type=color].input { padding: 3px; width: 46px; cursor: pointer; }
input[type=range] { width: 100%; accent-color: var(--blue); }
.field { display: grid; gap: 6px; }
.field-label { font-weight: 500; font-size: 13.5px; color: var(--ink-2); }
.field-hint { font-size: 12.5px; color: var(--ink-3); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14.5px; }
.check input { width: 17px; height: 17px; accent-color: var(--blue); margin: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .field { flex: 1 1 120px; }
.stack { display: grid; gap: 16px; }

.seg { display: inline-flex; flex-wrap: wrap; padding: 3px; border-radius: 9px; background: var(--paper-2); border: 1px solid var(--line-2); gap: 2px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { padding: 6px 12px; border-radius: 7px; cursor: pointer; font-size: 14px; color: var(--ink-2); white-space: nowrap; }
.seg input:checked + label { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 500; }
.seg input:focus-visible + label { outline: 2px solid var(--blue); }

.choice-list { display: grid; gap: 8px; }
.choice { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--paper); cursor: pointer; }
.choice input { grid-row: span 2; margin: 3px 0 0; width: 17px; height: 17px; accent-color: var(--blue); }
.choice b { font-weight: 600; font-size: 14.5px; }
.choice span { color: var(--ink-2); font-size: 13.5px; grid-column: 2; }
.choice:has(input:checked) { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.choice .sub { grid-column: 2; margin-top: 8px; }
.choice:not(:has(input:checked)) .sub { display: none; }

/* Bố cục công cụ: vùng chính + bảng tuỳ chọn */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.panel { position: sticky; top: 84px; padding: 18px; border-radius: var(--r); background: var(--paper); box-shadow: var(--shadow); display: grid; gap: 18px; }
.panel h3 { margin: 0; font-size: 15px; font-weight: 600; }
.panel .sep { height: 1px; background: var(--line-2); margin: 0 -18px; }
.surface { padding: 16px; border-radius: var(--r); background: var(--paper); box-shadow: var(--shadow); }
.note { padding: 10px 12px; border-radius: 8px; background: var(--paper-2); color: var(--ink-2); font-size: 13.5px; }
.note.warn { background: color-mix(in srgb, var(--amber) 14%, var(--paper)); color: var(--ink); }

/* Thanh hành động dưới cùng */
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: color-mix(in srgb, var(--paper) 94%, transparent); backdrop-filter: blur(8px); border-top: 1px solid var(--line); }
.actionbar .wrap { display: flex; align-items: center; gap: 14px; height: 72px; }
.actionbar .summary { color: var(--ink-2); font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actionbar .grow { flex: 1; }

/* Danh sách file */
.file-list { display: grid; gap: 8px; }
.file-row { display: grid; grid-template-columns: auto 46px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 12px; border-radius: var(--r); background: var(--paper); box-shadow: var(--shadow); }
.file-row.dragging { opacity: .45; }
.file-row.drop-before { box-shadow: 0 -3px 0 var(--blue), var(--shadow); }
.file-row.drop-after { box-shadow: 0 3px 0 var(--blue), var(--shadow); }
.file-row .handle { cursor: grab; color: var(--ink-3); display: inline-flex; }
.file-thumb { width: 46px; height: 60px; display: grid; place-items: center; background: var(--paper-2); border: 1px solid var(--line-2); border-radius: 3px; overflow: hidden; }
.file-thumb canvas { max-width: 100%; max-height: 100%; display: block; }
.file-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { color: var(--ink-2); font-size: 13px; }
.file-row .range { margin-top: 6px; max-width: 260px; height: 32px; font-size: 13.5px; }
.file-actions { display: flex; gap: 2px; }
.file-tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; align-items: center; }

/* Lưới trang */
.pg-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.pg-tools .grow { flex: 1; }
.pg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--thumb, 150px), 1fr)); gap: 18px 16px; }
.pg { position: relative; display: grid; justify-items: center; gap: 6px; padding: 10px 8px 8px; border-radius: var(--r); cursor: pointer; user-select: none; }
.pg:hover { background: color-mix(in srgb, var(--paper) 55%, transparent); }
.pg-frame { position: relative; display: grid; place-items: center; width: 100%; aspect-ratio: 1 / 1.1; }
.pg-sheet { position: relative; background: #fff; box-shadow: var(--sheet-shadow); transition: transform .2s ease; line-height: 0; max-width: 100%; max-height: 100%; }
.pg-sheet canvas { display: block; max-width: 100%; }
.pg-sheet.loading { width: 70%; aspect-ratio: 1/1.414; background: var(--paper-2); }
.pg-num { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.pg.sel .pg-sheet { outline: 3px solid var(--blue); outline-offset: 2px; }
.pg.sel .pg-num { color: var(--blue); font-weight: 600; }
.pg.marked-del .pg-sheet::after { content: ""; position: absolute; inset: 0; background: color-mix(in srgb, var(--red) 28%, transparent); }
.pg.marked-del .pg-sheet { outline: 3px solid var(--red); outline-offset: 2px; }
.pg.marked-del .pg-num { color: var(--red); font-weight: 600; text-decoration: line-through; }
.pg-check { position: absolute; top: 4px; left: 4px; z-index: 2; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--paper); border: 1.5px solid var(--line); color: transparent; }
.pg-check svg { width: 14px; height: 14px; }
.pg.sel .pg-check { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); }
.pg.marked-del .pg-check { background: var(--red); border-color: var(--red); color: #fff; }
.pg-actions { position: absolute; bottom: 34px; left: 50%; transform: translateX(-50%); z-index: 3; display: flex; gap: 2px; padding: 2px; border-radius: 8px; background: var(--paper); box-shadow: var(--shadow); opacity: 0; transition: opacity .12s; }
.pg:hover .pg-actions, .pg:focus-within .pg-actions { opacity: 1; }
.pg-actions button { width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--ink-2); }
.pg-actions button:hover { background: var(--paper-2); color: var(--ink); }
.pg-actions svg { width: 16px; height: 16px; }
.pg-badge { position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); z-index: 2; padding: 1px 7px; border-radius: 99px; background: var(--ink); color: var(--paper); font-size: 11.5px; white-space: nowrap; line-height: 1.6; }
.pg.dragging { opacity: .35; }
.pg.drop-before::before, .pg.drop-after::after { content: ""; position: absolute; top: 10%; bottom: 10%; width: 3px; background: var(--blue); border-radius: 2px; }
.pg.drop-before::before { left: -9px; }
.pg.drop-after::after { right: -9px; }
.pg-split-mark { position: absolute; right: -11px; top: 8%; bottom: 8%; width: 0; border-right: 2px dashed var(--red); }
.pg-insert { display: grid; place-items: center; align-content: center; gap: 6px; padding: 10px; border: 2px dashed var(--line); border-radius: var(--r); color: var(--ink-2); cursor: pointer; min-height: 160px; background: transparent; font-size: 13.5px; }
.pg-insert:hover { border-color: var(--blue); color: var(--blue); }
.file-sep { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 13.5px; font-weight: 500; margin-top: 6px; }
.file-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Kết quả */
.result { max-width: 640px; margin: 10px auto 0; padding: 30px; border-radius: var(--r); background: var(--paper); box-shadow: var(--shadow); text-align: center; }
.result h2 { margin: 0 0 6px; font: 700 28px/1.25 var(--font); letter-spacing: -.01em; }
.result .stat { margin: 12px 0 22px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.result .stat b { color: var(--green); }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.result-files { margin: 20px 0 0; display: grid; gap: 6px; text-align: left; max-height: 320px; overflow: auto; }
.result-file { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--paper-2); font-size: 14px; }
.result-file .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-file .size { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.continue { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line-2); }
.continue p { margin: 0 0 10px; color: var(--ink-2); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px 5px 8px; border-radius: 99px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font-size: 13.5px; cursor: pointer; text-decoration: none; }
.chip:hover { border-color: var(--blue); color: var(--blue); }
.chip svg { width: 16px; height: 16px; }

/* Thông báo, chờ, hộp thoại */
#toasts { position: fixed; z-index: 100; bottom: 88px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; width: min(460px, calc(100vw - 32px)); }
.toast { padding: 11px 15px; border-radius: 10px; background: var(--ink); color: var(--paper); font-size: 14px; box-shadow: var(--shadow); animation: tin .2s ease; }
.toast-error { background: var(--red); color: #fff; }
.toast-warn { background: var(--amber); color: #fff; }
.toast.out { opacity: 0; transition: opacity .3s; }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }
.busy { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: color-mix(in srgb, var(--desk) 70%, transparent); backdrop-filter: blur(2px); }
.busy-card { display: grid; justify-items: center; gap: 12px; padding: 26px 30px; min-width: 280px; border-radius: 14px; background: var(--paper); box-shadow: var(--shadow); }
.busy-text { font-weight: 500; text-align: center; }
.busy-bar { width: 220px; height: 4px; border-radius: 4px; background: var(--line-2); overflow: hidden; }
.busy-bar i { display: block; height: 100%; width: 30%; background: var(--blue); border-radius: 4px; animation: slide 1.1s ease-in-out infinite; }
.busy-bar.det i { animation: none; transition: width .2s; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--blue); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.modal { position: fixed; inset: 0; z-index: 95; display: grid; place-items: center; padding: 16px; background: rgba(10, 15, 20, .45); }
.modal-card { width: min(440px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 22px; border-radius: 14px; background: var(--paper); box-shadow: var(--shadow); display: grid; gap: 14px; }
.modal-card.wide { width: min(680px, 100%); }
.modal-card h3 { margin: 0; font: 700 19px/1.3 var(--font); }
.modal-card p { margin: 0; color: var(--ink-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* Xem trước một trang (crop, watermark, số trang...) */
.preview { position: relative; display: grid; place-items: center; padding: 24px; border-radius: var(--r); background: var(--paper-2); min-height: 360px; overflow: hidden; }
.preview-stage { position: relative; line-height: 0; box-shadow: var(--sheet-shadow); background: #fff; }
.preview-stage canvas { display: block; }
.preview-nav { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 10px; color: var(--ink-2); font-size: 14px; font-variant-numeric: tabular-nums; }
.crop-box { position: absolute; border: 2px solid var(--blue); box-shadow: 0 0 0 9999px rgba(15, 25, 40, .45); cursor: move; touch-action: none; }
.crop-box i { position: absolute; width: 14px; height: 14px; background: #fff; border: 2px solid var(--blue); border-radius: 3px; }
.crop-box i[data-h=nw] { left: -8px; top: -8px; cursor: nwse-resize; } .crop-box i[data-h=ne] { right: -8px; top: -8px; cursor: nesw-resize; }
.crop-box i[data-h=sw] { left: -8px; bottom: -8px; cursor: nesw-resize; } .crop-box i[data-h=se] { right: -8px; bottom: -8px; cursor: nwse-resize; }
.crop-box i[data-h=n] { left: calc(50% - 7px); top: -8px; cursor: ns-resize; } .crop-box i[data-h=s] { left: calc(50% - 7px); bottom: -8px; cursor: ns-resize; }
.crop-box i[data-h=w] { top: calc(50% - 7px); left: -8px; cursor: ew-resize; } .crop-box i[data-h=e] { top: calc(50% - 7px); right: -8px; cursor: ew-resize; }
.overlay-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.kbd { font: 500 12px var(--font); padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--paper-2); }
.empty { padding: 40px 16px; text-align: center; color: var(--ink-2); }

/* Trình sửa và ký */
.editor { margin: 0 -16px; }
.ed-top { position: sticky; top: 64px; z-index: 20; background: var(--paper); border-block: 1px solid var(--line); box-shadow: 0 6px 14px -12px rgba(0,0,0,.4); }
.ed-toolbar { display: flex; align-items: center; gap: 2px; padding: 6px 10px; overflow-x: auto; scrollbar-width: thin; }
.ed-tool { flex: none; display: grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); cursor: pointer; }
.ed-tool:hover { background: var(--paper-2); color: var(--ink); }
.ed-tool.on { background: var(--blue-2); color: var(--blue); }
.ed-tool:disabled { opacity: .35; cursor: default; background: transparent; }
.ed-tool svg { width: 21px; height: 21px; }
.ed-sep { flex: none; width: 1px; height: 24px; background: var(--line); margin: 0 5px; }
.ed-grow { flex: 1; min-width: 8px; }
.ed-zoom { flex: none; min-width: 58px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); font-size: 13px; font-variant-numeric: tabular-nums; cursor: pointer; }
.ed-props { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-height: 48px; padding: 6px 14px; border-top: 1px solid var(--line-2); background: var(--paper-2); }
.ed-props .input { height: 34px; width: auto; }
.ed-props select.input { padding-right: 28px; }
.ed-plabel { font-size: 13px; color: var(--ink-2); }
.ed-tbtn { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); cursor: pointer; font-size: 15px; }
.ed-tbtn.on { background: var(--blue-2); border-color: var(--blue); color: var(--blue); }
.ed-colors { display: flex; align-items: center; gap: 4px; }
.ed-swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--paper); box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.ed-swatch.on { box-shadow: 0 0 0 2px var(--blue); }
.ed-swatch.none { background: linear-gradient(135deg, transparent 45%, var(--red) 45% 55%, transparent 55%), var(--paper); }
.ed-color-in { width: 30px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }
.ed-hint { padding: 8px 16px; font-size: 13.5px; color: var(--ink-2); min-height: 36px; }
.ed-body { display: grid; grid-template-columns: 168px minmax(0, 1fr); align-items: start; }
.editor.no-side .ed-body { grid-template-columns: minmax(0, 1fr); }
.editor.no-side .ed-side { display: none; }
.ed-side { position: sticky; top: 172px; max-height: calc(100vh - 260px); overflow-y: auto; padding: 8px 10px 14px; border-right: 1px solid var(--line); scrollbar-width: thin; }
.ed-thumbs { display: grid; gap: 12px; }
.ed-thumb { position: relative; display: grid; justify-items: center; gap: 4px; padding: 6px; border-radius: 8px; cursor: pointer; }
.ed-thumb:hover, .ed-thumb:focus-visible { background: var(--paper-2); outline: none; }
.ed-thumb.dragging { opacity: .4; }
.ed-thumb.drop-before { box-shadow: 0 -3px 0 var(--blue); } .ed-thumb.drop-after { box-shadow: 0 3px 0 var(--blue); }
.ed-thumb-img { line-height: 0; box-shadow: 0 1px 4px rgba(0,0,0,.25); background: #fff; }
.ed-thumb-img canvas { display: block; max-width: 120px; max-height: 120px; }
.ed-thumb-n { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.ed-thumb-act { position: absolute; top: 4px; right: 4px; display: none; flex-direction: column; gap: 2px; }
.ed-thumb:hover .ed-thumb-act, .ed-thumb:focus-within .ed-thumb-act { display: flex; }
.ed-thumb-act button { width: 24px; height: 24px; display: grid; place-items: center; border: 0; border-radius: 6px; background: rgba(255,255,255,.95); color: #384350; box-shadow: 0 1px 4px rgba(0,0,0,.25); cursor: pointer; padding: 0; }
.ed-thumb-act button:hover { color: var(--blue); }
.ed-thumb-act svg { width: 14px; height: 14px; }
.ed-addfile { width: 100%; margin-top: 12px; height: auto; min-height: 34px; white-space: normal; font-size: 12.5px; }
.ed-pages { display: grid; justify-items: center; gap: 10px; padding: 6px 16px 40px; overflow-x: auto; }
.ed-cover { position: absolute; pointer-events: none; }
.ed-tl { display: block; overflow: visible; }
.ed-obj.ed-stamp { display: grid; place-items: center; border-style: solid; white-space: nowrap; overflow: hidden; letter-spacing: .02em; }
.ed-obj.ed-redact { background: #000; }
.ed-textbox-ghost { position: absolute; border: 1.5px dashed var(--blue); background: rgba(31,79,168,.05); pointer-events: none; }
.ed-target.ocr { background: rgba(229,50,45,.05); outline-color: rgba(229,50,45,.3); }
.ed-flash { position: absolute; pointer-events: none; background: rgba(255,200,0,.28); outline: 1px solid rgba(220,150,0,.7); border-radius: 2px; }
.ed-flash.cur { background: rgba(255,140,0,.45); outline: 2px solid #E07B00; }
.ed-find { padding: 8px 14px; border-top: 1px solid var(--line-2); background: var(--paper); }
.ed-find-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ed-find-row .input { height: 34px; width: 220px; }
.ed-find-res { display: grid; gap: 2px; max-height: 180px; overflow-y: auto; margin-top: 6px; }
.ed-find-sum { font-size: 13px; color: var(--ink-2); padding: 2px 0; }
.ed-find-item { text-align: left; border: 0; background: transparent; padding: 4px 6px; border-radius: 6px; font-size: 13px; color: var(--ink); cursor: pointer; }
.ed-find-item:hover { background: var(--paper-2); }
.ed-warn { color: var(--red, #B3261E); font-weight: 600; }
.ed-page-tools .btn { padding: 0 6px; }
@media (max-width: 900px) { .ed-body { grid-template-columns: minmax(0, 1fr); } .ed-side { display: none; } }
.ed-page-wrap { display: grid; gap: 6px; }
.ed-page-tools { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-2); }
.ed-page-tools span:first-child { flex: 1; }
.ed-page-tools .btn { height: 28px; font-size: 12.5px; padding: 0 8px; }
.ed-page-tools .btn .ico svg { width: 15px; height: 15px; }
.ed-page { position: relative; background: #fff; box-shadow: var(--sheet-shadow); line-height: 0; }
.ed-page canvas { display: block; }
.ed-layer { position: absolute; inset: 0; line-height: normal; overflow: hidden; touch-action: none; }
.editor[data-tool="text"] .ed-layer, .editor[data-tool="date"] .ed-layer { cursor: text; }
.editor:not([data-tool="select"]):not([data-tool="text"]):not([data-tool="date"]):not([data-tool="edittext"]) .ed-layer { cursor: crosshair; }
.ed-obj { position: absolute; box-sizing: border-box; user-select: none; }
.editor[data-tool="select"] .ed-obj { cursor: move; }
.editor:not([data-tool="select"]) .ed-obj { pointer-events: none; }
.ed-obj.ed-text { white-space: pre; padding: 0; outline: none; }
.ed-obj.ed-text.editing { cursor: text; user-select: text; outline: 1.5px solid var(--blue); outline-offset: 1px; background: rgba(255,255,255,.6); }
.ed-obj.ed-image img { width: 100%; height: 100%; display: block; pointer-events: none; }
.ed-obj.sel:not(.editing) { outline: 1px dashed var(--blue); outline-offset: 1px; }
.ed-handles { position: absolute; pointer-events: none; }
.ed-handles i { position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; background: #fff; border: 2px solid #1F4FA8; border-radius: 3px; pointer-events: auto; touch-action: none; }
.ed-handles i[data-h=nw] { left: 0; top: 0; cursor: nwse-resize; } .ed-handles i[data-h=n] { left: 50%; top: 0; cursor: ns-resize; } .ed-handles i[data-h=ne] { left: 100%; top: 0; cursor: nesw-resize; }
.ed-handles i[data-h=e] { left: 100%; top: 50%; cursor: ew-resize; } .ed-handles i[data-h=se] { left: 100%; top: 100%; cursor: nwse-resize; } .ed-handles i[data-h=s] { left: 50%; top: 100%; cursor: ns-resize; }
.ed-handles i[data-h=sw] { left: 0; top: 100%; cursor: nesw-resize; } .ed-handles i[data-h=w] { left: 0; top: 50%; cursor: ew-resize; }
.ed-handles i[data-h=p1], .ed-handles i[data-h=p2] { margin: 0; border-radius: 50%; cursor: move; }
.ed-mini { position: absolute; right: 0; bottom: 100%; margin-bottom: 8px; display: flex; gap: 2px; padding: 2px; border-radius: 8px; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.25); pointer-events: auto; }
.ed-del { width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 6px; background: transparent; color: #536170; cursor: pointer; }
.ed-del:hover { background: #F1F4F7; color: #B3261E; }
.ed-del svg { width: 16px; height: 16px; }
.ed-target { position: absolute; border-radius: 2px; cursor: text; background: rgba(31,79,168,.06); outline: 1px solid rgba(31,79,168,.22); }
.ed-target:hover { background: rgba(31,79,168,.16); outline-color: rgba(31,79,168,.7); }
body.editing-mode .tool-body { padding-bottom: 90px; }

/* Chữ ký */
.sig-box { position: relative; border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden; }
.sig-pad { display: block; width: 100%; aspect-ratio: 1120 / 400; touch-action: none; cursor: crosshair; }
.sig-hint { position: absolute; inset: 0; display: grid; place-items: center; color: #9AA7B4; pointer-events: none; font-size: 15px; }
.sig-line { position: absolute; left: 8%; right: 8%; bottom: 22%; border-bottom: 1px dashed #C7CFD8; pointer-events: none; }
.sig-types { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sig-type { padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
.sig-type.on { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.sig-type-canvas { width: 100%; display: block; }
.sig-img { min-height: 180px; display: grid; place-items: center; background: repeating-conic-gradient(#F1F4F7 0 25%, #fff 0 50%) 0 0 / 16px 16px; }
.sig-img-canvas { max-width: 100%; max-height: 260px; display: block; }
.sig-saved { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.sig-saved-item { display: flex; align-items: center; gap: 4px; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.sig-use { flex: 1; height: 80px; display: grid; place-items: center; border: 0; background: transparent; cursor: pointer; border-radius: 6px; }
.sig-use:hover { background: #F1F4F7; }
.sig-use img { max-width: 100%; max-height: 72px; }

@media (max-width: 1100px) { .top-nav { display: none; } }
@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .panel { position: static; }
  .hero { grid-template-columns: 1fr; }
  .hero-drop { width: 100%; }
}
@media (max-width: 560px) {
  .brand-sub { display: none; }
  .brand { margin-right: 4px; }
  .back { position: static; margin-bottom: 10px; }
  .tool-head { padding-top: 16px; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile { min-height: 0; padding: 16px; }
  .tile-desc { display: none; }
  .tile-title { font-size: 15.5px; }
  .tile-ico { width: 40px; height: 40px; }
  .top-search { width: auto; flex: 1; }
  .pg-grid { --thumb: 120px !important; gap: 12px 8px; }
  .actionbar .wrap { height: 64px; }
  .actionbar .summary { display: none; }
  .actionbar .grow { display: none; }
  .actionbar .btn-big { flex: 1; }
  .file-row { grid-template-columns: 46px minmax(0, 1fr) auto; }
  .file-row .handle { display: none; }
  .result { padding: 22px 16px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* Lưới công cụ trang chủ: 6 cột trên màn hình rộng */
@media (min-width: 1200px) {
  .tiles { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; }
  .tile { min-height: 188px; padding: 20px 18px 18px; }
  .tile-title { font-size: 17px; }
  .tile-desc { font-size: 13.5px; }
  .why-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 860px) and (max-width: 1199.98px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
