/* Every rule is scoped under .signlocal so the app can live inside a SharePoint page. */
.signlocal {
  --bg: #f3f4f1; --surface: #ffffff; --ink: #16202e; --muted: #5d6877; --line: #d9dcd6;
  --accent: #0b5f66; --accent-ink: #ffffff; --accent-soft: #e2f0ef; --danger: #a8321f; --ok: #1f7a4a; --warn: #9a6100;
  --desk: #e4e6e1; --shadow: 0 1px 2px rgba(22, 32, 46, .08), 0 6px 20px rgba(22, 32, 46, .08);
  --r: 10px;
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  min-height: 100dvh; display: flex; flex-direction: column; text-align: left;
  -webkit-text-size-adjust: 100%;
}
.signlocal.sl-embedded { min-height: 640px; border: 1px solid var(--line); border-radius: 8px; overflow: clip; }
@media (prefers-color-scheme: dark) {
  .signlocal:not(.sl-embedded) {
    --bg: #12171c; --surface: #1b2229; --ink: #e8ecef; --muted: #9aa5b1; --line: #2e3842;
    --accent: #3fa9b0; --accent-ink: #06282b; --accent-soft: #17343a; --danger: #ef8a76; --ok: #5cc48d; --warn: #e0b04f;
    --desk: #0c1014; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
  body.sl-page { background: #12171c; }
}
body.sl-page { margin: 0; background: #f3f4f1; }
.signlocal *, .signlocal *::before, .signlocal *::after { box-sizing: border-box; }
/* Neutralise host-page element styles (SharePoint, intranet themes) inside the app. */
.signlocal :where(h1, h2, p, label, button, input, dl, dt, dd, ul, li, strong, span, small) {
  text-transform: none; letter-spacing: normal; text-shadow: none; font-family: inherit;
}
.signlocal :where(button) { background: none; border: 0; box-shadow: none; min-width: 0; min-height: 0; height: auto; line-height: inherit; text-align: inherit; }
.signlocal :where(input:not([type="checkbox"]):not([type="file"])) { height: auto; box-shadow: none; outline: 0; }
.signlocal :where(ul) { list-style: none; }
.signlocal [hidden] { display: none !important; }
.signlocal h1 { font-size: clamp(1.45rem, 4.5vw, 1.9rem); line-height: 1.2; margin: 0 0 .4rem; letter-spacing: -.01em; text-wrap: balance; font-weight: 700; color: var(--ink); }
.signlocal h2 { font-size: 1.1rem; margin: 0 0 .2rem; font-weight: 650; color: var(--ink); }
.signlocal p { margin: 0 0 .8rem; }
.signlocal .muted { color: var(--muted); }
.signlocal .small { font-size: .88rem; margin: 0; }
.signlocal button, .signlocal input { font: inherit; color: inherit; margin: 0; }
.signlocal button { cursor: pointer; border: 0; background: none; padding: 0; }
.signlocal :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.signlocal .top {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.signlocal .brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: -.01em; }
.signlocal .tabs { display: flex; gap: 2px; background: var(--bg); padding: 3px; border-radius: 9px; }
.signlocal .tabs button { padding: 6px 13px; border-radius: 7px; color: var(--muted); font-weight: 550; }
.signlocal .tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

.signlocal main { flex: 1; display: flex; flex-direction: column; }
.signlocal section { flex: 1; display: flex; flex-direction: column; }
.signlocal .start { width: 100%; max-width: 620px; margin: 0 auto; padding: clamp(24px, 7vh, 64px) 18px 40px; }
.signlocal .lede { color: var(--muted); font-size: 1.02rem; margin-bottom: 1.4rem; max-width: 46ch; }
.signlocal .drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; cursor: pointer;
  padding: 34px 18px; border: 1.5px dashed var(--muted); border-radius: 14px; background: var(--surface); color: var(--muted);
  transition: border-color .15s, background .15s;
}
.signlocal .drop strong { color: var(--ink); font-size: 1.08rem; margin-top: 6px; }
.signlocal .drop svg { color: var(--accent); }
.signlocal .drop:hover, .signlocal .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.signlocal .facts { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 12px; color: var(--muted); font-size: .94rem; }
.signlocal .facts li { padding-left: 14px; border-left: 2px solid var(--line); }
.signlocal .facts b { color: var(--ink); font-weight: 600; }

.signlocal .card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 22px 20px; }
.signlocal .narrow { width: calc(100% - 28px); max-width: 620px; margin: clamp(16px, 5vh, 44px) auto 40px; display: grid; gap: 14px; }
.signlocal .narrow h2 { margin-top: 8px; overflow-wrap: anywhere; }
.signlocal label { display: grid; gap: 5px; font-size: .86rem; font-weight: 550; color: var(--muted); }
.signlocal input:not([type="checkbox"]):not([type="file"]) {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font-size: 16px; min-width: 0;
}
.signlocal input[type="file"] { font-size: .86rem; max-width: 100%; }
.signlocal label.check { display: flex; align-items: center; gap: 9px; font-weight: 450; color: var(--ink); font-size: .93rem; }
.signlocal label.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.signlocal .grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.signlocal .row { display: flex; align-items: center; gap: 10px; }
.signlocal .row.wrap { flex-wrap: wrap; }
.signlocal .row.end { justify-content: flex-end; }
.signlocal .row.between { justify-content: space-between; }
.signlocal .primary { background: var(--accent); color: var(--accent-ink); font-weight: 620; padding: 10px 18px; border-radius: 9px; white-space: nowrap; }
.signlocal .primary:hover { filter: brightness(1.08); }
.signlocal .primary.wide { width: 100%; padding: 13px; }
.signlocal .ghost { border: 1px solid var(--line); padding: 9px 15px; border-radius: 9px; font-weight: 550; background: var(--surface); white-space: nowrap; }
.signlocal .ghost.sm { padding: 5px 10px; font-size: .84rem; }
.signlocal .ghost:hover { border-color: var(--muted); }
.signlocal .ghost.danger { color: var(--danger); }
.signlocal .link { color: var(--accent); font-weight: 600; padding: 4px 2px; }
.signlocal .back { justify-self: start; }
.signlocal .icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 8px; font-size: 1.3rem; color: var(--muted); flex: none; }
.signlocal .icon.sm { width: 30px; height: 30px; }
.signlocal .icon:hover { background: var(--bg); color: var(--ink); }
.signlocal .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--sc, var(--accent)); flex: none; display: inline-block; }

/* Workspace */
.signlocal #work { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.signlocal .bar {
  position: sticky; top: 51px; z-index: 20; display: flex; align-items: center; gap: 6px;
  padding: 6px max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.signlocal .signer-chip {
  display: flex; align-items: center; gap: 7px; padding: 6px 10px; border-radius: 999px; border: 1.5px solid var(--sc, var(--accent));
  font-weight: 600; font-size: .88rem; max-width: 170px; flex: none;
}
.signlocal .signer-chip .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signlocal .tools { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.signlocal .tools::-webkit-scrollbar { display: none; }
.signlocal .tools button { display: flex; align-items: center; gap: 7px; padding: 8px 11px; border-radius: 8px; font-weight: 550; white-space: nowrap; flex: none; }
.signlocal .tools button:hover { background: var(--bg); }
.signlocal .tools button.on { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
.signlocal .zoom { display: flex; }
@media (max-width: 760px) {
  .signlocal .bar { flex-wrap: wrap; }
  .signlocal .tools { order: 5; flex-basis: 100%; }
  .signlocal .signer-chip { margin-right: auto; }
  .signlocal .tools button { flex-direction: column; gap: 1px; padding: 5px 9px; font-size: .68rem; }
  .signlocal .zoom { display: none; }
  .signlocal .primary { padding: 10px 14px; }
}
.signlocal .hint { font-size: .88rem; color: var(--accent); background: var(--accent-soft); padding: 7px 14px; text-align: center; }
.signlocal .hint:empty { display: none; }
.signlocal .pages { flex: 1; background: var(--desk); padding: 14px 10px 90px; overflow-x: auto; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.signlocal .page { position: relative; background: #fff; box-shadow: var(--shadow); flex: none; }
.signlocal .page canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.signlocal .page .layer { position: absolute; inset: 0; }
.signlocal .placing .layer { cursor: crosshair; }
.signlocal .pno { position: absolute; left: 0; bottom: -13px; font-size: .64rem; color: var(--muted); line-height: 1; }
.signlocal .field { position: absolute; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; --sc: #0b5f66; }
.signlocal .field img { width: 100%; height: 100%; display: block; pointer-events: none; -webkit-user-drag: none; }
.signlocal .field::after { content: ""; position: absolute; inset: -3px; border: 1.5px dashed transparent; border-radius: 3px; pointer-events: none; }
.signlocal .field:hover::after { border-color: var(--sc); opacity: .6; }
.signlocal .field.sel::after { border: 1.5px solid var(--sc); background: color-mix(in srgb, var(--sc) 7%, transparent); opacity: 1; }
.signlocal .field .tag { position: absolute; left: -3px; top: -19px; font-size: 10.5px; line-height: 1; padding: 3px 6px; border-radius: 4px; background: var(--sc); color: #fff; white-space: nowrap; display: none; pointer-events: none; }
.signlocal .field.sel .tag, .signlocal .multi .field .tag { display: block; }
.signlocal .field .del, .signlocal .field .grip { position: absolute; display: none; width: 26px; height: 26px; border-radius: 50%; background: var(--sc); color: #fff; place-items: center; box-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
.signlocal .field.sel .del, .signlocal .field.sel .grip { display: grid; }
.signlocal .field .del { top: -16px; right: -16px; font-size: 15px; line-height: 1; }
.signlocal .field .grip { bottom: -16px; right: -16px; cursor: nwse-resize; touch-action: none; }
.signlocal .field .grip::before { content: ""; width: 9px; height: 9px; border-right: 2px solid #fff; border-bottom: 2px solid #fff; transform: translate(-1.5px, -1.5px); }
.signlocal .slot {
  position: absolute; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 1px; padding: 4px 8px; overflow: hidden;
  border: 2px dashed #c2410c; background: rgba(255, 244, 230, .85); color: #7c2d12; border-radius: 4px; text-align: left; font-size: 12px; line-height: 1.2;
  animation: sl-pulse 2.4s ease-in-out infinite;
}
.signlocal .slot .sh { font-weight: 700; }
.signlocal .slot .sn { color: #44505e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.signlocal .slot:hover { background: rgba(255, 237, 213, .95); }
@keyframes sl-pulse { 50% { box-shadow: 0 0 0 4px rgba(194, 65, 12, .18); } }

/* Signers */
.signlocal .slist { display: grid; gap: 10px; }
.signlocal .srow { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: start; padding: 12px; border: 1px solid var(--line); border-left: 4px solid var(--sc); border-radius: 10px; }
.signlocal .srow.on { background: color-mix(in srgb, var(--sc) 6%, var(--surface)); }
.signlocal .srow > .dot { margin-top: 14px; }
.signlocal .sgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; min-width: 0; }
.signlocal .smeta { grid-column: 1 / -1; font-size: .8rem; color: var(--muted); }
.signlocal .sact { grid-column: 2; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.signlocal .sact .icon { margin-left: auto; }
@media (max-width: 480px) { .signlocal .sgrid { grid-template-columns: 1fr; } }
.signlocal .olist { display: grid; gap: 8px; }
.signlocal .orow { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "d n b" "d t t"; gap: 4px 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-left: 4px solid var(--sc); border-radius: 10px; }
.signlocal .orow .dot { grid-area: d; }
.signlocal .oname { grid-area: n; display: grid; min-width: 0; }
.signlocal .oname strong, .signlocal .oname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signlocal .orow button { grid-area: b; }
.signlocal .othumb { grid-area: t; background: #fff; border-radius: 6px; padding: 4px 8px; min-height: 30px; display: flex; align-items: center; }
.signlocal .othumb img { max-height: 54px; max-width: 100%; }
.signlocal .othumb .muted { color: #5d6877; font-size: .84rem; }
.signlocal .flist { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; }
.signlocal .flist li { display: flex; align-items: center; gap: 8px; font-size: .93rem; }
.signlocal .flist .nm { font-weight: 600; overflow-wrap: anywhere; }

/* Dialogs */
.signlocal dialog { border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--ink); width: min(560px, calc(100vw - 20px)); max-height: calc(100dvh - 20px); box-shadow: var(--shadow); }
.signlocal dialog::backdrop { background: rgba(10, 14, 18, .55); }
.signlocal .dlg { padding: 20px; display: grid; gap: 14px; }
.signlocal .seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bg); padding: 3px; border-radius: 9px; }
.signlocal .seg button { padding: 7px; border-radius: 7px; font-weight: 550; color: var(--muted); }
.signlocal .seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.signlocal .mode { display: grid; gap: 10px; }
.signlocal .padwrap { position: relative; border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden; }
.signlocal #pad { display: block; width: 100%; height: 190px; touch-action: none; cursor: crosshair; }
.signlocal .padline { position: absolute; left: 7%; right: 7%; bottom: 46px; border-bottom: 1px solid #c9ced3; pointer-events: none; }
.signlocal .swatches { display: flex; gap: 8px; }
.signlocal .swatches button { width: 26px; height: 26px; border-radius: 50%; background: var(--c); border: 2px solid var(--surface); box-shadow: 0 0 0 1.5px var(--line); }
.signlocal .swatches button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent); }
.signlocal .styles { display: grid; gap: 8px; }
.signlocal .styles button { background: #fff; color: #111827; border: 1.5px solid var(--line); border-radius: 10px; padding: 6px 14px; font-size: 1.9rem; line-height: 1.5; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 58px; }
.signlocal .styles button[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.signlocal .sigbox { min-height: 110px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 12px; text-align: center; }
.signlocal .sigbox img { max-width: 100%; max-height: 120px; }
.signlocal .sigbox .muted { color: #5d6877; font-size: .88rem; }
.signlocal .okmark { width: 46px; height: 46px; border-radius: 50%; background: var(--accent-soft); color: var(--ok); display: grid; place-items: center; }
.signlocal .kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: .9rem; }
.signlocal .kv dt { color: var(--muted); }
.signlocal .kv dd { margin: 0; overflow-wrap: anywhere; min-width: 0; }
.signlocal .kv .mono { font-family: ui-monospace, Consolas, Menlo, monospace; font-size: .76rem; }
@media (max-width: 480px) { .signlocal .kv { grid-template-columns: 1fr; gap: 0; } .signlocal .kv dd { margin-bottom: 8px; } }

.signlocal .verdict { margin-top: 14px; border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: var(--r); background: var(--surface); padding: 16px 18px; display: grid; gap: 10px; justify-items: start; }
.signlocal .verdict > * { justify-self: stretch; }
.signlocal .verdict > button { justify-self: start; }
.signlocal .verdict.good { border-left-color: var(--ok); }
.signlocal .verdict.warn { border-left-color: var(--warn); }
.signlocal .verdict.bad { border-left-color: var(--danger); }
.signlocal .verdict h2 { margin: 0; }
.signlocal .verdict.good h2 { color: var(--ok); }
.signlocal .verdict.warn h2 { color: var(--warn); }
.signlocal .verdict.bad h2 { color: var(--danger); }
.signlocal .vnum { font-size: .75rem; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.signlocal .vsum { margin: 18px 0 0; font-weight: 600; }
.signlocal .note { font-size: .86rem; color: var(--muted); margin: 0; }

.signlocal #busy { position: fixed; inset: 0; z-index: 1000; background: rgba(10, 14, 18, .55); display: grid; place-content: center; justify-items: center; gap: 12px; color: #fff; font-weight: 550; }
.signlocal .spin { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .3); border-top-color: #fff; animation: sl-spin .8s linear infinite; }
@keyframes sl-spin { to { transform: rotate(360deg); } }
.signlocal #toast { position: fixed; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 1001; background: #16202e; color: #fff; padding: 11px 18px; border-radius: 10px; max-width: calc(100vw - 28px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; font-size: .92rem; box-shadow: var(--shadow); }
.signlocal #toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .signlocal * { transition: none !important; animation: none !important; } }
