/* Fill & Sign: calm paper desk, blue ink accent */
:root {
  --bg: #f4f1ea; --panel: #fffdf9; --ink: #1d2230; --muted: #6c7180; --line: #e4ded2; --accent: #2f5bea; --accent-soft: #e6ecfd;
  --field: rgba(47, 91, 234, .09); --field-line: rgba(47, 91, 234, .45); --top-h: 56px;
  font-family: 'Inter', system-ui, -apple-system, sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); }
body { font-size: 14px; display: flex; flex-direction: column; overflow: hidden; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 13px; font-weight: 600; transition: background .15s, border-color .15s, transform .1s; }
button:hover { border-color: #cfc6b5; }
button:active { transform: scale(.97); }
button:disabled { opacity: .4; pointer-events: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #244ad0; }
button.ghost { background: transparent; }
button.big { padding: 12px 24px; font-size: 16px; border-radius: 12px; }
button.small { padding: 5px 10px; font-size: 13px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
[hidden] { display: none !important; }

/* ---------- top & tools ---------- */
#top button { white-space: nowrap; }
#top { height: calc(var(--top-h) + env(safe-area-inset-top, 0px)); padding: env(safe-area-inset-top, 0px) 14px 0; display: flex; align-items: center; gap: 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex: none; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; white-space: nowrap; }
.logo { font-size: 20px; }
.file-name { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.spacer { flex: 1; }
#tools { display: flex; align-items: center; gap: 4px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; flex: none; scrollbar-width: none; }
#tools button { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 10px; font-size: 11px; color: var(--muted); border-color: transparent; background: none; flex: none; min-width: 52px; }
#tools button span { font-size: 17px; line-height: 1.2; color: var(--ink); }
#tools button.on { background: var(--accent-soft); color: var(--accent); border-color: #c6d3fa; }
#tools .sign-tool span { filter: none; }
#tools #zoomIn, #tools #zoomOut, #tools #fitBtn { flex-direction: row; min-width: 0; font-size: 16px; color: var(--ink); padding: 6px 10px; }
#tools #fitBtn { font-size: 12px; }
.sep { width: 1px; height: 28px; background: var(--line); margin: 0 6px; flex: none; }
.zoom-lbl { font-size: 12px; color: var(--muted); min-width: 42px; text-align: center; font-variant-numeric: tabular-nums; flex: none; }
.hint-bar { position: fixed; left: 50%; top: calc(var(--top-h) + 64px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); z-index: 6; background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 99px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-width: calc(100% - 24px); text-align: center; pointer-events: none; }

/* ---------- viewer ---------- */
#viewer { flex: 1; overflow: auto; position: relative; overscroll-behavior: contain; }
#pages { --s: 1; padding: 24px 24px 80px; display: flex; flex-direction: column; align-items: center; gap: 22px; min-width: max-content; }
.page { position: relative; width: calc(var(--w) * var(--s) * 1px); height: calc(var(--h) * var(--s) * 1px); background: #fff; box-shadow: 0 2px 4px rgba(60, 40, 10, .08), 0 12px 32px rgba(60, 40, 10, .1); flex: none; }
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.layer { position: absolute; inset: 0; }
body:not([data-tool="select"]) .layer { cursor: crosshair; }
.page-num { position: absolute; right: 0; bottom: -18px; font-size: 11px; color: var(--muted); }

/* the PDF's own fields */
.field { position: absolute; margin: 0; border: 0; border-radius: 0; background: var(--field); outline: 1px solid transparent; padding: 0 calc(var(--s) * 2px); font-family: Arial, Helvetica, sans-serif; color: #000; transition: background .15s, outline-color .15s; }
.field:hover { outline-color: var(--field-line); }
.field:focus { background: rgba(47, 91, 234, .14); outline: 2px solid var(--accent); }
textarea.field { resize: none; line-height: 1.2; padding-top: calc(var(--s) * 1px); overflow: hidden; }
select.field { padding: 0; appearance: auto; }
.field.ro { background: transparent; }
.field.checkbox, .field.radio { padding: 0; display: grid; place-items: center; line-height: 1; color: #000; font-weight: 700; }
.field.radio { border-radius: 50%; }
.field.checkbox.on::after { content: '✓'; }
.field.radio.on::after { content: '●'; font-size: .85em; }
.field.sigfield { color: var(--accent); font-weight: 700; font-family: inherit; background: rgba(255, 196, 0, .2); outline: 1px dashed rgba(200, 140, 0, .7); }

/* placed items */
.item { position: absolute; touch-action: none; }
.item.image { cursor: move; }
.item.image img { width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; }
.item.text .txt { font-family: Arial, Helvetica, sans-serif; line-height: 1.2; white-space: pre; padding: calc(var(--s) * 1px) calc(var(--s) * 2px); min-width: calc(var(--s) * 8px); min-height: 1.2em; outline: none; cursor: text; }
.item.text .txt:empty::before { content: 'Type here'; color: rgba(0, 0, 0, .35); }
.item.sel { outline: 1.5px dashed var(--accent); outline-offset: 2px; }
.item.text:hover { outline: 1px dashed rgba(47, 91, 234, .5); outline-offset: 2px; }
.grip { position: absolute; left: -22px; top: 50%; transform: translateY(-50%); width: 18px; height: 22px; border-radius: 5px; background: var(--accent); color: #fff; font-size: 12px; line-height: 22px; text-align: center; cursor: move; opacity: 0; transition: opacity .15s; }
.item.sel .grip, .item.text:hover .grip { opacity: 1; }
.resize { position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); cursor: nwse-resize; opacity: 0; }
.item.sel .resize { opacity: 1; }
.sel-bar { position: fixed; z-index: 8; display: flex; gap: 2px; padding: 4px; background: var(--ink); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.sel-bar button { background: none; border: 0; color: #fff; padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.sel-bar button:hover { background: rgba(255,255,255,.12); }
.sel-bar .swatch i { display: block; width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff; }

/* ---------- welcome ---------- */
.welcome { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.drop { text-align: center; max-width: 460px; width: 100%; padding: 36px 28px; background: var(--panel); border: 2px dashed #d8cfbf; border-radius: 22px; }
body.dragging .drop, body.dragging #pages { outline: 3px dashed var(--accent); outline-offset: -10px; }
.drop h1 { font-size: 26px; margin: 18px 0 6px; letter-spacing: -.01em; }
.drop p { color: var(--muted); margin: 6px 0 14px; }
.drop .private { margin-top: 22px; font-size: 12.5px; }
.features { list-style: none; padding: 0; margin: 22px auto 0; text-align: left; display: inline-block; color: var(--ink); line-height: 2; }
.features li::before { content: '✓'; color: var(--accent); font-weight: 700; margin-right: 8px; }
.demo-link { margin-top: 6px; }
.doc-art { position: relative; width: 84px; height: 104px; margin: 0 auto; background: #fff; border: 2px solid #d8cfbf; border-radius: 6px 22px 6px 6px; box-shadow: 0 10px 24px rgba(60,40,10,.1); padding: 18px 12px; display: flex; flex-direction: column; gap: 8px; }
.doc-art i { display: block; height: 6px; border-radius: 3px; background: #e9e3d7; } .doc-art i:nth-child(2) { width: 70%; } .doc-art i:nth-child(3) { width: 85%; background: var(--accent-soft); }
.doc-art b { position: absolute; right: -18px; bottom: -10px; font-size: 34px; transform: rotate(-8deg); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(29, 34, 48, .45); display: grid; place-items: center; padding: 14px; }
.sheet { width: min(560px, 100%); max-height: calc(100% - 10px); overflow-y: auto; background: var(--panel); border-radius: 20px; padding: 20px; box-shadow: 0 24px 60px rgba(0,0,0,.25); }
.sheet h2 { margin: 0 0 12px; font-size: 19px; }
.sheet input[type=text], .sheet input[type=password] { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 16px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.seg { display: flex; gap: 2px; padding: 3px; background: #efe9de; border-radius: 12px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; font-size: 13px; color: var(--muted); border-radius: 9px; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.pane { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.pad-wrap { position: relative; width: 100%; height: 190px; background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.pad { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.pad-hint { position: absolute; inset: 0; display: grid; place-items: center; color: #b9b2a5; pointer-events: none; font-size: 14px; }
.pad-line { position: absolute; left: 24px; right: 24px; bottom: 44px; border-bottom: 1.5px dashed #ddd5c6; pointer-events: none; }
.fonts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
.fonts button { font-size: 28px; font-weight: 400; padding: 10px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: #fff; }
.fonts button.on { border-color: var(--accent); background: var(--accent-soft); }
.up-prev { width: 100%; min-height: 120px; display: grid; place-items: center; background: repeating-conic-gradient(#f3efe8 0 25%, #fff 0 50%) 0 0/16px 16px; border-radius: 14px; border: 1px solid var(--line); padding: 10px; text-align: center; }
.up-prev img { max-width: 100%; max-height: 160px; }
.inks { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.ink { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.ink.on { box-shadow: 0 0 0 2px var(--accent); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.saved { margin-bottom: 12px; }
.saved-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.saved-item { position: relative; }
.saved-item .use { width: 120px; height: 56px; padding: 6px; background: #fff; display: grid; place-items: center; }
.saved-item .use img { max-width: 100%; max-height: 100%; }
.saved-item .use:hover { border-color: var(--accent); }
.saved-item .x { position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; padding: 0; border-radius: 50%; font-size: 10px; background: var(--ink); color: #fff; border: 0; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 30; font-weight: 500; max-width: calc(100% - 32px); text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.25); }

@media (max-width: 600px) {
  .brand b { display: none; }
  #pages { padding: 12px 8px 80px; }
  #openBtn { padding: 8px 10px; }
  .fonts button { font-size: 22px; }
  .grip { left: auto; right: -22px; }
  .wide-only { display: none; }
  .hint-bar { top: auto; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); border-radius: 14px; }
}
