:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --border: #e1e3ea;
  --text: #1b1c24;
  --muted: #666a7a;
  --accent: #e5484d;
  --accent-hover: #cf3a40;
  --accent-soft: #fde9ea;
  --ok: #1f9d55;
  --shadow: 0 1px 2px rgb(20 20 40 / 6%), 0 4px 16px rgb(20 20 40 / 6%);
  --shadow-lg: 0 10px 40px rgb(20 20 40 / 14%);
  --radius: 14px;
  --c-organize: #e5484d; --c-optimize: #1f9d55; --c-to: #d97706; --c-from: #2563eb;
  --c-edit: #7c3aed; --c-security: #0f766e; --c-ai: #db2777;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121318; --surface: #1b1c24; --surface-2: #23252f; --border: #2e303c;
  --text: #ecedf3; --muted: #9a9eb0; --accent-soft: #3a1d20;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%); --shadow-lg: 0 10px 40px rgb(0 0 0 / 50%);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121318; --surface: #1b1c24; --surface-2: #23252f; --border: #2e303c;
    --text: #ecedf3; --muted: #9a9eb0; --accent-soft: #3a1d20;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%); --shadow-lg: 0 10px 40px rgb(0 0 0 / 50%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
  min-height: 100vh; display: flex; flex-direction: column;
}
main { flex: 1; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.lucide { width: 1.15em; height: 1.15em; stroke-width: 2; vertical-align: -0.2em; flex-shrink: 0; }
[hidden] { display: none !important; }

/* ---------- topo ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 21px; font-weight: 700; text-decoration: none; letter-spacing: -0.02em; }
.brand b { color: var(--accent); }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; }
.topnav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.topnav a { padding: 8px 12px; border-radius: 8px; text-decoration: none; font-weight: 600; font-size: 14px; color: var(--muted); white-space: nowrap; }
.topnav a:hover { background: var(--surface-2); color: var(--text); }
.icon-btn { border: 0; background: transparent; width: 38px; height: 38px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); }

/* ---------- home ---------- */
.hero { text-align: center; padding: 56px 16px 24px; }
.hero h1 { font-size: clamp(28px, 4vw, 42px); margin: 0 0 10px; letter-spacing: -0.03em; font-weight: 800; }
.hero p { color: var(--muted); font-size: 18px; margin: 0 auto; max-width: 680px; }
.filters { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding: 18px 16px 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); padding: 8px 16px; border-radius: 999px;
  cursor: pointer; font-weight: 600; font-size: 14px;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.search { display: block; margin: 8px auto 0; width: min(420px, calc(100% - 32px)); padding: 11px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px;
  max-width: 1240px; margin: 24px auto 64px; padding: 0 16px;
}
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px;
  text-decoration: none; display: flex; flex-direction: column; gap: 10px; transition: transform .15s, box-shadow .15s;
  position: relative;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.card h3 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
.card p { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.card .badge { position: absolute; top: 14px; right: 14px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.tool-icon { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; color: #fff; font-size: 22px; }

/* ---------- página de ferramenta ---------- */
.tool-head { text-align: center; padding: 40px 16px 8px; }
.tool-head h1 { font-size: clamp(26px, 3.5vw, 38px); margin: 0 0 8px; letter-spacing: -0.03em; }
.tool-head p { color: var(--muted); margin: 0 auto; max-width: 640px; font-size: 17px; }
.dropzone {
  max-width: 720px; margin: 28px auto 60px; padding: 48px 20px; text-align: center;
  border: 2px dashed var(--border); border-radius: 20px; background: var(--surface); transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .hint { color: var(--muted); margin-top: 12px; font-size: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; cursor: pointer;
  padding: 12px 22px; border-radius: 12px; font-weight: 700; background: var(--surface-2); text-decoration: none;
}
.btn:hover { filter: brightness(0.96); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); filter: none; }
.btn-xl { padding: 18px 42px; font-size: 20px; border-radius: 14px; box-shadow: 0 6px 20px rgb(229 72 77 / 30%); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }

.workspace { display: grid; grid-template-columns: 1fr 340px; min-height: calc(100vh - 60px); }
.work-main { padding: 24px; overflow: auto; min-width: 0; }
.sidebar { background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 60px; height: calc(100vh - 60px); }
.sidebar-head { padding: 20px 22px 12px; border-bottom: 1px solid var(--border); }
.sidebar-head h2 { margin: 0; font-size: 20px; letter-spacing: -0.02em; }
.sidebar-body { padding: 18px 22px; overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.sidebar-foot { padding: 16px 22px 22px; border-top: 1px solid var(--border); }
@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-left: 0; border-top: 1px solid var(--border); }
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-label { font-weight: 600; font-size: 13.5px; }
.field .help { color: var(--muted); font-size: 12.5px; }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg);
}
textarea.input { resize: vertical; min-height: 90px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-size: 14px; }
.check input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; }
.seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.seg label { border: 1.5px solid var(--border); border-radius: 11px; padding: 10px; cursor: pointer; text-align: center; font-size: 13px; font-weight: 600; background: var(--bg); }
.seg label small { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.seg input { display: none; }
.seg label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.pos-grid { display: grid; grid-template-columns: repeat(3, 38px); gap: 6px; }
.pos-grid label { width: 38px; height: 38px; border: 1.5px solid var(--border); border-radius: 8px; cursor: pointer; display: grid; place-items: center; background: var(--bg); }
.pos-grid label::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.pos-grid input { display: none; }
.pos-grid label:has(input:checked) { border-color: var(--accent); }
.pos-grid label:has(input:checked)::after { background: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
input[type=color].input { padding: 3px; height: 40px; }
input[type=range] { accent-color: var(--accent); width: 100%; }
.note { font-size: 13px; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; color: var(--muted); }
.note.warn { background: #fff4e0; color: #8a5300; }
:root[data-theme="dark"] .note.warn { background: #3a2a0c; color: #f4c46b; }

/* lista de arquivos */
.files { display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; align-items: flex-start; }
.file-card {
  width: 170px; background: var(--surface); border-radius: 12px; border: 1px solid var(--border); padding: 10px;
  position: relative; box-shadow: var(--shadow); cursor: grab; user-select: none;
}
.file-card.dragging { opacity: .4; }
.file-card.drop-before { box-shadow: -4px 0 0 var(--accent); }
.file-card .thumb { height: 190px; display: grid; place-items: center; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.file-card .thumb img, .file-card .thumb canvas { max-width: 100%; max-height: 100%; box-shadow: 0 1px 4px rgb(0 0 0 / 20%); background: #fff; transition: transform .2s; }
.file-card .name { font-size: 12.5px; margin-top: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.file-card .meta { font-size: 11.5px; color: var(--muted); }
.file-card .actions { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; z-index: 3; }
.file-card:hover .actions, .file-card:focus-within .actions { opacity: 1; }
@media (hover: none) { .file-card .actions { opacity: 1; } }
.mini { width: 30px; height: 30px; border-radius: 8px; border: 0; background: var(--surface); box-shadow: var(--shadow); cursor: pointer; display: grid; place-items: center; }
.mini:hover { background: var(--accent); color: #fff; }
.add-card { width: 170px; min-height: 240px; border: 2px dashed var(--border); border-radius: 12px; display: grid; place-items: center; cursor: pointer; background: transparent; color: var(--muted); font-weight: 600; }
.add-card:hover { border-color: var(--accent); color: var(--accent); }
.page-num { position: absolute; bottom: 38px; left: 50%; transform: translateX(-50%); background: rgb(0 0 0 / 60%); color: #fff; font-size: 11px; border-radius: 6px; padding: 1px 7px; }
.file-card.blank .thumb::after { content: "Página em branco"; color: var(--muted); font-size: 12px; }
.toolbar-line { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 18px; }

/* processamento e resultado */
.overlay { position: fixed; inset: 0; background: rgb(10 10 20 / 55%); display: grid; place-items: center; z-index: 100; }
.overlay .box { background: var(--surface); padding: 32px 40px; border-radius: 18px; text-align: center; min-width: 300px; box-shadow: var(--shadow-lg); }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid var(--surface-2); border-top-color: var(--accent); animation: spin 0.9s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 14px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.result { max-width: 760px; margin: 40px auto 80px; text-align: center; padding: 0 16px; }
.result h1 { font-size: 34px; letter-spacing: -0.03em; margin: 0 0 8px; }
.result .stat { font-size: 16px; color: var(--muted); margin-bottom: 24px; }
.result .stat b { color: var(--ok); font-size: 22px; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }
.continue { margin-top: 44px; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.continue h3 { margin: 0 0 12px; font-size: 15px; }
.continue-list { display: flex; flex-wrap: wrap; gap: 8px; }
.continue-list a { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); text-decoration: none; font-size: 13.5px; font-weight: 600; }
.continue-list a:hover { background: var(--accent-soft); color: var(--accent); }
.preview-frame { width: 100%; height: 75vh; border: 1px solid var(--border); border-radius: 12px; background: #fff; margin-top: 18px; }
.summary-box { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 26px; margin-top: 12px; }
.summary-box h3 { margin: 18px 0 8px; font-size: 16px; }
.summary-box h3:first-child { margin-top: 0; }
.summary-box li { margin: 6px 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags span { background: var(--surface-2); border-radius: 99px; padding: 3px 10px; font-size: 12.5px; }
.stats-grid { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-bottom: 8px; }
.stats-grid div { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 16px; min-width: 120px; }
.stats-grid b { display: block; font-size: 22px; }
.stats-grid span { color: var(--muted); font-size: 12.5px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #2b2d38; color: #fff; padding: 12px 20px; border-radius: 12px; z-index: 200; box-shadow: var(--shadow-lg); max-width: calc(100% - 32px); }
.toast.error { background: #b4232a; }

.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 16px; border-top: 1px solid var(--border); background: var(--surface); }

/* ---------- editor de páginas ---------- */
.editor-wrap { display: flex; flex-direction: column; align-items: center; gap: 22px; padding-bottom: 60px; }
.editor-toolbar {
  position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); justify-content: center;
}
.editor-toolbar button {
  border: 0; background: transparent; padding: 8px 11px; border-radius: 9px; cursor: pointer; display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600;
}
.editor-toolbar button:hover { background: var(--surface-2); }
.editor-toolbar button.active { background: var(--accent-soft); color: var(--accent); }
.editor-toolbar .sep { width: 1px; background: var(--border); margin: 4px 2px; }
.page-box { position: relative; box-shadow: 0 2px 12px rgb(0 0 0 / 18%); background: #fff; }
.page-box canvas { display: block; }
.page-label { text-align: center; font-size: 12px; color: var(--muted); margin-top: 6px; }
.overlay-layer { position: absolute; inset: 0; touch-action: none; }
.overlay-layer.tool-create { cursor: crosshair; }
.obj { position: absolute; box-sizing: border-box; }
.obj.selected { outline: 2px solid #3b82f6; outline-offset: 1px; }
.obj .handle { position: absolute; right: -7px; bottom: -7px; width: 13px; height: 13px; background: #3b82f6; border: 2px solid #fff; border-radius: 3px; cursor: nwse-resize; display: none; }
.obj.selected .handle { display: block; }
.obj .del { position: absolute; top: -13px; right: -13px; width: 22px; height: 22px; border-radius: 50%; background: #ef4444; color: #fff; border: 2px solid #fff; display: none; place-items: center; cursor: pointer; font-size: 12px; line-height: 1; padding: 0; }
.obj.selected .del { display: grid; }
.obj-text { white-space: pre-wrap; line-height: 1.18; cursor: move; min-width: 20px; outline: 1px dashed transparent; overflow: visible; font-family: Helvetica, Arial, sans-serif; }
.obj-text:hover { outline-color: #93c5fd; }
.obj-text[contenteditable="true"] { cursor: text; outline: 1px dashed #3b82f6; }
.obj-img, .obj-shape { cursor: move; }
.obj-img img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.obj-redact { background: rgb(0 0 0 / 80%); cursor: move; }
.obj-field { border: 1.5px solid #6366f1; background: rgb(99 102 241 / 12%); cursor: move; font-size: 10px; color: #4f46e5; padding: 1px 4px; overflow: hidden; white-space: nowrap; }
.obj-crop { outline: 2px dashed var(--accent); box-shadow: 0 0 0 9999px rgb(0 0 0 / 45%); cursor: move; }
.svg-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.svg-layer .hit { pointer-events: stroke; cursor: move; }
.svg-layer .sel { filter: drop-shadow(0 0 2px #3b82f6); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgb(10 10 20 / 55%); z-index: 120; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 18px; width: min(620px, 100%); box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--border); }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.sig-pad { width: 100%; height: 200px; border: 1px dashed var(--border); border-radius: 12px; background: #fff; touch-action: none; cursor: crosshair; display: block; }
.sig-fonts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.sig-fonts label { border: 1.5px solid var(--border); border-radius: 10px; padding: 10px; cursor: pointer; font-size: 26px; text-align: center; background: #fff; color: #1b1c24; overflow: hidden; white-space: nowrap; }
.sig-fonts input { display: none; }
.sig-fonts label:has(input:checked) { border-color: var(--accent); }
.sig-list { display: flex; flex-direction: column; gap: 8px; }
.sig-item { border: 1px solid var(--border); border-radius: 10px; padding: 8px; background: #fff; cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
.sig-item img { max-height: 46px; max-width: 200px; }
.sig-item:hover { border-color: var(--accent); }

.qr-box { display: flex; gap: 28px; align-items: center; justify-content: center; flex-wrap: wrap; max-width: 900px; margin: 24px auto; background: var(--surface); padding: 28px; border-radius: 20px; border: 1px solid var(--border); }
.qr-box img { width: 220px; height: 220px; background: #fff; border-radius: 12px; }
.qr-box ol { padding-left: 18px; color: var(--muted); }
.scan-thumbs { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 12px auto; max-width: 1000px; }

.fill-form { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; background: var(--surface); padding: 22px; border-radius: var(--radius); border: 1px solid var(--border); }
.mode-crop .page-box { overflow: hidden; }
