/* n3-sign — mobile first. Every rule here assumes a phone held in one hand;
   the wider breakpoints at the bottom are the afterthought, not the default.

   Brand: N3 Investment Partnerships — navy #1e3a5f taken from the logo, cream paper,
   gold as the one accent. Fraunces for anything that speaks, Instrument Sans for
   anything that labels. Both are self-hosted: a PWA that has to work in a hallway with
   one bar cannot wait on fonts.google.com. */

@font-face {
  font-family: 'Fraunces';
  src: url('/fonts/fraunces-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Instrument Sans';
  src: url('/fonts/instrument-sans-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f3efe6;
  --paper-2: #fdfbf6;
  --paper-3: #e9e3d6;
  --ink: #1a1a1a;
  --ink-2: #5b5b57;
  --ink-3: #8a8a85;
  --line: #d8d1c2;
  --accent: #1e3a5f;          /* the navy of the n3 mark */
  --accent-fg: #fdfbf6;       /* what is legible on top of --accent */
  --accent-soft: #e2e7ef;
  --gold: #9a7b2e;
  --gold-soft: #f6eeda;
  --good: #1f6b48;
  --good-soft: #e2efe7;
  --warn: #8a5410;
  --warn-soft: #f8ecd9;
  --bad: #97302b;
  --bad-soft: #f6e3e1;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(18, 23, 46, .06), 0 8px 24px rgba(18, 23, 46, .07);
  --tap: 46px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --serif: 'Fraunces', Georgia, "Times New Roman", serif;
  --sans: 'Instrument Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* the brand inverted: navy becomes the paper, cream becomes the ink, gold carries */
    --paper: #101c2e; --paper-2: #17263c; --paper-3: #1f3149;
    --ink: #f3efe6; --ink-2: #bcc5d2; --ink-3: #8794a5; --line: #2b3d55;
    --accent: #cfc9bb; --accent-fg: #101c2e; --accent-soft: #223449;
    --gold: #d9bb76; --gold-soft: #2c2415;
    --good: #6cc296; --good-soft: #16301f;
    --warn: #dca75f; --warn-soft: #302512;
    --bad: #e08b85; --bad-soft: #341d1c;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* the rules below set display on labels and buttons, which would otherwise win
   over the browser's own [hidden] and leave a hidden field on screen */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--paper); color: var(--ink);
  font-family: var(--sans);
  font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(64px + var(--safe-b)); }

h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 1.55rem; line-height: 1.2; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .7em; }
a { color: var(--accent); text-decoration: none; }

/* ---------------------------------------------------------------- chrome */

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px calc(12px);
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; min-width: 0; font-size: 1.22rem; }
.topbar .sub { font-size: .78rem; color: var(--ink-3); font-family: var(--sans); }

.wordmark { display: flex; align-items: baseline; gap: 7px; }
.wordmark b {
  font-family: var(--sans); font-size: 1.42rem; font-weight: 700;
  letter-spacing: -.035em; color: var(--accent);
}
.wordmark em {
  font-style: normal; font-family: var(--serif); font-size: 1.24rem; font-weight: 400;
  color: var(--ink-2); letter-spacing: -.01em;
}
.wordmark i {
  font-style: normal; font-size: .58rem; letter-spacing: .15em; text-transform: uppercase;
  color: var(--gold); padding: 2px 7px; border: 1px solid var(--gold);
  border-radius: 20px; font-weight: 600;
}

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

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--paper-2) 94%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar button {
  appearance: none; border: 0; background: none; cursor: pointer;
  padding: 9px 4px 8px; min-height: var(--tap);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--ink-3); font-size: .66rem; font-weight: 600; letter-spacing: .02em;
  font-family: var(--sans);
}
.tabbar button svg { width: 21px; height: 21px; stroke-width: 1.7; }
.tabbar button[aria-current="true"] { color: var(--accent); }

/* ---------------------------------------------------------------- blocks */

.card {
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card.tap { cursor: pointer; transition: transform .12s ease; }
.card.tap:active { transform: scale(.985); }

.row { display: flex; align-items: center; gap: 11px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.muted { color: var(--ink-3); font-size: .82rem; }
.tiny { font-size: .72rem; }
.mono { font-family: var(--mono); font-size: .72rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-label {
  font-size: .7rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 700; margin: 20px 2px 9px;
}

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 20px; font-size: .71rem; font-weight: 650;
  background: var(--paper-3); color: var(--ink-2); white-space: nowrap;
}
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad  { background: var(--bad-soft);  color: var(--bad); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.gold { background: var(--gold-soft); color: var(--gold); }

.avatar {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: .85rem; font-family: var(--sans);
}

/* ---------------------------------------------------------------- controls */

button, .btn {
  font-family: var(--sans); font-size: .93rem; font-weight: 650;
  min-height: var(--tap); padding: 0 17px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--paper-2); color: var(--ink);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .1s ease, opacity .15s ease;
}
button:active, .btn:active { transform: scale(.97); }
/* an inline SVG has no intrinsic size, so every icon in a control needs one */
button svg, .btn svg, .pill svg { width: 19px; height: 19px; flex: 0 0 auto; }
.pill svg { width: 13px; height: 13px; }
button[disabled] { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-good { background: var(--good); border-color: var(--good); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, var(--line)); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; font-size: .82rem; padding: 0 12px; }

input, textarea, select {
  font-family: var(--sans); font-size: 16px; /* 16px stops iOS zooming on focus */
  width: 100%; min-height: var(--tap); padding: 11px 13px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper-2); color: var(--ink);
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 1px;
  border-color: var(--accent);
}
label.field { display: block; margin-bottom: 11px; }
label.field > span { display: block; font-size: .78rem; font-weight: 650; color: var(--ink-2); margin-bottom: 5px; }

/* ---------------------------------------------------------------- viewer */

.pageview { display: flex; flex-direction: column; gap: 14px; margin: 14px 0; }
.pagewrap {
  position: relative; background: var(--paper-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  overflow: hidden; box-shadow: var(--shadow);
}
.pagewrap img { display: block; width: 100%; height: auto; }
.pagenum {
  position: absolute; top: 7px; right: 8px; z-index: 2;
  background: color-mix(in srgb, var(--ink) 72%, transparent); color: #fff;
  font-size: .64rem; font-weight: 700; padding: 2px 7px; border-radius: 20px;
}

.slot {
  position: absolute; border-radius: 5px; cursor: pointer;
  border: 1.5px dashed var(--accent);
  background: color-mix(in srgb, var(--accent) 11%, transparent);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease;
}
.slot:active { background: color-mix(in srgb, var(--accent) 24%, transparent); }
.slot .slot-tag {
  position: absolute; top: -9px; left: 3px;
  font-size: .56rem; font-weight: 750; letter-spacing: .02em;
  background: var(--accent); color: var(--accent-fg); padding: 1px 6px; border-radius: 20px;
  max-width: 94%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.slot.signed {
  border-style: solid; border-color: var(--good);
  background: color-mix(in srgb, var(--good) 8%, transparent);
}
.slot.signed .slot-tag { background: var(--good); color: #fff; }
.slot.unassigned { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 11%, transparent); }
.slot.unassigned .slot-tag { background: var(--warn); color: #fff; }
.slot.low { border-style: dotted; }

/* ---------------------------------------------------------------- editing a place */

/* touch-action none, or the first drag downwards scrolls the page instead of moving
   the mark; the cost is that a slot is not somewhere you can start a scroll in edit
   mode, which is the right trade when the whole point is dragging it */
.slot.editable {
  cursor: grab; touch-action: none; border-style: solid; border-width: 2px;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
}
.slot.dragging {
  cursor: grabbing; z-index: 4; transition: none;
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  box-shadow: 0 0 0 2px var(--accent), 0 6px 18px rgba(18, 23, 46, .25);
}
.slot-grip {
  position: absolute; right: -11px; bottom: -11px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--accent); border: 2px solid var(--paper-2);
  cursor: nwse-resize; touch-action: none;
}
.slot-grip::after {
  content: ''; position: absolute; inset: 5px;
  border-right: 2px solid var(--accent-fg); border-bottom: 2px solid var(--accent-fg);
  border-radius: 0 0 3px 0;
}
/* a dragging finger covers the box, so the numbers sit above it */
.slot-coord {
  position: absolute; left: 0; top: -21px; white-space: nowrap;
  font-family: var(--mono); font-size: .6rem; font-weight: 600;
  background: var(--ink); color: var(--paper); padding: 2px 6px; border-radius: 5px;
}
.pagewrap.editing { cursor: crosshair; }
.pagewrap.editing img { opacity: .92; }

.card.note { background: var(--accent-soft); border-color: transparent; box-shadow: none; }
.card.note p { color: var(--ink-2); }

.nudge {
  display: grid; grid-template-columns: repeat(3, 44px); gap: 5px; flex: 0 0 auto;
}
.nudge button { min-height: 40px; padding: 0; font-size: 1rem; }
.nudge button.sizer { color: var(--accent); font-weight: 750; }

/* on a share link: the places that are this signer's, and the ones that are not */
.slot.yours {
  border-color: var(--good); border-width: 2px; border-style: solid;
  background: color-mix(in srgb, var(--good) 14%, transparent);
}
.slot.yours .slot-tag { background: var(--good); color: #fff; }
.slot.theirs { opacity: .45; }
.slot.pulse { animation: pulse 1s ease 2; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); }
  50% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--good) 0%, transparent); }
}

/* a check shown before signing: a stop is not the same as a second look */
.card.check { margin-bottom: 9px; padding: 11px; box-shadow: none; }
.card.check.warn { background: var(--warn-soft); border-color: transparent; }
.card.check.stop { background: var(--bad-soft); border-color: var(--bad); }

/* someone from outside the firm: the library shows it at a glance */
.card.third { border-style: dashed; }

/* WhatsApp's own green, because that button is recognised before it is read */
.btn-wa {
  background: #25d366; border-color: #1fb757; color: #06281a; font-weight: 700;
}
.btn-wa svg { stroke-width: 1.9; }

/* a place picked out in the request sheet */
.btn-block.pick.on {
  border-color: var(--accent); background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* ---------------------------------------------------------------- signature pad */

.pad-wrap {
  position: relative; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper-2); overflow: hidden;
}
.pad-wrap canvas { display: block; width: 100%; height: 190px; touch-action: none; }
.pad-wrap .baseline {
  position: absolute; left: 22px; right: 22px; bottom: 46px;
  border-bottom: 1px dashed var(--line); pointer-events: none;
}
.pad-wrap .hint {
  position: absolute; left: 0; right: 0; bottom: 18px; text-align: center;
  font-size: .76rem; color: var(--ink-3); pointer-events: none;
}
/* The stored ink is anything from 700 to 4700 pixels wide. A percentage max-height
   inside a centred grid does not hold it — the image resolved to its own height and
   spilled a hundred pixels out of the strip and over the buttons — so the box is given
   to the image outright and object-fit does the scaling. */
.sig-preview {
  height: 72px; padding: 6px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper-3); border-radius: var(--radius-sm);
}
.sig-preview img {
  display: block; width: 100%; height: 100%;
  object-fit: contain; object-position: center;
}

/* ---------------------------------------------------------------- sheet */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 12, 26, .46); backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--paper); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + var(--safe-b));
  animation: rise .24s cubic-bezier(.2, .8, .3, 1);
}
.sheet .grip { width: 38px; height: 4px; border-radius: 3px; background: var(--line); margin: 6px auto 12px; }
@keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: calc(64px + var(--safe-b)); z-index: 35;
  padding: 10px 16px; display: flex; gap: 9px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(14px); border-top: 1px solid var(--line);
}
.actionbar .btn, .actionbar button { flex: 1; }

/* ---------------------------------------------------------------- misc */

.empty { text-align: center; padding: 46px 22px; color: var(--ink-3); }
.empty svg { width: 42px; height: 42px; opacity: .4; margin-bottom: 12px; stroke-width: 1.3; }

.progress { height: 5px; border-radius: 3px; background: var(--paper-3); overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; background: var(--good); transition: width .35s ease; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + var(--safe-b)); z-index: 60;
  background: var(--ink); color: var(--paper);
  padding: 11px 17px; border-radius: 30px; font-size: .86rem; font-weight: 600;
  box-shadow: var(--shadow); max-width: 90vw; text-align: center;
  animation: rise .2s ease;
}
.toast.bad { background: var(--bad); color: #fff; }

.spinner {
  width: 17px; height: 17px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 26px 18px; text-align: center; background: var(--paper-2);
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }

.qr { width: 172px; height: 172px; border-radius: var(--radius-sm); background: #fff; padding: 8px; }

.hr { height: 1px; background: var(--line); margin: 16px 0; border: 0; }

@media (min-width: 720px) {
  main { padding: 24px; }
  .tabbar { grid-template-columns: repeat(4, minmax(0, 150px)); justify-content: center; }
  .actionbar { justify-content: center; }
  .actionbar .btn, .actionbar button { flex: 0 1 220px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.slot-kind {
  font-size: .55rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--accent); opacity: .75; pointer-events: none;
}

/* a quoted clause from the document under review */
.clause {
  margin: 9px 0 0; padding: 8px 11px;
  border-left: 2.5px solid var(--line); border-radius: 0 6px 6px 0;
  background: var(--paper-3); color: var(--ink-2);
  font-family: var(--serif); font-size: .82rem; line-height: 1.45;
}
.ask {
  margin-top: 9px; padding: 8px 11px; border-radius: 7px;
  background: var(--good-soft); color: var(--good);
}
.ask b { color: inherit; }

/* a pill carrying a party name can be longer than the screen */
.pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
