:root {
  --bg: #f6f6f9;
  --surface: #ffffff;
  --surface-2: #f0f0f5;
  --border: #e3e3ec;
  --text: #1c1c28;
  --muted: #6b6b80;
  --accent: #5b5bd6;
  --accent-hover: #4a4ac4;
  --accent-soft: #ececfd;
  --danger: #e5484d;
  --ok: #12a594;
  --warn: #f5a524;
  --shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 4px 16px rgba(20, 20, 40, .06);
  --shadow-lg: 0 10px 40px rgba(20, 20, 40, .14);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111118; --surface: #1a1a24; --surface-2: #23232f; --border: #2e2e3d; --text: #ececf3; --muted: #9a9ab0;
    --accent: #7b7bf0; --accent-hover: #8f8ff5; --accent-soft: #26264a; --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111118; --surface: #1a1a24; --surface-2: #23232f; --border: #2e2e3d; --text: #ececf3; --muted: #9a9ab0;
  --accent: #7b7bf0; --accent-hover: #8f8ff5; --accent-soft: #26264a; --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh;
  display: flex; flex-direction: column; -webkit-font-smoothing: antialiased;
}
main { flex: 1; width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 16px 48px; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .4em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px;
  padding: 10px 24px; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.2rem; color: var(--text); letter-spacing: -.02em; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { color: var(--text); font-weight: 600; font-size: .92rem; padding: 8px 12px; border-radius: 8px; white-space: nowrap; }
.nav a:hover, .nav a.active { background: var(--surface-2); }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--text); width: 38px; height: 38px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; flex-shrink: 0; }
.icon-btn:hover { background: var(--surface-2); }

/* ---------- buttons & inputs ---------- */
.btn {
  font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid transparent; padding: 10px 18px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: background .15s, transform .05s;
  color: var(--text); background: var(--surface-2);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 12px; font-size: .85rem; border-radius: 8px; }
.btn-lg { padding: 14px 22px; font-size: 1.05rem; }
.btn-xl { padding: 18px 40px; font-size: 1.2rem; border-radius: 14px; box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn-block { width: 100%; }
.link-btn { display: block; text-align: center; margin-top: 10px; font-size: .9rem; color: var(--muted); }
.link-btn:hover { color: var(--accent); }
.input {
  font: inherit; width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 1px; }
.input-sm { padding: 6px 10px; font-size: .85rem; width: 190px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; }

/* ---------- home ---------- */
.hero { text-align: center; padding: 56px 0 28px; max-width: 820px; margin: 0 auto; }
.hero h1 { font-size: clamp(1.9rem, 4.5vw, 3rem); font-weight: 800; letter-spacing: -.03em; }
.lead { font-size: 1.15rem; color: var(--muted); margin: 0 auto 14px; max-width: 680px; }
.privacy { display: inline-flex; align-items: center; gap: 8px; font-size: .92rem; color: var(--ok); font-weight: 600; background: color-mix(in srgb, var(--ok) 12%, transparent); padding: 6px 14px; border-radius: 99px; }
.dot { flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 16px 0 28px; }
.chip { font: inherit; font-weight: 600; font-size: .9rem; padding: 8px 16px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.tool-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; color: var(--text);
  box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s, border-color .15s; display: flex; flex-direction: column;
}
.tool-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.tool-card h3 { font-size: 1.12rem; margin: 14px 0 6px; }
.tool-card p { margin: 0; color: var(--muted); font-size: .9rem; }
.tool-icon { display: inline-grid; place-items: center; border-radius: 12px; flex-shrink: 0; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; margin-top: 56px; }
.feature { background: var(--surface); border-radius: var(--radius); padding: 24px; border: 1px solid var(--border); }
.feature p { color: var(--muted); margin: 0; }

/* ---------- upload ---------- */
.tool-hero { text-align: center; padding: 40px 0; max-width: 760px; margin: 0 auto; position: relative; }
.tool-hero h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin-top: 16px; letter-spacing: -.02em; }
.back { position: absolute; left: 0; top: 16px; font-weight: 600; color: var(--muted); font-size: .9rem; }
.back:hover { color: var(--accent); }
.dropzone {
  margin: 28px 0 18px; padding: 48px 20px; border: 2px dashed var(--border); border-radius: 20px; background: var(--surface);
  display: flex; flex-direction: column; align-items: center; gap: 12px; transition: border-color .15s, background .15s;
}
.dropzone.over, .ws-main.over { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- workspace ---------- */
.workspace { display: grid; grid-template-columns: 1fr 340px; gap: 20px; margin-top: 20px; align-items: start; }
.ws-main { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 60vh; padding: 20px; min-width: 0; border-style: solid; }
.ws-side { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; position: sticky; top: 76px; max-height: calc(100vh - 96px); display: flex; flex-direction: column; }
.side-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.side-head h2 { font-size: 1.25rem; margin: 0; }
.hint { color: var(--muted); font-size: .9rem; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; margin: 6px 0 12px; }
.opts { overflow-y: auto; flex: 1; padding-right: 4px; margin-right: -4px; }
.side-foot { padding-top: 14px; border-top: 1px solid var(--border); margin-top: 8px; }
.ws-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 10px; }
.loading, .grid-loading { display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--muted); padding: 80px 0; }
.error-box { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); padding: 14px; border-radius: 10px; }

.field { margin-bottom: 16px; }
.field-label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
.help { color: var(--muted); font-size: .8rem; margin: 6px 0 0; }
.segmented { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button { flex: 1; font: inherit; font-size: .84rem; font-weight: 600; border: 0; background: transparent; color: var(--muted); padding: 7px 4px; border-radius: 8px; cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.opt-cards { display: grid; gap: 8px; }
.opt-card { font: inherit; text-align: left; border: 2px solid var(--border); background: var(--surface); border-radius: 12px; padding: 12px 14px; cursor: pointer; color: var(--text); display: flex; flex-direction: column; gap: 2px; }
.opt-card span { color: var(--muted); font-size: .84rem; }
.opt-card.active { border-color: var(--accent); background: var(--accent-soft); }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: .92rem; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.color-input { width: 56px; height: 36px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: var(--surface); cursor: pointer; }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input { flex: 1; accent-color: var(--accent); }
.range-row output { font-variant-numeric: tabular-nums; font-weight: 600; width: 44px; text-align: right; }
.file-opt { display: flex; align-items: center; gap: 10px; }
.pos-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.pos-grid { display: grid; grid-template-columns: repeat(3, 28px); gap: 4px; padding: 6px; background: var(--surface-2); border-radius: 8px; width: max-content; }
.pos-grid.disabled { opacity: .4; }
.pos-grid button { width: 28px; height: 34px; border: 1px solid var(--border); background: var(--surface); border-radius: 4px; cursor: pointer; }
.pos-grid button.active { background: var(--accent); border-color: var(--accent); }

/* file cards */
.file-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.file-card { position: relative; background: var(--surface-2); border-radius: 12px; padding: 12px; cursor: grab; text-align: center; border: 1px solid var(--border); }
.fc-thumb { height: 180px; display: grid; place-items: center; margin-bottom: 10px; }
.fc-thumb img { max-width: 100%; max-height: 180px; box-shadow: 0 2px 10px rgba(0,0,0,.15); background: #fff; opacity: 0; transition: opacity .2s; }
.fc-thumb img.loaded { opacity: 1; }
.fc-ext { width: 110px; height: 140px; display: grid; place-items: center; background: var(--surface); border-radius: 8px; font-weight: 800; color: var(--muted); font-size: 1.4rem; box-shadow: var(--shadow); }
.fc-name { font-size: .85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-meta { font-size: .78rem; color: var(--muted); }
.fc-remove, .pe-del {
  position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: var(--danger);
  color: #fff; cursor: pointer; font-size: .75rem; display: grid; place-items: center; box-shadow: var(--shadow); z-index: 3;
}
.drag-ghost { opacity: .35; }

/* page grid */
.grid-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 18px; }
.pg-card { position: relative; background: var(--surface-2); border: 2px solid transparent; border-radius: 12px; padding: 10px; cursor: grab; user-select: none; }
.selecting .pg-card { cursor: pointer; }
.pg-card.selected { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--surface-2)); }
.pg-thumb { height: 170px; display: grid; place-items: center; position: relative; overflow: hidden; }
.pg-thumb img { max-width: 100%; max-height: 160px; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.15); transition: transform .25s, opacity .2s; opacity: 0; }
.pg-thumb img.loaded { opacity: 1; }
.pg-blank { width: 110px; height: 150px; background: #fff; display: grid; place-items: center; color: #aaa; font-size: .8rem; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.pg-check { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border); color: transparent; display: grid; place-items: center; font-size: .8rem; font-weight: 800; }
.pg-card.selected .pg-check { background: var(--danger); border-color: var(--danger); color: #fff; }
.pg-label { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 6px; font-size: .82rem; font-weight: 600; color: var(--muted); }
.pg-file { color: #fff; font-size: .7rem; width: 18px; height: 18px; border-radius: 4px; display: grid; place-items: center; }
.pg-tools { position: absolute; top: 6px; left: 0; right: 0; display: flex; justify-content: center; gap: 4px; opacity: 0; transition: opacity .15s; }
.pg-card:hover .pg-tools, .pg-card:focus-within .pg-tools { opacity: 1; }
@media (hover: none) { .pg-tools { opacity: 1; } }
.pg-btn { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-size: 1rem; box-shadow: var(--shadow); }
.pg-btn:hover { background: var(--accent); color: #fff; }
.pg-btn.danger:hover { background: var(--danger); }
.pg-add { border: 2px dashed var(--border); border-radius: 12px; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 200px; }
.pg-add span { font-size: 2rem; }
.pg-add:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- page editor ---------- */
.workspace.wide { grid-template-columns: 1fr 300px; }
.workspace.wide .ws-main { padding: 0; background: var(--surface-2); overflow: hidden; }
.pe-toolbar { position: relative; z-index: 5; display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.pe-tools, .pe-props, .pe-find { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pe-props { gap: 8px; }
.pe-props label { display: flex; align-items: center; gap: 4px; font-size: .8rem; color: var(--muted); }
.pe-color input { width: 32px; height: 30px; border: 1px solid var(--border); border-radius: 6px; padding: 1px; background: var(--surface); cursor: pointer; }
.pe-tool { font: inherit; font-size: .82rem; font-weight: 600; display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--text); cursor: pointer; }
.pe-tool:hover { background: var(--surface-2); }
.pe-tool.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.pe-ico { font-weight: 800; min-width: 16px; text-align: center; }
.pe-pages { display: flex; flex-direction: column; align-items: center; gap: 22px; padding: 22px 16px; max-height: calc(100vh - 150px); overflow: auto; }
.pe-page { position: relative; background: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.18); flex-shrink: 0; }
.pe-page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.pe-layer { position: absolute; inset: 0; }
[data-tool="text"] .pe-layer { cursor: text; }
[data-tool="rect"] .pe-layer, [data-tool="highlight"] .pe-layer, [data-tool="redact"] .pe-layer, [data-tool="whiteout"] .pe-layer, [data-tool="draw"] .pe-layer { cursor: crosshair; }
.pe-pageno { position: absolute; bottom: -20px; right: 0; font-size: .75rem; color: var(--muted); }
.pe-drawing { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.pe-item { position: absolute; cursor: move; touch-action: none; }
.pe-item.selected { outline: 2px dashed var(--accent); outline-offset: 2px; }
.pe-item img { width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; }
.pe-text { outline: none; line-height: 1.2; min-height: 1em; white-space: pre-wrap; word-break: break-word; padding: 2px; cursor: text; }
.pe-text:empty::before { content: 'Type here'; opacity: .4; }
.pe-item .pe-del { display: none; top: -13px; right: -13px; width: 22px; height: 22px; }
.pe-item.selected .pe-del { display: grid; }
.pe-handle { display: none; position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; background: var(--accent); border: 2px solid #fff; border-radius: 3px; cursor: nwse-resize; }
.pe-item.selected .pe-handle { display: block; }
.pe-grip { display: none; position: absolute; left: -22px; top: 0; width: 18px; height: 22px; background: var(--accent); color: #fff; border-radius: 4px; font-size: .7rem; place-items: center; cursor: move; }
.pe-item.selected .pe-grip { display: grid; }
.pe-redact.selected { outline-color: var(--danger); }

/* crop */
.crop-nav { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 14px; font-weight: 600; }
.crop-stage { display: flex; justify-content: center; }
.crop-wrap { position: relative; box-shadow: 0 4px 18px rgba(0,0,0,.18); }
.crop-wrap canvas { display: block; }
.crop-rect { position: absolute; border: 2px solid var(--accent); box-shadow: 0 0 0 9999px rgba(10, 10, 30, .5); cursor: move; touch-action: none; }
.crop-wrap { overflow: hidden; }
.crop-h { position: absolute; width: 16px; height: 16px; background: #fff; border: 2px solid var(--accent); border-radius: 50%; }
.crop-nw { left: -8px; top: -8px; cursor: nwse-resize; } .crop-ne { right: -8px; top: -8px; cursor: nesw-resize; }
.crop-sw { left: -8px; bottom: -8px; cursor: nesw-resize; } .crop-se { right: -8px; bottom: -8px; cursor: nwse-resize; }

/* scan */
.scan-box { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.scan-video { width: 100%; max-width: 640px; border-radius: 12px; background: #000; }
.scan-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.scan-shots { display: flex; gap: 12px; flex-wrap: wrap; }
.scan-shot { position: relative; }
.scan-shot img { height: 120px; border-radius: 8px; box-shadow: var(--shadow); }

/* ---------- signature modal ---------- */
.modal { border: 0; border-radius: 18px; padding: 24px; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.modal::backdrop { background: rgba(10, 10, 25, .55); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab { font: inherit; font-weight: 600; padding: 8px 14px; border: 0; background: none; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.sig-pane { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.sig-fonts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
.sig-font { font-size: 1.9rem; padding: 10px; border: 2px solid var(--border); border-radius: 10px; background: #fff; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sig-font.active { border-color: var(--accent); }
.sig-pad { width: 100%; height: 170px; border: 2px dashed var(--border); border-radius: 10px; background: #fff; touch-action: none; cursor: crosshair; }
.sig-upload-preview { max-height: 120px; max-width: 100%; background: #fff; border-radius: 8px; }
.sig-colors { display: flex; gap: 8px; margin: 14px 0 4px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--border); cursor: pointer; }
.swatch.active { box-shadow: 0 0 0 2px var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- processing & result ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 75%, transparent); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 16px; }
.overlay-card { background: var(--surface); border-radius: 18px; padding: 32px; width: min(420px, 100%); text-align: center; box-shadow: var(--shadow-lg); }
.progress-bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 18px 0 10px; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress-msg { color: var(--muted); font-size: .9rem; margin: 0; min-height: 1.4em; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--surface-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.lg { width: 42px; height: 42px; border-width: 4px; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

.result { text-align: center; max-width: 760px; margin: 0 auto; padding: 48px 0; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.result.wide { max-width: none; text-align: left; align-items: stretch; }
.result h1 { font-size: 2rem; }
.result-check { width: 64px; height: 64px; border-radius: 50%; background: var(--ok); display: grid; place-items: center; }
.note { background: var(--accent-soft); color: var(--text); border-radius: 10px; padding: 10px 16px; margin: 0; font-weight: 500; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.result.wide .result-actions { justify-content: flex-start; }
.out-list { list-style: none; padding: 0; margin: 8px 0; width: 100%; max-height: 300px; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.out-list li { display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-bottom: 1px solid var(--border); text-align: left; }
.out-list li:last-child { border-bottom: 0; }
.out-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.continue { margin-top: 28px; width: 100%; }
.continue h3 { color: var(--muted); font-size: 1rem; }
.continue-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.continue-item { font: inherit; font-weight: 600; font-size: .9rem; display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); cursor: pointer; text-align: left; }
.continue-item:hover { border-color: var(--accent); }
.continue-item .tool-icon { border-radius: 8px; }

/* compare */
.cmp-summary { font-weight: 600; font-size: 1.05rem; }
.compare { display: flex; flex-direction: column; gap: 20px; }
.cmp-page { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.cmp-page h4 { display: flex; align-items: center; gap: 10px; }
.badge { font-size: .72rem; padding: 3px 8px; border-radius: 99px; font-weight: 700; }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.cmp-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.cmp-row figure { margin: 0; min-width: 0; }
.cmp-row figcaption { font-size: .8rem; color: var(--muted); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-canvas { width: 100%; height: auto; box-shadow: 0 2px 8px rgba(0,0,0,.15); background: #fff; }
.cmp-missing { aspect-ratio: 3/4; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); border-radius: 8px; }
.diff-text { white-space: pre-wrap; font-size: .88rem; background: var(--surface-2); padding: 12px; border-radius: 10px; max-height: 360px; overflow: auto; margin-top: 8px; }
.diff-text ins { background: color-mix(in srgb, var(--ok) 30%, transparent); text-decoration: none; }
.diff-text del { background: color-mix(in srgb, var(--danger) 30%, transparent); }
details summary { cursor: pointer; font-weight: 600; margin-top: 12px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; width: calc(100% - 32px); max-width: 480px; }
.toast { background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow-lg); font-weight: 500; font-size: .92rem; transition: opacity .4s, transform .4s; }
.toast-error { background: var(--danger); color: #fff; }
.toast-warn { background: var(--warn); color: #1c1c28; }
.toast-ok { background: var(--ok); color: #fff; }
.toast.out { opacity: 0; transform: translateY(10px); }

/* ---------- off-screen rendering ---------- */
#render-host { position: fixed; left: -20000px; top: 0; pointer-events: none; }
.render-sheet { background: #fff; color: #000; font-family: Calibri, Carlito, Arial, sans-serif; font-size: 14.5px; line-height: 1.4; }
.render-frame { border: 0; background: #fff; }
.doc-sheet img { max-width: 100%; }
.doc-sheet table { border-collapse: collapse; width: 100%; margin: 8px 0; }
.doc-sheet td, .doc-sheet th { border: 1px solid #999; padding: 4px 6px; vertical-align: top; }
.doc-sheet p { margin: 0 0 10px; }
.xls-sheet { font-size: 11px; }
.xls-sheet h3 { font-size: 14px; margin: 16px 0 8px; }
.xls-sheet table { border-collapse: collapse; }
.xls-sheet td { border: 1px solid #c8c8c8; padding: 3px 6px; white-space: nowrap; }
.xls-sheet.nogrid td { border-color: transparent; }
.ppt-slide { position: relative; overflow: hidden; font-family: Calibri, Carlito, Arial, sans-serif; }
.ppt-shape { position: absolute; overflow: hidden; }
.ppt-shape p { margin: 0 0 .25em; line-height: 1.15; }
.ppt-bullet::before { content: '• '; }

/* ---------- footer ---------- */
.footer { text-align: center; padding: 28px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: .92rem; background: var(--surface); }
.footer p { margin: 4px 0; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .workspace, .workspace.wide { grid-template-columns: 1fr; }
  .ws-side { position: static; max-height: none; }
  .nav { display: none; }
  .topbar { justify-content: space-between; padding: 10px 16px; }
  .back { position: static; display: inline-block; margin-bottom: 12px; }
  .cmp-row { grid-template-columns: 1fr; }
  .pe-pages { max-height: 70vh; }
}
@media (max-width: 520px) {
  .tool-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tool-card { padding: 14px; }
  .tool-card p { display: none; }
  .tool-card h3 { font-size: .98rem; margin-top: 10px; }
  .file-list { grid-template-columns: 1fr 1fr; }
  .page-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .pe-tool span:not(.pe-ico) { display: none; }
  .btn-xl { padding: 16px 26px; font-size: 1.05rem; }
}

/* ---------- fonts used for editing (loaded only when used) ---------- */
@font-face { font-family: "Noto Sans"; src: url(../vendor/fonts/NotoSans-Regular.ttf) format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Noto Sans"; src: url(../vendor/fonts/NotoSans-Bold.ttf) format("truetype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Noto Sans Bengali"; src: url(../vendor/fonts/NotoSansBengali-Regular.ttf) format("truetype"); font-weight: 400; font-display: swap; unicode-range: U+0980-09FF, U+200C-200D, U+25CC; }
@font-face { font-family: "Noto Sans Bengali"; src: url(../vendor/fonts/NotoSansBengali-Bold.ttf) format("truetype"); font-weight: 700; font-display: swap; unicode-range: U+0980-09FF, U+200C-200D, U+25CC; }

/* ---------- full PDF editor ---------- */
.ed-root { display: flex; flex-direction: column; height: calc(100vh - 110px); min-height: 520px; }
.ed-toolbar { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding: 8px 10px; background: var(--surface); border-bottom: 1px solid var(--border); }
.ed-group { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; }
.ed-tool { font: inherit; font-size: .82rem; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--text); cursor: pointer; white-space: nowrap; }
.ed-tool:hover:not(:disabled) { background: var(--surface-2); }
.ed-tool:disabled { opacity: .35; cursor: default; }
.ed-tool.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.ed-ico { font-weight: 800; min-width: 16px; text-align: center; }
.ed-icon-only { padding: 7px 9px; }
.ed-zoom-label { font-size: .8rem; font-weight: 600; min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }
.ed-menu-wrap { position: relative; }
.ed-menu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; min-width: 210px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; display: flex; flex-direction: column; }
.ed-menu > button { font: inherit; font-size: .88rem; text-align: left; padding: 8px 10px; border: 0; background: none; color: var(--text); border-radius: 8px; cursor: pointer; }
.ed-menu > button:hover { background: var(--surface-2); }
.ed-menu-title { font-size: .75rem; color: var(--muted); padding: 4px 10px; font-weight: 600; }
.ed-sig-row { display: flex; align-items: center; gap: 4px; }
.ed-sig { flex: 1; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 4px; cursor: pointer; height: 48px; }
.ed-sig img { max-height: 38px; max-width: 170px; }
.ed-sig-del { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 6px; }
.ed-sig-del:hover { color: var(--danger); }
.ed-context { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 12px; min-height: 44px; background: var(--surface); border-bottom: 1px solid var(--border); font-size: .85rem; }
.ed-select { font-size: .82rem; padding: 5px 6px; }
.ed-toggle { width: 30px; height: 30px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; cursor: pointer; font: inherit; }
.ed-toggle.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.ed-prop { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .8rem; }
.ed-prop input[type=color], .ed-context > input[type=color] { width: 32px; height: 28px; border: 1px solid var(--border); border-radius: 6px; padding: 1px; background: var(--surface); cursor: pointer; }
.ed-hint { color: var(--muted); font-size: .8rem; }
.ed-wide { width: 280px; max-width: 100%; }
.ed-del { margin-left: auto; }
.ed-context .swatch { width: 22px; height: 22px; }
.ed-find { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; background: var(--accent-soft); border-bottom: 1px solid var(--border); }
.ed-pages { flex: 1; overflow: auto; display: flex; flex-direction: column; align-items: center; padding: 22px 16px 40px; background: var(--surface-2); }
.ed-page { position: relative; background: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.18); flex-shrink: 0; }
.ed-canvas, .ed-covers, .ed-layer, .ed-fields, .ed-runs, .ed-items { position: absolute; inset: 0; width: 100%; height: 100%; }
.ed-covers, .ed-fields, .ed-runs, .ed-items { pointer-events: none; }
.ed-cover { position: absolute; }
.ed-pagebar { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 10px 0 22px; font-size: .78rem; color: var(--muted); flex-shrink: 0; }
.ed-pagebar .btn-sm { font-size: .75rem; padding: 4px 10px; }
[data-tool="text"] .ed-layer { cursor: text; }
[data-tool="link"] .ed-layer, [data-tool="whiteout"] .ed-layer, [data-tool="rect"] .ed-layer, [data-tool="ellipse"] .ed-layer,
[data-tool="line"] .ed-layer, [data-tool="arrow"] .ed-layer, [data-tool="draw"] .ed-layer, [data-tool^="field-"] .ed-layer { cursor: crosshair; }
[data-tool="highlight"] .ed-layer, [data-tool="underline"] .ed-layer, [data-tool="strike"] .ed-layer { cursor: text; }
.ed-run { position: absolute; border-radius: 2px; }
[data-tool="text"] .ed-run { pointer-events: auto; cursor: text; }
[data-tool="text"] .ed-run:hover { outline: 1.5px dashed var(--accent); background: rgba(91, 91, 214, .08); }
.ed-run.covered { display: none; }
.ed-field-input { position: absolute; pointer-events: auto; border: 1px solid rgba(91, 91, 214, .55); background: rgba(221, 228, 255, .55); color: #000; font-family: Helvetica, Arial, sans-serif; padding: 0 3px; margin: 0; border-radius: 2px; resize: none; }
.ed-field-input:focus { outline: 2px solid var(--accent); background: #fff; }
input.ed-field-input[type=checkbox], input.ed-field-input[type=radio] { accent-color: var(--accent); padding: 0; }
.ed-item { position: absolute; pointer-events: auto; cursor: move; touch-action: none; }
.ed-item.selected { outline: 1.5px dashed var(--accent); outline-offset: 2px; z-index: 2; }
.ed-body { width: 100%; height: 100%; box-sizing: border-box; }
.ed-image .ed-body { display: block; pointer-events: none; user-select: none; }
.ed-textbox { outline: none; line-height: 1.2; min-width: 12px; min-height: 1em; word-break: break-word; cursor: text; }
.ed-textbox:empty::before { content: 'Type here'; opacity: .4; }
.ed-text.selected .ed-textbox:focus { background: rgba(255, 255, 255, .6); }
.ed-symbol .ed-body { display: grid; place-items: center; font-family: system-ui, sans-serif; }
.ed-shape svg, .ed-draw svg { overflow: visible; display: block; }
.ed-mark { position: absolute; }
.ed-mark-highlight { background: var(--mark); opacity: .4; mix-blend-mode: multiply; }
.ed-mark-underline::after, .ed-mark-strike::after { content: ''; position: absolute; left: 0; right: 0; height: max(1px, 7%); background: var(--mark); }
.ed-mark-underline::after { bottom: 5%; }
.ed-mark-strike::after { top: 50%; }
.ed-link .ed-body { border: 1.5px dashed #0090ff; background: rgba(0, 144, 255, .08); color: #0070cc; font-size: 11px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 1px 4px; }
.ed-field .ed-body { border: 1px solid #8a8aa0; background: rgba(221, 228, 255, .7); color: #556; font-size: 10px; padding: 1px 4px; overflow: hidden; white-space: nowrap; display: flex; align-items: center; justify-content: space-between; }
.ed-field .ed-field-radio { border-radius: 50%; }
.ed-x { display: none; position: absolute; top: -12px; right: -12px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--danger); color: #fff; font-size: .7rem; cursor: pointer; place-items: center; box-shadow: var(--shadow); z-index: 3; }
.ed-item.selected .ed-x { display: grid; }
.ed-resize, .ed-end { display: none; position: absolute; width: 12px; height: 12px; background: var(--accent); border: 2px solid #fff; border-radius: 3px; z-index: 3; }
.ed-resize { right: -7px; bottom: -7px; cursor: nwse-resize; }
.ed-item.selected .ed-resize, .ed-item.selected .ed-end { display: block; }
.ed-end { border-radius: 50%; cursor: grab; }
.ed-grip { display: none; position: absolute; left: -20px; top: 0; width: 16px; height: 20px; background: var(--accent); color: #fff; border-radius: 4px; font-size: .65rem; place-items: center; cursor: move; }
.ed-text.selected .ed-grip { display: grid; }
.ed-preview { position: absolute; border: 1.5px dashed var(--accent); background: rgba(91, 91, 214, .08); }
.ed-preview-whiteout { background: #fff; border-color: #999; }
.ed-preview-highlight { background: rgba(255, 212, 0, .35); border: 0; }

/* resume card + session note */
.resume-card { display: flex; align-items: center; gap: 14px; text-align: left; background: var(--surface); border: 2px solid var(--accent); border-radius: 16px; padding: 14px 18px; margin: 24px 0 0; box-shadow: var(--shadow); flex-wrap: wrap; }
.resume-icon { width: 42px; height: 42px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 1.4rem; font-weight: 800; flex-shrink: 0; }
.resume-text { flex: 1; display: flex; flex-direction: column; min-width: 180px; }
.session-note { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--ok); font-size: .8rem; font-weight: 600; margin: 10px 0 0; }
.sig-saved { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.sig-saved p { margin: 0; width: 100%; }
.sig-saved-item { background: #fff; border: 2px solid var(--border); border-radius: 10px; padding: 4px 8px; cursor: pointer; height: 56px; }
.sig-saved-item:hover { border-color: var(--accent); }
.sig-saved-item img { max-height: 44px; max-width: 180px; }
.sig-remember { margin-top: 10px; }

@media (max-width: 900px) {
  .ed-root { height: 80vh; }
  .ed-lbl { display: none; }
  .ed-tool { padding: 8px; }
}
