:root {
  --blue: #1a478a;
  --gold: #c8a95e;
  --bg: #f4f6fa;
  --card: #fff;
  --ok: #1aa179;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: #1a1a1a;
}
.topbar {
  background: linear-gradient(90deg, var(--blue), #2a5aa8);
  color: #fff; padding: 12px 20px; display: flex; justify-content: space-between;
  align-items: center;
}
.brand { font-size: 18px; font-weight: 700; }
.brand span { color: var(--gold); }
.userbox { display: flex; gap: 10px; align-items: center; font-size: 13px; }
.topbar .btn-mini { background: rgba(255,255,255,0.22); color: #fff; }
.topbar .btn-mini:hover { background: rgba(255,255,255,0.34); }
.card {
  background: var(--card); border-radius: 12px; padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06); margin-bottom: 18px;
}
.center { max-width: 360px; margin: 60px auto; text-align: center; }
#result { max-width: 640px; text-align: left; padding: 24px 28px; }
#result h3 { overflow-wrap: anywhere; word-break: break-word; line-height: 1.3; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 720px) { .grid { grid-template-columns: 1fr; } }
h2, h3 { margin-top: 0; color: var(--blue); }
.muted { color: #777; font-size: 13px; }
input[type=password], input[type=email], input[type=text] {
  width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 8px; margin: 10px 0;
  font-size: 14px;
}
.btn {
  background: var(--blue); color: #fff; border: 0; padding: 11px 18px;
  border-radius: 8px; cursor: pointer; font-weight: 600; width: 100%;
}
.btn:disabled { background: #aaa; cursor: not-allowed; }
.btn-mini {
  background: var(--blue); color: #fff; border: 0; padding: 7px 14px;
  border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px;
}
.btn-mini:hover { background: #2a5aa8; }
.drop {
  border: 2px dashed #c5cede; border-radius: 10px; padding: 28px; text-align: center;
  margin: 12px 0; transition: .2s;
}
.drop.over { border-color: var(--blue); background: #eef3fb; }
.drop input { display: none; }
.drop label { cursor: pointer; color: var(--blue); font-weight: 600; }
.fname { font-size: 13px; color: #444; margin-bottom: 10px; }
.user-row { display: flex; gap: 8px; align-items: center; }
.user-row input { flex: 1; margin: 10px 0; }
.user-tag { display: inline-flex; align-items: center; gap: 6px; background: #eef3fb; color: var(--blue);
  border: 1px solid #d4e0f5; border-radius: 20px; padding: 3px 10px; margin: 3px; font-size: 12px; }
.user-tag .rm { background: transparent; border: 0; color: #d33; cursor: pointer; font-weight: 700; font-size: 14px; line-height: 1; }

/* PDF viewer modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: #fff; border-radius: 12px; width: min(960px, 96vw); height: min(88vh, 900px); display: flex; flex-direction: column; overflow: hidden; }
.modal-top { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid #eee; }
.modal-box iframe { flex: 1; width: 100%; border: 0; }
.status { margin-top: 12px; font-size: 13px; line-height: 1.6; }
.err { color: #d33; font-size: 13px; min-height: 18px; }
.gallery { display: flex; flex-direction: column; gap: 10px; }
.rec { border: 1px solid #e5e9f0; border-radius: 8px; padding: 12px; }
.rec-top { display: flex; justify-content: space-between; align-items: center; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 700; }
.badge.ok { background: #e3f6ee; color: var(--ok); }
.rec-meta { font-size: 12px; color: #666; margin: 6px 0; }
.rec-link { color: var(--blue); font-size: 13px; text-decoration: none; font-weight: 600; }
.rec-code { display: block; font-size: 11px; color: #999; margin-top: 4px; }
.hidden { display: none !important; }
.vtbl { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; }
.vtbl td { padding: 7px 4px; border-bottom: 1px solid #eef1f6; vertical-align: top; overflow-wrap: anywhere; }
.vtbl td:first-child { color: #777; width: 38%; white-space: nowrap; }
.sha { font-size: 11px; word-break: break-all; }

/* searchable documents table */
input[type=search] {
  width: 100%; padding: 10px 12px; border: 1px solid #ccc; border-radius: 8px;
  margin-bottom: 12px; font-size: 14px;
}
.table-wrap { overflow-x: auto; }
table.docs { width: 100%; border-collapse: collapse; font-size: 13px; }
table.docs th, table.docs td { text-align: left; padding: 9px 8px; border-bottom: 1px solid #eef1f6; }
table.docs th { color: #777; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
table.docs tbody tr:hover { background: #f7f9fc; }
.draft-actions { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.draft-actions .btn-mini:disabled { background: #aaa; cursor: not-allowed; }
.row-actions { position: relative; }
.menu { position: absolute; right: 8px; top: 30px; background: #fff; border: 1px solid #dde3ee; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.14); z-index: 20; min-width: 140px; overflow: hidden; }
.menu a, .menu button { display: block; width: 100%; text-align: left; background: #fff; border: 0; padding: 10px 14px; font-size: 13px; font-weight: 600; color: var(--blue); cursor: pointer; text-decoration: none; }
.menu a:hover, .menu button:hover { background: #f3f6fc; }
.pager { display: flex; gap: 12px; align-items: center; margin-top: 12px; }
.pager .btn-mini:disabled { background: #ccc; cursor: not-allowed; }

/* Compose editor modal */
.compose-box { width: min(1100px, 97vw); height: min(92vh, 960px); }
.compose-grid { display: grid; grid-template-columns: 320px 1fr; gap: 0; flex: 1; min-height: 0; }
@media (max-width: 820px) { .compose-grid { grid-template-columns: 1fr; } }
.compose-side { padding: 16px; border-right: 1px solid #eee; overflow-y: auto; overflow-x: hidden; min-width: 0; box-sizing: border-box; }
.compose-side .lbl { display: block; font-size: 12px; color: #555; margin: 12px 0 4px; font-weight: 600; }
.compose-side input[type=text], .compose-side textarea, .compose-side input[type=number] {
  width: 100%; max-width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 7px; font-size: 13px; margin: 0; box-sizing: border-box;
}
.compose-side textarea { resize: vertical; }
.compose-main { padding: 16px; display: flex; flex-direction: column; min-height: 0; }
.page-nav { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.page-stage { position: relative; flex: 1; overflow: auto; background: #e9edf4; border-radius: 8px; padding: 12px; text-align: left; }
.page-stage img { max-width: 100%; box-shadow: 0 2px 12px rgba(0,0,0,.15); background: #fff; display: block; }
#sigLayer { position: absolute; left: 12px; top: 12px; pointer-events: none; }
.sig-box { position: absolute; pointer-events: auto; border: 1px dashed #1a478a; cursor: move; }
.sig-box img { width: 100%; height: 100%; object-fit: contain; display: block; }
.sig-box .tag { position: absolute; bottom: -16px; left: 0; right: 0; text-align: center; font-size: 10px; color: #333; white-space: nowrap; }
.field-list { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.field-add { display: flex; gap: 6px; }
.field-add input { flex: 1; min-width: 0; margin: 0; }
.field-add .btn-mini { flex: 0 0 auto; }
.sig-box .del, .sig-box .rot { position: absolute; top: -10px; border: 0; border-radius: 50%; width: 20px; height: 20px; cursor: pointer; font-size: 11px; z-index: 6; }
.sig-box .del { right: -10px; background: #e44; color: #fff; }
.sig-box .rot { right: 14px; background: #1a478a; color: #fff; }
/* four-corner resize handles (larger, easier to grab); z-index below del/rot so buttons stay clickable */
.sig-box .handle { position: absolute; width: 16px; height: 16px; background: #1a478a;
  border: 2px solid #fff; border-radius: 3px; z-index: 4; }
.sig-box .handle[data-corner="nw"] { left: -8px;  top: -8px;  cursor: nwse-resize; }
.sig-box .handle[data-corner="ne"] { right: -8px; top: -8px;  cursor: nesw-resize; }
.sig-box .handle[data-corner="sw"] { left: -8px;  bottom: -8px; cursor: nesw-resize; }
.sig-box .handle[data-corner="se"] { right: -8px; bottom: -8px; cursor: nwse-resize; }
/* text stamp box */
.sig-box.txt-box { border-color: #1aa179; background: rgba(26,161,121,0.07); display: flex; align-items: center; justify-content: center; }
.sig-box.txt-box .txt { font-size: 11px; font-weight: 600; color: #14532d; text-align: center;
  padding: 2px 4px; width: 100%; height: 100%; overflow: hidden; white-space: normal; line-height: 1.15; word-break: break-word; }
.sig-box.txt-box .rot { background: #1aa179; }
/* organization dropdown row (compose sidebar) */
.org-row { display: flex; gap: 6px; margin-bottom: 6px; }
.org-row .org-select { flex: 1; min-width: 0; padding: 8px; }
.org-new { width: 100%; padding: 8px; margin-top: 2px; }
/* custom field tag (compose sidebar) */
.field-tag { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: #f3f6fb;
  border: 1px solid #e1e8f2; border-radius: 8px; padding: 6px 8px; width: 100%; }
.field-tag code { flex: 1; min-width: 0; font-size: 12px; color: #334; }
.stamp-chk { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: #1aa179;
  font-weight: 600; cursor: pointer; white-space: nowrap; }
.field-tag .place { background: #1aa179; color: #fff; border: 0; border-radius: 6px; padding: 3px 8px;
  font-size: 11px; cursor: pointer; }
.field-tag .rm { background: #e44; color: #fff; border: 0; border-radius: 50%; width: 18px; height: 18px;
  font-size: 11px; cursor: pointer; line-height: 1; }
.signer-list { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.signer-add { display: flex; gap: 6px; }
.signer-add input { flex: 1; min-width: 0; margin: 0; padding: 7px; }
.drop.small { padding: 14px; margin: 6px 0; }
.drop.small input { display: none; }
.sig-preview img { max-width: 160px; max-height: 80px; border: 1px solid #ddd; border-radius: 6px; background: #fff; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn-mini.wide { width: 100%; margin-top: 6px; }
.sig-draw-actions { display: flex; gap: 6px; }
.sig-draw-actions .btn-mini { flex: 1; }
#sigCanvas { width: 100%; height: 120px; border: 1px solid #ccc; border-radius: 8px; background: #fff; margin-top: 6px; touch-action: none; }

/* ── Public landing page (verify.html) ── */
.login-cta { background: rgba(255,255,255,0.22); color: #fff; padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; text-decoration: none; }
.login-cta:hover { background: rgba(255,255,255,0.34); }
.hero { background: linear-gradient(135deg, var(--blue), #2a5aa8); color: #fff; text-align: center; padding: 64px 16px 56px; }
.hero .brand { color: #fff; font-size: 22px; margin-bottom: 18px; }
.hero .brand span { color: var(--gold); }
.hero-banner { display: inline-block; background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.3); padding: 6px 16px; border-radius: 20px; font-size: 13px; font-weight: 600; margin-bottom: 22px; }
.hero h1 { font-size: 34px; margin: 0 auto 14px; max-width: 720px; line-height: 1.2; }
.hero-sub { font-size: 16px; max-width: 620px; margin: 0 auto 28px; opacity: 0.95; }
.hero-cta { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-bottom: 36px; }
.hero-btn { width: auto; min-width: 220px; padding: 13px 22px; font-size: 15px; }
.hero-btn.ghost { background: rgba(255,255,255,0.14); border: 1px solid rgba(255,255,255,0.5); }
.hero-btn.ghost:hover { background: rgba(255,255,255,0.26); }
.hero-features { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; max-width: 880px; margin: 0 auto; }
.hero-features .feat { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); border-radius: 12px; padding: 16px; flex: 1 1 220px; max-width: 280px; text-align: left; }
.hero-features .feat b { display: block; font-size: 15px; margin-bottom: 4px; }
.hero-features .feat span { font-size: 13px; opacity: 0.92; }
main { max-width: 1000px; margin: 24px auto; padding: 0 16px; }
main .card { background: var(--card); border-radius: 12px; padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.06); margin-bottom: 18px; }
.legal { text-align: center; max-width: 1000px; margin: 8px auto 32px; }
#checkName { font-size: 13px; color: #444; margin: 6px 0 10px; }

/* ── Verify mode (when ?code= is present): prominent, hero-free ── */
body.verify-mode main { margin-top: 32px; }
body.verify-mode .hero,
body.verify-mode #check { display: none; }
body.verify-mode #result { display: block; }
body.verify-mode #result {
  text-align: center; max-width: 640px; margin: 0 auto 18px; padding: 28px 24px;
  border: 1px solid #d8eee3; background: linear-gradient(180deg, #f4fcf8, #ffffff);
  box-shadow: 0 10px 30px rgba(26,161,121,0.12);
}
body.verify-mode #result .badge.ok {
  display: inline-block; font-size: 15px; font-weight: 800; letter-spacing: .3px;
  padding: 8px 22px; border-radius: 22px; background: #1aa179; color: #fff;
}
body.verify-mode #result .vtbl {
  margin: 18px auto 0; max-width: 520px; text-align: left;
}
body.verify-mode #result .vtbl td:first-child { font-weight: 600; color: #555; width: 42%; }
