:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --accent: #2f6fed;
  --border: #e2e2e6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --card: #1c1c1f;
    --text: #f2f2f3;
    --muted: #9a9a9e;
    --accent: #5b8dff;
    --border: #2c2c30;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.card {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
}
.card.wide { max-width: 760px; }
h1 { font-size: 1.4rem; margin: 0 0 16px; }
.head { display: flex; align-items: center; justify-content: space-between; }
.logout { color: var(--muted); font-size: 0.85rem; text-decoration: none; }
.logout:hover { text-decoration: underline; }
label { display: block; margin-bottom: 14px; font-size: 0.9rem; color: var(--muted); }
input[type="text"], input[type="password"], select {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
button {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  cursor: pointer;
}
button:hover { opacity: 0.92; }
button:disabled { opacity: 0.5; cursor: default; }
.error { color: #e5484d; font-size: 0.9rem; }
.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 56px 20px;
  min-height: 160px;
  margin-bottom: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 1.05rem;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.drop input { display: none; }
.drop .dropIcon { font-size: 2.4rem; line-height: 1; }
.drop:hover { border-color: var(--accent); }
.drop.drag { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.hint { color: var(--muted); font-size: 0.8rem; }
#status { min-height: 1.2em; font-size: 0.9rem; color: var(--muted); }
#result { margin-top: 12px; }
.resultHead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.resultHead button { width: auto; padding: 6px 12px; font-size: 0.85rem; }
#list { list-style: none; margin: 0; padding: 0; }
#list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
#list a { color: var(--accent); text-decoration: none; }
#list a:hover { text-decoration: underline; }

/* Tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tabBtn {
  width: auto;
  background: transparent;
  color: var(--muted);
  border-radius: 8px 8px 0 0;
  padding: 9px 16px;
  font-size: 0.95rem;
}
.tabBtn.active { background: var(--bg); color: var(--text); font-weight: 600; }
.tabBtn:hover { opacity: 1; color: var(--text); }
.tabPanel { display: none; }
.tabPanel.active { display: block; }

/* Signature pad */
.sigManage { margin-bottom: 16px; }
.sigPadWrap { border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
#sigPad {
  width: 100%;
  max-width: 420px;
  aspect-ratio: 420 / 160;
  display: block;
  margin: 8px auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  touch-action: none;
  cursor: crosshair;
}
.sigPadBtns { display: flex; gap: 10px; justify-content: center; }
.sigPadBtns button { width: auto; padding: 8px 16px; }
#sigClear { background: var(--muted); }

.sigThumbWrap {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  flex-wrap: wrap;
}
.sigThumbWrap img { height: 48px; max-width: 160px; object-fit: contain; background: #fff; border-radius: 6px; padding: 4px; border: 1px solid var(--border); }
.sigThumbInfo { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); flex: 1; }
.sigThumbInfo button { width: auto; padding: 7px 14px; font-size: 0.85rem; }

/* Page toolbar */
.pageToolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  position: sticky;
  top: 8px;
  background: var(--card);
  z-index: 5;
}
.toolBtn {
  width: auto;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 0.85rem;
}
.toolBtn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
#autoPlaceBtn { width: auto; padding: 8px 12px; font-size: 0.85rem; }
.dpiInline { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--muted); margin: 0; margin-left: auto; }
.dpiInline select { width: auto; margin-top: 0; padding: 6px 8px; }

/* Pages */
.pagesContainer { display: flex; flex-direction: column; align-items: center; gap: 20px; margin-bottom: 16px; }
.pageWrap {
  position: relative;
  width: 100%;
  max-width: 700px;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,.18);
  border-radius: 4px;
  overflow: hidden;
  touch-action: none;
}
.pageImg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; user-select: none; -webkit-user-drag: none; }
.inkCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.pageLabel {
  position: absolute;
  bottom: 6px;
  right: 8px;
  font-size: 0.7rem;
  color: rgba(0,0,0,.45);
  background: rgba(255,255,255,.7);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}

/* Stamp */
.stamp {
  position: absolute;
  border: 1px dashed color-mix(in srgb, var(--accent) 60%, transparent);
  touch-action: none;
  cursor: move;
}
.stamp img { width: 100%; height: 100%; pointer-events: none; user-select: none; display: block; }
.stamp .handle {
  position: absolute;
  width: 16px;
  height: 16px;
  right: -8px;
  bottom: -8px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: se-resize;
}
.stamp .remove {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 20px;
  height: 20px;
  background: #e5484d;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.finalizeBtn { margin-bottom: 10px; }
