/* Vellinko — editor */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

body.app-open { overflow: hidden; }
body.app-open #site { display: none; }

.app {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: #eceef5;
  padding-top: env(safe-area-inset-top, 0px);
}
.app-bar {
  flex: none; height: 62px; display: flex; align-items: center; gap: 12px; background: #fff; border-bottom: 1px solid var(--line);
  padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px));
}
.app-icon-btn {
  flex: none; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--ink-2); transition: background .15s, border-color .15s;
}
.app-icon-btn:hover { background: var(--bg-soft); border-color: #cfd4e2; }
.app-icon-btn svg { width: 18px; height: 18px; }
.app-logo { flex: none; display: inline-flex; }
.app-logo img { width: 28px; height: 28px; border-radius: 7px; }
.app-file { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.app-file-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34ch; }
.app-file-meta { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--ok); font-weight: 500; }
.app-file-meta svg { width: 13px; height: 13px; }
.app-bar-mid { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.page-ind { font-size: 13px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }
.zoom { display: flex; align-items: center; gap: 4px; }
.zoom .app-icon-btn { width: 34px; height: 34px; }
.zoom-val { min-width: 62px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: #fff; font-size: 13px; font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums; }
.zoom-val:hover { background: var(--bg-soft); }
.app-bar-end { display: flex; align-items: center; gap: 10px; }
.net { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: #8a5a00; background: #fff4dc; padding: 5px 10px; border-radius: 999px; }
.net svg { width: 14px; height: 14px; }
#downloadBtn { height: 40px; padding: 0 16px; }

.app-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 236px minmax(0, 1fr); }
.tools {
  background: #fff; border-right: 1px solid var(--line); overflow-y: auto; padding: 18px 12px;
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 20px;
}
.tool-group { display: flex; flex-direction: column; gap: 2px; }
.tool-label { margin: 0 0 6px 10px; font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--faint); }
.tool {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left; padding: 8px 10px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; cursor: pointer; font-size: 14.5px; font-weight: 500; color: var(--ink-2);
  transition: background .12s, color .12s;
}
.tool:hover { background: var(--brand-soft); color: var(--brand); }
.tool .ti { flex: none; width: 32px; height: 32px; border-radius: 9px; background: var(--bg-soft); display: grid; place-items: center; color: var(--ink-2); transition: background .12s, color .12s; }
.tool:hover .ti { background: #fff; color: var(--brand); }
.tool .ti svg { width: 18px; height: 18px; }
.tool-main { background: var(--brand); color: #fff; margin-bottom: 4px; }
.tool-main .ti { background: rgba(255,255,255,.18); color: #fff; }
.tool-main:hover { background: var(--brand-hover); color: #fff; }
.tool-main:hover .ti { background: rgba(255,255,255,.24); color: #fff; }
.saved-list { display: flex; flex-direction: column; gap: 8px; }
.saved-item { position: relative; display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 18px 34px 4px 10px; height: 64px; cursor: pointer; transition: border-color .12s, box-shadow .12s; }
.saved-item:hover { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.saved-item img { max-height: 36px; max-width: 100%; object-fit: contain; }
.saved-item .kind { position: absolute; left: 8px; top: 4px; font-size: 9.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.saved-item .del { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; border: 0; border-radius: 7px; background: transparent; color: var(--faint); cursor: pointer; display: grid; place-items: center; }
.saved-item .del:hover { background: #fdecef; color: var(--danger); }
.saved-item .del svg { width: 15px; height: 15px; }
.tools-foot { margin: auto 0 0; display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--muted); padding: 12px 10px 0; border-top: 1px solid var(--line); }
.tools-foot svg { width: 14px; height: 14px; flex: none; margin-top: 2px; color: var(--ok); }

.viewer { overflow: auto; position: relative; padding: 24px 20px 140px; padding-right: max(20px, env(safe-area-inset-right, 0px)); overscroll-behavior: contain; }
.fields-banner { display: flex; align-items: center; gap: 10px; max-width: 760px; margin: 0 auto 18px; padding: 11px 14px; border-radius: 11px; background: #fff; border: 1px solid #d9defb; box-shadow: var(--shadow-sm); font-size: 14px; color: var(--ink-2); }
.fields-banner svg { width: 18px; height: 18px; color: var(--brand); flex: none; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 26px; }
.page { position: relative; background: #fff; box-shadow: 0 1px 3px rgba(10,15,31,.12), 0 12px 32px rgba(10,15,31,.10); flex: none; border-radius: 2px; }
.page canvas.render { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: 2px; }
.page.loading::after { content: ""; position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px; border-radius: 50%; border: 3px solid #e1e4ee; border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.page-num { position: absolute; top: calc(100% + 6px); left: 0; right: 0; text-align: center; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.overlay { position: absolute; inset: 0; }

/* Placed items */
.item { position: absolute; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.item:active { cursor: grabbing; }
.item::after { content: ""; position: absolute; inset: -4px; border: 1.5px dashed transparent; border-radius: 4px; pointer-events: none; }
.item:hover::after { border-color: rgba(45, 60, 255, .4); }
.item.selected::after { border: 1.5px solid var(--brand); }
.item img { display: block; width: 100%; height: 100%; pointer-events: none; -webkit-user-drag: none; }
.item .txt { display: block; white-space: pre; line-height: 1.25; outline: none; font-family: Arial, Helvetica, sans-serif; min-width: 1ch; }
.item.editing { cursor: text; }
.item.editing .txt { user-select: text; -webkit-user-select: text; }
.item.editing::after { border: 1.5px solid var(--brand); background: rgba(45, 60, 255, .05); }
.handle {
  position: absolute; right: -11px; bottom: -11px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  border: 2px solid var(--brand); box-shadow: 0 1px 4px rgba(0,0,0,.2); cursor: nwse-resize; display: none; touch-action: none; z-index: 2;
}
.handle::before { content: ""; position: absolute; inset: -10px; }
.item.selected .handle { display: block; }
.item-bar {
  position: absolute; bottom: calc(100% + 10px); left: 50%; transform: translateX(-50%); display: none; gap: 2px; padding: 4px;
  background: var(--ink); border-radius: 10px; box-shadow: 0 8px 24px rgba(10, 15, 31, .28); white-space: nowrap; z-index: 5;
}
.item.bar-below .item-bar { bottom: auto; top: calc(100% + 14px); }
.item.selected .item-bar { display: flex; }
.item.editing .item-bar { display: none; }
.item-bar button {
  border: 0; background: transparent; color: #fff; font: 600 12.5px/1 var(--font-body); padding: 8px 10px; border-radius: 7px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.item-bar button svg { width: 15px; height: 15px; }
.item-bar button:hover { background: rgba(255,255,255,.14); }
.item-bar button.danger { color: #ff9aa8; }
.item-bar .sep { width: 1px; background: rgba(255,255,255,.16); margin: 4px 2px; }
.item-bar .swatch { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); }

/* PDF form fields */
.pdf-field { position: absolute; background: rgba(45, 60, 255, .07); border-bottom: 1.5px solid rgba(45, 60, 255, .55); border-radius: 2px 2px 0 0; transition: background .12s; }
.pdf-field:hover, .pdf-field:focus-within { background: rgba(45, 60, 255, .14); }
.pdf-field input[type="text"], .pdf-field textarea, .pdf-field select {
  display: block; width: 100%; height: 100%; border: 0; background: transparent; color: #111; padding: 0 4px; line-height: 1; outline: none; font-family: Helvetica, Arial, sans-serif; resize: none;
}
.pdf-field textarea { padding-top: 2px; line-height: 1.2; }
.pdf-field.check { display: grid; place-items: center; border: 1.5px solid rgba(45, 60, 255, .55); border-radius: 2px; }
.pdf-field.check.radio { border-radius: 50%; }
.pdf-field.check input { width: 86%; height: 86%; margin: 0; accent-color: var(--brand); cursor: pointer; }

.drag-veil { position: fixed; inset: 0; z-index: 90; background: rgba(45, 60, 255, .86); display: grid; place-items: center; color: #fff; pointer-events: none; text-align: center; }
.drag-veil svg { width: 48px; height: 48px; margin-bottom: 10px; }
.drag-veil p { font: 600 26px/1.2 var(--font-display); margin: 0; }

/* ---------- Signature dialog ---------- */
.sig-dialog, .confirm-dialog {
  border: 0; padding: 0; border-radius: 20px; background: #fff; color: var(--ink);
  box-shadow: 0 30px 80px rgba(10, 15, 31, .35); width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
}
.sig-dialog::backdrop, .confirm-dialog::backdrop { background: rgba(10, 15, 31, .5); backdrop-filter: blur(3px); }
.sig-form { display: flex; flex-direction: column; gap: 16px; padding: 22px 24px 22px; }
.sig-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.sig-head h2 { font-size: 24px; letter-spacing: -.02em; }
.sig-sub { margin: 4px 0 0; color: var(--muted); font-size: 14.5px; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--bg-soft); border-radius: 12px; }
.tab { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 0; background: transparent; padding: 9px 6px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.tab svg { width: 16px; height: 16px; }
.tab[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(10, 15, 31, .12); }
.tab-panel { display: flex; flex-direction: column; gap: 10px; min-height: 236px; }
.pad-wrap { position: relative; height: 236px; border-radius: 14px; background: #fff; border: 1px solid #dde1ec; overflow: hidden; background-image: radial-gradient(#e9ecf4 1px, transparent 1px); background-size: 16px 16px; }
.pad { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.pad-line { position: absolute; left: 9%; right: 9%; bottom: 58px; border-bottom: 1.5px solid #c9cfdf; pointer-events: none; }
.pad-hint { position: absolute; left: 0; right: 0; bottom: 26px; text-align: center; font-size: 13.5px; color: var(--faint); pointer-events: none; }
.pad-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }
.pad-tools .app-icon-btn { width: 34px; height: 34px; }
.f-label { font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.f-input { height: 48px; border: 1px solid #d6dbe7; border-radius: 11px; padding: 0 14px; font-size: 17px; background: #fff; }
.f-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(45, 60, 255, .12); }
.font-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 4px; }
.font-choice { height: 76px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; font-size: 30px; padding: 0 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; transition: border-color .12s, box-shadow .12s; }
.font-choice:hover { border-color: #c9cfe0; }
.font-choice[aria-checked="true"] { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.upload-box { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; min-height: 236px; border: 2px dashed #d3d8e6; border-radius: 14px; padding: 22px; cursor: pointer; transition: border-color .12s, background .12s; }
.upload-box:hover { border-color: var(--brand); background: var(--brand-soft); }
.ub-ico { width: 46px; height: 46px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; }
.ub-ico svg { width: 22px; height: 22px; }
.upload-title { font-weight: 600; }
.upload-sub { font-size: 13.5px; color: var(--muted); max-width: 44ch; }
.photo-result { display: flex; flex-direction: column; gap: 10px; }
.checker { height: 158px; border-radius: 12px; border: 1px solid var(--line); display: grid; place-items: center; padding: 10px; background-color: #fff; background-image: linear-gradient(45deg, #f0f2f7 25%, transparent 25%), linear-gradient(-45deg, #f0f2f7 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #f0f2f7 75%), linear-gradient(-45deg, transparent 75%, #f0f2f7 75%); background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0; }
.checker canvas { max-width: 100%; max-height: 136px; }
.photo-result input[type="range"] { width: 100%; accent-color: var(--brand); }
.photo-result .btn { align-self: flex-start; }
.sig-options { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.ink { display: flex; align-items: center; gap: 10px; }
.ink-opt { position: relative; cursor: pointer; display: inline-flex; }
.ink-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ink-opt .sw { width: 24px; height: 24px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); transition: box-shadow .12s; }
.ink-opt input:checked + .sw { box-shadow: 0 0 0 2px var(--ink); }
.ink-opt input:focus-visible + .sw { outline: 2px solid var(--brand); outline-offset: 3px; }
.remember { display: inline-flex; align-items: center; gap: 9px; font-size: 14.5px; font-weight: 500; cursor: pointer; }
.remember input { width: 18px; height: 18px; accent-color: var(--brand); }
.sig-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; padding-top: 4px; }
.sig-error { margin: 0 auto 0 0; color: var(--danger); font-size: 13.5px; font-weight: 500; }

.confirm-dialog { width: min(420px, calc(100vw - 24px)); padding: 26px; }
.confirm-dialog h2 { font-size: 22px; margin-bottom: 8px; letter-spacing: -.015em; }
.confirm-dialog p { margin: 0 0 22px; color: var(--muted); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

/* Toasts */
.toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; align-items: center; gap: 8px; width: max-content; max-width: calc(100vw - 32px); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14.5px; font-weight: 500; box-shadow: 0 10px 30px rgba(10,15,31,.3); animation: toast-in .22s ease-out; display: flex; align-items: center; gap: 10px; }
.toast svg { width: 17px; height: 17px; flex: none; }
.toast.ok svg { color: #4ee49a; }
.toast.error { background: #a3192f; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Mobile editor ---------- */
@media (max-width: 860px) {
  .app-bar { height: 58px; gap: 8px; }
  .app-logo, .page-ind, .zoom-val, .net { display: none; }
  .app-file-name { max-width: 100%; font-size: 14px; }
  .app-bar-mid { gap: 4px; }
  #downloadBtn { padding: 0 12px; }
  .app-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .viewer { grid-row: 1; padding: 14px 10px 40px; }
  .tools {
    grid-row: 2; flex-direction: row; overflow-x: auto; overflow-y: hidden; gap: 6px; border-right: 0; border-top: 1px solid var(--line);
    padding: 8px max(8px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
    scrollbar-width: none;
  }
  .tools::-webkit-scrollbar { display: none; }
  .tool-group { flex-direction: row; gap: 2px; }
  .tool-label, .tools-foot, .saved-group { display: none !important; }
  .tool { flex-direction: column; gap: 4px; width: auto; min-width: 70px; padding: 6px 4px; font-size: 11.5px; text-align: center; }
  .tool .tool-text { white-space: nowrap; }
  .tool-main { margin: 0; }
  .item-bar button span { display: none; }
  .sig-form { padding: 18px 16px; gap: 14px; }
  .tab-panel, .upload-box { min-height: 200px; }
  .pad-wrap { height: 210px; }
  .font-choice { height: 62px; font-size: 25px; }
}
@media (max-width: 400px) {
  #downloadBtn span { display: none; }
  .zoom .app-icon-btn { width: 32px; height: 32px; }
}
