/* Signing page: PDF stage, field overlay, signature pads. */

.sign-body .page { max-width: 1440px; }

.sign-layout {
  display: grid;
  /* The document column gets the room; the action panel is a fixed rail. */
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: start;
}

.sign-doc__head { margin-bottom: 14px; }
.sign-doc__head h1 { font-size: 1.45rem; margin: 4px 0 6px; }
.sign-message {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .03);
  font-size: .88rem;
  color: var(--muted);
}

.pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.pdf-toolbar__label {
  font-family: var(--mono);
  font-size: .75rem;
  color: var(--muted);
  min-width: 92px;
  text-align: center;
}
.pdf-toolbar__label[data-zoom-label] { min-width: 52px; }
.pdf-toolbar__divider {
  width: 1px;
  height: 18px;
  background: var(--line-strong);
  margin: 0 2px;
}

/* The stage sizes to the canvas; the field layer is absolutely positioned on top. */
/* The stage fills its column so the renderer can measure a real width; drawing
 * from its own clientWidth would be circular (the canvas sizes the stage). */
.pdf-stage {
  position: relative;
  display: block;
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: auto;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
}
.pdf-stage canvas { display: block; }
.sign-doc { min-width: 0; }

.field-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.sign-field {
  position: absolute;
  pointer-events: auto;
  border: 1px dashed rgba(255, 0, 170, .55);
  border-radius: 3px;
  background: rgba(255, 0, 170, .05);
  font-family: var(--mono);
  font-size: 8px;
  line-height: 1;
  color: #7a0052;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  /* Long recipient names must not spill outside the placement box. */
  overflow: hidden;
  padding: 0 2px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.sign-field.is-mine {
  border-color: #ff00aa;
  border-width: 1.5px;
  background: rgba(255, 0, 170, .1);
  color: #9d0069;
  font-weight: 700;
}
.sign-field.is-action {
  cursor: pointer;
  /* Action boxes carry a short prompt; keep it inside the border. */
  flex-direction: column;
  gap: 1px;
  padding: 1px 3px;
  font-size: 8px;
  letter-spacing: .2px;
}
.sign-field.is-action:empty::before { content: 'Sign here'; }
.sign-field.is-mine.is-action { border-style: solid; }
.sign-field.is-mine.is-action:hover { background: rgba(255, 0, 170, .2); }
.sign-field.is-signed { border-color: rgba(16, 185, 129, .7); background: rgba(16, 185, 129, .06); }
.sign-field img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.sign-field--signature, .sign-field--initials { color: #6d0048; }
.sign-field.is-typed { font-family: 'Courier New', monospace; font-size: 13px; font-style: italic; }

.sign-field__input {
  width: 100%;
  height: 100%;
  border: 0;
  background: rgba(255, 255, 255, .85);
  font: inherit;
  color: #111;
  padding: 1px 2px;
  outline: none;
}
.sign-field input[type="checkbox"] { width: 80%; height: 80%; accent-color: #ff00aa; }

/* Side panel */
.sign-side { display: grid; gap: 16px; position: sticky; top: 16px; }
.sign-side .panel { margin-bottom: 0; }
.sign-side h2 { font-size: 1rem; margin-bottom: 12px; }
.disclosure {
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: .78rem;
  line-height: 1.5;
  color: var(--muted);
  background: rgba(255, 255, 255, .03);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin: 0 0 12px;
}
.checkline {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  font-size: .82rem;
  color: var(--muted);
  margin-bottom: 12px;
}
.checkline input { margin-top: 3px; accent-color: #ff00aa; }

.sig-tabs {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.sig-tab {
  border: 1px solid var(--line-strong);
  background: none;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: .76rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.sig-tab.is-active { background: var(--accent); border-color: var(--accent); color: #000; }

.sig-pad {
  width: 100%;
  height: 110px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  touch-action: none;
  cursor: crosshair;
  display: block;
}
.sig-pad--short { height: 74px; }
.sig-typed { font-family: 'Courier New', monospace; font-size: 1.1rem; font-style: italic; }

.signers { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.signer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: .82rem;
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, .07);
  border-radius: 8px;
}
.signer__role {
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .8px;
  color: var(--dim);
}
.signer__name { color: rgba(255, 255, 255, .9); overflow: hidden; text-overflow: ellipsis; }
.notice-inline {
  font-size: .8rem;
  border: 1px solid rgba(251, 191, 36, .4);
  background: rgba(251, 191, 36, .08);
  color: #fde68a;
  border-radius: 8px;
  padding: 9px 11px;
  margin-bottom: 12px;
}
.list-fields { gap: 10px; margin-bottom: 14px; }

@media (max-width: 1080px) {
  .sign-layout { grid-template-columns: 1fr; }
  .sign-side { order: -1; }
  .sign-side { position: static; }
}
@media (max-width: 620px) {
  .sign-doc__head h1 { font-size: 1.2rem; }
  .pdf-toolbar { gap: 6px; }
  .sig-pad { height: 92px; }
}

/* ---- Admin: send-for-signature dialog ---- */
.dialog--wide { width: min(900px, calc(100vw - 32px)); }
.sign-recipients { display: grid; gap: 8px; margin-bottom: 8px; }
.recipient-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr auto auto;
  gap: 6px;
  align-items: center;
}
.sign-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.sign-toolbar .btn.is-active { background: var(--accent); border-color: var(--accent); color: #000; }
.placed-fields { display: grid; gap: 6px; }
.placed-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  align-items: center;
  font-size: .8rem;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 8px;
  padding: 6px 10px;
}
.link-list { display: grid; gap: 10px; margin: 12px 0; }
.link-row__who { font-family: var(--mono); font-size: .74rem; color: var(--muted); margin-bottom: 4px; }
.link-row .input { font-size: .7rem; }

@media (max-width: 620px) {
  .recipient-row { grid-template-columns: 1fr 1fr auto auto; }
}

/* The prepare layer must receive clicks; the signer layer stays pass-through
   except on a signer's own fields. */
.field-layer--interactive { pointer-events: auto; cursor: crosshair; }
.field-layer--interactive .sign-field { cursor: pointer; }

/* ---- Client lookup in the upload dialog ---- */
.assign-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.assign-current {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 8px 11px;
  background: rgba(255, 255, 255, .03);
  display: grid;
  gap: 1px;
}
.assign-current__label { font-size: .82rem; color: rgba(255, 255, 255, .88); }
.assign-current__email {
  font-family: var(--mono);
  font-size: .7rem;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lookup {
  border: 1px solid rgba(255, 0, 170, .4);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 0, 170, .04);
}
.lookup__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.lookup__list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 5px;
  max-height: 220px;
  overflow-y: auto;
}
.lookup__item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #0b090d;
  cursor: pointer;
  font-size: .84rem;
}
.lookup__item:hover, .lookup__item:focus-visible {
  border-color: var(--accent);
  background: rgba(255, 0, 170, .1);
  outline: none;
}
.lookup__who { display: grid; min-width: 0; }
.lookup__email {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}
.lookup__meta { font-size: .72rem; color: var(--dim); white-space: nowrap; }
.lookup__empty { padding: 10px; color: var(--dim); font-size: .82rem; text-align: center; }

.checkstack { display: grid; gap: 8px; }
.checkstack .checkline { margin-bottom: 0; }

/* ---- Draggable / resizable field placement ---- */
.field-layer--interactive .sign-field { cursor: grab; touch-action: none; }
.field-layer--interactive .sign-field.is-dragging { cursor: grabbing; opacity: .9; }
.field-layer--interactive .sign-field.is-resizing { opacity: .9; }
.sign-field__handle {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  background: var(--accent);
  border: 1px solid #000;
  border-radius: 2px;
  cursor: nwse-resize;
  touch-action: none;
}
.sign-field.is-dragging .sign-field__handle,
.sign-field.is-resizing .sign-field__handle { background: #fff; }
.placed-row { grid-template-columns: auto auto auto 1fr auto; }

/* The placement handle sits on the corner, so the prepare layer must not clip
   it; the signer-facing layer keeps overflow hidden for long labels. */
.field-layer--interactive .sign-field { overflow: visible; }

.lookup__manual { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; display: grid; gap: 6px; }
.lookup__manual .btn-row { align-items: center; }
.lookup__manual .input { flex: 1; min-width: 160px; }

/* ---- Document comments ---- */
.doc__pills { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.pill--button { cursor: pointer; font-family: var(--mono); }
.pill--button:hover { border-color: var(--accent); color: #fff; }

.comment-thread {
  display: grid;
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 4px;
}
.comment {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, .02);
  box-shadow: none;
}
.comment.is-mine { border-color: rgba(255, 0, 170, .35); background: rgba(255, 0, 170, .05); }
.comment__head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
}
.comment__author { font-weight: 600; font-size: .84rem; }
.comment__when { font-family: var(--mono); font-size: .68rem; color: var(--dim); }
.comment__body { font-size: .86rem; color: var(--muted); white-space: pre-wrap; line-height: 1.5; }
.comment__side {
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--accent);
}
.comment-empty { color: var(--dim); font-size: .85rem; text-align: center; padding: 18px; }
textarea.input { resize: vertical; min-height: 74px; font-family: inherit; }

/* ---- Admin: documents grouped by client ---- */
.client-groups { display: grid; gap: 18px; }
.client-group {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, .02);
}
.client-group__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.client-group__head h3 {
  font-size: .95rem;
  color: #fff;
  letter-spacing: -.01em;
  word-break: break-word;
}
.client-group .table td:first-child { padding-left: 2px; }
.client-group .table th:first-child { padding-left: 2px; }

/* ---- Billing ---- */
.billing-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.metric {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  background: rgba(255, 255, 255, .025);
  display: grid;
  gap: 4px;
}
.metric__label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--dim);
}
.metric__value { font-size: 1.55rem; font-weight: 800; letter-spacing: -.02em; }
.metric__note { font-size: .78rem; color: var(--muted); }
.metric__note--bad { color: var(--bad); }

.table .num, .metric.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }

.due-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.due-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: .86rem;
}
.due-list .num { font-variant-numeric: tabular-nums; }

/* Shared account lookup dialog: wider than a confirm because it lists results. */
.dialog--lookup { width: min(560px, calc(100vw - 32px)); }
.dialog--lookup .modal-body { display: grid; gap: 10px; }
.dialog--lookup h2 { font-size: 1.05rem; }

/* ---- Administration tabs ---- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font: inherit;
  font-size: .88rem;
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: #fff; }
.tab.is-active { color: #fff; border-bottom-color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab-panel.is-hidden { display: none; }

/* ---- Ledger page ---- */
.ledger-controls { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.ledger-filter { min-width: 260px; }
.ledger-filter .input { padding: 8px 12px; font-size: .85rem; }
.ledger-owner { font-weight: 600; }
.ledger-table-wrap { max-height: min(62vh, 640px); overflow-y: auto; position: relative; }
.ledger-table-wrap thead th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
.ledger-loading { text-align: center; padding: 14px 0 4px; }
.ledger-sentinel { height: 1px; }

/* ---- Documents page: the files container fills the remaining height ---- */
body:not(.auth-body):not(.sign-body) .page {
  display: flex;
  flex-direction: column;
}
.doc-fill {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 320px;
  margin-bottom: 20px;
}
.doc-fill .panel__head { flex: 0 0 auto; }
.doc-fill .table-wrap,
.doc-fill #docList {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.doc-fill #docList > .table-wrap { flex: 1 1 auto; }
.doc-fill .client-groups { flex: 1 1 auto; }
