/* ---------- toasts ---------- */
.toast-host {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  z-index: 2000; display: flex; flex-direction: column-reverse; gap: 10px; align-items: center;
  pointer-events: none; max-width: 92vw;
}
.toast-host.top {
  bottom: auto; top: 68px; flex-direction: column;
}
.toast {
  display: flex; align-items: center; gap: 11px; padding: 12px 18px; border-radius: 14px;
  background: #ffffff;
  border: 1px solid var(--line); box-shadow: 0 14px 36px -16px rgba(20, 18, 12, 0.4);
  font-size: 14.5px; font-weight: 500; color: var(--ink); pointer-events: auto;
  opacity: 0; transform: translateY(12px); transition: opacity 0.24s, transform 0.24s; max-width: 460px;
}
.toast.in { opacity: 1; transform: translateY(0); }
.toast-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.toast-msg { line-height: 1.4; }
.toast-progress-track { width: 90px; height: 5px; border-radius: 3px; background: rgba(20, 30, 70, 0.1); overflow: hidden; flex: none; }
.toast-bar { height: 100%; width: 0%; background: var(--accent-grad); transition: width 0.2s ease; }
.toast-error { border-color: color-mix(in srgb, var(--danger) 40%, white); }

/* ---------- dropzone (shared drag/drop + click-to-browse target) ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 28px 20px; border-radius: var(--r-lg); border: 1.5px dashed #d8d6d0; background: #fcfcfb;
  cursor: pointer; text-align: center; transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone-compact { padding: 16px 14px; gap: 6px; }
.dropzone-icon { color: var(--accent-deep); display: flex; }
.dropzone-label { font-weight: 600; font-size: 15px; color: var(--ink); }
.dropzone-hint { font-size: 13px; color: var(--ink3); }

/* ---------- celebrate / support popup ---------- */
.celebrate {
  position: relative; width: min(420px, 92vw); padding: 26px 26px 22px; border-radius: 22px;
  pointer-events: auto; opacity: 0; transform: translateY(14px) scale(0.98); transition: all 0.26s ease;
  box-shadow: var(--shadow-inset), 0 40px 90px -40px rgba(20, 30, 70, 0.6);
}
.celebrate.in { opacity: 1; transform: translateY(0) scale(1); }
.celebrate-x { position: absolute; top: 12px; right: 14px; background: none; border: none; font-size: 22px; color: var(--ink3); cursor: pointer; line-height: 1; }
.celebrate-check { width: 46px; height: 46px; border-radius: 14px; background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px -10px rgba(214, 178, 0, 0.6), inset 0 0 0 1px rgba(0, 0, 0, 0.05); }
.celebrate-title { font-size: 20px; margin: 16px 0 0; font-family: var(--font-head); font-weight: 700; }
.celebrate-body { font-size: 14.5px; color: var(--ink2); margin: 8px 0 0; line-height: 1.5; }
.celebrate-actions { display: flex; gap: 10px; margin-top: 18px; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1500; display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 24px; background: rgba(20, 26, 45, 0.34); backdrop-filter: blur(3px); overflow-y: auto;
  opacity: 0; transition: opacity 0.2s ease;
}
.modal-backdrop.in { opacity: 1; }
.modal {
  width: 100%; border-radius: var(--r-xl); position: relative; overflow: hidden;
  background: #ffffff; border: 1px solid var(--line); transform: translateY(14px); transition: transform 0.22s ease;
  box-shadow: 0 40px 90px -40px rgba(20, 18, 12, 0.4); margin: auto 0;
}
.modal-backdrop.in .modal { transform: translateY(0); }
.modal-head { display: flex; align-items: flex-start; gap: 14px; padding: 22px 24px 6px; }
.modal-icon { width: 42px; height: 42px; border-radius: 12px; background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center; flex: none; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05); }
.modal-titles { flex: 1; }
.modal-title { font-size: 20px; font-family: var(--font-head); font-weight: 700; }
.modal-sub { font-size: 14px; color: var(--ink2); margin-top: 4px; line-height: 1.45; }
.modal-x { background: none; border: none; font-size: 24px; color: var(--ink3); cursor: pointer; line-height: 1; padding: 0 2px; }
.modal-x:hover { color: var(--ink); }
.modal-body { padding: 14px 24px 6px; display: flex; flex-direction: column; gap: 16px; }
.modal-text { font-size: 15px; color: var(--ink2); line-height: 1.55; padding: 8px 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 18px 24px 22px; flex-wrap: wrap; }
.modal-busy { position: absolute; inset: 0; background: rgba(255, 255, 255, 0.78); backdrop-filter: blur(6px); display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 5; }
.modal-busy.show { display: flex; animation: fadein 0.15s ease; }
.modal-busy-label { font-size: 14.5px; font-weight: 600; color: var(--ink2); }
.modal-busy .spinner { width: 30px; height: 30px; border-width: 3px; }

/* form controls (shared) */
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider { flex: 1; accent-color: var(--accent); }
.slider-val { font-size: 13.5px; font-weight: 700; color: var(--ink2); min-width: 34px; text-align: right; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.swatch { width: 28px; height: 28px; border-radius: 8px; border: 2px solid #fff; cursor: pointer; box-shadow: 0 0 0 1px var(--line); padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--accent); }
.swatch-picker { position: relative; display: flex; align-items: center; justify-content: center; background: conic-gradient(from 90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); overflow: hidden; }
.swatch-custom { position: absolute; inset: -4px; opacity: 0; cursor: pointer; }
.segmented { display: inline-flex; gap: 4px; padding: 4px; border-radius: 12px; background: rgba(20, 18, 12, 0.06); }
.seg { padding: 7px 14px; border-radius: 9px; border: none; background: none; font-size: 13.5px; font-weight: 600; color: var(--ink2); cursor: pointer; display: flex; align-items: center; gap: 6px; }
.seg.on { background: #fff; color: var(--ink); box-shadow: 0 2px 8px -4px rgba(20, 18, 12, 0.35); }
.result-stat { text-align: center; }
.result-stat-v { font-family: var(--font-head); font-weight: 700; font-size: 24px; }
.result-stat-v.ok { color: var(--ok); }
.result-stat-l { font-size: 12.5px; color: var(--ink3); margin-top: 2px; }
.result-row { display: flex; gap: 26px; justify-content: center; padding: 6px 0; }

/* ---------- feature source picker ---------- */
.source-picker { display: flex; flex-direction: column; gap: 10px; }
.source-current { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line)); background: color-mix(in srgb, var(--accent) 7%, rgba(255,255,255,0.6)); color: var(--ink); font-size: 13.5px; font-weight: 600; cursor: pointer; text-align: left; }
.source-current:hover { border-color: var(--accent); }
.source-list { display: flex; flex-direction: column; gap: 7px; }
.source-file { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 11px; background: rgba(255,255,255,0.7); border: 1px solid var(--line); font-size: 13.5px; }
.source-file-icon { color: var(--accent); display: inline-flex; }
.source-file-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-file-size { color: var(--ink3); font-size: 12px; }
.source-file-x { background: none; border: none; font-size: 18px; color: var(--ink3); cursor: pointer; line-height: 1; }
.source-file-x:hover { color: var(--danger); }
.range-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 6px; max-height: 160px; overflow-y: auto; padding: 4px; }
.range-cell { aspect-ratio: 3/4; border-radius: 5px; border: 1px solid var(--line); background: #fff; display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--ink3); cursor: pointer; }
.range-cell.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, #fff); color: var(--accent); font-weight: 700; }
.result-panel { text-align: center; padding: 10px 0; }
.result-panel h4 { font-size: 18px; margin-bottom: 6px; }

/* ---------- scan to PDF ---------- */
.scan-stage { border-radius: 14px; overflow: hidden; background: #12141b; aspect-ratio: 4/3; display: flex; align-items: center; justify-content: center; }
.scan-video { width: 100%; height: 100%; object-fit: cover; }
.scan-nocam { color: rgba(255,255,255,0.75); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 30px; text-align: center; }
.scan-controls { display: flex; gap: 10px; }
.scan-controls .btn { flex: 1; }
.scan-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; }
.scan-thumb { position: relative; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); aspect-ratio: 3/4; }
.scan-thumb img { width: 100%; height: 100%; object-fit: cover; }
.scan-thumb-x { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; border: none; background: rgba(20,26,45,0.75); color: #fff; cursor: pointer; font-size: 14px; line-height: 1; }

/* ---------- bookmarks ---------- */
.bm-list { display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow-y: auto; padding: 2px; }
.bm-row { display: flex; gap: 8px; align-items: center; }
.bm-title { flex: 1; }
.bm-page { width: 74px; flex: none; }
.bm-del { width: 32px; height: 38px; flex: none; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,0.7); color: var(--ink3); cursor: pointer; font-size: 17px; }
.bm-del:hover { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, white); }
.bm-add { align-self: flex-start; }

/* ---------- color picker ---------- */
.color-picker { display: flex; flex-direction: column; gap: 8px; }
.color-swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.color-sw { width: 24px; height: 24px; border-radius: 7px; border: 2px solid #fff; cursor: pointer; box-shadow: 0 0 0 1px var(--line); padding: 0; }
.color-sw.on { box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--accent); }
.color-sw.color-none { display: flex; align-items: center; justify-content: center; background: repeating-conic-gradient(#e6e8ee 0% 25%, #fff 0% 50%) 0/10px 10px; color: var(--ink3); font-size: 12px; }
.color-trigger { width: 24px; height: 24px; border-radius: 7px; cursor: pointer; padding: 0; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); position: relative; background-image: linear-gradient(135deg, transparent 45%, rgba(0,0,0,0.18) 45% 55%, transparent 55%); }
.color-trigger::after { content: '+'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: rgba(255,255,255,0.95); text-shadow: 0 1px 2px rgba(0,0,0,0.4); }
.color-trigger.is-none { background: repeating-conic-gradient(#e6e8ee 0% 25%, #fff 0% 50%) 0/10px 10px; }

.color-pop {
  position: fixed; z-index: 1600; width: 232px; padding: 12px; border-radius: 16px;
  background: rgba(255,255,255,0.96); display: flex; flex-direction: column; gap: 12px; animation: pop 0.12s ease;
}
.color-sv { position: relative; width: 100%; height: 130px; border-radius: 10px; cursor: crosshair; touch-action: none; box-shadow: inset 0 0 0 1px rgba(20,30,70,0.12); }
.color-sv-thumb { position: absolute; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; transform: translate(-50%, -50%); box-shadow: 0 0 0 1px rgba(0,0,0,0.35), 0 2px 4px rgba(0,0,0,0.3); pointer-events: none; }
.color-hue { position: relative; width: 100%; height: 14px; border-radius: 7px; cursor: pointer; touch-action: none; background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%); box-shadow: inset 0 0 0 1px rgba(20,30,70,0.12); }
.color-hue-thumb { position: absolute; top: 50%; width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 2px solid #fff; transform: translate(-50%, -50%); box-shadow: 0 0 0 1px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.25); pointer-events: none; }
.color-fields { display: flex; flex-direction: column; gap: 8px; }
.color-field { display: flex; flex-direction: column; gap: 3px; }
.color-field > span { font-size: 9.5px; font-weight: 700; letter-spacing: 0.05em; color: var(--ink3); }
.color-hex { font-family: ui-monospace, monospace; text-transform: uppercase; padding: 7px 10px; font-size: 13px; }
.color-rgb { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.color-num { width: 100%; padding: 6px 6px; border-radius: 8px; border: 1px solid rgba(20,30,70,0.12); font-size: 12.5px; text-align: center; font-family: var(--font-body); background: rgba(255,255,255,0.9); }
.color-num:focus { outline: none; border-color: var(--accent); }

/* ---------- autofill soft-fill ---------- */
/* The completion ghost is pinned to the caret and never part of any field's
   value — that's what makes "click out keeps only what you typed" true. */
.autofill-ghost {
  position: fixed; z-index: 1650; left: 0; top: 0;
  pointer-events: none; white-space: pre;
  color: var(--ink3); opacity: 0.7;
}
.autofill-enable { margin-bottom: 14px; }
.autofill-rows { display: flex; flex-direction: column; gap: 8px; }
.autofill-row { display: flex; align-items: center; gap: 8px; }
.autofill-row .input { flex: 1; }
.autofill-row-del {
  flex: none; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: transparent; color: var(--ink2); cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.autofill-row-del:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

/* ---- Crop margins preview ---- */
.crop-preview { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.crop-preview-stage {
  position: relative; overflow: hidden; line-height: 0;
  border: 1px solid var(--line); border-radius: var(--r-sm);
}
.crop-preview-mask {
  position: absolute; pointer-events: none;
  border: 2px dashed var(--accent2);
  box-shadow: 0 0 0 4000px rgba(33, 29, 24, 0.45);
}
.crop-preview-pager { display: flex; align-items: center; gap: 10px; }
.crop-preview-label { font-size: 12.5px; color: var(--ink2); font-variant-numeric: tabular-nums; }
.crop-page-btn {
  flex: none; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: transparent; color: var(--ink2);
  cursor: pointer; font-size: 16px; line-height: 1;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.crop-page-btn:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent-deep); border-color: var(--accent-line); }
.crop-page-btn:disabled { opacity: 0.4; cursor: default; }
