:root {
  --bg: #f3f4f7;
  --panel: #ffffff;
  --panel-2: #eef0f4;
  --viewer: #e4e6eb;
  --ink: #1b2330;
  --muted: #5d6778;
  --line: #dfe3ea;
  --accent: #1d5fd1;
  --accent-hover: #174fae;
  --accent-soft: #e6eefc;
  --ok: #157a46;
  --ok-bg: #e8f6ee;
  --warn: #8f5400;
  --warn-bg: #fff5e1;
  --bad: #b3261e;
  --bad-bg: #fdecea;
  --gold: #a86a00;
  --gold-bg: #fff4dc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1d22;
    --panel: #23262d;
    --panel-2: #2c3039;
    --viewer: #15171b;
    --ink: #e7ebf1;
    --muted: #a3acba;
    --line: #353a45;
    --accent: #7aa7ff;
    --accent-hover: #9dbdff;
    --accent-soft: #1d2a44;
    --ok: #5fd39a;
    --ok-bg: #16301f;
    --warn: #f3b955;
    --warn-bg: #33270f;
    --bad: #ff8a80;
    --bad-bg: #3a1a18;
    --gold: #f0b440;
    --gold-bg: #3a2c10;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.45 "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-user-select: none; user-select: none;
}
.pub-page, .results { -webkit-user-select: text; user-select: text; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 24px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 0 6px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; }
i[data-icon] { display: inline-flex; width: 18px; height: 18px; flex: none; }
i[data-icon] svg { width: 100%; height: 100%; }

/* ---------- App bar ---------- */
.appbar {
  height: 56px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand img { width: 28px; height: 28px; }
.appbar-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer;
  white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0d1526; } }
.btn.gold { color: var(--gold); border-color: transparent; background: var(--gold-bg); font-weight: 600; }
.btn.big { height: 44px; padding: 0 22px; font-size: 15px; border-radius: 10px; }
.btn.wide { width: 100%; justify-content: center; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 8px;
  border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--panel-2); color: var(--ink); }
.icon-btn.small { width: 26px; height: 26px; }
.icon-btn.small i { width: 14px; height: 14px; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; }
.link:hover { text-decoration: underline; }
.pro-tag {
  font-size: 10px; font-weight: 700; letter-spacing: .06em; padding: 1px 6px; border-radius: 6px;
  background: var(--gold-bg); color: var(--gold); border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent);
}
.pro-tag.big { font-size: 12px; vertical-align: middle; }
body.is-pro .pro-tag { display: none; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; margin-top: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }

/* ---------- Views ---------- */
main { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; overflow: auto; }

/* Home */
.home { max-width: 860px; margin: 0 auto; padding: 36px 24px 48px; display: flex; flex-direction: column; gap: 20px; }
.drop {
  text-align: center; padding: 40px 32px 30px; border-radius: 18px;
  border: 2px dashed color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--panel);
}
.drop-art img { width: 84px; height: 84px; }
.drop h1 { margin: 14px 0 6px; }
.lead { color: var(--muted); font-size: 15px; margin-bottom: 20px; max-width: 620px; margin-left: auto; margin-right: auto; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 10px; }
.feature-row { list-style: none; padding: 0; margin: 22px 0 6px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.feature-row li { display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px; background: var(--panel-2); color: var(--muted); font-size: 13px; }
.feature-row li i { color: var(--accent); }
.privacy { display: inline-flex; align-items: center; gap: 8px; color: var(--ok); font-size: 13px; margin-top: 16px; }
.recent-list { list-style: none; margin: 0; padding: 6px; }
.recent-list li { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.recent-list li:hover { background: var(--panel-2); }
.recent-list .ext { width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700; text-transform: uppercase; flex: none; }
.recent-list .rname { font-weight: 600; }
.recent-list .rpath { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 640px; }

/* ---------- Document ---------- */
#viewDoc { display: flex; flex-direction: column; overflow: hidden; }
.doc-head { flex: none; display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.doc-title { flex: 1; min-width: 0; }
.doc-title .name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-title .meta { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zoom { display: flex; align-items: center; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; }
.zoom .icon-btn { width: 32px; height: 32px; }
.zoom-value { min-width: 58px; height: 32px; border: none; background: transparent; cursor: pointer; border-radius: 8px; font-variant-numeric: tabular-nums; }
.zoom-value:hover { background: var(--panel-2); }
.doc-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.notice { flex: none; display: flex; align-items: center; gap: 10px; padding: 7px 16px; background: var(--accent-soft); color: var(--ink); font-size: 13px; border-bottom: 1px solid var(--line); }
.notice i { color: var(--accent); }
.notice span { flex: 1; }
.viewer { flex: 1; min-height: 0; overflow: auto; background: var(--viewer); }
.pages { --zoom: 1; display: flex; flex-direction: column; align-items: center; gap: 20px; padding: 24px; width: max-content; min-width: 100%; }
.pages > .pub-page { zoom: var(--zoom); box-shadow: 0 1px 3px rgba(0, 0, 0, .2), 0 8px 24px rgba(0, 0, 0, .12); }
.page-indicator {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); padding: 5px 12px; border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 80%, transparent); color: var(--bg); font-size: 12.5px; font-variant-numeric: tabular-nums; pointer-events: none;
  transition: opacity .4s;
}
.page-indicator.faded { opacity: 0; }
.empty { min-height: 100%; display: grid; place-items: center; padding: 24px; text-align: center; }
.empty .box { max-width: 520px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 30px 32px; box-shadow: var(--shadow); }
.empty .box > i { width: 44px; height: 44px; color: var(--warn); }
.empty h2 { margin: 10px 0 4px; font-size: 19px; }
.empty #errorFile { word-break: break-all; font-size: 12.5px; }

/* ---------- Batch ---------- */
.batch { max-width: 900px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.batch-head { display: flex; gap: 12px; align-items: flex-start; }
.batch-head h1 { font-size: 22px; }
.step { display: flex; gap: 14px; padding: 16px; }
.step-n { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.step-body { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.path { padding: 9px 12px; border-radius: 8px; background: var(--panel-2); font-family: "Cascadia Mono", Consolas, monospace; font-size: 12.5px; word-break: break-all; }
.check { display: inline-flex; gap: 6px; align-items: center; margin-left: 8px; cursor: pointer; }
.progress { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin: 16px 16px 8px; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress-row { display: flex; justify-content: space-between; gap: 12px; padding: 0 16px 14px; color: var(--muted); font-size: 13px; }
.progress-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-wrap { max-height: 420px; overflow: auto; }
table.results { width: 100%; border-collapse: collapse; font-size: 13px; }
.results th { position: sticky; top: 0; background: var(--panel); text-align: left; padding: 8px 12px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); }
.results td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; word-break: break-all; }
.results td.ok { color: var(--ok); white-space: nowrap; }
.results td.bad { color: var(--bad); white-space: nowrap; }
.results td.r { text-align: right; white-space: nowrap; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(10, 14, 22, .45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-card { position: relative; width: min(560px, 100%); max-height: 100%; overflow: auto; background: var(--panel); border-radius: 16px; padding: 26px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-card .close { position: absolute; top: 12px; right: 12px; }
.modal-card.pro { text-align: center; }
.modal-card.pro h2 { font-size: 24px; margin-bottom: 4px; }
.modal-card h2 { font-size: 20px; }
.pro-badge { width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 16px; display: grid; place-items: center; background: var(--gold-bg); color: var(--gold); }
.pro-badge i { width: 28px; height: 28px; }
.pro-list { list-style: none; padding: 0; margin: 18px 0; text-align: left; }
.pro-list li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.pro-list li:last-child { border-bottom: 0; }
.pro-list li > i { color: var(--accent); margin-top: 2px; }
.pro-list b { display: block; }
.pro-list span { color: var(--muted); font-size: 13px; }
.fine { color: var(--muted); font-size: 12px; margin-top: 10px; }
.pro-active { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px; border-radius: 10px; background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.info-head { display: flex; gap: 14px; align-items: center; margin-bottom: 4px; }
.info-head img { width: 48px; height: 48px; }
.lang-select { height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 0 8px; font: inherit; }

/* ---------- Misc ---------- */
.busy { position: fixed; inset: 0; z-index: 60; display: grid; place-content: center; justify-items: center; gap: 14px; background: color-mix(in srgb, var(--bg) 70%, transparent); font-weight: 600; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.drop-overlay { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 18%, transparent); border: 3px dashed var(--accent); }
.drop-overlay > div { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 26px 34px; background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); font-weight: 600; pointer-events: none; }
.drop-overlay i { width: 36px; height: 36px; color: var(--accent); }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast { display: flex; align-items: center; gap: 12px; max-width: 460px; padding: 11px 14px; border-radius: 10px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow); font-size: 13.5px; animation: pop .18s ease-out; }
.toast.error { background: var(--bad); color: #fff; }
.toast.warn { background: #7a4a00; color: #fff; }
.toast.success { background: var(--ok); color: #fff; }
.toast .link { color: inherit; text-decoration: underline; font-weight: 600; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 1150px) {
  .doc-actions .btn span:not(.pro-tag) { display: none; }
  .doc-actions .btn { padding: 0 10px; }
}

/* ---------- Print: only the pages, at their real size (the @page rules come from app.js) ---------- */
@media print {
  html, body { height: auto; overflow: visible; display: block; background: #fff; }
  .appbar, .doc-head, .notice, .page-indicator, #viewHome, #viewBatch, #viewError, .modal, .busy, .toasts, .drop-overlay { display: none !important; }
  main, #viewDoc, .viewer { position: static; display: block; overflow: visible; height: auto; background: #fff; }
  .pages { display: block; padding: 0; gap: 0; width: auto; min-width: 0; }
  .pages > .pub-page { zoom: 1 !important; box-shadow: none; break-after: page; }
  .pages > .pub-page:last-child { break-after: auto; }
}
