:root {
  --navy: #1f3a5f;
  --ink: #1d2733;
  --muted: #667085;
  --line: #e3e6ea;
  --bg: #f3f4f6;
  --card: #ffffff;
  --yellow: #ffd84d;
  --yellow-edge: #c79a00;
  --yellow-ink: #5a4500;
  --orange: #f05a28;
  --green: #1a9a55;
  --red: #c62828;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100dvh; }
button { font: inherit; cursor: pointer; }
a { color: var(--navy); }

.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--navy); color: #fff;
  padding: 10px 16px; min-height: 56px;
}
.bar h1 { font-size: 16px; font-weight: 600; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar a { color: #fff; text-decoration: none; font-size: 14px; }

.wrap { max-width: 760px; margin: 0 auto; padding: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 18px; border-radius: var(--radius);
  border: 0; background: var(--navy); color: #fff; font-weight: 700; font-size: 16px; text-decoration: none;
}
.btn.block { display: flex; width: 100%; }
.btn.green { background: var(--green); }
.btn.light { background: #e9edf2; color: var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
a.card { display: block; color: inherit; text-decoration: none; }
.card b { display: block; font-size: 15px; }
.card small { color: var(--muted); font-size: 13px; }

.tag { float: right; font-size: 12px; font-weight: 700; border-radius: 10px; padding: 3px 9px; }
.tag.sent { background: #fff1c2; color: #7a5a00; }
.tag.signed { background: #d7f3e3; color: #11683a; }
.tag.expired, .tag.draft { background: #eceef1; color: #555; }

label { display: block; font-size: 13px; font-weight: 600; color: #444; margin: 16px 0 6px; }
input[type=text] { width: 100%; min-height: 48px; padding: 0 12px; border: 1px solid #bbb; border-radius: 10px; font-size: 16px; }
.file {
  display: block; border: 2px dashed #bbb; border-radius: var(--radius);
  padding: 22px 12px; text-align: center; background: #fafafa; color: #555; font-size: 14px;
}
.file input { display: none; }
.error { color: var(--red); font-size: 14px; margin-top: 10px; min-height: 20px; }

table { border-collapse: collapse; width: 100%; font-size: 13px; background: #fff; }
th, td { border: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: top; }
th { background: #f6f7f9; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; }

/* PDF pages */
.pages { padding: 12px 12px 120px; max-width: 900px; margin: 0 auto; }
.page { position: relative; margin: 0 auto 12px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.page canvas { display: block; width: 100%; height: auto; }

.box {
  position: absolute; display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--yellow-edge); border-radius: 6px;
  background: rgba(255, 216, 77, .92); color: var(--yellow-ink);
  font-weight: 700; font-size: clamp(11px, 3.4vw, 16px);
  min-height: 24px; padding: 0; font-family: inherit; user-select: none; -webkit-user-select: none;
}
.box.date { background: rgba(204, 225, 255, .92); border-color: #4a78b5; color: #1f3a5f; }
.box.signed { background: transparent; border: 1px solid rgba(31,58,95,.25); }
.box.signed img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.box.flash { animation: flash 1s ease 2; }
@keyframes flash { 50% { box-shadow: 0 0 0 6px rgba(240, 90, 40, .5); } }

/* admin placement */
.placing .box { touch-action: none; cursor: grab; }
.box .x {
  position: absolute; top: -16px; right: -16px; width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: var(--ink); color: #fff; font-size: 18px; line-height: 32px; padding: 0;
}
.toolbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid var(--line);
}
.toolbar button { flex: 1; min-height: 48px; border: 0; border-radius: 10px; background: #eef2f7; font-weight: 600; font-size: 15px; }
.toolbar button.on { background: var(--yellow); }
.toolbar button.send { background: var(--navy); color: #fff; }
.hint { text-align: center; color: var(--muted); font-size: 13px; padding: 8px 12px 0; }

/* ND signing */
.pill {
  border: 0; border-radius: 20px; background: var(--orange); color: #fff;
  font-weight: 800; font-size: 15px; min-height: 40px; padding: 0 16px; white-space: nowrap;
}
.pill.done { background: var(--green); }
.finish {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line);
}
.finish .btn { min-height: 56px; font-size: 18px; }

.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; width: 100%; max-width: 640px; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.pad { position: relative; height: 210px; border: 2px solid #ccc; border-radius: 12px; background: #fafafa; }
.pad canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; border-radius: 10px; }
.pad .line { position: absolute; left: 16px; right: 16px; bottom: 48px; border-bottom: 1px dashed #aaa; pointer-events: none; }
.row { display: flex; gap: 10px; margin-top: 12px; }
.row .btn { flex: 1; min-height: 52px; font-size: 17px; }

.message { min-height: 70dvh; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; font-size: 20px; font-weight: 600; line-height: 1.4; }
.loading { text-align: center; color: var(--muted); padding: 40px 16px; }
