/* Doc Signer — palette drawn from Indian office paperwork:
   stamp-paper green-grey, blue-black fountain-pen ink, rubber-stamp violet for seals. */
:root {
  --paper: #f2f4f0;
  --sheet: #ffffff;
  --ink: #1c2a5a;          /* signature ink, primary actions */
  --ink-soft: #e6e9f3;
  --text: #1e2320;
  --muted: #5d6660;
  --line: #d3d9d2;
  --seal: #5b3e8f;         /* completed / sealed only */
  --seal-soft: #efeaf7;
  --warn: #8a5a00;
  --warn-soft: #fbf1dc;
  --bad: #a1271d;
  --bad-soft: #fbe9e7;
  --ok: #2c6b45;
  --radius-s: 4px;
  --radius-m: 8px;
  --font: "Segoe UI", system-ui, -apple-system, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --font-doc: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #8fa3e0; outline-offset: 2px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font: 600 1.6rem/1.2 var(--font-doc); letter-spacing: -.01em; }
h2 { font: 600 1.2rem/1.3 var(--font-doc); }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: .4em; border: 1px solid var(--line); background: var(--sheet);
  padding: .5em 1em; border-radius: var(--radius-s); cursor: pointer; text-decoration: none; color: var(--text); }
.btn:hover { border-color: #aab3ab; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #142048; }
.btn.danger { color: var(--bad); }
.btn.link { border: 0; background: none; padding: .2em .3em; color: var(--ink); text-decoration: underline; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.big { padding: .7em 1.4em; font-size: 1.05rem; }

/* forms */
label { display: block; font-size: .88rem; color: var(--muted); margin: .7em 0 .25em; }
input[type=text], input[type=email], input[type=password], input[type=tel], select, textarea {
  width: 100%; padding: .55em .7em; border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; }
textarea { min-height: 4.5em; resize: vertical; }
.check { display: flex; gap: .55em; align-items: flex-start; color: var(--text); font-size: .95rem; }
.check input { margin-top: .3em; }
.error { color: var(--bad); background: var(--bad-soft); padding: .6em .8em; border-radius: var(--radius-s); margin: .6em 0; }
.notice { background: var(--warn-soft); color: var(--warn); padding: .6em .8em; border-radius: var(--radius-s); margin: .6em 0; }
.info { background: var(--ink-soft); color: var(--ink); padding: .6em .8em; border-radius: var(--radius-s); margin: .6em 0; }

/* auth screen */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 440px); }
.auth-side { padding: 8vh 6vw; display: flex; flex-direction: column; justify-content: center; }
.auth-side h1 { font-size: clamp(2rem, 4vw, 3.1rem); max-width: 14em; }
.auth-side p { max-width: 34em; color: var(--muted); font-size: 1.05rem; }
.auth-card { background: var(--sheet); padding: 8vh 2.5rem; border-left: 1px solid var(--line);
  display: flex; flex-direction: column; justify-content: center; }
.tabs { display: flex; gap: 1.2em; border-bottom: 1px solid var(--line); margin-bottom: .6em; }
.tabs button { border: 0; background: none; padding: .5em 0; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected=true] { color: var(--text); border-color: var(--ink); }
.methods-list { margin: 1.4em 0 0; padding: 0; list-style: none; display: grid; gap: .55em; max-width: 34em; }
.methods-list li { padding-left: 1.1em; border-left: 3px solid var(--line); }
.methods-list b { font-weight: 600; }

/* shell */
.shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.nav { background: var(--sheet); border-right: 1px solid var(--line); padding: 1.2em .9em; display: flex; flex-direction: column; gap: .2em; }
.brand { font: 600 1.15rem var(--font-doc); padding: 0 .5em 1em; display: flex; align-items: center; gap: .5em; }
.brand-mark { width: 26px; height: 26px; border: 2px solid var(--seal); border-radius: 50%; display: grid; place-items: center;
  color: var(--seal); font-size: .7rem; font-weight: 700; }
.nav a { display: flex; justify-content: space-between; padding: .45em .6em; border-radius: var(--radius-s); text-decoration: none; color: var(--text); }
.nav a[aria-current=page] { background: var(--ink-soft); color: var(--ink); font-weight: 600; }
.nav a .count { color: var(--muted); font-size: .85rem; }
.nav .spacer { flex: 1; }
.nav .who { padding: .6em; font-size: .85rem; color: var(--muted); border-top: 1px solid var(--line); margin-top: .6em; }
.main { padding: 1.6em 2.2em 4em; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1em; margin-bottom: 1.2em; flex-wrap: wrap; }

/* list */
.search { max-width: 320px; }
.rows { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-m); }
.row { display: grid; grid-template-columns: minmax(0, 1fr) 150px 120px; gap: 1em; padding: .85em 1.1em; align-items: center;
  border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.row:first-child { border-top: 0; }
.row:hover { background: #fafbf9; }
.row .title { font-weight: 600; }
.row .sub { color: var(--muted); font-size: .85rem; }
.empty { padding: 3em 1.5em; text-align: center; }
.empty p { color: var(--muted); }

/* status chips */
.status { display: inline-block; font-size: .8rem; padding: .15em .6em; border-radius: 999px; border: 1px solid var(--line); background: #fff; white-space: nowrap; }
.status.s-COMPLETED { color: var(--seal); border-color: #cdbfe3; background: var(--seal-soft); }
.status.s-AWAITING_SIGNATURE, .status.s-PARTIALLY_SIGNED, .status.s-AWAITING_PROVIDER { color: var(--ink); border-color: #c4cbe3; background: var(--ink-soft); }
.status.s-DECLINED, .status.s-FAILED { color: var(--bad); border-color: #efc4bf; background: var(--bad-soft); }
.status.s-EXPIRED, .status.s-CANCELLED { color: var(--muted); }
.status.s-ACTION_REQUIRED { color: var(--warn); background: var(--warn-soft); border-color: #ecd7a8; }

/* the seal — the one bold element */
.seal { width: 112px; height: 112px; border-radius: 50%; border: 3px double var(--seal); color: var(--seal);
  display: grid; place-items: center; text-align: center; transform: rotate(-9deg); font-weight: 700; line-height: 1.1;
  font-size: .78rem; padding: .6em; position: relative; flex: none; }
.seal::before { content: ""; position: absolute; inset: 6px; border: 1px solid var(--seal); border-radius: 50%; opacity: .55; }
.seal span { display: block; font: 700 1rem var(--font-doc); }
@media (prefers-reduced-motion: no-preference) {
  .seal.stamp-in { animation: stamp .45s cubic-bezier(.2, 1.6, .4, 1) both; }
  @keyframes stamp { from { transform: rotate(-9deg) scale(1.6); opacity: 0; } to { transform: rotate(-9deg) scale(1); opacity: 1; } }
}

/* detail layout */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1.6em; align-items: start; }
.panel { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1.1em 1.2em; margin-bottom: 1em; }
.panel h2 { margin-bottom: .6em; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: .25em .8em; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.signer-chain { list-style: none; margin: 0; padding: 0; }
.signer-chain li { display: grid; grid-template-columns: 24px 1fr auto; gap: .6em; padding: .55em 0; border-top: 1px dashed var(--line); align-items: start; }
.signer-chain li:first-child { border-top: 0; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); margin-top: .3em; }
.dot.signed { background: var(--ink); border-color: var(--ink); }
.dot.active { border-color: var(--ink); }
.dot.declined { background: var(--bad); border-color: var(--bad); }
.method-tag { font-size: .78rem; color: var(--muted); }
.kind-crypto { color: var(--seal); }

/* document viewer + editor */
.viewer { display: flex; flex-direction: column; align-items: center; gap: 1.2em; }
.page { position: relative; background: #fff; box-shadow: 0 1px 2px rgba(28, 42, 90, .12), 0 6px 24px rgba(28, 42, 90, .06); max-width: 100%; }
.page canvas { display: block; width: 100%; height: auto; }
.page-no { position: absolute; top: -1.4em; left: 0; font-size: .78rem; color: var(--muted); }
.field { position: absolute; border: 1.5px solid; border-radius: 3px; font-size: .72rem; display: flex; align-items: center;
  justify-content: center; text-align: center; overflow: hidden; user-select: none; touch-action: none; line-height: 1.1; }
.field.editable { cursor: move; }
.field .x { position: absolute; top: -1px; right: -1px; border: 0; background: rgba(0,0,0,.55); color: #fff; width: 16px; height: 16px;
  font-size: 11px; line-height: 16px; padding: 0; cursor: pointer; border-radius: 0 2px 0 3px; }
.field .grip { position: absolute; right: 0; bottom: 0; width: 10px; height: 10px; cursor: nwse-resize; background: currentColor; opacity: .5; }
.field.mine { background: rgba(28, 42, 90, .07); border-color: var(--ink); color: var(--ink); cursor: pointer; }
.field.mine.filled { background: rgba(44, 107, 69, .08); border-color: var(--ok); color: var(--ok); }
.field.mine.focus { box-shadow: 0 0 0 3px rgba(143, 163, 224, .7); }
.field img { max-width: 100%; max-height: 100%; }
.palette { display: flex; flex-wrap: wrap; gap: .4em; }
.palette button { font-size: .85rem; }
.palette button[aria-pressed=true] { background: var(--ink); color: #fff; border-color: var(--ink); }

/* signer setup */
.signer-card { border: 1px solid var(--line); border-radius: var(--radius-m); padding: .8em; margin-bottom: .7em; border-left: 5px solid; }
.signer-card .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .7em; }
.signer-card label { margin-top: .45em; }
.method-help { font-size: .8rem; color: var(--muted); margin-top: .3em; }

/* signing page */
.sign-top { position: sticky; top: 0; z-index: 5; background: var(--sheet); border-bottom: 1px solid var(--line); }
.sign-top .inner { max-width: 1100px; margin: 0 auto; padding: .8em 1.2em; display: flex; gap: 1em; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.sign-wrap { max-width: 1100px; margin: 0 auto; padding: 1.6em 1.2em 6em; }
.center-card { max-width: 480px; margin: 10vh auto; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 2em; }
.otp-input { font-size: 1.6rem; letter-spacing: .4em; text-align: center; font-family: ui-monospace, monospace; }

/* modal */
dialog { border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1.4em; max-width: 560px; width: calc(100% - 2em); }
dialog::backdrop { background: rgba(20, 28, 50, .45); }
.pad { border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; touch-action: none; width: 100%; height: 180px; display: block; cursor: crosshair; }
.typed-preview { font: italic 2rem var(--font-doc); color: var(--ink); padding: .3em .2em; border-bottom: 1px solid var(--line); min-height: 1.6em; }
.actions { display: flex; gap: .6em; justify-content: flex-end; margin-top: 1em; flex-wrap: wrap; }

.audit { font-size: .85rem; }
.audit li { padding: .35em 0; border-top: 1px solid var(--line); list-style: none; }
.audit ol { padding: 0; margin: 0; }
.audit time { color: var(--muted); font-variant-numeric: tabular-nums; }
.mock-banner { background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid #ecd7a8; padding: .4em 1em; font-size: .85rem; text-align: center; }

@media (max-width: 960px) {
  .detail { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-card { border-left: 0; border-top: 1px solid var(--line); padding: 2em 1.2em; }
  .auth-side { padding: 3em 1.2em 1em; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .nav { flex-direction: row; overflow-x: auto; padding: .5em; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { align-items: center; }
  .nav .spacer, .nav .brand, .nav .nav-group { display: none; }
  .nav p { margin: 0; }
  .nav a { white-space: nowrap; }
  .nav .who { display: flex; align-items: center; gap: .5em; border-top: 0; margin: 0; padding: 0 .4em; white-space: nowrap; }
  .nav .who > div:first-child { display: none; }
  .nav .who select { width: auto; margin: 0; }
  .main { padding: 1em; }
  .row { grid-template-columns: 1fr auto; }
  .row .when { display: none; }
  .signer-card .grid2 { grid-template-columns: 1fr; }
}

/* Keep the side panel in view while scrolling long documents. */
@media (min-width: 961px) {
  .detail > aside { position: sticky; top: 1em; max-height: calc(100vh - 2em); overflow-y: auto; padding-right: 4px; }
}

/* Editor guidance */
.place-hint { position: sticky; top: 0; z-index: 4; background: var(--ink-soft); color: var(--ink); border: 1px solid #c4cbe3;
  border-radius: var(--radius-s); padding: .5em .8em; margin-bottom: 1.4em; font-size: .92rem; }
.quick-row { display: flex; justify-content: space-between; align-items: center; gap: .6em; padding: .45em 0; border-top: 1px dashed var(--line); flex-wrap: wrap; }
.quick-row:first-child { border-top: 0; }
.missing { color: var(--bad); }

pre.cmd { white-space: pre-wrap; word-break: break-all; background: #10172f; color: #e7ecff; padding: .7em .8em;
  border-radius: var(--radius-s); font: .8rem/1.45 ui-monospace, Menlo, Consolas, monospace; margin: .4em 0; }

/* ---- reminders, templates, clients, team --------------------------------- */
input[type=date], input[type=search], input[type=number] { width: 100%; box-sizing: border-box; padding: .5em .6em;
  border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; }
dialog.wide { max-width: 720px; }
.toast { position: fixed; bottom: 1.4em; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: .6em 1.1em; border-radius: var(--radius-s); z-index: 50; box-shadow: 0 6px 24px rgba(0,0,0,.18); }
.nav .nav-group { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 1em .6em .2em; }
.nav .who select { margin: .4em 0; font-size: .85rem; }
.due { font-size: .8rem; }
.due.soon { color: var(--warn); }
.due.over { color: var(--bad); }
.list { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-m); }
.list-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .4em 1em; padding: .85em 1.1em;
  border-top: 1px solid var(--line); align-items: center; }
.list-row:first-child { border-top: 0; }
.list-row .title { font-weight: 600; }
.list-row .sub { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.list-row .actions { margin: 0; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: .3em; margin-top: .35em; }
.chip { font-size: .78rem; border: 1px solid var(--line); border-radius: 999px; padding: .05em .55em; background: #fff; color: var(--muted); }
.role-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .7em; border-top: 1px dashed var(--line); padding-top: .4em; margin-top: .6em; }
.role-row h3 { grid-column: 1 / -1; margin: .2em 0 0; }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) 160px auto; gap: .6em; align-items: end; }
.inline-form label { margin-top: 0; }
.filter { display: flex; gap: .6em; align-items: center; }
.filter select { width: auto; }
@media (max-width: 720px) {
  .inline-form { grid-template-columns: 1fr; }
  .list-row { grid-template-columns: 1fr; }
  .role-row { grid-template-columns: 1fr; }
}

/* ---- plans + admin console ------------------------------------------------- */
.nav .who .usage { display: block; padding: .3em 0; color: var(--muted); text-decoration: none; font-size: .8rem; }
.nav .who .usage.near { color: var(--warn); }
.meter-row { margin: .6em 0; }
.meter-row > div:first-child { display: flex; justify-content: space-between; gap: 1em; font-size: .9rem; }
.meter { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: .3em; }
.meter span { display: block; height: 100%; background: var(--ink); }
.meter span.near { background: var(--warn); }
.meter span.full { background: var(--bad); }
.tabs .tab-link { padding: .5em 0; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs .tab-link[aria-selected=true] { color: var(--text); border-color: var(--ink); }
.tabs { margin-bottom: 1.2em; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .8em; margin-bottom: 1.2em; }
.tile { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-m); padding: .9em 1em; }
.tile-value { font: 600 1.6rem/1.1 var(--font-doc); font-variant-numeric: tabular-nums; }
.tile-label { font-size: .85rem; color: var(--muted); margin-top: .2em; }
.tile.bad .tile-value { color: var(--bad); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1em; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 90px; }
.bars span { flex: 1; background: var(--ink); border-radius: 2px 2px 0 0; min-width: 3px; }
.bars span.zero { background: var(--line); }
.bars-axis { display: flex; justify-content: space-between; margin-top: .3em; }
.chip.bad { color: var(--bad); border-color: #efc4bf; background: var(--bad-soft); }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } .nav .who .usage { display: none; } }

/* ---- legal pages, account ---------------------------------------------------- */
.legal { max-width: 760px; margin: 0 auto; padding: 2em 1.2em 4em; }
.legal h2 { margin-top: 1.6em; }
.legal li { margin: .35em 0; }
.legal-links { font-size: .8rem; color: var(--muted); margin-top: 1.4em; }
.legal-links a { color: var(--muted); }
.qr { width: 200px; height: 200px; border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; }
.codes { font: 1rem/1.9 ui-monospace, monospace; columns: 2; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-s); padding: .6em 1em; }
.secret { font-family: ui-monospace, monospace; letter-spacing: .05em; word-break: break-all; }

/* ---- brand -------------------------------------------------------------------- */
.brand-logo { max-height: 30px; max-width: 120px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text small { font: 400 .72rem var(--font); color: var(--muted); letter-spacing: .01em; }
.toast.bad { background: var(--bad); }
