:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #eceef3;
  --surface-3: #e2e5ec;
  --text: #171a21;
  --muted: #5d6474;
  --border: #d8dce5;
  --accent: #ff8c28;
  --accent-2: #ff6a1a;
  --accent-ink: #c2410c; /* the accent as text or a thin line on a light surface (5:1 on white) */
  --accent-soft: rgba(255, 140, 40, .14);
  --accent-text: #1b1f27;
  --danger: #d33a3a;
  --ok: #1f9d55;
  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 1px 2px rgba(16, 20, 30, .06), 0 1px 1px rgba(16, 20, 30, .04);
  --shadow-2: 0 10px 30px rgba(16, 20, 30, .14);
  --ring: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent-ink);
  --topbar: 54px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121418;
    --surface: #1b1e26;
    --surface-2: #242834;
    --surface-3: #2d3240;
    --text: #e9ebf1;
    --muted: #9ba3b3;
    --border: #323846;
    --accent-ink: #ff6a1a;
    --accent-text: #171a21;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 14px 40px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  --bg: #121418;
  --surface: #1b1e26;
  --surface-2: #242834;
  --surface-3: #2d3240;
  --text: #e9ebf1;
  --muted: #9ba3b3;
  --border: #323846;
  --accent-ink: #ff6a1a;
  --accent-text: #171a21;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 14px 40px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
html { scroll-behavior: smooth; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); }
kbd { font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 3px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.ic { flex: none; vertical-align: -3px; }

/* ---------- controls ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 8px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
button:hover:not(:disabled) { background: var(--surface-3); border-color: var(--muted); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: var(--accent-text); border-color: transparent; font-weight: 600; box-shadow: 0 1px 2px rgba(255, 106, 26, .35); }
button.primary:hover:not(:disabled) { background: linear-gradient(180deg, #ff9a42, #ff7426); border-color: transparent; }
button.link { background: none; border: none; padding: 0; color: var(--accent-ink); text-decoration: underline; display: inline; }
button.icon { padding: 6px; line-height: 1; border-radius: var(--radius-s); }
button.icon.mini { padding: 1px 6px; }
button.ghost { background: transparent; }
button.small { padding: 4px 10px; font-size: 13px; }
:is(button, input, select, textarea, a, [tabindex]):focus-visible { outline: none; box-shadow: var(--ring); border-color: var(--accent); }
input[type="number"], input[type="text"], input[type="search"], input[type="url"], input[type="password"], select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 7px 10px;
  min-width: 0;
}
input[type="number"] { width: 110px; }
input[type="text"], input[type="url"] { width: 220px; max-width: 100%; }
textarea { width: 100%; resize: vertical; }
input[type="range"] { width: 220px; max-width: 100%; accent-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; }
input[type="color"] { width: 48px; height: 38px; padding: 2px; border: 1px solid var(--border); border-radius: var(--radius-s); background: var(--surface); }
select { padding-right: 28px; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar); padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: inherit; text-decoration: none; letter-spacing: -.01em; }
.brand img { border-radius: 6px; }
.topbar-spacer { flex: 1; }
.search-btn { gap: 10px; padding: 6px 10px 6px 12px; color: var(--muted); background: var(--surface-2); border-color: transparent; min-width: 220px; justify-content: space-between; font-size: 14px; }
.search-btn:hover:not(:disabled) { border-color: var(--border); }
.view, .theme, .settings-btn { color: var(--muted); background: transparent; border-color: transparent; }
.view:hover, .theme:hover, .settings-btn:hover { color: var(--text); }
.nav-select { display: none; }

/* ---------- layout + sidebar ---------- */
.layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: calc(100% - var(--topbar)); }
.sidebar { padding: 12px 10px 24px; border-right: 1px solid var(--border); background: var(--surface); position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); overflow: auto; }
.nav-filter { width: 100%; margin: 6px 0 8px; font-size: 13px; padding: 6px 10px; }
.nav-group { display: flex; align-items: center; gap: 6px; width: calc(100% - 4px); margin: 12px 2px 4px; padding: 4px 8px; background: none; border: none; border-radius: var(--radius-s); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); cursor: pointer; }
.nav-group:hover:not(:disabled) { background: var(--surface-2); border: none; color: var(--text); }
.nav-group-title { flex: 1; text-align: left; }
.nav-count { font-weight: 500; letter-spacing: 0; opacity: .7; }
.nav-group .ic { transition: transform .15s; }
.nav-group[aria-expanded="false"] .ic { transform: rotate(-90deg); }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 6px 10px; border-radius: var(--radius-s); color: inherit; text-decoration: none; font-size: 14px; }
.nav-item .ic { color: var(--muted); }
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.nav-item.active .ic { color: var(--accent-2); }
.nav-empty { padding: 10px; color: var(--muted); font-size: 13px; }

.main { padding: 24px 28px 48px; max-width: 1040px; width: 100%; min-width: 0; display: flex; flex-direction: column; gap: 16px; }

/* ---------- home ---------- */
.hero { padding: 12px 0 4px; }
.hero h1 { margin: 0 0 6px; font-size: 32px; letter-spacing: -.02em; line-height: 1.15; }
.hero p { margin: 0 0 16px; color: var(--muted); max-width: 640px; font-size: 16px; }
.home-search { width: 100%; max-width: 560px; justify-content: flex-start; gap: 10px; padding: 11px 14px; background: var(--surface); border-color: var(--border); color: var(--muted); font-size: 15px; box-shadow: var(--shadow); }
.home-search kbd { margin-left: auto; }
.home-group h2 { display: flex; align-items: center; gap: 8px; margin: 14px 0 10px; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.home-group h2 .count { font-weight: 500; font-size: 12px; background: var(--surface-2); border-radius: 999px; padding: 1px 8px; }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.tool-card { display: flex; gap: 12px; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: inherit; text-decoration: none; box-shadow: var(--shadow); transition: transform .12s, border-color .12s, box-shadow .12s; }
.tool-card:hover { transform: translateY(-1px); border-color: var(--accent); box-shadow: var(--shadow-2); }
.tool-card-icon { flex: none; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent-2); }
.tool-card-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.tool-card-text strong { font-size: 14px; line-height: 1.3; }
/* Keeps the end of the title's first line clear of the corner star. */
.tool-card-text strong::before { content: ""; float: right; width: 14px; height: 1.3em; }
.tool-card-text span { font-size: 12.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: inherit; text-decoration: none; font-size: 13px; }
.chip:hover { border-color: var(--accent); }
.home-foot { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.home-foot span { display: inline-flex; align-items: center; gap: 4px; }
.home-foot .made-by { margin-left: auto; color: inherit; }
.app-tip { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.app-tip a { white-space: nowrap; }

/* ---------- tool page ---------- */
.tool-head { display: flex; gap: 14px; align-items: flex-start; }
.tool-head-icon { flex: none; width: 46px; height: 46px; display: flex; align-items: center; justify-content: center; border-radius: 12px; background: var(--accent-soft); color: var(--accent-2); }
.tool-head h1 { margin: 0 0 2px; font-size: 24px; letter-spacing: -.01em; }
.tool-head p { margin: 0; color: var(--muted); }
.tool-head-text { flex: 1; min-width: 0; }
.fav-btn { flex: none; color: var(--muted); }
.fav-btn[aria-pressed="true"] { color: #f5a623; }
.fav-btn[aria-pressed="true"] .ic { fill: #f5a623; }
.tool-card { position: relative; }
/* The star floats in the corner instead of taking a column of its own away from the text. */
.tool-card .fav-btn { position: absolute; top: 3px; right: 3px; width: 28px; height: 28px; padding: 0; background: none; border: none; border-radius: 8px; opacity: 0; }
.tool-card .fav-btn .ic { width: 16px; height: 16px; }
.tool-card .fav-btn:hover:not(:disabled) { background: none; }
.tool-card .fav-btn[aria-pressed="false"]:hover { color: var(--text); }
.tool-card:hover .fav-btn, .tool-card .fav-btn:focus-visible, .tool-card .fav-btn[aria-pressed="true"] { opacity: 1; }
/* No hover on a touch screen: the star is always there, dimmed until it is on, and finger-sized. */
@media (hover: none) {
  .tool-card .fav-btn { opacity: .55; top: 0; right: 0; width: 36px; height: 36px; }
  .tool-card-text strong::before { width: 16px; }
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  background: var(--surface);
  outline: none;
  transition: border-color .15s, background .15s;
}
.dropzone .dz-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.dropzone .ic { color: var(--muted); }
.dropzone.over, .dropzone:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.dz-hint { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
/* Once files are in, the drop target shrinks to a slim "add more" bar. */
.dropzone.compact { padding: 10px 14px; }
.dropzone.compact .dz-inner { flex-direction: row; justify-content: center; flex-wrap: wrap; gap: 10px; }
.dropzone.compact .dz-hint { display: none; }
.dropzone.compact .ic { width: 18px; height: 18px; }
/* The group links are navigation, not one more row of tool chips: plain text tabs on a rule that stays under the top bar. */
.chips.jump { position: sticky; top: var(--topbar); z-index: 3; flex-wrap: nowrap; gap: 2px; margin: 14px 0 0; padding: 6px 0; overflow-x: auto; scrollbar-width: none; background: var(--bg); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.chips.jump::-webkit-scrollbar { display: none; }
.chips.jump .chip { flex: none; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; padding: 6px 10px; border: none; border-radius: var(--radius-s); background: none; color: var(--muted); }
.chips.jump .chip:hover { background: var(--surface-2); color: var(--text); }
.chips.jump .count { font-size: 12px; font-weight: 500; color: var(--muted); }
.home-group { scroll-margin-top: calc(var(--topbar) + 52px); }
.results-list li[draggable="true"] { cursor: grab; }
.home-drop { padding: 34px 20px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 10px; font-size: 16px; }
.results h2 { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; }
.results h2 .ic { color: var(--ok); }
.results h2 .stat { margin-left: auto; font-weight: 400; }
.results { animation: rise .25s ease-out; scroll-margin-top: calc(var(--topbar) + 12px); }
.results .actions { margin-top: 12px; }
/* The heading row of the results: the title, then "Download all" / "Save to a folder" on the right. */
.results-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 0 0 10px; }
.results-head h2 { margin: 0; flex: 1 1 auto; min-width: 0; }
.results-head .actions { margin: 0 0 0 auto; }
.results-head .actions:empty { display: none; }
.saved-hint { font-size: 13px; font-weight: 400; color: var(--muted); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.files li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-s);
}
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size, .file-note { color: var(--muted); font-size: 13px; white-space: nowrap; }
.file-note { overflow-wrap: anywhere; }
.file-note.good { color: color-mix(in srgb, var(--ok) 78%, var(--text)); }
/* A file to work on: the name with a muted line of size and details under it, then the row buttons. */
.file-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.file-text .file-name { flex: none; }
.file-meta { display: flex; flex-wrap: wrap; gap: 0 6px; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; }
.file-meta > * + *::before { content: "·"; margin-right: 6px; }
.file-actions { display: inline-flex; flex: none; gap: 2px; align-items: center; margin-left: auto; }
.results-list .file-actions { gap: 4px; }
/* Row buttons (move, remove, preview, copy, download) are big enough to hit. */
.file-actions button.icon { min-width: 34px; min-height: 34px; }
.file-actions button.small { min-height: 34px; }
.thumb { flex: 0 0 64px; width: 64px; height: 64px; padding: 0; border: none; display: flex; align-items: center; justify-content: center; background: var(--surface-2); border-radius: 6px; overflow: hidden; color: var(--muted); }
.thumb canvas { max-width: 64px; max-height: 64px; width: auto; height: auto; }
button.thumb { cursor: zoom-in; transition: box-shadow .15s; }
button.thumb:hover { box-shadow: 0 0 0 2px var(--accent); }
button.thumb:focus-visible { box-shadow: var(--ring); }
.results-list .thumb { flex-basis: 48px; width: 48px; height: 48px; }
.results-list .thumb canvas { max-width: 48px; max-height: 48px; }
/* A long batch scrolls inside the card, so the heading and the buttons under the list stay close. */
.results-list { max-height: 60vh; overflow-y: auto; }
.results-list > li { flex: none; }
.file-info { color: var(--muted); font-size: 13px; white-space: nowrap; }
.file-info:empty { display: none; }
.grip { color: var(--muted); cursor: grab; letter-spacing: -3px; user-select: none; }
.files.orderable li { cursor: grab; }
.files li.dragging { opacity: .4; }
.files li.drop-before { box-shadow: 0 -3px 0 0 var(--accent); }
.files li.drop-after { box-shadow: 0 3px 0 0 var(--accent); }
.sort-row { margin-top: 8px; }

.options { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
/* Fields line up by label and control, so a hint under one field does not push its neighbours down. A bare
   checkbox, caption or button beside fields drops to the control line: 23px is the label line plus the field gap.
   A row without labelled fields (a caption and its checkboxes, a select and a button) is centred instead. */
.row { display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: flex-start; }
.row:has(> .field) > :is(.check, .field-label, button, .actions) { margin-top: 23px; }
.row:has(> .field) > :is(.check, .field-label) { display: inline-flex; align-items: center; min-height: 38px; padding-bottom: 0; }
.row:has(> .field) > button.small { margin-top: 27px; }
.row:not(:has(> .field)) { align-items: center; }
.row:not(:has(> .field)) > .check { padding-bottom: 0; }
.field > .row { align-items: center; min-height: 38px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 13px; color: var(--muted); }
.field-hint { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.check { display: inline-flex; align-items: center; gap: 8px; padding-bottom: 8px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.run-row { position: sticky; bottom: 0; padding: 10px 0; background: linear-gradient(180deg, transparent, var(--bg) 30%); z-index: 2; }
.progress { flex: 1 1 220px; min-width: 160px; height: 28px; position: relative; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-s); overflow: hidden; }
.progress-bar { position: absolute; inset: 0; width: 0; background: var(--accent); opacity: .35; transition: width .15s; }
.progress-text { position: relative; display: block; line-height: 26px; padding: 0 10px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link.small { font-size: 12px; align-self: flex-start; }
table.meta { border-collapse: collapse; font-size: 13px; }
table.meta th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 14px 3px 0; vertical-align: top; white-space: nowrap; }
table.meta td { padding: 3px 0; word-break: break-word; }
.copy { align-self: flex-start; margin-top: 6px; padding: 5px 10px; font-size: 13px; }
.preview { max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius-s); background: var(--surface-2); }
.preview-wrap { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.stat { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.stat.ok { color: var(--ok); }
.stat.bad { color: var(--danger); }

.crop-stage { position: relative; display: inline-block; max-width: 100%; }
.crop-stage canvas { display: block; max-width: 100%; touch-action: none; cursor: crosshair; border-radius: var(--radius-s); }

/* annotate, sign: tool chips, colour dots */
.annot-bar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: flex-end; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip-btn { padding: 6px 10px; gap: 6px; font-size: 14px; }
.chip-btn .glyph { font-weight: 700; min-width: 1em; text-align: center; }
.chip-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.dot { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 2px solid var(--border); }
.dot.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.chip-row input[type="color"] { width: 32px; height: 28px; padding: 0; border: none; background: none; }
.annot-input { position: absolute; z-index: 2; min-width: 140px; padding: 2px 4px; font-weight: 600; background: rgba(255,255,255,.92); border: 1px dashed var(--accent); border-radius: 4px; transform: translateY(-2px); }

/* document scan */
.scan-grid { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.scan-side { display: flex; flex-direction: column; gap: 6px; }
.scan-preview { max-width: 240px; max-height: 340px; border: 1px solid var(--border); border-radius: var(--radius-s); background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); }

/* sign & fill */
.sig-row { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.sig-preview { min-width: 120px; height: 44px; padding: 2px 8px; display: flex; align-items: center; justify-content: center; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-s); }
.sig-preview img { max-height: 40px; max-width: 200px; }
.sig-pad { display: flex; flex-direction: column; gap: 8px; padding: 12px; background: var(--surface-2); border-radius: var(--radius-s); }
.sig-canvas { width: 100%; max-width: 600px; aspect-ratio: 3 / 1; background: #fff; border: 1px dashed var(--muted); border-radius: var(--radius-s); touch-action: none; cursor: crosshair; }
.sig-pad .sig-canvas[height="220"] { aspect-ratio: 900 / 220; cursor: default; }
.sign-pages { display: flex; flex-direction: column; align-items: center; gap: 14px; max-height: 78vh; overflow: auto; padding: 12px; background: var(--surface-2); border-radius: var(--radius-s); }
.sign-sheet { position: relative; flex-shrink: 0; max-width: 100%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.sign-sheet .ph, .sign-sheet .sign-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.sign-sheet .page-n { position: absolute; right: 8px; bottom: 8px; padding: 1px 8px; border-radius: 10px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; pointer-events: none; }
.sign-layer { position: absolute; inset: 0; }
.sign-pages.placing .sign-sheet { cursor: copy; }
.sign-item { position: absolute; cursor: move; touch-action: none; outline: 1px dashed transparent; }
.sign-item:hover, .sign-item.selected { outline-color: var(--accent); }
.sign-item img { display: block; width: 100%; height: 100%; pointer-events: none; }
.sign-text { white-space: pre; line-height: 1.2; padding: 0 2px; min-width: 1ch; font-family: "Noto Sans", Helvetica, Arial, sans-serif; outline: none; }
.sign-item.editing { cursor: text; outline: 1px solid var(--accent); background: rgba(255,255,255,.6); }
.sign-del, .sign-handle { position: absolute; display: none; }
.sign-item.selected .sign-del, .sign-item.selected .sign-handle, .sign-item:hover .sign-del { display: flex; }
.sign-del { top: -11px; right: -11px; width: 20px; height: 20px; padding: 0; border-radius: 50%; font-size: 14px; line-height: 1; background: var(--danger); color: #fff; border: none; }
.sign-handle { right: -6px; bottom: -6px; width: 12px; height: 12px; background: var(--accent); border-radius: 3px; cursor: nwse-resize; }

.redact-pages .sign-sheet { cursor: crosshair; touch-action: none; }
.redact-box { position: absolute; background: rgba(0, 0, 0, .82); outline: 1.5px solid var(--accent); cursor: pointer; }
.redact-box.live { background: rgba(0, 0, 0, .45); pointer-events: none; }

.checker { background: repeating-conic-gradient(#d9dce3 0 25%, #fff 0 50%) 0 0 / 18px 18px; }
.crop-stage canvas.checker { cursor: crosshair; }

.doc-preview { height: 560px; }
.sheet-preview td, .sheet-preview th { padding-right: 14px; white-space: nowrap; }
/* its own size, not stretched across the options column (a flex item would be) */
.video-preview { display: block; align-self: flex-start; width: auto; height: auto; max-width: 100%; max-height: 50vh; background: #000; border-radius: var(--radius-s); }
.video-probe { white-space: pre-line; }
.video-row { align-items: center; }
.video-scrub { flex: 1 1 260px; min-width: 160px; }

.qr-results { display: flex; flex-direction: column; gap: 12px; }
.qr-item { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius-s); }
.qr-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.qr-text { width: 100%; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
.button-link { display: inline-flex; align-items: center; padding: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius-s); background: var(--surface-2); color: inherit; text-decoration: none; }
.button-link:hover { border-color: var(--muted); background: var(--surface-3); }

.compare { position: relative; display: inline-block; max-width: 100%; overflow: hidden; border-radius: var(--radius-s); border: 1px solid var(--border); }
.compare canvas { display: block; max-width: 100%; }
.compare .after { position: absolute; inset: 0; clip-path: inset(0 0 0 50%); }
.compare .after canvas { width: 100%; height: 100%; }
.compare .divider { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; background: var(--accent); pointer-events: none; }
.compare .tag { position: absolute; top: 6px; padding: 2px 8px; font-size: 12px; border-radius: 6px; background: rgba(0,0,0,.55); color: #fff; pointer-events: none; }
.compare .tag.l { left: 6px; } .compare .tag.r { right: 6px; }
.compare input[type="range"] { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; margin: 0; opacity: 0; height: 100%; cursor: ew-resize; }

.pages { display: flex; flex-wrap: wrap; gap: 10px; max-height: 420px; overflow: auto; padding: 4px; }
.page { position: relative; width: 112px; padding: 4px 4px 20px; background: var(--surface-2); border: 2px solid var(--border); border-radius: var(--radius-s); cursor: pointer; text-align: center; display: block; }
.page canvas, .page .ph { display: block; width: 100%; height: auto; min-height: 60px; background: #fff; border-radius: 3px; }
.page .page-n { position: absolute; left: 0; right: 0; bottom: 3px; font-size: 12px; color: var(--muted); }
.page.on { border-color: var(--accent); background: var(--accent-soft); }
.page.removed canvas { opacity: .3; }
.page.removed::after { content: "✕"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 28px; color: var(--danger); }
.page .mini { position: absolute; top: 2px; right: 2px; padding: 1px 6px; font-size: 12px; line-height: 1.4; }
.page.dragging { opacity: .4; }
.page .mini.rot { right: auto; left: 2px; }
.page canvas, .page .ph { transform: rotate(var(--rot, 0deg)); transition: transform .15s; }
.page.sideways canvas, .page.sideways .ph { transform: rotate(var(--rot, 0deg)) scale(.72); }
.page.drop-before { box-shadow: -3px 0 0 0 var(--accent); }
.page.drop-after { box-shadow: 3px 0 0 0 var(--accent); }

.md-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.md-grid textarea { min-height: 420px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.md-grid .field { min-width: 0; }
.md-preview { width: 100%; height: 420px; border: 1px solid var(--border); border-radius: var(--radius-s); background: #fff; }
.field > textarea { min-height: 320px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* swatches (palette tool), diff, pipeline, stamps */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 88px; font-size: 12px; cursor: pointer; background: none; border: none; padding: 0; }
.swatch i { display: block; width: 88px; height: 56px; border-radius: var(--radius-s); border: 1px solid var(--border); }
.swatch code { font-size: 12px; }
.diff { font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-word; max-height: 520px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-s); background: var(--surface); }
.diff .l { display: block; padding: 0 10px; }
.diff .l.add { background: color-mix(in srgb, var(--ok) 18%, transparent); }
.diff .l.del { background: color-mix(in srgb, var(--danger) 16%, transparent); }
.diff .l.ctx { color: var(--muted); }
.diff .l .n { display: inline-block; width: 3.5em; color: var(--muted); user-select: none; }
.steps { display: flex; flex-direction: column; gap: 10px; }
.step { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.step-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.step-head .n { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; }
.step-head strong { flex: 1; }
.step-body { padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.pos-grid { display: grid; grid-template-columns: repeat(3, 32px); gap: 4px; }
.pos-grid button { padding: 0; height: 28px; }
.pos-grid button.on { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.regex-out mark { background: var(--accent-soft); color: inherit; border-radius: 3px; outline: 1px solid var(--accent); }
.regex-out { white-space: pre-wrap; word-break: break-word; font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; border: 1px solid var(--border); border-radius: var(--radius-s); padding: 10px; max-height: 360px; overflow: auto; background: var(--surface); }
.qr-preview { background: #fff; padding: 12px; border-radius: var(--radius-s); border: 1px solid var(--border); display: inline-block; }
.qr-preview img, .qr-preview canvas { display: block; }
.qr-preview:empty { display: none; }
.form-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 14px; }
.form-fields .field { min-width: 0; }
.table-wrap { max-height: 360px; overflow: auto; }
.table-wrap table.meta th { max-width: 320px; white-space: normal; word-break: break-all; }
.contrast { display: flex; flex-direction: column; gap: 8px; }
.contrast-sample { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: var(--radius-s); border: 1px solid var(--border); }
.contrast-sample strong { font-size: 24px; }
.badge { display: inline-block; padding: 0 6px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.badge.bad { background: color-mix(in srgb, #e5484d 18%, transparent); color: #e5484d; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.stats div { background: var(--surface-2); border-radius: var(--radius-s); padding: 8px 10px; }
.stats b { display: block; font-size: 20px; }
.stats span { font-size: 12px; color: var(--muted); }

/* ---------- dialogs ---------- */
.dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow-2); width: min(560px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(10, 12, 18, .45); backdrop-filter: blur(2px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; font-size: 16px; min-width: 0; overflow-wrap: anywhere; }
.dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
/* Pinned near the top, so the field does not move as the list of matches grows and shrinks. */
.palette { margin: 12vh auto auto; }
.palette input { width: 100%; border: none; border-bottom: 1px solid var(--border); border-radius: 14px 14px 0 0; padding: 14px 16px; font-size: 16px; background: transparent; }
.palette input:focus-visible { box-shadow: none; }
.palette-note { display: flex; gap: 10px; align-items: baseline; padding: 12px 16px 0; font-size: 13px; }
.palette-note span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.palette-list { max-height: 60vh; overflow: auto; padding: 6px; }
.palette-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: none; border: none; padding: 9px 10px; border-radius: var(--radius-s); }
.palette-item .ic { color: var(--muted); }
.palette-item.active { background: var(--accent-soft); }
.palette-item.active .ic { color: var(--accent-2); }
.palette-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.palette-text small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-group { flex: none; }
.palette-empty { padding: 16px; color: var(--muted); text-align: center; }
.palette-foot { display: flex; gap: 10px; align-items: center; padding: 8px 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.lightbox { width: min(1100px, calc(100vw - 32px)); }
.lightbox .dialog-body { align-items: center; max-height: calc(100vh - 120px); overflow: auto; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 160px); border-radius: var(--radius-s); background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 20px 20px; }
.lightbox iframe { width: 100%; height: calc(100vh - 160px); border: none; border-radius: var(--radius-s); background: #fff; }
.pdf-sheet { position: relative; width: min(900px, 100%); flex-shrink: 0; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); border-radius: 2px; overflow: hidden; background: #fff; }
.pdf-sheet canvas, .pdf-sheet .ph { display: block; width: 100%; height: auto; background: #fff; }
.pdf-sheet .page-n { position: absolute; right: 8px; bottom: 8px; padding: 2px 8px; border-radius: 10px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 12px; }
.lightbox pre { width: 100%; margin: 0; white-space: pre-wrap; word-break: break-word; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }

.drop-overlay { position: fixed; inset: 0; z-index: 30; background: rgba(255, 140, 40, .12); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.drop-overlay-box { padding: 24px 36px; border: 3px dashed var(--accent); border-radius: 16px; background: var(--surface); font-size: 20px; font-weight: 600; box-shadow: var(--shadow-2); }

/* Centred by its margins (no transform: `rise` animates that) and as wide as its text, up to the screen. It sits
   under the top bar: at the bottom it would land on the Run row or on the results. */
.toast {
  position: fixed; left: 16px; right: 16px; top: calc(var(--topbar) + 10px);
  width: fit-content; max-width: min(560px, calc(100vw - 32px)); margin-inline: auto;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-2); z-index: 40; overflow-wrap: anywhere;
  animation: rise .2s ease-out;
}
.toast-error { background: var(--danger); color: #fff; }

.skip-link { position: absolute; left: 8px; top: -40px; padding: 8px 12px; background: var(--accent); color: var(--accent-text); border-radius: var(--radius-s); z-index: 20; }
.skip-link:focus { top: 8px; }

/* ---------- narrow screens ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .nav-select { display: block; flex: 1; min-width: 0; max-width: 420px; margin-right: auto; }
  .search-btn, .brand span, .topbar-spacer { display: none; }
  .topbar { gap: 8px; padding: 0 12px; }
  .topbar button.icon { order: 2; min-width: 40px; min-height: 40px; }
  /* Once the search button has an icon, it stays as an icon button after the tool picker. */
  .search-btn:has(svg) { display: inline-flex; order: 1; justify-content: center; min-width: 40px; min-height: 40px; padding: 6px; background: transparent; }
  .search-btn:has(svg) :is(.search-text, kbd) { display: none; }
  .main { padding: 16px; }
  .hero h1 { font-size: 26px; }
  .md-grid { grid-template-columns: 1fr; }
  .tool-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) { .tool-grid { grid-template-columns: 1fr; } }
/* A phone-width tab gets the same compact tool page as the side panel below. */
@media (max-width: 560px) {
  .topbar { gap: 6px; }
  .topbar button.icon, .search-btn:has(svg) { min-width: 36px; min-height: 36px; }
  .tool-head h1 { font-size: 20px; }
  .tool-head p { font-size: 13px; }
  .tool-head-icon { width: 38px; height: 38px; }
  .dropzone { padding: 18px 12px; }
  .page { width: 84px; }
  input[type="text"], input[type="range"], input[type="url"] { width: 100%; }
  .field > textarea { min-height: 200px; }
  select { width: 100%; min-width: 0; }
  .compare canvas { width: 100%; height: auto; }
  /* A long name may take two lines; a result puts its note and buttons on a second line. */
  .file-text .file-name { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
  .results-list li { flex-wrap: wrap; row-gap: 4px; }
  .results-list li > .file-name { flex: 1 1 calc(100% - 140px); }
  .file-note { white-space: normal; }
  .thumb { flex-basis: 48px; width: 48px; height: 48px; }
  .thumb canvas { max-width: 48px; max-height: 48px; }
  .file-actions button.icon { min-width: 36px; min-height: 36px; }
  .file-actions button.small { min-height: 36px; }
}

/* Compact layout: the extension's side panel / sidebar or a small pop-up window (?view=side). */
:root[data-view="side"] { --topbar: 48px; }
:root[data-view="side"] .layout { grid-template-columns: minmax(0, 1fr); }
:root[data-view="side"] .sidebar, :root[data-view="side"] .brand span, :root[data-view="side"] .search-btn, :root[data-view="side"] .topbar-spacer, :root[data-view="side"] .hero p { display: none; }
:root[data-view="side"] .topbar { gap: 6px; padding: 0 12px; }
:root[data-view="side"] .topbar button.icon { order: 2; min-width: 36px; min-height: 36px; }
:root[data-view="side"] .search-btn:has(svg) { display: inline-flex; order: 1; justify-content: center; min-width: 36px; min-height: 36px; padding: 6px; background: transparent; }
:root[data-view="side"] .search-btn:has(svg) :is(.search-text, kbd) { display: none; }
:root[data-view="side"] .nav-select { display: block; flex: 1; min-width: 0; max-width: 420px; margin-right: auto; }
:root[data-view="side"] .main { padding: 12px; gap: 12px; }
:root[data-view="side"] .hero h1 { font-size: 20px; }
:root[data-view="side"] .tool-grid { grid-template-columns: 1fr; }
:root[data-view="side"] .tool-head h1 { font-size: 19px; }
:root[data-view="side"] .tool-head p { font-size: 13px; }
:root[data-view="side"] .tool-head-icon { width: 38px; height: 38px; }
:root[data-view="side"] .dropzone { padding: 18px 12px; }
:root[data-view="side"] .md-grid { grid-template-columns: 1fr; }
:root[data-view="side"] .page { width: 84px; }
:root[data-view="side"] input[type="text"], :root[data-view="side"] input[type="range"], :root[data-view="side"] input[type="url"] { width: 100%; }
:root[data-view="side"] .field > textarea { min-height: 200px; }
/* A long name may take two lines; a result puts its note and buttons on a second line. */
:root[data-view="side"] .file-text .file-name { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
:root[data-view="side"] .results-list li { flex-wrap: wrap; row-gap: 4px; }
:root[data-view="side"] .results-list li > .file-name { flex: 1 1 calc(100% - 140px); }
:root[data-view="side"] .file-note { white-space: normal; }
:root[data-view="side"] .thumb { flex-basis: 48px; width: 48px; height: 48px; }
:root[data-view="side"] .thumb canvas { max-width: 48px; max-height: 48px; }
:root[data-view="side"] .file-actions button.icon { min-width: 36px; min-height: 36px; }
:root[data-view="side"] .file-actions button.small { min-height: 36px; }
:root[data-view="side"] select { width: 100%; min-width: 0; }
:root[data-view="side"] .compare canvas { width: 100%; height: auto; }
:root[data-view="side"] .lightbox, :root[data-view="side"] .dialog { width: calc(100vw - 16px); }

/* ---------- 1.6: long file lists, file insights, safe copy, privacy check ---------- */
.files-head { margin: 0 0 6px 2px; }
.files.long { max-height: 50vh; overflow: auto; overscroll-behavior: contain; }

.search-ico { flex: none; color: var(--muted); }

.palette-note { flex-wrap: wrap; }
.palette-insights { flex: 1 0 100%; display: flex; flex-direction: column; gap: 6px; margin-top: 2px; }
.palette-insights:empty { display: none; }
.palette-insight {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 9px 12px;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); border-radius: var(--radius-s);
  color: var(--text); font-size: 14px; animation: rise .18s ease-out;
}
.palette-insight:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.palette-insight .ic { flex: none; color: var(--accent-ink); }
.palette-insight span { flex: 1; min-width: 0; color: var(--text); white-space: normal; }
.palette-insight strong { flex: none; color: var(--accent-ink); white-space: nowrap; }
.palette-label { padding: 8px 10px 4px; font-size: 12px; color: var(--muted); }

.safe-preview { display: block; max-width: min(100%, 420px); height: auto; margin: 4px 0 6px; border: 1px solid var(--border); border-radius: var(--radius-s); background: #fff; }

.leak-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.leak-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 12px 14px; }
.leak-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.leak-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leak-kind { color: var(--muted); font-size: 13px; }
.leak-verdict { margin: 6px 0 8px; font-weight: 600; font-size: 14px; }
.leak-verdict.high { color: var(--danger); }
.leak-verdict.medium { color: var(--accent-ink); }
.leak-verdict.none { color: color-mix(in srgb, var(--ok) 78%, var(--text)); font-weight: 500; }
.leak-verdict.unknown { color: var(--muted); font-weight: 400; }
.leak-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.leak-row { display: grid; grid-template-columns: 10px minmax(110px, 190px) minmax(0, 1fr) auto; gap: 2px 10px; align-items: baseline; padding: 6px 0; border-top: 1px solid var(--border); font-size: 14px; }
.leak-dot { width: 8px; height: 8px; border-radius: 50%; align-self: center; background: var(--muted); }
.leak-dot.high { background: var(--danger); }
.leak-dot.medium { background: var(--accent); }
.leak-dot.info { background: var(--surface-3); border: 1px solid var(--muted); }
.leak-label { color: var(--muted); }
.leak-value { min-width: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.leak-tag { font-size: 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.leak-thumb { grid-column: 3 / -1; max-width: 160px; max-height: 160px; border: 1px solid var(--border); border-radius: 6px; margin-top: 4px; }
.leak-why { grid-column: 3 / -1; font-size: 13px; color: var(--muted); }
.leak-manual { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.leak-checked { margin-top: 8px; font-size: 13px; color: var(--muted); }
.leak-checked summary { cursor: pointer; }
.leak-checked p { margin: 6px 0 0; }
.leak-options { border: 1px solid var(--border); border-radius: var(--radius-s); padding: 8px 12px; margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.leak-options legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.leak-status:empty { display: none; }
@media (max-width: 560px) {
  .leak-row { grid-template-columns: 10px minmax(0, 1fr); }
  .leak-value, .leak-tag, .leak-thumb, .leak-why { grid-column: 2; justify-self: start; }
}
:root[data-view="side"] .leak-row { grid-template-columns: 10px minmax(0, 1fr); }
:root[data-view="side"] .leak-value, :root[data-view="side"] .leak-tag, :root[data-view="side"] .leak-thumb, :root[data-view="side"] .leak-why { grid-column: 2; justify-self: start; }
