/* electronic-sign — clean SaaS look, Sarabun, blue accent */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #182136;
  --muted: #61697a;
  --line: #e4e7ee;
  --accent: #2456e6;
  --accent-soft: #e8eefc;
  --tenant: #0e8a6d;
  --tenant-soft: #e2f5ef;
  --warn-soft: #fdf3d8;
  --warn-ink: #8a6116;
  --ok-soft: #ddf3e4;
  --ok-ink: #176a3a;
  --danger: #c92f3f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(24, 33, 54, .05), 0 8px 24px rgba(24, 33, 54, .07);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Sarabun', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}
.wrap { max-width: 880px; margin: 0 auto; padding: 24px 16px 120px; }
h1 { font-size: clamp(1.35rem, 1.1rem + 1.2vw, 1.7rem); font-weight: 700; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 10px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); font-size: .9rem; }
.small { font-size: .82rem; }

.topbar { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.brand { color: var(--muted); font-size: .82rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

button, .btn {
  font-family: inherit; font-size: .95rem; font-weight: 600;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  padding: 9px 16px; cursor: pointer;
  transition: filter .12s ease, background .12s ease;
  text-decoration: none; display: inline-flex; align-items: center; gap: 7px;
}
@media (prefers-reduced-motion: reduce) { button, .btn { transition: none; } }
button:hover, .btn:hover { filter: brightness(.97); }
button:focus-visible, .btn:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-tenant { background: var(--tenant); border-color: var(--tenant); color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn-big { font-size: 1.05rem; padding: 13px 22px; border-radius: 12px; }

input[type=text], input[type=password] {
  font-family: inherit; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; width: 100%; background: #fff; color: var(--ink);
}

.pill {
  display: inline-block; font-size: .78rem; font-weight: 600;
  border-radius: 999px; padding: 3px 12px; white-space: nowrap;
}
.pill-draft { background: #ecedf1; color: #565e6e; }
.pill-wait { background: var(--warn-soft); color: var(--warn-ink); }
.pill-done { background: var(--ok-soft); color: var(--ok-ink); }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { justify-content: space-between; }

/* contract list */
.contract-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 4px; border-bottom: 1px solid var(--line); }
.contract-item:last-child { border-bottom: none; }
.contract-item .title { font-weight: 600; }

/* steps */
.steps { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 2px; }
.step { font-size: .8rem; padding: 4px 12px; border-radius: 999px; background: #ecedf1; color: #565e6e; }
.step.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.step.done { background: var(--ok-soft); color: var(--ok-ink); }

/* pages */
.page-wrap {
  position: relative; margin: 0 auto 18px; max-width: 820px;
  background: #fff; border: 1px solid var(--line); border-radius: 6px;
  box-shadow: var(--shadow); overflow: hidden;
}
.page-wrap img.page { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.page-num {
  position: absolute; top: 8px; right: 10px; z-index: 5;
  font-size: .72rem; color: var(--muted);
  background: rgba(255,255,255,.85); border: 1px solid var(--line);
  border-radius: 999px; padding: 1px 9px;
}
.placing .page-wrap { cursor: crosshair; }

/* signature boxes */
.sigbox {
  position: absolute; z-index: 10;
  border: 2px dashed var(--accent); border-radius: 6px;
  background: rgba(36, 86, 230, .07);
  touch-action: none;
}
.sigbox.tenant { border-color: var(--tenant); background: rgba(14, 138, 109, .08); }
.sigbox .tag {
  position: absolute; top: -11px; left: 6px;
  font-size: .68rem; font-weight: 700; line-height: 1;
  background: var(--accent); color: #fff; border-radius: 999px; padding: 3px 9px;
  white-space: nowrap;
}
.sigbox.tenant .tag { background: var(--tenant); }
.sigbox .del {
  position: absolute; top: -12px; right: -12px; width: 24px; height: 24px;
  border-radius: 50%; border: none; background: var(--danger); color: #fff;
  font-size: 13px; font-weight: 700; line-height: 1; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.sigbox .rez {
  position: absolute; right: -8px; bottom: -8px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; border: 2px solid currentColor;
  color: var(--accent); cursor: nwse-resize; touch-action: none;
}
.sigbox.tenant .rez { color: var(--tenant); }
.sigbox.editable { cursor: move; }
.sigbox.locked { border-style: solid; background: transparent; }
.sigbox.locked .del, .sigbox.locked .rez { display: none; }
.sigbox img.sigimg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; pointer-events: none;
}
.sigbox.textbox {
  border: 1.5px solid #7c5cd6; border-radius: 4px;
  background: rgba(124, 92, 214, .06);
}
.sigbox.textbox .tag { background: #7c5cd6; }
.sigbox.textbox .rez { color: #7c5cd6; }
.sigbox.textbox input.txt, .sigbox.textbox .txtval {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border: none; background: transparent; outline: none;
  font-family: 'Sarabun', system-ui, sans-serif; color: #20308f;
  padding: 0 4px; display: flex; align-items: center; white-space: nowrap; overflow: hidden;
}
.sigbox.textbox.locked { border-color: transparent; background: transparent; }
.sigbox.mine { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(14,138,109,.25); } 50% { box-shadow: 0 0 0 7px rgba(14,138,109,0); } }
@media (prefers-reduced-motion: reduce) { .sigbox.mine { animation: none; } }

/* hint bar when placing */
.hintbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--accent); color: #fff; font-weight: 600;
  border-radius: 10px; padding: 10px 14px; margin-bottom: 12px;
  display: none; align-items: center; justify-content: space-between; gap: 10px;
}
.placing .hintbar { display: flex; }
.hintbar button { background: rgba(255,255,255,.16); border-color: transparent; color: #fff; }

/* sticky action bar (tenant) */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: rgba(255,255,255,.94); backdrop-filter: blur(6px);
  border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.actionbar .inner { max-width: 880px; margin: 0 auto; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* modal */
.modal-back {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(24, 33, 54, .5);
  display: none; align-items: center; justify-content: center; padding: 14px;
}
.modal-back.open { display: flex; }
.modal {
  background: #fff; border-radius: 16px; box-shadow: var(--shadow);
  width: 100%; max-width: 560px; padding: 18px;
}
.sig-canvas-wrap {
  position: relative; border: 1.5px dashed #b9c1d2; border-radius: 12px;
  background: #fbfcfe; height: 220px; margin: 12px 0 4px; overflow: hidden;
}
.sig-canvas-wrap canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.sig-baseline {
  position: absolute; left: 10%; right: 10%; bottom: 46px;
  border-bottom: 1.5px solid #d6dbe6; pointer-events: none;
}
.sig-x { position: absolute; left: 10%; bottom: 50px; color: #b9c1d2; font-size: 1rem; pointer-events: none; }
label.check { display: flex; gap: 9px; align-items: flex-start; font-size: .88rem; color: var(--muted); margin: 10px 0; cursor: pointer; }
label.check input { margin-top: 3px; }

.linkbox {
  display: flex; gap: 8px; align-items: center;
  background: var(--accent-soft); border-radius: 10px; padding: 10px 12px;
  font-size: .86rem; word-break: break-all;
}
.linkbox code { flex: 1; font-family: ui-monospace, monospace; font-size: .8rem; }

.banner-ok { background: var(--ok-soft); color: var(--ok-ink); border-radius: 10px; padding: 12px 14px; font-weight: 600; }
.banner-warn { background: var(--warn-soft); color: var(--warn-ink); border-radius: 10px; padding: 12px 14px; }

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); z-index: 120;
  background: var(--ink); color: #fff; border-radius: 10px; padding: 10px 18px;
  font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
.toast.show { opacity: 1; }

.hidden { display: none !important; }
