:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --workspace: #e2e8f0;
  --danger: #dc2626;
  --text-2: #334155;
  --text-3: #475569;
  --hover: #f1f5f9;
  --line-strong: #cbd5e1;
  --subtle: #f8fafc;
  --accent-strong: #1d4ed8;
  --danger-soft: #fee2e2;
  --success-soft: #dcfce7;
  --veil: rgba(248,250,252,.86);
  --chip: rgba(255,255,255,.95);
  color-scheme: light;
}
/* Dark theme: follows the system unless the user picked one (html[data-theme]). PDF pages stay white. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --panel: #111827; --line: #1f2a3c; --text: #e2e8f0; --muted: #94a3b8;
    --accent: #3b82f6; --accent-soft: #1e3a5f; --workspace: #030712; --danger: #f87171;
  --text-2: #cbd5e1;
  --text-3: #94a3b8;
  --hover: #1e293b;
  --line-strong: #475569;
  --subtle: #0f172a;
  --accent-strong: #93c5fd;
  --danger-soft: #3b1a1d;
  --success-soft: #14321f;
  --veil: rgba(2,6,23,.8);
  --chip: rgba(30,41,59,.95);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --panel: #111827; --line: #1f2a3c; --text: #e2e8f0; --muted: #94a3b8;
  --accent: #3b82f6; --accent-soft: #1e3a5f; --workspace: #030712; --danger: #f87171;
  --text-2: #cbd5e1;
  --text-3: #94a3b8;
  --hover: #1e293b;
  --line-strong: #475569;
  --subtle: #0f172a;
  --accent-strong: #93c5fd;
  --danger-soft: #3b1a1d;
  --success-soft: #14321f;
  --veil: rgba(2,6,23,.8);
  --chip: rgba(30,41,59,.95);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.busy, body.busy * { cursor: progress !important; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.spacer { flex: 1; }
.muted { color: var(--muted); }

/* ---------- views ---------- */
.editor-view { display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: minmax(0, 1fr); height: 100vh; }
body:not([data-view=editor]) .editor-view { display: none; }
body[data-view=editor] .site { display: none; }
.site { display: flex; flex-direction: column; height: 100vh; }
.site-scroll { flex: 1; overflow-y: auto; }
.small { font-size: 12.5px; }
.error-text { color: var(--danger); }
.docx-render-host { position: fixed; left: -30000px; top: 0; font: initial; color: #000; line-height: normal; text-align: left; background: #fff; }

/* ---------- web vs. Android app ---------- */
.native-only { display: none !important; }
.native-app .native-only { display: inline-flex !important; }
.native-app .web-only { display: none !important; }
.app-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 14px; color: var(--accent); font-weight: 500; text-decoration: none; }
.app-link:hover { text-decoration: underline; }
.app-link svg { width: 17px; height: 17px; }
/* Keep content clear of the status bar and gesture area on phones. */
.native-app .sitebar, .native-app .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
.native-app .site-scroll, .native-app .statusbar { padding-bottom: env(safe-area-inset-bottom); }

/* ---------- site header ---------- */
.sitebar {
  display: flex; align-items: center; gap: 22px; padding: 10px 28px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
a.brand { color: inherit; text-decoration: none; }
.sitebar .brand span { font-size: 17px; letter-spacing: -.01em; }
.sitenav { display: flex; gap: 4px; flex-wrap: wrap; }
.sitenav a { white-space: nowrap; padding: 7px 11px; border-radius: 8px; color: var(--text-2); text-decoration: none; font-weight: 500; }
.sitenav a:hover { background: var(--hover); color: var(--text); }
a.btn { text-decoration: none; }

/* ---------- home ---------- */
#homeView { max-width: 1180px; margin: 0 auto; padding: 0 24px 40px; }
.hero { text-align: center; padding: 56px 0 26px; }
.hero h1 { margin: 0 auto; max-width: 760px; font-size: clamp(30px, 4.6vw, 48px); line-height: 1.12; letter-spacing: -.025em; text-wrap: balance; }
.hero h1 span { color: var(--accent); }
.hero p { margin: 16px auto 0; max-width: 620px; font-size: 17px; color: var(--muted); text-wrap: pretty; }
.hero-search { position: relative; max-width: 460px; margin: 26px auto 0; }
.hero-search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.hero-search input { width: 100%; height: 48px; padding: 0 16px 0 42px; border: 1px solid var(--line); border-radius: 12px; font-size: 15px; background: var(--panel); box-shadow: 0 1px 2px rgba(15,23,42,.05); }
.hero-search input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.cat-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 10px 0 24px; }
.cat-chip { padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); cursor: pointer; font-weight: 500; color: var(--text-2); }
.cat-chip:hover { border-color: var(--line-strong); }
.cat-chip.active { background: var(--text); border-color: var(--text); color: var(--panel); }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tool-card {
  display: flex; flex-direction: column; gap: 6px; padding: 18px; min-height: 150px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; color: inherit; text-decoration: none;
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.tool-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--tool) 40%, var(--line)); box-shadow: 0 10px 24px rgba(15,23,42,.08); }
.tool-card:focus-visible { outline: 2px solid var(--tool); outline-offset: 2px; }
.tool-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 11px; color: var(--tool); background: color-mix(in srgb, var(--tool) 12%, var(--panel)); margin-bottom: 6px; flex: none; }
.tool-icon svg { width: 22px; height: 22px; }
.tool-icon.big { width: 56px; height: 56px; border-radius: 14px; margin: 0; }
.tool-icon.big svg { width: 28px; height: 28px; }
.tool-name { font-weight: 650; font-size: 15.5px; }
.tool-desc { color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.home-empty { text-align: center; padding: 30px; }
.trust { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; margin-top: 44px; padding: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.trust-item { display: flex; gap: 12px; align-items: flex-start; }
.trust-item svg { width: 22px; height: 22px; color: var(--accent); margin-top: 2px; }
.trust-item b { display: block; margin-bottom: 2px; }
.trust-item span { color: var(--muted); font-size: 13.5px; }
.seo-info { max-width: 820px; margin: 34px auto 0; color: var(--text-2); line-height: 1.6; }
.seo-info h2 { font-size: 20px; letter-spacing: -.01em; color: var(--text); margin: 0 0 8px; }
.seo-info h3 { font-size: 15px; color: var(--text); margin: 22px 0 6px; }
.seo-info ol { margin: 0; padding-left: 22px; }
.seo-info dt { font-weight: 600; color: var(--text); margin-top: 10px; }
.seo-info dd { margin: 2px 0 0; }
.home-info { margin-top: 40px; }
.sitefoot { display: flex; justify-content: center; gap: 16px; padding: 20px; color: var(--muted); font-size: 13px; }
.sitefoot a { color: var(--muted); }

/* ---------- tool page ---------- */
#toolView { position: relative; max-width: 1180px; margin: 0 auto; padding: 18px 24px 40px; min-height: calc(100vh - 140px); }
.tv-back { display: inline-block; color: var(--muted); text-decoration: none; font-weight: 500; margin-bottom: 14px; }
.tv-back:hover { color: var(--text); }
.tv-title { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.tv-title h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
.tv-title p { margin: 4px 0 0; color: var(--muted); font-size: 15px; }
.tv-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 300px; padding: 30px;
  border: 2px dashed color-mix(in srgb, var(--tool) 45%, var(--line-strong)); border-radius: 18px; cursor: pointer;
  background: color-mix(in srgb, var(--tool) 5%, var(--panel));
}
.tv-drop:hover { background: color-mix(in srgb, var(--tool) 9%, var(--panel)); }
.tv-drop * { pointer-events: none; }
.tv-drop .btn { pointer-events: auto; background: var(--tool); border-color: var(--tool); }
.tv-drop .btn:hover { filter: brightness(.92); background: var(--tool) !important; }
.tv-drop-icon { width: 44px; height: 44px; color: var(--tool); }
.tv-drop p { margin: 0; }
.tv-private { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: 13px; }
.tv-private svg { width: 15px; height: 15px; }
.tv-work { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.tv-main { min-height: 300px; padding: 18px; background: var(--workspace); border-radius: 14px; }
.tv-side { position: sticky; top: 0; display: flex; flex-direction: column; gap: 10px; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.tv-options { display: flex; flex-direction: column; gap: 8px; }
.tv-options .stack-field { margin-top: 4px; }
.tv-options .text-input { font-size: 14px; }
.tv-options .check { margin-top: 2px; color: var(--text); }
.tv-options #tvRanges { margin: 0 0 0 22px; width: calc(100% - 22px); }
.opt-title { font-weight: 600; font-size: 13px; margin-top: 4px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.tv-run { width: 100%; margin-top: 6px; background: var(--tool); border-color: var(--tool); }
.tv-run:hover:not(:disabled) { filter: brightness(.92); background: var(--tool) !important; }

.file-grid, .page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; align-content: start; }
.file-card, .pg-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 10px 10px; background: var(--panel); border: 2px solid transparent; border-radius: 12px; box-shadow: 0 1px 3px rgba(15,23,42,.08); }
.file-card[draggable=true], .pg-card[draggable=true] { cursor: grab; }
.file-card.dragging, .pg-card.dragging { opacity: .4; }
.drop-before { box-shadow: -4px 0 0 var(--tool), 0 1px 3px rgba(15,23,42,.08); }
.drop-after { box-shadow: 4px 0 0 var(--tool), 0 1px 3px rgba(15,23,42,.08); }
.file-thumb { display: grid; place-items: center; width: 100%; height: 150px; }
.file-thumb img { max-width: 100%; max-height: 150px; box-shadow: 0 1px 4px rgba(15,23,42,.25); background: #fff; }
.file-thumb svg { width: 56px; height: 56px; color: var(--tool); }
.file-name { max-width: 100%; font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-info { color: var(--muted); font-size: 12px; text-align: center; }
.file-order { position: absolute; top: 8px; left: 8px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--tool); color: #fff; font-size: 12px; font-weight: 600; display: grid; place-items: center; }
.file-remove { position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border: 0; border-radius: 50%; background: rgba(15,23,42,.06); cursor: pointer; font-size: 17px; line-height: 1; color: var(--text-3); }
.file-remove:hover { background: var(--danger-soft); color: var(--danger); }
.add-card { justify-content: center; min-height: 200px; border: 2px dashed var(--line-strong); background: transparent; box-shadow: none; cursor: pointer; color: var(--muted); font-weight: 500; }
.add-card:hover { border-color: var(--tool); color: var(--tool); }
.add-plus { font-size: 34px; line-height: 1; }

.pg-thumb { position: relative; width: 100%; max-width: 130px; max-height: 180px; background: #fff; box-shadow: 0 1px 4px rgba(15,23,42,.25); }
.pg-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; }
.pg-num { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pg-badge:empty { display: none; }
.pg-badge { position: absolute; top: 6px; left: 6px; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; color: #fff; background: #64748b; }
.pg-card[data-part="1"] { border-color: #f97316; } .pg-card[data-part="1"] .pg-badge { background: #f97316; }
.pg-card[data-part="2"] { border-color: #2563eb; } .pg-card[data-part="2"] .pg-badge { background: #2563eb; }
.pg-card[data-part="3"] { border-color: #16a34a; } .pg-card[data-part="3"] .pg-badge { background: #16a34a; }
.pg-card[data-part="4"] { border-color: #9333ea; } .pg-card[data-part="4"] .pg-badge { background: #9333ea; }
.pg-card[data-part="5"] { border-color: #db2777; } .pg-card[data-part="5"] .pg-badge { background: #db2777; }
.pg-card[data-part="6"] { border-color: #0891b2; } .pg-card[data-part="6"] .pg-badge { background: #0891b2; }
.mode-remove .pg-card, .mode-pick .pg-card { cursor: pointer; }
.pg-mark { position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--panel); }
.mode-pick .pg-card.selected { border-color: var(--tool); }
.mode-pick .pg-card.selected .pg-mark { background: var(--tool) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center/16px no-repeat; border-color: var(--tool); }
.mode-remove .pg-card.selected { border-color: var(--danger); }
.mode-remove .pg-card.selected .pg-thumb { opacity: .35; }
.mode-remove .pg-card.selected .pg-mark { background: var(--danger) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M7 7l10 10M17 7L7 17'/%3E%3C/svg%3E") center/14px no-repeat; border-color: var(--danger); }
.pg-actions { position: absolute; top: 6px; right: 6px; display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.pg-card:hover .pg-actions, .pg-card:focus-within .pg-actions { opacity: 1; }
.pg-actions button { display: grid; place-items: center; width: 26px; height: 26px; border: 0; border-radius: 6px; background: var(--chip); box-shadow: 0 1px 3px rgba(0,0,0,.2); cursor: pointer; font-size: 16px; color: var(--text-2); }
.pg-actions button:hover { color: var(--tool); }
.pg-actions button[data-act=del]:hover { color: var(--danger); }
.pg-actions svg { width: 15px; height: 15px; }

.single-view { display: grid; place-items: center; }
.file-order { width: auto; }

/* Crop tool */
.crop-view { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.crop-nav { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.crop-nav .icon-btn { font-size: 22px; background: var(--panel); border: 1px solid var(--line); }
.crop-frame { position: relative; overflow: hidden; line-height: 0; box-shadow: 0 2px 10px rgba(15,23,42,.2); touch-action: none; user-select: none; }
.crop-frame canvas { display: block; }
.crop-box { position: absolute; border: 2px solid var(--tool, var(--accent)); box-shadow: 0 0 0 9999px rgba(15,23,42,.5); cursor: move; }
.crop-h { position: absolute; width: 14px; height: 14px; margin: -8px 0 0 -8px; background: #fff; border: 2px solid var(--tool, var(--accent)); border-radius: 3px; }
.crop-nw { left: 0; top: 0; cursor: nwse-resize; } .crop-n { left: 50%; top: 0; cursor: ns-resize; }
.crop-ne { left: 100%; top: 0; cursor: nesw-resize; } .crop-e { left: 100%; top: 50%; cursor: ew-resize; }
.crop-se { left: 100%; top: 100%; cursor: nwse-resize; } .crop-s { left: 50%; top: 100%; cursor: ns-resize; }
.crop-sw { left: 0; top: 100%; cursor: nesw-resize; } .crop-w { left: 0; top: 50%; cursor: ew-resize; }
@media (pointer: coarse) { .crop-h { width: 24px; height: 24px; margin: -13px 0 0 -13px; } }
.single-card { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 20px; }
.single-thumb img { display: block; max-width: 240px; max-height: 320px; background: #fff; box-shadow: 0 4px 16px rgba(15,23,42,.18); }
.single-meta { text-align: center; }
.single-meta .file-name { font-size: 15px; white-space: normal; }

.tv-done { display: grid; place-items: center; padding: 30px 0; }
.tv-done-card { width: min(560px, 100%); display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 34px 28px; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; }
.tv-check { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--success-soft); color: #16a34a; }
.tv-check svg { width: 34px; height: 34px; stroke-width: 2.6; }
.tv-done-card h2 { margin: 6px 0 0; font-size: 24px; letter-spacing: -.01em; }
.tv-done-card p { margin: 0; }
.tv-done-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 10px; }
.tv-done-actions .btn.primary { background: var(--tool); border-color: var(--tool); }
.tv-next-wrap { width: 100%; margin-top: 14px; padding-top: 16px; border-top: 1px solid var(--line); }
.tv-next { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }
.next-chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--text); text-decoration: none; font-weight: 500; font-size: 13.5px; }
.next-chip svg { width: 16px; height: 16px; color: var(--tool); }
.next-chip:hover { border-color: var(--tool); }

.tv-progress { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: var(--veil); font-weight: 500; text-align: center; padding: 20px; }
.spinner { width: 40px; height: 40px; border: 4px solid color-mix(in srgb, var(--tool, #2563eb) 25%, transparent); border-top-color: var(--tool, #2563eb); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.job-overlay { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px; background: rgba(15,23,42,.28); }
.job-card { width: min(380px, 100%); display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 22px 22px 18px; background: var(--panel); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.25); text-align: center; }
.job-text { font-weight: 500; min-height: 20px; }
.job-track { width: 100%; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.job-bar { height: 100%; width: 0; border-radius: 3px; background: var(--accent); transition: width .2s; }
.job-bar.indeterminate { width: 35%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
body.busy .job-overlay, body.busy .job-overlay * { cursor: default !important; }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } .tool-card { transition: none; } }

@media (max-width: 860px) {
  .tv-work { grid-template-columns: minmax(0, 1fr); }
  .tv-side { position: static; }
  .sitebar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .sitenav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  #homeView, #toolView { padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 480px) {
  .file-grid, .page-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .tv-title h1 { font-size: 22px; }
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; }
.brand .logo { width: 22px; height: 22px; color: var(--accent); }
.group { display: flex; align-items: center; gap: 2px; padding-left: 14px; border-left: 1px solid var(--line); }
.brand + .group { border-left: 0; padding-left: 0; }

button, select, input { font: inherit; color: inherit; }
.btn, .icon-btn, .tool, .zoom-label {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px;
  border: 1px solid transparent; border-radius: 8px;
  background: transparent; cursor: pointer; white-space: nowrap;
}
.btn { border-color: var(--line); background: var(--panel); }
.btn:hover:not(:disabled), .icon-btn:hover:not(:disabled), .tool:hover, .zoom-label:hover:not(:disabled) { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn.link { border: 0; background: none; color: var(--accent); }
.btn.link:hover { text-decoration: underline; background: none !important; }
.btn.big { height: 44px; padding: 0 22px; font-size: 15px; }
.icon-btn { width: 34px; padding: 0; font-size: 18px; }
.theme-btn svg { display: none; }
.theme-btn[data-current=system] .ti-system, .theme-btn[data-current=light] .ti-light, .theme-btn[data-current=dark] .ti-dark { display: block; }
.icon-btn.sm { width: 28px; height: 28px; border-radius: 6px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.icon-btn.danger:hover:not(:disabled) { color: var(--danger); background: var(--danger-soft); }
.icon-btn.toggle { font-size: 15px; font-family: Georgia, serif; }
.icon-btn.toggle[aria-pressed=true] { background: var(--accent-soft); color: var(--accent-strong); }
.link-btn { border: 0; background: none; padding: 2px 4px; color: var(--accent); cursor: pointer; font-size: 12px; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; border-radius: 6px; }
code { font: 12px ui-monospace, Consolas, monospace; background: var(--hover); padding: 1px 4px; border-radius: 4px; color: var(--text); }
kbd { display: inline-block; min-width: 20px; padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--subtle); font: 11.5px ui-monospace, Consolas, monospace; text-align: center; color: var(--text); }

/* "More" menu */
.menu-wrap { position: relative; }
.chev { width: 14px; height: 14px; margin-left: -2px; }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 45; min-width: 290px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(15,23,42,.16);
}
.menu button { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; padding: 8px 10px; border: 0; border-radius: 6px; background: none; text-align: left; cursor: pointer; }
.menu button:hover:not(:disabled) { background: var(--hover); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 2px; }
#stampKind { height: 30px; padding: 0 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.stamp-text { width: 130px; height: 30px; margin-left: 4px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; }

/* Find bar */
.searchbar {
  position: absolute; top: 12px; right: 22px; z-index: 30; display: flex; align-items: center; gap: 4px;
  padding: 5px 6px 5px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15,23,42,.14); max-width: calc(100% - 44px);
}
.searchbar > svg { width: 16px; height: 16px; color: var(--muted); }
.searchbar input { width: 190px; min-width: 60px; height: 28px; padding: 0 4px; border: 0; outline: 0; }
.search-count { min-width: 64px; font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tool { padding: 0 9px; color: var(--text-2); }
.tool.active { background: var(--accent-soft); color: var(--accent-strong); }
.zoom-label { min-width: 58px; padding: 0 6px; font-variant-numeric: tabular-nums; }

#fontFamily { height: 30px; padding: 0 6px; margin-right: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.field { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 4px; color: var(--muted); font-size: 12px; }
.field input[type=color] { width: 34px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }
.field input[type=color]:disabled { opacity: .35; cursor: default; }
.field input[type=number] { width: 58px; height: 28px; padding: 0 6px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); }

/* ---------- layout ---------- */
.main { position: relative; display: flex; min-height: 0; }
.sidebar { width: 206px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); }
body:not(.has-doc) .sidebar { display: none; }
.viewer { position: relative; flex: 1; overflow: auto; background: var(--workspace); }
.pages { display: flex; flex-direction: column; align-items: center; gap: 20px; padding: 24px; width: max-content; min-width: 100%; }

.page { position: relative; background: #fff; box-shadow: 0 1px 3px rgba(15,23,42,.12), 0 6px 20px rgba(15,23,42,.08); flex: none; }
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.page svg.overlay { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; touch-action: none; stroke: none; stroke-width: 0; fill: none; }

.viewer.tool-text svg.overlay { cursor: text; }
.viewer.tool-draw svg.overlay, .viewer.tool-highlight svg.overlay,
.viewer.tool-rect svg.overlay, .viewer.tool-whiteout svg.overlay { cursor: crosshair; }
.viewer.tool-image svg.overlay, .viewer.tool-sign svg.overlay { cursor: copy; }
.viewer.tool-select .annot { cursor: move; }
.viewer.tool-text .annot-text { cursor: text; }

.viewer.tool-shape svg.overlay, .viewer.tool-redact svg.overlay { cursor: crosshair; }
#dlSecureSet .check { align-items: flex-start; margin-top: 0; color: var(--text); }
#dlSecureSet .check input { margin-top: 3px; }
#dlSecureSet .check span { color: var(--muted); }
#dlSecureSet .check b { color: var(--text); }
.viewer.tool-note svg.overlay, .viewer.tool-stamp svg.overlay { cursor: copy; }
.viewer.tool-edittext svg.overlay { pointer-events: none; }

.annot text { font-synthesis: style; white-space: pre; }
.annot-text, .annot-stamp { pointer-events: bounding-box; }
.annot rect, .annot image, .annot ellipse { pointer-events: visible; }
.annot path { pointer-events: none; }
.annot path.hit { pointer-events: stroke; stroke: transparent; }
.annot .note-body { cursor: pointer; }
.decor, .decor text { pointer-events: none; }
.sel-box { fill: none; stroke: var(--accent); pointer-events: none; }
.handle { fill: #fff; stroke: var(--accent); pointer-events: all; cursor: nwse-resize; }
.handle.end { cursor: move; }
.search-hit { fill: #fde047; fill-opacity: .45; pointer-events: none; mix-blend-mode: multiply; }
.search-hit.current { fill: #fb923c; fill-opacity: .55; stroke: #ea580c; stroke-width: 1; }

/* Invisible copy of the page's text, used for selecting/copying and "Edit text". */
.text-layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; z-index: 3; line-height: 1; }
.text-layer .tl-line { position: absolute; white-space: pre; color: transparent; transform-origin: 0 0; cursor: text; }
.text-layer br { display: none; }
.text-layer ::selection { background: rgba(37,99,235,.3); color: transparent; }
.viewer.tool-edittext .text-layer { pointer-events: auto; }
.viewer.tool-edittext .tl-line:hover { background: rgba(37,99,235,.08); outline: 1px dashed rgba(37,99,235,.55); }
.viewer:not(.tool-edittext) .text-layer { user-select: none; }

.note-editor {
  position: absolute; z-index: 6; width: 240px; padding: 8px;
  background: #fffbe6; color: #0f172a; border: 1px solid #e5d58a; border-radius: 10px; box-shadow: 0 8px 24px rgba(15,23,42,.18);
}
.note-editor textarea { display: block; width: 100%; resize: vertical; min-height: 70px; padding: 6px; border: 1px solid #eadf9f; border-radius: 6px; background: #fff; font: 13px/1.4 system-ui, sans-serif; }
.note-actions { display: flex; align-items: center; margin-top: 6px; }

.text-editor {
  position: absolute; z-index: 5; margin: 0; padding: 0; border: 0;
  outline: 1.5px dashed var(--accent); outline-offset: 2px;
  background: rgba(255,255,255,.75); resize: none; overflow: hidden;
  white-space: pre; line-height: 1.2; font-synthesis: style;
  unicode-bidi: plaintext; text-align: left;
  transform-origin: 0 0;
}

/* ---------- form fields ---------- */
.form-layer { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.form-field {
  position: absolute; margin: 0; padding: 0 3px; pointer-events: auto;
  border: 1px solid rgba(37,99,235,.35); border-radius: 2px;
  background: rgba(232,240,254,.92); color: #0f172a;
  font-family: Helvetica, Arial, sans-serif; line-height: 1.15;
}
textarea.form-field { resize: none; padding-top: 2px; }
select.form-field { padding: 0 1px; }
input.form-field[type=checkbox], input.form-field[type=radio] { padding: 0; accent-color: var(--accent); cursor: pointer; }
.form-field:hover:not(:disabled) { border-color: var(--accent); }
.form-field:focus { outline: 2px solid var(--accent); outline-offset: 0; background: #fff; }
.form-field:disabled { background: rgba(241,245,249,.9); color: #475569; }
.viewer:not(.tool-select):not(.tool-text) .form-field { pointer-events: none; }

/* ---------- sidebar ---------- */
.side-head { padding: 10px 12px 8px; border-bottom: 1px solid var(--line); }
.side-title { display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 13px; }
.side-actions { display: flex; gap: 2px; margin: 6px -4px 4px; }
.side-sel { font-size: 11.5px; color: var(--muted); min-height: 16px; }
#thumbs { flex: 1; overflow-y: auto; padding: 12px; }
.thumb { position: relative; margin-bottom: 12px; border-radius: 8px; padding: 8px 6px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; border: 2px solid transparent; }
.thumb:hover { background: var(--hover); }
.thumb.current { background: var(--hover); }
.thumb.picked { border-color: var(--accent); background: var(--accent-soft); }
.thumb.dragging { opacity: .4; }
.thumb.drop-before::before, .thumb.drop-after::after {
  content: ""; position: absolute; left: 4px; right: 4px; height: 3px; border-radius: 2px; background: var(--accent);
}
.thumb.drop-before::before { top: -8px; }
.thumb.drop-after::after { bottom: -8px; }
.thumb-page { position: relative; background: #fff; box-shadow: 0 1px 3px rgba(15,23,42,.25); max-width: 100%; }
.thumb.current .thumb-page { box-shadow: 0 0 0 2px #94a3b8; }
.thumb-page img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.thumb-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.thumb .num { margin-top: 4px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.thumb-check {
  position: absolute; top: 2px; left: 2px; z-index: 1; display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: 6px; background: var(--chip); box-shadow: 0 1px 2px rgba(0,0,0,.2);
  opacity: 0; transition: opacity .12s;
}
.thumb-check input { margin: 0; cursor: pointer; accent-color: var(--accent); }
.thumb:hover .thumb-check, .thumb.picked .thumb-check, .thumb-check:focus-within { opacity: 1; }

/* ---------- empty state ---------- */
.empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; }
.dropcard {
  max-width: 480px; text-align: center; padding: 40px 32px;
  background: var(--panel); border: 2px dashed var(--line-strong); border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.dropcard h1 { margin: 0; font-size: 24px; letter-spacing: -.01em; }
.dropcard p { margin: 0 0 8px; color: var(--muted); }
.dropcard .muted { font-size: 13px; margin: 4px 0 0; }

/* ---------- status bar ---------- */
.statusbar {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 6px 16px; font-size: 12px; color: var(--muted);
  background: var(--panel); border-top: 1px solid var(--line);
}
.statusbar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(15,23,42,.45); }
.modal-card { width: min(600px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border-radius: 14px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-card.narrow { width: min(440px, 100%); }
/* Dialogs that preview changes live sit to the side with a light backdrop. */
.modal.side { place-items: center end; background: rgba(15,23,42,.12); }
.modal.side .modal-card { margin-right: 8px; }
.decor-section { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.decor-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.decor-row .text-input { flex: 1; min-width: 150px; }
.decor-row select { height: 32px; padding: 0 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.mini { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--muted); }
.mini input[type=color] { width: 30px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.mini input[type=range] { width: 110px; accent-color: var(--accent); }
.check.strong { margin-top: 0; font-weight: 600; color: var(--text); }
dl.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; font-size: 13px; }
dl.keys dt { white-space: nowrap; }
dl.keys dd { margin: 0; color: var(--muted); }
.modal-card h2 { margin: 0 0 12px; font-size: 17px; }
.modal-card p { margin: 0 0 12px; font-size: 13px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal fieldset { border: 0; padding: 0; margin: 14px 0 0; }
.modal legend { padding: 0; margin-bottom: 6px; font-weight: 600; font-size: 13px; }
.radio { display: flex; align-items: flex-start; gap: 8px; padding: 5px 0; font-size: 13px; cursor: pointer; }
.radio input { margin: 2px 0 0; accent-color: var(--accent); }
.radio b { font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; color: var(--muted); cursor: pointer; }
.check input { margin: 0; accent-color: var(--accent); }
.stack-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.input-suffix { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font-weight: 400; }
.input-suffix:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.input-suffix input { flex: 1; min-width: 0; height: 36px; padding: 0 10px; border: 0; outline: 0; }
.input-suffix span { padding: 0 10px; color: var(--muted); background: var(--subtle); align-self: stretch; display: grid; place-items: center; }
.text-input { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; }
.inline-num { width: 56px; height: 26px; padding: 0 6px; margin: 0 4px; border: 1px solid var(--line); border-radius: 6px; }
#splitRanges { margin: 2px 0 8px 22px; width: calc(100% - 22px); }
#splitPreview.error { color: var(--danger); }

.tabs { display: flex; gap: 4px; margin-bottom: 10px; border-bottom: 1px solid var(--line); }
.tab { border: 0; background: none; padding: 8px 12px; margin-bottom: -1px; border-bottom: 2px solid transparent; cursor: pointer; color: var(--muted); font-weight: 500; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
#sigCanvas { display: block; width: 100%; height: 200px; border: 1px solid var(--line); border-radius: 10px; background: #fff; touch-action: none; cursor: crosshair;
  background-image: linear-gradient(transparent 150px, #cbd5e1 150px, #cbd5e1 151px, transparent 151px); }
.sig-preview {
  display: flex; align-items: center; height: 150px; margin-top: 10px; padding: 0 20px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 10px; font: 56px/1 EdScript, cursive; white-space: nowrap;
}
.saved-sigs { margin-bottom: 14px; }
.saved-sigs .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.saved-row { display: flex; gap: 8px; flex-wrap: wrap; }
.saved-sig { position: relative; }
.saved-sig .use { display: grid; place-items: center; width: 130px; height: 56px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.saved-sig .use:hover { border-color: var(--accent); background: var(--subtle); }
.saved-sig img { max-width: 100%; max-height: 100%; }
.saved-sig .remove { position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); cursor: pointer; line-height: 1; color: var(--muted); }
.saved-sig .remove:hover { color: var(--danger); border-color: var(--danger); }

.dropmask { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(37,99,235,.12); border: 3px dashed var(--accent); pointer-events: none; }
.dropmask div { background: var(--accent); color: #fff; font-weight: 600; font-size: 16px; padding: 12px 22px; border-radius: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 48px; transform: translateX(-50%); z-index: 60;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: #0f172a; color: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

.mobile-only { display: none !important; }
.kebab { display: none; }
.contextbar { display: contents; }
.sidebar-backdrop { display: none; }

/* Touch screens: the editor handles gestures itself (touch.js), and hover-only controls stay visible. */
@media (pointer: coarse) {
  .viewer { touch-action: none; overscroll-behavior: contain; }
  .thumb-check, .thumb-actions { opacity: 1; }
}
@media (hover: none) {
  .pg-actions { opacity: 1; }
}

@media (max-width: 1360px) { .tool span { display: none; } .tool { width: 34px; padding: 0; } }

/* Phones: compact top bar, tools along the bottom, pages in a slide-out drawer. */
@media (max-width: 760px) {
  .mobile-only:not([hidden]) { display: revert !important; }
  button.mobile-only:not([hidden]), .icon-btn.mobile-only:not([hidden]) { display: inline-flex !important; }
  .group.mobile-only:not([hidden]) { display: flex !important; }
  .editor-view { grid-template-rows: auto 1fr; }
  .topbar { flex-wrap: nowrap; gap: 4px; padding: 6px 8px; overflow-x: auto; scrollbar-width: none; }
  .topbar::-webkit-scrollbar { display: none; }
  .topbar .brand span, .file-btn, .btn-label, .desktop-only, .chev, #btnZoomIn, #btnZoomOut, .statusbar { display: none; }
  .kebab { display: block; }
  #btnMore { width: 38px; padding: 0; border-color: transparent; }
  .topbar .group { padding-left: 0; border-left: 0; gap: 0; flex: none; }
  .topbar .spacer { min-width: 4px; }
  #btnDownload { width: 38px; padding: 0; flex: none; }
  .zoom-label { min-width: 48px; }
  .menu { position: fixed; left: 8px; right: 8px; top: 52px; min-width: 0; max-height: calc(100vh - 140px); overflow-y: auto; }

  /* Bottom tool bar */
  .tools {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: flex; gap: 2px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--panel); border-top: 1px solid var(--line);
    overflow-x: auto; scrollbar-width: none;
  }
  .tools::-webkit-scrollbar { display: none; }
  .tool { flex-direction: column; gap: 2px; width: auto; min-width: 58px; height: 52px; padding: 4px 6px; border-radius: 10px; }
  .tool span { display: block; font-size: 10.5px; line-height: 1; white-space: nowrap; }
  .tool svg { width: 20px; height: 20px; }

  /* Context bar: style options for the current tool, just above the tools */
  .contextbar {
    position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 29;
    display: flex; align-items: center; gap: 8px; padding: 6px 10px;
    background: color-mix(in srgb, var(--panel) 94%, transparent); border-top: 1px solid var(--line);
    overflow-x: auto; scrollbar-width: none; backdrop-filter: blur(6px);
  }
  .contextbar.empty { display: none; }
  .contextbar .group { padding-left: 0; border-left: 0; flex: none; }
  #fontFamily { max-width: 130px; }

  .pages { padding: 12px 8px 150px; gap: 12px; }
  .searchbar { top: 8px; right: 8px; left: 8px; max-width: none; flex-wrap: wrap; }
  .searchbar input { flex: 1; width: auto; }
  #searchHighlight, #searchRedact { flex: 1; }

  /* Pages drawer */
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 60; width: min(260px, 80vw);
    transform: translateX(-102%); transition: transform .2s ease; box-shadow: 0 0 30px rgba(15,23,42,.25);
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.open { transform: none; }
  .sidebar-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 59; background: rgba(15,23,42,.35); }
  body:not(.has-doc) .sidebar { display: flex; }
  .toast { bottom: calc(130px + env(safe-area-inset-bottom)); }
  .note-editor { width: min(240px, calc(100vw - 32px)); }
}
@media (max-width: 760px) and (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
