/* Nossic eSign. Colours and type from the Nossic Branding Pack (v1). */
@font-face { font-family: "Bricolage Grotesque"; src: url("/fonts/bricolage.ttf") format("truetype"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible Next"; src: url("/fonts/atkinson-next.ttf") format("truetype"); font-weight: 200 800; font-display: swap; }

:root {
  --blue: #266BD9; --yellow: #FFCC33; --navy: #1F2438;
  --bg: #EAF2FD; --surface: #FFFFFF; --surface-2: #F5F8FD; --fg: #1F2438; --muted: #5A6278; --line: #DCE3F0;
  --primary: #266BD9; --primary-fg: #FFFFFF; --primary-hover: #1A4FA8; --link: #1A4FA8;
  --good: #1F8A4C; --good-bg: #E5F5EC; --warn: #9A6B00; --warn-bg: #FFF4D1; --bad: #D9483B; --bad-bg: #FDECEA;
  --paper-shadow: 0 1px 3px rgba(31, 36, 56, .12), 0 8px 24px rgba(31, 36, 56, .08);
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12162A; --surface: #1A2036; --surface-2: #20283F; --fg: #EEF2FA; --muted: #A3ADC6; --line: #2C3552;
    --primary: #5A93F0; --primary-fg: #0E1424; --primary-hover: #82AEF5; --link: #8DB4F5;
    --good: #5FD08F; --good-bg: #173326; --warn: #FFCC33; --warn-bg: #3A3216; --bad: #FF8A80; --bad-bg: #3C1F22;
    --paper-shadow: 0 2px 10px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--body); font-size: 16px; line-height: 1.55; min-height: 100vh; }
a { color: var(--link); }
h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 1.15; text-wrap: balance; }
h1 { font-size: 1.85rem; font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0; max-width: 65ch; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mono { font-family: var(--mono); font-size: .85em; overflow-wrap: anywhere; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; border-radius: 6px; }
.light-only { display: block; } .dark-only { display: none; }
@media (prefers-color-scheme: dark) { .light-only { display: none; } .dark-only { display: block; } }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; }
.logo { height: 32px; width: auto; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
@media (max-width: 640px) { .who-name { display: none; } .logo { height: 28px; } }

/* Layout */
.wrap { max-width: 1040px; margin: 0 auto; padding: 28px 16px 64px; display: grid; gap: 20px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.page-head > div { display: grid; gap: 6px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; display: grid; gap: 14px; min-width: 0; }
.rows { display: grid; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.row:first-child { border-top: 0; padding-top: 0; }
.row:last-child { padding-bottom: 0; }
.row > div { display: grid; gap: 2px; min-width: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.empty { color: var(--muted); padding: 6px 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; align-items: start; }

/* Controls */
.btn { font: inherit; font-weight: 700; font-size: .92rem; border-radius: 9px; padding: 9px 16px; border: 1.5px solid transparent; cursor: pointer; background: var(--primary); color: var(--primary-fg); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: var(--primary-hover); }
.btn.secondary { background: transparent; color: var(--fg); border-color: var(--line); }
.btn.secondary:hover { border-color: var(--primary); }
.btn.ghost { background: transparent; color: var(--fg); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.yellow { background: var(--yellow); color: var(--navy); }
.btn.yellow:hover { background: #F5BD1A; }
.btn.sm { padding: 6px 11px; font-size: .85rem; }
.btn.lg { padding: 13px 22px; font-size: 1rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
label { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
label.check input { width: 18px; height: 18px; accent-color: var(--primary); }
input, select, textarea { font: inherit; font-weight: 400; padding: 10px 12px; border-radius: 9px; border: 1.5px solid var(--line); background: var(--surface); color: var(--fg); width: 100%; min-width: 0; }
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
input[type="range"] { padding: 0; border: 0; box-shadow: none; accent-color: var(--primary); }
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; background: var(--surface-2); flex-wrap: wrap; }
.seg button { font: inherit; font-weight: 600; font-size: .88rem; border: 0; background: transparent; color: var(--fg); padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

.state { min-height: calc(100vh - 70px); display: grid; place-items: center; padding: 16px; }
.state-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 32px 28px; display: grid; gap: 14px; justify-items: center; text-align: center; max-width: 460px; }
.state-card .mark { width: 52px; height: 52px; }
.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--navy); color: #fff; padding: 11px 18px; border-radius: 10px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 50; max-width: calc(100vw - 32px); }
.toast.error { background: var(--bad); }
.dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--surface); color: var(--fg); width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
.dialog.wide { width: min(760px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(18, 22, 42, .55); }
.dlg { padding: 22px; display: grid; gap: 16px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--surface); padding-top: 8px; }

/* Landing */
.hero { display: grid; gap: 18px; justify-items: start; padding: 40px 0 8px; }
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); }
.hero .sig { width: min(420px, 90%); height: auto; color: var(--blue); }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.features .card { gap: 6px; }

/* Document list */
.doc-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px; padding: 14px 0; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.doc-row:first-child { border-top: 0; padding-top: 0; }
.doc-row:hover .doc-title { color: var(--primary); }
.doc-title { font-weight: 700; overflow-wrap: anywhere; }
.doc-meta { display: flex; gap: 6px 12px; flex-wrap: wrap; color: var(--muted); font-size: .85rem; align-items: center; }
.people { display: inline-flex; gap: 4px; align-items: center; }
.drop { border: 2px dashed var(--line); border-radius: 14px; padding: 28px 16px; text-align: center; display: grid; gap: 8px; justify-items: center; cursor: pointer; background: var(--surface-2); }
.drop.over { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); }

/* PDF pages and fields */
.pages { display: grid; gap: 18px; justify-items: center; padding: 18px 0 120px; }
.page { position: relative; width: 100%; max-width: 860px; background: #fff; box-shadow: var(--paper-shadow); border-radius: 2px; }
.page canvas { display: block; width: 100%; height: 100%; border-radius: 2px; }
.page .layer { position: absolute; inset: 0; }
.page-no { position: absolute; right: 8px; bottom: -22px; font-size: .75rem; color: var(--muted); }
.fld { position: absolute; border: 2px solid var(--c, var(--blue)); background: color-mix(in srgb, var(--c, var(--blue)) 14%, transparent); border-radius: 4px; display: grid; place-items: center; font-size: clamp(9px, 1.4vw, 13px); font-weight: 700; color: color-mix(in srgb, var(--c) 80%, #000); overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.fld .tag { padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; pointer-events: none; }
.fld svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.fld.sel { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 35%, transparent); }
.fld .grip { position: absolute; right: -2px; bottom: -2px; width: 14px; height: 14px; background: var(--c); border-radius: 3px 0 3px 0; cursor: nwse-resize; }
.fld.other { border-style: dashed; opacity: .55; cursor: default; }
.fld.mine { cursor: pointer; }
.fld.mine.todo { animation: pulse 2s ease-in-out infinite; }
.fld.mine.filled { background: transparent; border-color: color-mix(in srgb, var(--c) 35%, transparent); border-style: dashed; }
.fld.mine.current { box-shadow: 0 0 0 4px var(--yellow); }
.fld input.inline { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; padding: 0 4px; font-size: inherit; background: color-mix(in srgb, #fff 90%, transparent); color: #1F2438; box-shadow: none; }
@keyframes pulse { 50% { background: color-mix(in srgb, var(--c) 28%, transparent); } }
@media (prefers-reduced-motion: reduce) { .fld.mine.todo { animation: none; } }

/* Editor */
.editor { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: calc(100vh - 57px); }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 16px; display: grid; gap: 18px; align-content: start; position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto; }
.side section { display: grid; gap: 10px; }
.side h2 { font-size: 1rem; }
.canvas-area { padding: 0 20px; min-width: 0; }
.signer { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 6px 8px; align-items: center; padding: 10px; border: 1.5px solid var(--line); border-radius: 10px; cursor: pointer; }
.signer[aria-current="true"] { border-color: var(--c); box-shadow: inset 4px 0 0 var(--c); }
.signer input { padding: 6px 8px; font-size: .9rem; }
.signer .inputs { display: grid; gap: 6px; grid-column: 1 / -1; }
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.palette button { font: inherit; font-weight: 600; font-size: .88rem; padding: 10px 8px; border-radius: 9px; border: 1.5px solid var(--line); background: var(--surface-2); color: var(--fg); cursor: pointer; display: flex; align-items: center; gap: 6px; }
.palette button:hover { border-color: var(--c, var(--primary)); }
.palette button[aria-pressed="true"] { border-color: var(--c, var(--primary)); background: color-mix(in srgb, var(--c, var(--primary)) 14%, var(--surface)); }
.placing .page .layer { cursor: crosshair; }
.savebar { position: sticky; top: 57px; z-index: 6; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; background: var(--bg); flex-wrap: wrap; }
@media (max-width: 860px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .canvas-area { padding: 0 10px; }
}

/* Signing */
.signbar { position: sticky; top: 57px; z-index: 6; background: var(--surface); border-bottom: 1px solid var(--line); }
.signbar-in { max-width: 900px; margin: 0 auto; padding: 12px 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.signbar h1 { font-size: 1.15rem; }
.intro { max-width: 900px; margin: 16px auto 0; padding: 0 16px; }
.intro .card { gap: 8px; }
.next-fab { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); z-index: 9; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.styles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.style-opt { border: 1.5px solid var(--line); border-radius: 10px; background: #fff; padding: 6px; cursor: pointer; display: grid; gap: 2px; text-align: left; font: inherit; color: var(--muted); font-size: .75rem; }
.style-opt svg { width: 100%; height: auto; display: block; }
.style-opt[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
.pad { position: relative; border: 1.5px dashed var(--line); border-radius: 10px; background: #fff; touch-action: none; }
.pad canvas { display: block; width: 100%; height: 180px; cursor: crosshair; }
.pad .hint { position: absolute; left: 12px; bottom: 8px; color: #8A93A8; font-size: .8rem; pointer-events: none; }
.pad.small canvas { height: 120px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1.5px var(--line); cursor: pointer; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--primary); }
.specimen { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.specimen svg { height: 70px; width: auto; max-width: 100%; }
.tune { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; align-items: start; }
.timeline { display: grid; gap: 0; }
.timeline div { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: .9rem; }
.timeline div:first-child { border-top: 0; }
@media (max-width: 560px) { .timeline div { grid-template-columns: minmax(0, 1fr); gap: 0; } }
